graph: remove `mapping_idx` and `graph_update_width()`
authorJames Coglan <jcoglan@gmail.com>
Tue, 15 Oct 2019 23:47:51 +0000 (23:47 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 16 Oct 2019 02:11:24 +0000 (11:11 +0900)
commit46ba2abdfa95a26a86714dab386a72a3a5b706a5
tree58980fd44362f365da3ab71a37d1fc61e58b40b2
parenta551fd5efd7b82604c3254e3f7cac08eaaa97ba9
graph: remove `mapping_idx` and `graph_update_width()`

There's a duplication of logic between `graph_insert_into_new_columns()`
and `graph_update_width()`. `graph_insert_into_new_columns()` is called
repeatedly by `graph_update_columns()` with an `int *` that tracks the
offset into the `mapping` array where we should write the next value.
Each call to `graph_insert_into_new_columns()` effectively pushes one
column index and one "null" value (-1) onto the `mapping` array and
therefore increments `mapping_idx` by 2.

`graph_update_width()` duplicates this process: the `width` of the graph
is essentially the initial width of the `mapping` array before edges
begin collapsing. The `graph_update_width()` function's logic
effectively works out how many times `graph_insert_into_new_columns()`
was called based on the relationship of the current commit to the rest
of the graph.

I'm about to make some changes that make the assignment of values into
the `mapping` array more complicated. Rather than make
`graph_update_width()` more complicated at the same time, we can simply
remove this function and use `graph->width` to track the offset into the
`mapping` array as we're building it. This removes the duplication and
makes sure that `graph->width` is the same as the visual width of the
`mapping` array once `graph_update_columns()` is complete.

Signed-off-by: James Coglan <jcoglan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
graph.c