Skip to content

Commit 9bab3ce

Browse files
pabloosabaterrgitster
authored andcommitted
graph: add truncation mark to capped lanes
When lanes are hidden by --graph-lane-limit, show a "~" truncation mark, so users know that there are lanes being truncated. The "~" is chosen because it is not used elsewhere in the graph and it is discrete. Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f756a3c commit 9bab3ce

File tree

3 files changed

+52
-39
lines changed

3 files changed

+52
-39
lines changed

Documentation/rev-list-options.adoc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,8 +1261,9 @@ This implies the `--topo-order` option by default, but the
12611261

12621262
`--graph-lane-limit=<n>`::
12631263
When `--graph` is used, limit the number of graph lanes to be shown.
1264-
Lanes over the limit are not shown. By default it is set to 0
1265-
(no limit), zero and negative values are ignored and treated as no limit.
1264+
Lanes over the limit are replaced with a truncation mark '~'.
1265+
By default it is set to 0 (no limit), zero and negative values
1266+
are ignored and treated as no limit.
12661267

12671268
ifdef::git-rev-list[]
12681269
`--count`::

graph.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,11 +706,11 @@ static void graph_update_columns(struct git_graph *graph)
706706
}
707707

708708
/*
709-
* If graph_max_lanes is set, cap the width
709+
* If graph_max_lanes is set, cap the width
710710
*/
711711
if (graph->revs->graph_max_lanes > 0) {
712712
/*
713-
* Width is column index while a lane is half that.
713+
* width of "| " per lanes plus truncation mark "~ ".
714714
* Allow commits from merges to align to the merged lane.
715715
*/
716716
int max_width = graph->revs->graph_max_lanes * 2 + 2;
@@ -868,8 +868,10 @@ static void graph_output_padding_line(struct git_graph *graph,
868868
* Output a padding row, that leaves all branch lines unchanged
869869
*/
870870
for (i = 0; i < graph->num_new_columns; i++) {
871-
if (graph_needs_truncation(graph, i))
871+
if (graph_needs_truncation(graph, i)) {
872+
graph_line_addstr(line, "~ ");
872873
break;
874+
}
873875
graph_line_write_column(line, &graph->new_columns[i], '|');
874876
graph_line_addch(line, ' ');
875877
}
@@ -928,6 +930,7 @@ static void graph_output_pre_commit_line(struct git_graph *graph,
928930
graph_line_write_column(line, col, '|');
929931
graph_line_addchars(line, ' ', graph->expansion_row);
930932
} else if (seen_this && graph_needs_truncation(graph, i)) {
933+
graph_line_addstr(line, "~ ");
931934
break;
932935
} else if (seen_this && (graph->expansion_row == 0)) {
933936
/*
@@ -1025,8 +1028,10 @@ static void graph_draw_octopus_merge(struct git_graph *graph, struct graph_line
10251028
* Commit is at commit_index, each iteration move one lane to
10261029
* the right from the commit.
10271030
*/
1028-
if (graph_needs_truncation(graph, graph->commit_index + 1 + i))
1031+
if (graph_needs_truncation(graph, graph->commit_index + 1 + i)) {
1032+
graph_line_addstr(line, "~ ");
10291033
break;
1034+
}
10301035

10311036
graph_line_write_column(line, col, (i == dashed_parents - 1) ? '.' : '-');
10321037
}
@@ -1070,6 +1075,7 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line
10701075
if (graph->num_parents > 2)
10711076
graph_draw_octopus_merge(graph, line);
10721077
} else if (graph_needs_truncation(graph, i)) {
1078+
graph_line_addstr(line, "~ ");
10731079
seen_this = 1;
10741080
break;
10751081
} else if (seen_this && (graph->edges_added > 1)) {
@@ -1203,6 +1209,7 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l
12031209
j / 2 + i <= graph->num_columns) {
12041210
if ((j + i * 2) % 2 != 0)
12051211
graph_line_addch(line, ' ');
1212+
graph_line_addstr(line, "~ ");
12061213
truncated = 1;
12071214
break;
12081215
}
@@ -1214,6 +1221,7 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l
12141221
*/
12151222
if (graph_needs_truncation(graph, (j + 1) / 2 + i) &&
12161223
j < graph->num_parents - 1) {
1224+
graph_line_addstr(line, "~ ");
12171225
truncated = 1;
12181226
break;
12191227
} else if (graph->edges_added > 0 || j < graph->num_parents - 1)
@@ -1228,6 +1236,7 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l
12281236
if (graph->edges_added == 0)
12291237
graph_line_addch(line, ' ');
12301238
} else if (graph_needs_truncation(graph, i)) {
1239+
graph_line_addstr(line, "~ ");
12311240
break;
12321241
} else if (seen_this) {
12331242
if (graph->edges_added > 0)
@@ -1388,6 +1397,7 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l
13881397
int target = graph->mapping[i];
13891398

13901399
if (!truncated && graph_needs_truncation(graph, i / 2)) {
1400+
graph_line_addstr(line, "~ ");
13911401
truncated = 1;
13921402
}
13931403

@@ -1487,8 +1497,10 @@ static void graph_padding_line(struct git_graph *graph, struct strbuf *sb)
14871497
for (i = 0; i < graph->num_columns; i++) {
14881498
struct column *col = &graph->columns[i];
14891499

1490-
if (graph_needs_truncation(graph, i))
1500+
if (graph_needs_truncation(graph, i)) {
1501+
graph_line_addstr(&line, "~ ");
14911502
break;
1503+
}
14921504

14931505
graph_line_write_column(&line, col, '|');
14941506

t/t4215-log-skewed-merges.sh

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,9 @@ test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' '
376376
|\ \
377377
| | * 7_G
378378
| | * 7_F
379-
| * 7_E
380-
| * 7_D
381-
* | 7_C
379+
| * ~ 7_E
380+
| * ~ 7_D
381+
* | ~ 7_C
382382
| |/
383383
|/|
384384
* | 7_B
@@ -389,16 +389,16 @@ test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' '
389389

390390
test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge' '
391391
check_graph --graph-lane-limit=1 M_7 <<-\EOF
392-
*- 7_M4
393-
|\
394-
| 7_G
395-
| 7_F
392+
*-~ 7_M4
393+
|\~
394+
| ~ 7_G
395+
| ~ 7_F
396396
| * 7_E
397397
| * 7_D
398-
* 7_C
399-
|
400-
|/
401-
* 7_B
398+
* ~ 7_C
399+
| ~
400+
|/~
401+
* ~ 7_B
402402
|/
403403
* 7_A
404404
EOF
@@ -411,24 +411,24 @@ test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' '
411411
| | * 7_M2
412412
| | |\
413413
| | | * 7_H
414-
| | | 7_M3
415-
| | | 7_J
416-
| | | 7_I
417-
| | | 7_M4
418-
| |_|_
419-
|/| |
420-
| | |_
421-
| |/|
422-
| | |
423-
| | |/
424-
| | * 7_G
425-
| | |
426-
| | |/
427-
| | * 7_F
428-
| * | 7_E
429-
| | |/
430-
| |/|
431-
| * | 7_D
414+
| | | ~ 7_M3
415+
| | | ~ 7_J
416+
| | | ~ 7_I
417+
| | | ~ 7_M4
418+
| |_|_~
419+
|/| | ~
420+
| | |_~
421+
| |/| ~
422+
| | | ~
423+
| | |/~
424+
| | * ~ 7_G
425+
| | | ~
426+
| | |/~
427+
| | * ~ 7_F
428+
| * | ~ 7_E
429+
| | |/~
430+
| |/| ~
431+
| * | ~ 7_D
432432
| | |/
433433
| |/|
434434
* | | 7_C
@@ -452,9 +452,9 @@ test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows fir
452452
| | | | | * 7_J
453453
| | | | * | 7_I
454454
| | | | | | * 7_M4
455-
| |_|_|_|_|/
456-
|/| | | | |/
457-
| | |_|_|/|
455+
| |_|_|_|_|/~
456+
|/| | | | |/~
457+
| | |_|_|/| ~
458458
| |/| | | |/
459459
| | | |_|/|
460460
| | |/| | |

0 commit comments

Comments
 (0)