| 558 | } |
| 559 | |
| 560 | static void graph_insert_into_new_columns(struct git_graph *graph, |
| 561 | struct commit *commit, |
| 562 | int idx) |
| 563 | { |
| 564 | int i = graph_find_new_column_by_commit(graph, commit); |
| 565 | int mapping_idx; |
| 566 | |
| 567 | /* |
| 568 | * If the commit is not already in the new_columns array, then add it |
| 569 | * and record it as being in the final column. |
| 570 | */ |
| 571 | if (i < 0) { |
| 572 | i = graph->num_new_columns++; |
| 573 | graph->new_columns[i].commit = commit; |
| 574 | graph->new_columns[i].color = graph_find_commit_color(graph, commit); |
| 575 | } |
| 576 | |
| 577 | if (graph->num_parents > 1 && idx > -1 && graph->merge_layout == -1) { |
| 578 | /* |
| 579 | * If this is the first parent of a merge, choose a layout for |
| 580 | * the merge line based on whether the parent appears in a |
| 581 | * column to the left of the merge |
| 582 | */ |
| 583 | int dist, shift; |
| 584 | |
| 585 | dist = idx - i; |
| 586 | shift = (dist > 1) ? 2 * dist - 3 : 1; |
| 587 | |
| 588 | graph->merge_layout = (dist > 0) ? 0 : 1; |
| 589 | graph->edges_added = graph->num_parents + graph->merge_layout - 2; |
| 590 | |
| 591 | mapping_idx = graph->width + (graph->merge_layout - 1) * shift; |
| 592 | graph->width += 2 * graph->merge_layout; |
| 593 | |
| 594 | } else if (graph->edges_added > 0 && i == graph->mapping[graph->width - 2]) { |
| 595 | /* |
| 596 | * If some columns have been added by a merge, but this commit |
| 597 | * was found in the last existing column, then adjust the |
| 598 | * numbers so that the two edges immediately join, i.e.: |
| 599 | * |
| 600 | * * | * | |
| 601 | * |\ \ => |\| |
| 602 | * | |/ | * |
| 603 | * | * |
| 604 | */ |
| 605 | mapping_idx = graph->width - 2; |
| 606 | graph->edges_added = -1; |
| 607 | } else { |
| 608 | mapping_idx = graph->width; |
| 609 | graph->width += 2; |
| 610 | } |
| 611 | |
| 612 | graph->mapping[mapping_idx] = i; |
| 613 | } |
| 614 | |
| 615 | static void graph_update_columns(struct git_graph *graph) |
| 616 | { |
no test coverage detected