graph: add indentation for commits preceded by a root
Subsystems (2)
cover graph: add indentation for commits preceded by a root
When having a history with multiple root commits and drawing the history near the roots, the graphing engine renders the commit one below the other, seeming that they are related, which makes the graph confusing.
This issue was reported by Junio at:
https://lore.kernel.org/git/[email protected]/
e.g.:
* root-B
* child-A2
* child-A1
* root-A
This happens because the engine prints left to right from the first free column and the root has no parents thus for the next row, its column becomes free and the engine fills that gap with the next commit (child-A2) seeming that root-B and child-A2 are related when they are not.
The actual implementation is very minimal.
This patch makes the roots to be kept alive at least one more row to avoid that and indent the next commit to the next column and then clean the mapping letting the indented commit to naturally collapse to the column where the root was.
e.g.:
* root-B
* child-A2
/
* child-A1
* root-A
This is done by adding a is_placeholder flag to the columns, the root commit is actually there but marked as a placeholder
e.g.:
* root-B
(B) * child-A2
/
* child-A1
* root-A
(B) would be root-B column with the placeholder flag active.
Then teaching the rendering function to print a padding ' ' when meeting a placeholder column outputs the second example.
There could also be the case where there are multiple roots
without the patch:
* A root
* B root
* C root
* D1 child
* D root
with the patch, the indentation cascades:
* A root
* B root
* C root
* D1 child
_ /
/
/
* D root
the _ / might look weird but that's how the collapsing rendering does it for big gaps, this case being from the 4th column to the 0th column. Another patch could change the collapsing rendering for placeholders ? I haven't done it to keep it minimal, but a follow up could make it to be straight '/'. This would make it bigger but easier for the eye to follow. IMO is not worth it, but opinions are welcome.
The patch also adds tests for different cases like a root preceding multiple parents merges and the examples above.
There could be some edge cases still so any testing is very welcome.
Pablo Sabater (1):
graph: add indentation for commits preceded by a root
graph.c | 68 ++++++++++++++++-- t/t4215-log-skewed-merges.sh | 136 +++++++++++++++++++++++++++++++++++ 2 files changed, 198 insertions(+), 6 deletions(-)
base-commit: 256554692df0685b45e60778b08802b720880c50
Signature · 1 line
2.43.0
RFC PATCH 1/1 graph: add indentation for commits preceded by a root
When having a history with multiple root commits and drawing the history near the roots the graphing engine renders the commit one below the other, seeming that they are related.
This issue was reported by Junio at:
https://lore.kernel.org/git/[email protected]/
This happens because the root has no parents thus for the next row printing, the column becomes free and the engine prints from the first free columns left to right.
Keep the root commit at least one row more to avoid having the column empty but hide it, therefore making the next unrelated commit to live in the next column (column means even positions where edges live:
0, 2, 4), then clean that "placeholder" column and let the unrelated commit to naturally collapse to the column where the root commit was.
Add is_placeholder to the struct column to mark if a column is acting as a placeholder for the padding.
When the column is a root, add a column with the root commit data to prevent segfaults when 'column->commit' and mark it as a placeholder.
After, unless the next commit is also a root (then we need to keep cascading the indentation) clean the mapping and the columns from the placeholder to allow it to collapse naturally.
Teach rendering functions to print a padding
' ' when a placeholder column is met.
Add tests for different cases.
before this patch:
* root-B
* child-A2
* child-A1
* root-A
after this patch:
* root-B
* child-A2
/
* child-A1
* root-A
--- graph.c | 68 ++++++++++++++++-- t/t4215-log-skewed-merges.sh | 136 +++++++++++++++++++++++++++++++++++ 2 files changed, 198 insertions(+), 6 deletions(-)
graph.c +62 -6
@@ -60,6 +60,13 @@ struct column {* index into column_colors. */ unsigned short color; +/* +* A placeholder column keeps the column of the root filled for one +* extra row, avoiding a next unrelated commit to be printed in the +* same column. Placeholder columns don't propagate to the following +* commit. +*/ + unsigned is_placeholder:1; };enum graph_state {
@@ -563,6 +570,7 @@ static void graph_insert_into_new_columns(struct git_graph *graph, i = graph->num_new_columns++; graph->new_columns[i].commit = commit; graph->new_columns[i].color =graph_find_commit_color (graph, commit); + graph->new_columns[i].is_placeholder =0 ; }if (graph->num_parents >1 && idx >-1 && graph->merge_layout ==-1 ) {
@@ -607,7 +615,7 @@ static void graph_update_columns(struct git_graph *graph) {struct commit_list *parent;int max_new_columns; -int i, seen_this, is_commit_in_columns; +int i, seen_this, is_commit_in_columns, is_root;/* * Swap graph->columns with graph->new_columns
@@ -654,6 +662,9 @@ static void graph_update_columns(struct git_graph *graph)*/ seen_this =0 ; is_commit_in_columns =1 ; + is_root = graph->num_parents ==0 && + !graph->commit->parents && + !(graph->commit->object.flags &BOUNDARY );for (i =0 ; i <= graph->num_columns; i++) {struct commit *col_commit;if (i == graph->num_columns) {
@@ -688,11 +699,40 @@ static void graph_update_columns(struct git_graph *graph)* least 2, even if it has no interesting parents. * The current commit always takes up at least 2 * spaces. +* +* Check for the commit to be a root, no parents +* and that it is not a boundary commit. If so, add a +* placeholder to keep that column filled for +* at least one row. +* +* Prevents the next commit from being inserted +* just below and making the graph confusing. */ -if (graph->num_parents ==0 ) +if (is_root) { +graph_insert_into_new_columns (graph, graph->commit, i); + graph->new_columns[graph->num_new_columns -1 ] + .is_placeholder =1 ; + }else if (graph->num_parents ==0 ) { graph->width +=2 ; + } }else { -graph_insert_into_new_columns (graph, col_commit,-1 ); +if (graph->columns[i].is_placeholder) { +/* +* Keep the placeholders if the next commit is +* a root also, making the indentation cascade. +*/ +if (!seen_this && is_root) { +graph_insert_into_new_columns (graph, + graph->columns[i].commit, i); + graph->new_columns[graph->num_new_columns -1 ] + .is_placeholder =1 ; + }else if (!seen_this) { + graph->mapping[graph->width] =-1 ; + graph->width +=2 ; + } + }else { +graph_insert_into_new_columns (graph, col_commit,-1 ); + } } }
@@ -846,7 +886,10 @@ static void graph_output_padding_line(struct git_graph *graph,* Output a padding row, that leaves all branch lines unchanged */ for (i =0 ; i < graph->num_new_columns; i++) { -graph_line_write_column (line, &graph->new_columns[i],'|' ); +if (graph->new_columns[i].is_placeholder) +graph_line_write_column (line, &graph->new_columns[i],' ' ); +else +graph_line_write_column (line, &graph->new_columns[i],'|' );graph_line_addch (line,' ' ); } }
@@ -1058,7 +1101,13 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line graph->mapping[2 * i] < i) { graph_line_write_column(line, col, '/'); } else { -graph_line_write_column (line, col,'|' ); +if (col->is_placeholder) { +if (seen_this) +continue ; +graph_line_write_column (line, col,' ' ); + }else { +graph_line_write_column (line, col,'|' ); + } }graph_line_addch (line,' ' ); }
@@ -1135,7 +1184,14 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_lgraph_line_write_column (line, col,'|' );graph_line_addch (line,' ' ); }else { -graph_line_write_column (line, col,'|' ); +if (col->is_placeholder) { +if (seen_this) +continue ; +graph_line_write_column (line, col,' ' ); + }else { +graph_line_write_column (line, col,'|' ); + } +if (graph->merge_layout !=0 || i != graph->commit_index -1 ) {if (parent_col) graph_line_write_column(
t/t4215-log-skewed-merges.sh +136 -0
140 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 5 lines · Pablo Sabater
t/t4215-log-skewed-merges.sh +0
-0
t/t4215-log-skewed-merges.sh test_expect_success 'log --graph with multiple tips' ' · line 378
Quoted 9 lines
t/t4215-log-skewed-merges.sh +6
-0@@ -370,4 +370,140 @@ test_expect_success 'log --graph with multiple tips' ' EOF ' +test_expect_success 'log --graph with root commit' ' + git checkout --orphan 8_a && + test_commit 8_A && + test_commit 8_A1 && + git checkout --orphan 8_b && + test_commit 8_B &&
On case challenged filesystems, you cannot have a commit "8_a" and "8_A" without being ambiguous. The CI failures from last night are all from Windows and macOS X.
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · Pablo Sabater
t/t4215-log-skewed-merges.sh +0
-0@@ -370,4 +370,140 @@ test_expect_success 'log --graph with multiple tips' ' EOF '
Quoted 13 lines
t/t4215-log-skewed-merges.sh test_expect_success 'log --graph with multiple tips' ' · line 378
Quoted 6 lines
t/t4215-log-skewed-merges.sh +6
-0+test_expect_success 'log --graph with root commit' ' + git checkout --orphan 8_a && + test_commit 8_A && + test_commit 8_A1 && + git checkout --orphan 8_b && + test_commit 8_B &&On case challenged filesystems, you cannot have a commit "8_a" and "8_A" without being ambiguous. The CI failures from last night are all from Windows and macOS X.
Okay I'll send a v2 with the "seems_root" change and fix the names, hadn't thought about it , I'll make sure that CI passes, sorry.
Quoted 2 lines · Pablo Sabater
This issue was reported by Junio at:
https://lore.kernel.org/git/[email protected]/
You are giving me too much credit. I just knew about previous attempts and the gotchas.
One thing that we may want to make sure your solution gets right is the issue depicated in two graphs in the footnote of this message:
https://lore.kernel.org/git/[email protected]/
Stepping back a bit, I think concentrating too much on "is it root?" is a wrong way to think about the problem. Suppose you have two histories, e.g. (time flows from left to right; A and X are roots)
A---B
\
X---Y---Z
and doing "git log --graph --oneline Z" would show A, B, X, Y and Z.
But in a slightly modified graph:
C
/
O---A---B
\
X---Y---Z
if you do "git log --graph --oneline C..Z", you should see the same commits listed as above (A, B, X, Y and Z), and most likely in the same order.
The way we draw A and make sure one raw below A in the same lane is vacant (to avoid something that is not an ancestor of A steals that spot) is applicable to both graphs. The reason why we try to keep one row below A vacant is not because it is a root, but because in the graph being drawn, none of A's parent will appear. Obviously if A is root, none of A's parent will appear in the graph, but in the latter topology where we are drawing C..Z, none of A's parent will appear not because A is root, but because all the parents of A is excluded.
Quoted 8 lines · Junio C Hamano
Quoted 2 lines · Pablo Sabater
This issue was reported by Junio at:
https://lore.kernel.org/git/[email protected]/You are giving me too much credit. I just knew about previous attempts and the gotchas.
Should I mention that thread instead ?
Quoted 26 lines
One thing that we may want to make sure your solution gets right is the issue depicated in two graphs in the footnote of this message:
https://lore.kernel.org/git/[email protected]/
Stepping back a bit, I think concentrating too much on "is it root?" is a wrong way to think about the problem. Suppose you have two histories, e.g. (time flows from left to right; A and X are roots)
A---B
\
X---Y---Zand doing "git log --graph --oneline Z" would show A, B, X, Y and Z.
But in a slightly modified graph:
C
/
O---A---B
\
X---Y---Z
Quoted 3 lines
if you do "git log --graph --oneline C..Z", you should see the same commits listed as above (A, B, X, Y and Z), and most likely in the same order.
I can't find the issue with the graph above, it would be shown:
A---B
\
X---Y---Zbut we shouldn't want indentation here tho
* Z
|\ | * B | * A
* Y
* X
B is the parent of A and there is no commit on a third branch that could try to get below A.
But I do find the issue with focusing on: is a root ? for example with this graph:
O---A
X---Y
If we O..A Y, it shows A, Y, X but because I only look for roots it ends up looking like:
* A <- not a root but O is excluded
* Y <- no indentation
* X
Then it's more something like 'seems_root' rather than 'is_root', and it should look like
* A
* Y
/
* X
This would make on your last graph to have indentation at the right of Y, below A, even if not needed, it would protect A's spot the row below, which I think is desirable and what you meant with the examples.
Quoted 11 lines
The way we draw A and make sure one raw below A in the same lane is vacant (to avoid something that is not an ancestor of A steals that spot) is applicable to both graphs. The reason why we try to keep one row below A vacant is not because it is a root, but because in the graph being drawn, none of A's parent will appear. Obviously if A is root, none of A's parent will appear in the graph, but in the latter topology where we are drawing C..Z, none of A's parent will appear not because A is root, but because all the parents of A is excluded.
Thanks for the feedback
Pablo
v2 cover graph: add indentation for commits preceded by a parentless commit
In reply to Pablo SabaterWhen having a history with multiple root commits or commits that act like roots (they have excluded parents), let's call them parentless, and drawing the history near them, the graphing engine renders the commits one below the other, seeming that they are related.
e.g.:
* parentless-B
* child-A2
* child-A1
* parentless-A
This issue has been attempted multiple times:
https://lore.kernel.org/git/[email protected]/
This happens because the engine prints left to right from the first free column and these parentless commits for the next row, their column becomes empty and the engine fills that gap with the next commit (child-A2) seeming that parentless-B and child-A2 are related when they are not.
The actual implementation is very minimal.
This patch makes the parentless commits to be kept alive at least one more row to avoid that, indenting the next commit to the next column and then clean the mapping letting the indented commit to naturally collapse to the column where the parentless commit was.
e.g.:
* parentless-B
* child-A2
/
* child-A1
* parentless-A
This is done by adding a is_placeholder flag to the columns, the parentless commit is actually there but marked as a placeholder
e.g.:
* parentless-B
(B) * child-A2
/
* child-A1
* parentless-A
(B) would be parentless-B column with the placeholder flag active.
By teaching the rendering function to print a padding ' ' when meeting a placeholder column hides them, printing the second example.
There could also be the case where there are multiple parentless commits
without the patch:
* A parentless
* B parentless
* C parentless
* D1 child
* D parentless
with the patch, the indentation cascades:
* A parentless
* B parentless
* C parentless
* D1 child
_ /
/
/
* D parentless
the _ / might look weird but that's how the collapsing rendering does it for big gaps, this case being from the 4th column to the 0th column.
Another patch could change the collapsing rendering for placeholders? I haven't done it to keep it minimal, but a follow up could make it to be straight '/'. This would make it bigger but easier for the eye to follow. IMO is not worth it, but opinions are welcome.
The patch also adds tests for different cases like a parentless commit preceding multiple parents merges and the examples above.
There could be some edge cases still so any testing is very welcome.
PSA: the tests are on t4215-log-skewed-merges.sh, which is not very related,
but other graph related tests have +140 tests, and this one has less than 20 and some of them are also not very related and differ in style. A cleanup patch before this renaming the file and style of the tests is fine?
Changes from v1:
- Changed to parentless commits instead of root commits to make it more generic
- Fixed the branch names to pass CI and fixed tests style.
Pablo Sabater (1):
graph: add indentation for commits preceded by a parentless commit
graph.c | 70 ++++++++++++++++++-- t/t4215-log-skewed-merges.sh | 124 +++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+), 6 deletions(-)
base-commit: 8de2f1b07a8053d7f1aad70dc1131d6afcf5a28a
Signature · 1 line
2.43.0
RFC PATCH v2 1/1 graph: add indentation for commits preceded by a parentless commit
When having a history with multiple root commits or commits that act like roots (they have excluded parents), let's call them parentless, and drawing the history near them, the graphing engine renders the commits one below the other, seeming that they are related.
This issue has been attempted multiple times:
https://lore.kernel.org/git/[email protected]/
This happens because for these parentless commits, in the next row the column becomes empty and the engine prints from left to right from the first empty column, filling the gap below these parentless commits.
Keep a parentless commit for at least one row more to avoid having the column empty but hide it as indentation, therefore making the next unrelated commit live in the next column (column means even positions where edges live:
0, 2, 4), then clean that "placeholder" column and let the unrelated commit to naturally collapse to the column where the parentless commit was.
Add is_placeholder to the struct column to mark if a column is acting as a placeholder for the padding.
When a column is parentless, add a column with the parentless commit data to prevent segfaults when 'column->commit' and mark it as a placeholder.
Teach rendering functions to print a padding ' ' instead of an edge when a placeholder column is met.
Then, unless the next commit is also parentless (then we need to keep cascading the indentation) clean the mapping and columns from the placeholder to allow it to collapse naturally.
Add tests for different cases.
before this patch:
* parentless-B
* child-A2
* child-A1
* parentless-A
after this patch:
* parentless-B
* child-A2
/
* child-A1
* parentless-A
--- graph.c | 70 ++++++++++++++++++-- t/t4215-log-skewed-merges.sh | 124 +++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+), 6 deletions(-)
graph.c +64 -6
@@ -60,6 +60,12 @@ struct column {* index into column_colors. */ unsigned short color; +/* +* A placeholder column keeps the column of a parentless commit filled +* for one extra row, avoiding a next unrelated commit to be printed +* in the same column. +*/ + unsigned is_placeholder:1; };enum graph_state {
@@ -563,6 +569,7 @@ static void graph_insert_into_new_columns(struct git_graph *graph, i = graph->num_new_columns++; graph->new_columns[i].commit = commit; graph->new_columns[i].color =graph_find_commit_color (graph, commit); + graph->new_columns[i].is_placeholder =0 ; }if (graph->num_parents >1 && idx >-1 && graph->merge_layout ==-1 ) {
@@ -607,7 +614,7 @@ static void graph_update_columns(struct git_graph *graph) {struct commit_list *parent;int max_new_columns; -int i, seen_this, is_commit_in_columns; +int i, seen_this, is_commit_in_columns, seems_root;/* * Swap graph->columns with graph->new_columns
@@ -654,6 +661,12 @@ static void graph_update_columns(struct git_graph *graph)*/ seen_this =0 ; is_commit_in_columns =1 ; +/* +* num_parents == 0 means that there are no parents flagged as +* interesting to being shown. +*/ + seems_root = graph->num_parents ==0 && + !(graph->commit->object.flags &BOUNDARY );for (i =0 ; i <= graph->num_columns; i++) {struct commit *col_commit;if (i == graph->num_columns) {
@@ -688,11 +701,40 @@ static void graph_update_columns(struct git_graph *graph)* least 2, even if it has no interesting parents. * The current commit always takes up at least 2 * spaces. +* +* Check for the commit to seem like a root, no parents +* rendered and that it is not a boundary commit. If so, +* add a placeholder to keep that column filled for +* at least one row. +* +* Prevents the next commit from being inserted +* just below and making the graph confusing. */ -if (graph->num_parents ==0 ) +if (seems_root) { +graph_insert_into_new_columns (graph, graph->commit, i); + graph->new_columns[graph->num_new_columns -1 ] + .is_placeholder =1 ; + }else if (graph->num_parents ==0 ) { graph->width +=2 ; + } }else { -graph_insert_into_new_columns (graph, col_commit,-1 ); +if (graph->columns[i].is_placeholder) { +/* +* Keep the placeholders if the next commit is +* parentless also, making the indentation cascade. +*/ +if (!seen_this && seems_root) { +graph_insert_into_new_columns (graph, + graph->columns[i].commit, i); + graph->new_columns[graph->num_new_columns -1 ] + .is_placeholder =1 ; + }else if (!seen_this) { + graph->mapping[graph->width] =-1 ; + graph->width +=2 ; + } + }else { +graph_insert_into_new_columns (graph, col_commit,-1 ); + } } }
@@ -846,7 +888,10 @@ static void graph_output_padding_line(struct git_graph *graph,* Output a padding row, that leaves all branch lines unchanged */ for (i =0 ; i < graph->num_new_columns; i++) { -graph_line_write_column (line, &graph->new_columns[i],'|' ); +if (graph->new_columns[i].is_placeholder) +graph_line_write_column (line, &graph->new_columns[i],' ' ); +else +graph_line_write_column (line, &graph->new_columns[i],'|' );graph_line_addch (line,' ' ); } }
@@ -1058,7 +1103,13 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line graph->mapping[2 * i] < i) { graph_line_write_column(line, col, '/'); } else { -graph_line_write_column (line, col,'|' ); +if (col->is_placeholder) { +if (seen_this) +continue ; +graph_line_write_column (line, col,' ' ); + }else { +graph_line_write_column (line, col,'|' ); + } }graph_line_addch (line,' ' ); }
@@ -1135,7 +1186,14 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_lgraph_line_write_column (line, col,'|' );graph_line_addch (line,' ' ); }else { -graph_line_write_column (line, col,'|' ); +if (col->is_placeholder) { +if (seen_this) +continue ; +graph_line_write_column (line, col,' ' ); + }else { +graph_line_write_column (line, col,'|' ); + } +if (graph->merge_layout !=0 || i != graph->commit_index -1 ) {if (parent_col) graph_line_write_column(
t/t4215-log-skewed-merges.sh +124 -0
128 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [GSoC RFC PATCH v2 0/1] graph: add indentation for commits preceded by a parentless commit
In reply to Pablo SabaterQuoted 99 lines · Pablo Sabater
When having a history with multiple root commits or commits that act like roots (they have excluded parents), let's call them parentless, and drawing the history near them, the graphing engine renders the commits one below the other, seeming that they are related.
e.g.:
* parentless-B
* child-A2
* child-A1
* parentless-AThis issue has been attempted multiple times:
https://lore.kernel.org/git/[email protected]/This happens because the engine prints left to right from the first free column and these parentless commits for the next row, their column becomes empty and the engine fills that gap with the next commit (child-A2) seeming that parentless-B and child-A2 are related when they are not.
The actual implementation is very minimal.
This patch makes the parentless commits to be kept alive at least one more row to avoid that, indenting the next commit to the next column and then clean the mapping letting the indented commit to naturally collapse to the column where the parentless commit was.e.g.:
* parentless-B
* child-A2
/
* child-A1
* parentless-AThis is done by adding a
is_placeholderflag to the columns, the parentless commit is actually there but marked as a placeholdere.g.:
* parentless-B
(B) * child-A2/* child-A1
* parentless-A(B) would be parentless-B column with the placeholder flag active.
By teaching the rendering function to print a padding ' ' when meeting a placeholder column hides them, printing the second example.
There could also be the case where there are multiple parentless commits
without the patch:
* A parentless
* B parentless
* C parentless
* D1 child
* D parentlesswith the patch, the indentation cascades:
* A parentless
* B parentless
* C parentless
* D1 child
_ /
/
/
* D parentlessthe _ / might look weird but that's how the collapsing rendering does it for big gaps, this case being from the 4th column to the 0th column.
Another patch could change the collapsing rendering for placeholders? I haven't done it to keep it minimal, but a follow up could make it to be straight '/'. This would make it bigger but easier for the eye to follow. IMO is not worth it, but opinions are welcome.
The patch also adds tests for different cases like a parentless commit preceding multiple parents merges and the examples above.
There could be some edge cases still so any testing is very welcome.
PSA: the tests are on
t4215-log-skewed-merges.sh, which is not very related,
but other graph related tests have +140 tests, and this one has less than 20 and some of them are also not very related and differ in style. A cleanup patch before this renaming the file and style of the tests is fine?Changes from v1:
- Changed to parentless commits instead of root commits to make it more generic
- Fixed the branch names to pass CI and fixed tests style.Pablo Sabater (1):
graph: add indentation for commits preceded by a parentless commit
Quoted 9 lines
graph.c | 70 ++++++++++++++++++-- t/t4215-log-skewed-merges.sh | 124 +++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+), 6 deletions(-)base-commit:
8de2f1b07a8053d7f1aad70dc1131d6afcf5a28a--
2.43.0
Hi,
I'm sending this because I think it has fallen through. Sorry about the ping,
Pablo
Re: [GSoC RFC PATCH v2 0/1] graph: add indentation for commits preceded by a parentless commit
Quoted 10 lines · Pablo
Quoted 3 lines · Pablo Sabater
When having a history with multiple root commits or commits that act like roots (they have excluded parents), let's call
...
Hi,
I'm sending this because I think it has fallen through. Sorry about the ping,
Pablo
Pinging is good than no pinging, so no need to say sorry.
I think this topic (the one on April 04) has been on the "What's cooking" report since issue #02 of this month, waiting for comments and responses to them. I haven't seen problems in it but that may be because I do not view commits near the root commit very often.
Thanks.
v3 cover graph: add indentation for commits preceded by a parentless commit
In reply to Pablo SabaterWhen having a history with multiple root commits or commits that act like roots (they have excluded parents), let's call them parentless, and drawing the history near them, the graphing engine renders the commits one below the other, seeming that they are related:
* parentless A
* child B
* parentless B
This issue has been attempted multiple times:
https://lore.kernel.org/git/[email protected]/
This happens because the engine prints left to right from the first free column and their column of these parentless commits for the next row becomes empty and the engine fills that gap with the next commit (child B) seeming that parentless A and child B are related when they are not.
The actual implementation is very minimal.
This patch makes the parentless commits to be kept alive at least one more row to avoid that, indenting the next commit to the next column and then clean the mapping letting the indented commit to naturally collapse to the column where the parentless commit was:
* parentless A
* child B
/
* parentless B
This is done by adding a is_placeholder flag to the columns, the parentless commit is actually there but marked as a placeholder:
* parentless A
(A) * child B
/
* parentless B
(A) would be "parentless A" column with the placeholder flag active.
By teaching the rendering function to print a padding ' ' when meeting a placeholder column hides them, printing the second example.
There could also be the case where there are multiple parentless commits
without the patch:
* parentless A
* parentless B
* parentless C
* child D
* parentless D
with the patch, the indentation cascades:
* parentless A
* parentless B
* parentless C
* child D
_ /
/
/
* parentless D
the _ / might look weird but that's how the collapsing rendering does it for big gaps, this case being from the 4th column to the 0th column.
A follow-up could change the collapsing rendering for placeholders? I haven't done it to keep it minimal, but a follow up could make it to be straight '/'. This would make it bigger but easier for the eye to follow. Is not worth it IMO, but opinions are welcome.
The patch also adds tests for different cases like a parentless commit preceding multiple parents merges and the examples above.
PSA: the tests are on t4215-log-skewed-merges.sh, which is not very related,
but other graph related tests have +140 tests, and this one has less than 20 and some of them are also not very related and differ in style. A cleanup patch before this renaming the file and style of the tests is fine?
Changes from v2:
- Removed trailing whitespace.
- Added more comments to make it more clear an reviewable.
- Changed is_root to is_parentless to follow the name at the cover letter and commit.
- simplified cover letter and commit ascii graphs.
Pablo Sabater (1):
graph: add indentation for commits preceded by a parentless commit
graph.c | 115 ++++++++++++++++++++++++++++++-- t/t4215-log-skewed-merges.sh | 124 +++++++++++++++++++++++++++++++++++ 2 files changed, 233 insertions(+), 6 deletions(-)
base-commit: 94f057755b7941b321fd11fec1b2e3ca5313a4e0 --
2.43.0
PATCH v3 1/1 graph: add indentation for commits preceded by a parentless commit
When having a history with multiple root commits or commits that act like roots (they have excluded parents), let's call them parentless, and drawing the history near them, the graphing engine renders the commits one below the other, seeming that they are related.
This issue has been attempted multiple times:
https://lore.kernel.org/git/[email protected]/
This happens because for these parentless commits, in the next row the column becomes empty and the engine prints from left to right from the first empty column, filling the gap below these parentless commits.
Keep a parentless commit for at least one row more to avoid having the column empty but hide it as indentation, therefore making the next unrelated commit live in the next column (column means even positions where edges live:
0, 2, 4), then clean that "placeholder" column and let the unrelated commit to naturally collapse to the column where the parentless commit was.
Add is_placeholder to the struct column to mark if a column is acting as a placeholder for the padding.
When a column is parentless, add a column with the parentless commit data to prevent segfaults when 'column->commit' and mark it as a placeholder.
Teach rendering functions to print a padding ' ' instead of an edge when a placeholder column is met.
Then, unless the next commit is also parentless (then we need to keep cascading the indentation) clean the mapping and columns from the placeholder to allow it to collapse naturally.
Add tests for different cases.
before this patch:
* parentless A
* child B
* parentless B
after this patch:
* parentless A
* child B
/
* parentless B
--- graph.c | 115 ++++++++++++++++++++++++++++++-- t/t4215-log-skewed-merges.sh | 124 +++++++++++++++++++++++++++++++++++ 2 files changed, 233 insertions(+), 6 deletions(-)
graph.c +109 -6
@@ -60,6 +60,12 @@ struct column {* index into column_colors. */ unsigned short color; +/* +* A placeholder column keeps the column of a parentless commit filled +* for one extra row, avoiding a next unrelated commit to be printed +* in the same column. +*/ + unsigned is_placeholder:1; };enum graph_state {
@@ -563,6 +569,7 @@ static void graph_insert_into_new_columns(struct git_graph *graph, i = graph->num_new_columns++; graph->new_columns[i].commit = commit; graph->new_columns[i].color =graph_find_commit_color (graph, commit); + graph->new_columns[i].is_placeholder =0 ; }if (graph->num_parents >1 && idx >-1 && graph->merge_layout ==-1 ) {
@@ -607,7 +614,7 @@ static void graph_update_columns(struct git_graph *graph) {struct commit_list *parent;int max_new_columns; -int i, seen_this, is_commit_in_columns; +int i, seen_this, is_commit_in_columns, is_parentless;/* * Swap graph->columns with graph->new_columns
@@ -654,6 +661,26 @@ static void graph_update_columns(struct git_graph *graph)*/ seen_this =0 ; is_commit_in_columns =1 ; +/* +* A commit is "parentless" (is a visual root that starts a new column) +* only if has no visible parents AND it's not a boundary commit. +* +* Boundary commits also have no visible parents, but they are +* NOT a visual root: +* +* 1. A boundary only appears in the output because an included commit +* is its child. Children are always above, and the renderer draws an +* edge down to the boundary from that child. Rather than starting +* a column like a visual root would do, it "inherits" its child +* column. +* +* 2. Included commit CAN'T appear below a boundary. Boundaries are +* ancestors of the exclusion point; if an included commit were an +* ancestor of the boundary it would be excluded and not rendered. +* Boundaries therefore always sink to the bottom. +*/ + is_parentless = graph->num_parents ==0 && + !(graph->commit->object.flags &BOUNDARY );for (i =0 ; i <= graph->num_columns; i++) {struct commit *col_commit;if (i == graph->num_columns) {
@@ -688,11 +715,46 @@ static void graph_update_columns(struct git_graph *graph)* least 2, even if it has no interesting parents. * The current commit always takes up at least 2 * spaces. +* +* Check for the commit to seem like a root, no parents +* rendered and that it is not a boundary commit. If so, +* add a placeholder to keep that column filled for +* at least one row. +* +* Prevents the next commit from being inserted +* just below and making the graph confusing. */ -if (graph->num_parents ==0 ) +if (is_parentless) { +graph_insert_into_new_columns (graph, graph->commit, i); + graph->new_columns[graph->num_new_columns -1 ] + .is_placeholder =1 ; + }else if (graph->num_parents ==0 ) { graph->width +=2 ; + } }else { -graph_insert_into_new_columns (graph, col_commit,-1 ); +if (graph->columns[i].is_placeholder) { +/* +* Keep the placeholders if the next commit is +* parentless also, making the indentation cascade. +*/ +if (!seen_this && is_parentless) { +graph_insert_into_new_columns (graph, + graph->columns[i].commit, i); + graph->new_columns[graph->num_new_columns -1 ] + .is_placeholder =1 ; + }else if (!seen_this) { + graph->mapping[graph->width] =-1 ; + graph->width +=2 ; + } +/* +* seen_this && is_placeholder means that this +* line is the one after the indented one, the +* placeholder is no longer needed, gets +* dropped and the columns collapses naturally. +*/ + }else { +graph_insert_into_new_columns (graph, col_commit,-1 ); + } } }
@@ -846,7 +908,10 @@ static void graph_output_padding_line(struct git_graph *graph,* Output a padding row, that leaves all branch lines unchanged */ for (i =0 ; i < graph->num_new_columns; i++) { -graph_line_write_column (line, &graph->new_columns[i],'|' ); +if (graph->new_columns[i].is_placeholder) +graph_line_write_column (line, &graph->new_columns[i],' ' ); +else +graph_line_write_column (line, &graph->new_columns[i],'|' );graph_line_addch (line,' ' ); } }
@@ -1058,7 +1123,34 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line graph->mapping[2 * i] < i) { graph_line_write_column(line, col, '/'); } else { -graph_line_write_column (line, col,'|' ); +if (col->is_placeholder) { +/* +* When the indented commit is a merge commit, +* the placeholder column adds unwanted padding +* between the commit and its subject. +* +* * parentless commit +* * merge commit +* /| +* | * parent A +* * parent B +* ^^ unwanted padding +* +* Once the current commit has been seen, don't +* let placeholder columns to be rendered: +* +* * parentless commit +* * merge commit +* /| +* | * parent A +* * parent B +*/ +if (seen_this) +continue ; +graph_line_write_column (line, col,' ' ); + }else { +graph_line_write_column (line, col,'|' ); + } }graph_line_addch (line,' ' ); }
@@ -1135,7 +1227,18 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_lgraph_line_write_column (line, col,'|' );graph_line_addch (line,' ' ); }else { -graph_line_write_column (line, col,'|' ); +if (col->is_placeholder) { +/* +* Same placeholder handling as in +* graph_output_commit_line(). +*/ +if (seen_this) +continue ; +graph_line_write_column (line, col,' ' ); + }else { +graph_line_write_column (line, col,'|' ); + } +if (graph->merge_layout !=0 || i != graph->commit_index -1 ) {if (parent_col) graph_line_write_column(
t/t4215-log-skewed-merges.sh +124 -0
128 lines not on this page · raw message
--
2.43.0
Re: [GSoC PATCH v3 1/1] graph: add indentation for commits preceded by a parentless commit
Quoted 6 lines · Pablo Sabater
graph.c +1
-1@@ -1135,7 +1227,18 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_lgraph_line_write_column (line, col,'|' );graph_line_addch (line,' ' ); }else { -graph_line_write_column (line, col,'|' ); +if (col->is_placeholder) {
graph.c static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l · line 1240
Quoted 10 lines
graph.c +10
-0+/* +* Same placeholder handling as in +* graph_output_commit_line(). +*/ +if (seen_this) +continue ; +graph_line_write_column (line, col,' ' ); + }else { +graph_line_write_column (line, col,'|' ); + }
I haven't looked closely at the patch, but Coverity complained that the "if (seen_this)" check here is dead code, because this whole else block follows:
} else if (seen_this) {
if (graph->edges_added > 0)
graph_line_write_column(line, col, '\\');
else
graph_line_write_column(line, col, '|');
graph_line_addch(line, ' ');
} else {
...the code above...I don't know if that just means the continue here is redundant and can be removed, or if it's a sign of a larger logic error.
-Peff
Re: [GSoC PATCH v3 1/1] graph: add indentation for commits preceded by a parentless commit
Quoted 33 lines · Jeff King
Quoted 6 lines · Pablo Sabater
graph.c +1
-1@@ -1135,7 +1227,18 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_lgraph_line_write_column (line, col,'|' );graph_line_addch (line,' ' ); }else { -graph_line_write_column (line, col,'|' ); +if (col->is_placeholder) {graph.c static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l · line 1240
Quoted 10 lines
graph.c +10
-0+/* +* Same placeholder handling as in +* graph_output_commit_line(). +*/ +if (seen_this) +continue ; +graph_line_write_column (line, col,' ' ); + }else { +graph_line_write_column (line, col,'|' ); + }I haven't looked closely at the patch, but Coverity complained that the "if (
seen_this)" check here is dead code, because this whole else block follows:} else if (seen_this) { if (graph->edges_added > 0) graph_line_write_column(line, col, '\\'); else graph_line_write_column(line, col, '|'); graph_line_addch(line, ' '); } else { ...the code above...
Quoted 4 lines
I don't know if that just means the continue here is redundant and can be removed, or if it's a sign of a larger logic error.
-Peff
It is dead code. The behaviour for placeholder at "graph_output_commit_line()" and "graph_output_post_merge_line()" is the same, if it's a placeholder print a padding instead of an edge, but I didn't give it a second thought, graph_output_commit_line() can have a placeholder at its right (that's why it needs the continue to avoid extra padding) but post merge can't and as it is dead code I didn't notice.
I'll drop the dead code.
Thanks,
--
Pablo
Re: [GSoC PATCH v3 0/1] graph: add indentation for commits preceded by a parentless commit
In reply to Pablo SabaterQuoted 10 lines · Pablo Sabater
Pablo Sabater (1):
graph: add indentation for commits preceded by a parentless commitgraph.c | 115 ++++++++++++++++++++++++++++++-- t/t4215-log-skewed-merges.sh | 124 +++++++++++++++++++++++++++++++++++ 2 files changed, 233 insertions(+), 6 deletions(-)base-commit:
94f057755b7941b321fd11fec1b2e3ca5313a4e0
Hi!
This patch seems to have a problem to get reviewed, I improved the comments at the code and simplified the example graphs at the cover letter and patch to try
to make it easier to review.
Let me know if any clarification is needed,
--
Pablo
v4 cover graph: indent visual roots in graph
In reply to Pablo SabaterWhen rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This series adds indentation to the visual root commits, so they cannot be vertically adjacent anymore making it easier to identify them.
before indentation:
* A
* B1
* B2
* C1
* C2
after indentation:
* A
* B1
\
* B2
* C1
* C2
Indents the visual root commits that have still commits to show after them, and if they have children it connects them with an edge at a new row.
If there are multiple visual roots adjacent in history, the indentation starts with the second one, avoiding redundant indentation of the first one and cascades after the second.
* A
* B
* C
* D1
* D2
This series first commit is a cleanup that brings a common function from t4215 and t6016 to a graph functions file which they both use, so the new test file for indentation, t4218, can use it as well.
The lookahead used to set the cascading and avoid extra indentation is not completely reliable, as the walker goes through the commits it simplifies the history of the current commit and its parents, but it doesn't simplify it for the next unrelated or the grandparents. When the walker simplifies the history, it removes filtered commits from the history and sets its flags. When the next commit is an unrelated commit and its parents will be filtered out, for the lookahead the commit is still a child of, it cannot know that the next commit once simplified (advancing the walker) it will become a visual root. This makes the lookahead fail, failing to set the cascading and starting it with the first visual root, carrying an extra indent for the cascade.
given:
* A unrelated (visual root)
* B child of C
* C visual root WILL BE FILTERED OUT
* D unrelated (visual root)
the actual output is:
* A
* B
* D
A test has been added to t4218 and a NEEDSWORK to the lookahead function to document this edge case but I'm not that familiar with revision.c. Maybe there's a better way to make the lookahead more reliable.
[1]: https://lore.kernel.org/git/[email protected]/
V3 DIFF:
- Completly changes the approach to indent the visual roots instead of the commits after the visual roots.
---
Pablo Sabater (2):
lib-log-graph: move check_graph function
graph: indent visual root in graph
graph.c | 262 +++++++++++++++++ t/lib-log-graph.sh | 5 + t/meson.build | 1 + t/t4215-log-skewed-merges.sh | 33 +-- t/t4218-log-graph-indentation.sh | 455 +++++++++++++++++++++++++++++ t/t6016-rev-list-graph-simplify-history.sh | 25 +- 6 files changed, 747 insertions(+), 34 deletions(-)
---
base-commit: 3e65291872de10c3f0bf05ea8c24187e7a71ebf0
change-id: 20260612-ps-pre-commit-indent-39ca72816382
Best regards,
Signature · 1 line
Pablo Sabater <[email protected]>
PATCH v4 1/2 lib-log-graph: move check_graph function
check_graph is a function shared in the test files t4215 and t6016 used to format the output graph, but instead of being in a file called by both test, the function code is repeated in each file.
Move check_graph to lib-log-graph.sh file which both tests already import graph functions from, renaming it to lib_test_check_graph.
This function is needed for the following commit which includes graph tests in a new file and requires check_graph.
--- t/lib-log-graph.sh | 5 +++++ t/t4215-log-skewed-merges.sh | 33 +++++++++++++----------------- t/t6016-rev-list-graph-simplify-history.sh | 25 +++++++++------------- 3 files changed, 29 insertions(+), 34 deletions(-)
t/lib-log-graph.sh +5 -0
@@ -26,3 +26,8 @@ lib_test_cmp_colored_graph () { test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors && test_cmp expect.colors output.colors } + +lib_test_check_graph () { + cat >expect && + lib_test_cmp_graph --format=%s "$@" +}
t/t4215-log-skewed-merges.sh +14 -19
@@ -5,11 +5,6 @@ test_description='git log --graph of skewed merges' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh -check_graph () { - cat >expect && - lib_test_cmp_graph --format=%s "$@" -} - test_expect_success 'log --graph with merge fusing with its left and right neighbors' ' git checkout --orphan _p && test_commit A &&
@@ -21,7 +16,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh git checkout _p && git merge --no-ff _r -m G && git checkout @^^ && git merge --no-ff _p -m H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * H |\ | * G
@@ -49,7 +44,7 @@ test_expect_success 'log --graph with left-skewed merge' ' git checkout 0_p && git merge --no-ff 0_s -m 0_G && git checkout @^ && git merge --no-ff 0_q 0_r 0_t 0_p -m 0_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF *-----. 0_H |\ \ \ \ | | | | * 0_G
@@ -83,7 +78,7 @@ test_expect_success 'log --graph with nested left-skewed merge' ' git checkout 1_p && git merge --no-ff 1_r -m 1_G && git checkout @^^ && git merge --no-ff 1_p -m 1_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 1_H |\ | * 1_G
@@ -115,7 +110,7 @@ test_expect_success 'log --graph with nested left-skewed merge following normal git checkout -b 2_s @^^ && git merge --no-ff 2_q -m 2_J && git checkout 2_p && git merge --no-ff 2_s -m 2_K && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 2_K |\ | * 2_J
@@ -151,7 +146,7 @@ test_expect_success 'log --graph with nested right-skewed merge following left-s git checkout 3_p && git merge --no-ff 3_r -m 3_H && git checkout @^^ && git merge --no-ff 3_p -m 3_J && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 3_J |\ | * 3_H
@@ -182,7 +177,7 @@ test_expect_success 'log --graph with right-skewed merge following a left-skewed git merge --no-ff 4_p -m 4_G && git checkout @^^ && git merge --no-ff 4_s -m 4_H && - check_graph --date-order <<-\EOF + lib_test_check_graph --date-order <<-\EOF * 4_H |\ | * 4_G
@@ -218,7 +213,7 @@ test_expect_success 'log --graph with octopus merge with column joining its penu git checkout 5_r && git merge --no-ff 5_s -m 5_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 5_H |\ | *-. 5_G
@@ -257,7 +252,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout 6_1 && git merge --no-ff 6_2 -m 6_I && - check_graph 6_1 6_3 6_5 <<-\EOF + lib_test_check_graph 6_1 6_3 6_5 <<-\EOF * 6_I |\ | | * 6_H
@@ -334,7 +329,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout -b M_7 7_1 && git merge --no-ff 7_2 7_3 -m 7_M4 && - check_graph M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -371,7 +366,7 @@ test_expect_success 'log --graph with multiple tips' ' ' test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' ' - check_graph --graph-lane-limit=2 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=2 M_7 <<-\EOF *-. 7_M4 |\ \ | | * 7_G
@@ -388,7 +383,7 @@ test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' ' ' test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge' ' - check_graph --graph-lane-limit=1 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=1 M_7 <<-\EOF *-~ 7_M4 |\~ | ~ 7_G
@@ -405,7 +400,7 @@ test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge ' test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' ' - check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -441,7 +436,7 @@ test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' ' ' test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows first of 3 parent merge' ' - check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -478,7 +473,7 @@ test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows fir ' test_expect_success 'log --graph --graph-lane-limit=7 check if it shows all 3 parent merge' ' - check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
t/t6016-rev-list-graph-simplify-history.sh +10 -15
@@ -13,11 +13,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh -check_graph () { - cat >expect && - lib_test_cmp_graph --format=%s "$@" -} - test_expect_success 'set up rev-list --graph test' ' # 3 commits on branch A test_commit A1 foo.txt &&
@@ -54,7 +49,7 @@ test_expect_success 'set up rev-list --graph test' ' ' test_expect_success '--graph --all' ' - check_graph --all <<-\EOF + lib_test_check_graph --all <<-\EOF * A7 * A6 |\
@@ -82,7 +77,7 @@ test_expect_success '--graph --all' ' # that undecorated merges are interesting, even with --simplify-by-decoration test_expect_success '--graph --simplify-by-decoration' ' git tag -d A4 && - check_graph --all --simplify-by-decoration <<-\EOF + lib_test_check_graph --all --simplify-by-decoration <<-\EOF * A7 * A6 |\
@@ -114,7 +109,7 @@ test_expect_success 'setup: get rid of decorations on B' ' # Graph with branch B simplified away test_expect_success '--graph --simplify-by-decoration prune branch B' ' - check_graph --simplify-by-decoration --all <<-\EOF + lib_test_check_graph --simplify-by-decoration --all <<-\EOF * A7 * A6 |\
@@ -133,7 +128,7 @@ test_expect_success '--graph --simplify-by-decoration prune branch B' ' ' test_expect_success '--graph --full-history -- bar.txt' ' - check_graph --full-history --all -- bar.txt <<-\EOF + lib_test_check_graph --full-history --all -- bar.txt <<-\EOF * A7 * A6 |\
@@ -148,7 +143,7 @@ test_expect_success '--graph --full-history -- bar.txt' ' ' test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' - check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF + lib_test_check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF * A7 * A6 |\
@@ -161,7 +156,7 @@ test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' ' test_expect_success '--graph -- bar.txt' ' - check_graph --all -- bar.txt <<-\EOF + lib_test_check_graph --all -- bar.txt <<-\EOF * A7 * A5 * A3
@@ -172,7 +167,7 @@ test_expect_success '--graph -- bar.txt' ' ' test_expect_success '--graph --sparse -- bar.txt' ' - check_graph --sparse --all -- bar.txt <<-\EOF + lib_test_check_graph --sparse --all -- bar.txt <<-\EOF * A7 * A6 * A5
@@ -189,7 +184,7 @@ test_expect_success '--graph --sparse -- bar.txt' ' ' test_expect_success '--graph ^C4' ' - check_graph --all ^C4 <<-\EOF + lib_test_check_graph --all ^C4 <<-\EOF * A7 * A6 * A5
@@ -202,7 +197,7 @@ test_expect_success '--graph ^C4' ' ' test_expect_success '--graph ^C3' ' - check_graph --all ^C3 <<-\EOF + lib_test_check_graph --all ^C3 <<-\EOF * A7 * A6 |\
@@ -220,7 +215,7 @@ test_expect_success '--graph ^C3' ' # that important, but this test depends on it. If the ordering ever changes # in the code, we'll need to update this test. test_expect_success '--graph --boundary ^C3' ' - check_graph --boundary --all ^C3 <<-\EOF + lib_test_check_graph --boundary --all ^C3 <<-\EOF * A7 * A6 |\
Signature · 1 line
2.54.0
PATCH v4 2/2 graph: indent visual root in graph
In reply to Pablo SabaterWhen rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This happens because the commits fill the space from left to right and when a visual root ends, its column becomes free for the following commit even if they are not related. Once this happens the unrelated commit is rendered below the visual root. Because there is no special character or way to identify when a visual root is rendered making the graph confusing.
By indenting the visual roots when there are still commits to show the vertical adjacency can be avoided.
Add is_visual_root flag to git_graph making it visible in all graph states, give graph_update() a new function, graph_is_visual_root() to know if the current commit is a visual root and set is_visual_root.
The different handled cases are:
- If a visual root has children: similar to GRAPH_PRE_COMMIT state when octopus merges need space, an edge row needs to be printed to connect the child with the indented visual root. A new state GRAPH_PRE_ROOT is needed to connect the child with the visual root:
* child of the visual root
\ GRAPH_PRE_ROOT
* visual root indented
- If a visual root is child-less we can skip GRAPH_PRE_ROOT state and render the indented commit directly.
* visual root indented
* unrelated commit
- If two or more visual roots are adjacent: by having a lookahead to the next commit that will be rendered, if the next commit is also a visual root and we are on a visual root, meaning two visual root adjacent in the history, the top one can omit the indent, making the one below to indent only once, if there are more adjacent visual commits, the indentation will increase for each adjacent one, cascading.
* visual root
* visual root
* visual root
* last commit
Even if the last commit is a root, because there is nothing that will be rendered below we can omit the indentation on purpose.
The lookahead is not completely reliable, on graphs with filtered parents, the walker when processing the current commit it will simplify its parents by removing the ones that won't be shown, (They have the TREESAME flag when filtering by path for example), but it doesn't act for the grandparents or the next commit if it is unrelated until we move to the next.
For example given
A visual root
B child
C parent of B, visual root FILTERED
D last commit
We would expect
A
B
D
When processing A, for the walker and the information at the renderer, B is still a child of C, as B parent, hasn't been removed yet. This makes cascade to not trigger as the lookahead fails to detect if the next commit will be a visual root.
Once at B, its parent has been removed and has become a visual root, and it just adds its indent to the one left by A. We end up with an extra indent:
A
B
D
The output isn't broken as unrelated commits are successfully separated by indentation, but an indent level should have been avoided.
Create a new test file for graph indentations test called 't4218-log-graph-indentation.sh'.
The filtered parents edge case is documented as a NEEDSWORK on the lookahead function and it has its own 'test_expect_failure' at 't4218'.
[1]: https://lore.kernel.org/git/[email protected]/
--- graph.c | 262 ++++++++++++++++++++++ t/meson.build | 1 + t/t4218-log-graph-indentation.sh | 455 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 718 insertions(+)
graph.c +262 -0
@@ -60,12 +60,23 @@ struct column {* index into column_colors. */ unsigned short color; +/* +* Marks if a commit is a non-first parent of a merge. These columns are +* already visually connected to the merge commit and do not need +* indentation. +* +* The first parent is the one that inherits the column and it can need +* indentation if turns out to be a visual root and there's still +* commits to render. +*/ + unsigned is_merge_parent:1; };enum graph_state {GRAPH_PADDING ,GRAPH_SKIP ,GRAPH_PRE_COMMIT , +GRAPH_PRE_ROOT ,GRAPH_COMMIT ,GRAPH_POST_MERGE ,GRAPH_COLLAPSING
@@ -315,6 +326,48 @@ struct git_graph {* diff_output_prefix_callback(). */ struct strbuf prefix_buf; + +/* +* If a commit is a visual root, we need to indent it to prevent +* unrelated commits from being vertically adjacent to it. +*/ + unsigned is_visual_root:1; + +/* +* Indentation increases for each visual root adjacent to another visual +* root, making visual root commits indentation cascade. +*/ +unsigned int visual_root_depth; + +/* +* When a visual root is adjacent to other visual roots, the first one +* can avoid indentation and the rest cascades, increasing the indentation +* for each one. +*/ + unsigned visual_root_cascade:1; + +/* +* Set when the current commit was already present in graph->columns +* before being processed. +*/ + unsigned commit_in_columns:1; +}; + +struct graph_lookahead_flags { +/* +* Set when there will be a commit after the current one that will be +* rendered. +*/ +unsigned int is_next_visible:1 ; +/* +* Set when the next visible commit is candidate to be a visual root. +*/ +unsigned int is_next_visual_root:1 ; +/* +* Set when the next visible commit will be rendered under the current +* commit. +*/ +unsigned int next_has_column:1 ; };static inline int graph_needs_truncation (struct git_graph *graph,int lane)
@@ -388,6 +441,8 @@ struct git_graph *graph_init(struct rev_info *opt) graph->num_columns =0 ; graph->num_new_columns =0 ; graph->mapping_size =0 ; + graph->visual_root_depth =0 ; + graph->visual_root_cascade =0 ;/* * Start the column color at the maximum value, since we'll * always increment it for the first commit we output.
@@ -561,6 +616,11 @@ static void graph_insert_into_new_columns(struct git_graph *graph, struct commit *commit, int idx) { +/* +* Get the initial merge_layout before it's modified to know if this +* is a merge. +*/ +int initial_merge_layout = graph->merge_layout;int i =graph_find_new_column_by_commit (graph, commit);int mapping_idx;
@@ -572,6 +632,7 @@ static void graph_insert_into_new_columns(struct git_graph *graph, i = graph->num_new_columns++; graph->new_columns[i].commit = commit; graph->new_columns[i].color =graph_find_commit_color (graph, commit); + graph->new_columns[i].is_merge_parent =0 ; }if (graph->num_parents >1 && idx >-1 && graph->merge_layout ==-1 ) {
@@ -610,6 +671,12 @@ static void graph_insert_into_new_columns(struct git_graph *graph, } graph->mapping[mapping_idx] = i; + +/* +* Mark non-first parents of a merge. +*/ +if (graph->num_parents >1 && initial_merge_layout >=0 && idx >-1 ) + graph->new_columns[i].is_merge_parent =1 ; }static void graph_update_columns (struct git_graph *graph)
@@ -701,10 +768,20 @@ static void graph_update_columns(struct git_graph *graph)if (graph->num_parents ==0 ) graph->width +=2 ; }else { +int j;graph_insert_into_new_columns (graph, col_commit,-1 ); +/* +* This column is not the current commit, but we need to +* propagate the flag until the commit is processed. +*/ + j =graph_find_new_column_by_commit (graph, col_commit); +if (j >=0 && graph->columns[i].is_merge_parent) + graph->new_columns[j].is_merge_parent =1 ; } } + graph->commit_in_columns = is_commit_in_columns; +/* * If graph_max_lanes is set, cap the width */
@@ -763,9 +840,135 @@ static int graph_needs_pre_commit_line(struct git_graph *graph) graph->expansion_row <graph_num_expansion_rows (graph); } +/* +* A commit can be a visual root when: +* - It has no parents. +* +* - It has parents but they are all filtered out and +* commit->parents arrives NULL. +* +* - It is not a boundary commit. Boundary commits also have no visible +* parents, but they are not selected as visual roots because they cannot +*. cause the ambiguity of being vertically adjacent because: +* +* 1. A boundary only appears because an included commit is its child. +* Children are always above, and the renderer draws an edge down to +* the boundary from that child. Rather than starting a column like a +* visual root would do, it inherits its child column. +* +* 2. Included commits cannot appear below a boundary. Boundaries are +* ancestors of the exclusion point; if an included commit were an +* ancestor of the boundary it would be excluded and not rendered. +* Boundaries therefore always sink to the bottom. +*/ +static int graph_is_visual_root_candidate (struct commit *c) +{ +return c->parents ==NULL && !(c->object.flags &BOUNDARY ); +} + +static int graph_is_visual_root (struct git_graph *graph, +struct graph_lookahead_flags *flags) +{ +/* +* This must be only called for the current commit as graph contains +* the state for the current commit only. +* +* To check if a commit is a visual root, call graph_is_visual_root_candidate() +* but we won't know if it is really a visual root until we get to the +* next commit state. +* +* The current commit is an actual visual root if it is a candidate and +* the commit is not a non-first parent of a merge. +* +* * +* |\ +* | * <- it is a visual root candidate but it shouldn't be indented +* * because it is already connected by an edge. +* ^ if commit_in_columns && is_merge_parent means the commit +* | was put by a merge and is connected. +* | +* `-------- if !is_next_visible means we're on the last commit, avoid +* indentation unless the one before is a visual root, then +* we need to differentiate from the one above. +* +* If next_has_columns means that the next commit has +* already a column, so it will not be rendered below, the +* current commit has to act as the last commit and omit +* indentation. +*/ +return graph_is_visual_root_candidate (graph->commit) && + !(graph->commit_in_columns && + graph->columns[graph->commit_index].is_merge_parent) && + flags->is_next_visible && + (!flags->next_has_column || graph->visual_root_depth >0 ); +} + +/* +* Iterates the commits queue searching for the next visible commit, once found +* sets visibleness and visual-root flags. +* Knowing if the next commit is also a visual root avoids redundant indentations +* +* NEEDSWORK: The queue is actively being modified by the walker, for each commit +* its parents and itself get simplified and their flags set, but for the next +* unrelated commit or the grandparents they are not simplified yet, which means +* that a commit whose parents are all filtered will not be marked as a visual +* root candidate at the lookahead. +* This causes the lookahead to fail, failing to set the cascade flag to avoid +* redundant indentations. +* See 'test_expect_failure' at t4218-log-graph-indentation.sh. +*/ +static void graph_peek_next_visible (struct git_graph *graph, +struct graph_lookahead_flags *flags) +{ +struct commit_list *cl; + + flags->is_next_visible =0 ; + flags->is_next_visual_root =0 ; + flags->next_has_column =0 ; + +for (cl = graph->revs->commits; cl; cl = cl->next) { +if (get_commit_action (graph->revs, cl->item) != commit_show) +continue ; + flags->is_next_visible =1 ; + flags->next_has_column =graph_find_new_column_by_commit (graph, cl->item) >=0 ; +/* +* We do not need graph->commit_in_columns or is_merge_parent, +* because we only need to know whether the next one might be a +* visual root, affecting the current commit where the cascade +* would have to be set and the first visual root not indented. +* +* It will set next_is_visual_root to true for merge parents that +* graph_is_visual_root() would return false, but if the next is +* a merge parent, the current commit is the child and cannot +* be a visual root and therefore having no effect. +*/ +if (!graph_is_visual_root_candidate (cl->item)) +return ; + +/* +* The next visible commit is a visual root candidate, but +* only set cascade if it's not the last commit to be rendered. +*/ +for (cl = cl->next; cl; cl = cl->next) { +if (get_commit_action (graph->revs, cl->item) != commit_show) +continue ; + flags->is_next_visual_root =1 ; +return ; + } +return ; + } +} + +static int graph_needs_pre_root_line (struct git_graph *graph) +{ +return graph->commit_in_columns && graph->is_visual_root && + graph->num_columns >0 && !graph->visual_root_cascade; +} +void graph_update (struct git_graph *graph,struct commit *commit) {struct commit_list *parent; +struct graph_lookahead_flags flags;/* * Set the new commit
@@ -796,6 +999,23 @@ void graph_update(struct git_graph *graph, struct commit *commit)*/ graph_update_columns (graph); +graph_peek_next_visible (graph, &flags); + + graph->is_visual_root =graph_is_visual_root (graph, &flags); + +if (graph->is_visual_root) { +/* +* If next is a visual root we can omit the indent for the first +* visual root and start cascading. +*/ +if (!graph->visual_root_depth && flags.is_next_visual_root) + graph->visual_root_cascade =1 ; + graph->visual_root_depth++; + }else { + graph->visual_root_depth =0 ; + graph->visual_root_cascade =0 ; + } + graph->expansion_row =0 ;/*
@@ -813,11 +1033,16 @@ void graph_update(struct git_graph *graph, struct commit *commit)* room for it. We need to do this only if there is a branch row * (or more) to the right of this commit. * +* If it is a visual root, we need to print an extra row to +* connect the indentation. +* * If there are less than 3 parents, we can immediately print the * commit line. */ if (graph->state !=GRAPH_PADDING ) graph->state =GRAPH_SKIP ; +else if (graph_needs_pre_root_line (graph)) + graph->state =GRAPH_PRE_ROOT ;else if (graph_needs_pre_commit_line (graph)) graph->state =GRAPH_PRE_COMMIT ;else
@@ -1065,6 +1290,17 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_lineif (col_commit == graph->commit) { seen_this =1 ; +if (graph->is_visual_root) { +int depth = graph->visual_root_depth; +/* +* Each visual column is 2 characters wide. +* Omit the indentation for the first visual +* root in cascade mode. +*/ +int padding = (depth - graph->visual_root_cascade) *2 ; +graph_line_addchars (line,' ' , padding); + graph->width += padding; + }graph_output_commit_char (graph, line);if (graph_needs_truncation (graph, i)) {
@@ -1436,6 +1672,29 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_lgraph_update_state (graph,GRAPH_PADDING ); } +static void graph_output_pre_root_line (struct git_graph *graph,struct graph_line *line) +{ +/* +* This function adds a row before a visual root, to connect the +* branch to the indented commit. It should only be called on a +* visual root. +*/ +assert (graph->is_visual_root); + +for (size_t i =0 ; i < graph->num_columns; i++) { +struct column *col = &graph->columns[i]; +if (col->commit == graph->commit) { +graph_line_addch (line,' ' ); +graph_line_write_column (line, col,'\\' ); + }else { +graph_line_write_column (line, col,'|' ); + } +graph_line_addch (line,' ' ); + } + +graph_update_state (graph,GRAPH_COMMIT ); +} +int graph_next_line (struct git_graph *graph,struct strbuf *sb) {int shown_commit_line =0 ;
@@ -1461,6 +1720,9 @@ int graph_next_line(struct git_graph *graph, struct strbuf *sb)case GRAPH_PRE_COMMIT :graph_output_pre_commit_line (graph, &line);break ; +case GRAPH_PRE_ROOT : +graph_output_pre_root_line (graph, &line); +break ;case GRAPH_COMMIT :graph_output_commit_line (graph, &line); shown_commit_line =1 ;
t/meson.build +1 -0
@@ -576,6 +576,7 @@ integration_tests = [ 't4215-log-skewed-merges.sh', 't4216-log-bloom.sh', 't4217-log-limit.sh', + 't4218-log-graph-indentation.sh', 't4252-am-options.sh', 't4253-am-keep-cr-dos.sh', 't4254-am-corrupt.sh',
t/t4218-log-graph-indentation.sh new file +455 -0
455 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v4 0/2] graph: indent visual roots in graph
In reply to Pablo SabaterQuoted 9 lines · Pablo Sabater
When rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
...
[1]: https://lore.kernel.org/git/[email protected]/V3 DIFF:
Quoted 8 lines
- Completly changes the approach to indent the visual roots instead of the commits after the visual roots.
Signed-off-by Pablo Sabater <[email protected]>---
Pablo Sabater (2):
lib-log-graph: movecheck_graphfunction
graph: indent visual root in graph
The new tests added here does not seem to play well with linux-TEST-vars CI job when merged to 'seen' or 'jch' with other topics in flight.
https://github.com/git/git/actions/runs/27445164550/job/81128391150#step:10:1779
https://github.com/git/git/actions/runs/27445164037/job/81128386244#step:10:1778
I suspect that these tests are failing the same way even standalone.
https://github.com/git/git/actions/runs/27447146727/job/81134594264#step:9:2136
v5 cover graph: indent visual roots in graph
In reply to Pablo SabaterWhen rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This series adds indentation to the visual root commits, so they cannot be vertically adjacent anymore making it easier to identify them.
before indentation:
* A
* B1
* B2
* C1
* C2
after indentation:
* A
* B1
\
* B2
* C1
* C2
Indents the visual root commits that have still commits to show after them, and if they have children it connects them with an edge at a new row.
If there are multiple visual roots adjacent in history, the indentation starts with the second one, avoiding redundant indentation of the first one and cascades after the second.
* A
* B
* C
* D1
* D2
This series first commit is a cleanup that brings a common function from t4215 and t6016 to a graph functions file which they both use, so the new test file for indentation, t4218, can use it as well.
The lookahead used to set the cascading and avoid extra indentation is not completely reliable, as the walker goes through the commits it simplifies the history of the current commit and its parents, but it doesn't simplify it for the next unrelated or the grandparents. When the walker simplifies the history, it removes filtered commits from the history and sets its flags. When the next commit is an unrelated commit and its parents will be filtered out, for the lookahead the commit is still a child of, it cannot know that the next commit once simplified (advancing the walker) it will become a visual root. This makes the lookahead fail, failing to set the cascading and starting it with the first visual root, carrying an extra indent for the cascade.
given:
* A unrelated (visual root)
* B child of C
* C visual root WILL BE FILTERED OUT
* D unrelated (visual root)
the actual output is:
* A
* B
* D
A test has been added to t4218 and a NEEDSWORK to the lookahead function to document this edge case but I'm not that familiar with revision.c. Maybe there's a better way to make the lookahead more reliable.
[1]: https://lore.kernel.org/git/[email protected]/
V4 DIFF:
- Fixed test to be shown as expected by unsetting COMMIT_GRAPH
---
Pablo Sabater (2):
lib-log-graph: move check_graph function
graph: indent visual root in graph
graph.c | 262 ++++++++++++++++ t/lib-log-graph.sh | 5 + t/meson.build | 1 + t/t4215-log-skewed-merges.sh | 33 +- t/t4218-log-graph-indentation.sh | 467 +++++++++++++++++++++++++++++ t/t6016-rev-list-graph-simplify-history.sh | 25 +- 6 files changed, 759 insertions(+), 34 deletions(-)
---
base-commit: 3e65291872de10c3f0bf05ea8c24187e7a71ebf0
change-id: 20260612-ps-pre-commit-indent-39ca72816382
Best regards,
Signature · 1 line
Pablo Sabater <[email protected]>
PATCH v5 1/2 lib-log-graph: move check_graph function
check_graph is a function shared in the test files t4215 and t6016 used to format the output graph, but instead of being in a file called by both test, the function code is repeated in each file.
Move check_graph to lib-log-graph.sh file which both tests already import graph functions from, renaming it to lib_test_check_graph.
This function is needed for the following commit which includes graph tests in a new file and requires check_graph.
--- t/lib-log-graph.sh | 5 +++++ t/t4215-log-skewed-merges.sh | 33 +++++++++++++----------------- t/t6016-rev-list-graph-simplify-history.sh | 25 +++++++++------------- 3 files changed, 29 insertions(+), 34 deletions(-)
t/lib-log-graph.sh +5 -0
@@ -26,3 +26,8 @@ lib_test_cmp_colored_graph () { test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors && test_cmp expect.colors output.colors } + +lib_test_check_graph () { + cat >expect && + lib_test_cmp_graph --format=%s "$@" +}
t/t4215-log-skewed-merges.sh +14 -19
@@ -5,11 +5,6 @@ test_description='git log --graph of skewed merges' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh -check_graph () { - cat >expect && - lib_test_cmp_graph --format=%s "$@" -} - test_expect_success 'log --graph with merge fusing with its left and right neighbors' ' git checkout --orphan _p && test_commit A &&
@@ -21,7 +16,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh git checkout _p && git merge --no-ff _r -m G && git checkout @^^ && git merge --no-ff _p -m H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * H |\ | * G
@@ -49,7 +44,7 @@ test_expect_success 'log --graph with left-skewed merge' ' git checkout 0_p && git merge --no-ff 0_s -m 0_G && git checkout @^ && git merge --no-ff 0_q 0_r 0_t 0_p -m 0_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF *-----. 0_H |\ \ \ \ | | | | * 0_G
@@ -83,7 +78,7 @@ test_expect_success 'log --graph with nested left-skewed merge' ' git checkout 1_p && git merge --no-ff 1_r -m 1_G && git checkout @^^ && git merge --no-ff 1_p -m 1_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 1_H |\ | * 1_G
@@ -115,7 +110,7 @@ test_expect_success 'log --graph with nested left-skewed merge following normal git checkout -b 2_s @^^ && git merge --no-ff 2_q -m 2_J && git checkout 2_p && git merge --no-ff 2_s -m 2_K && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 2_K |\ | * 2_J
@@ -151,7 +146,7 @@ test_expect_success 'log --graph with nested right-skewed merge following left-s git checkout 3_p && git merge --no-ff 3_r -m 3_H && git checkout @^^ && git merge --no-ff 3_p -m 3_J && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 3_J |\ | * 3_H
@@ -182,7 +177,7 @@ test_expect_success 'log --graph with right-skewed merge following a left-skewed git merge --no-ff 4_p -m 4_G && git checkout @^^ && git merge --no-ff 4_s -m 4_H && - check_graph --date-order <<-\EOF + lib_test_check_graph --date-order <<-\EOF * 4_H |\ | * 4_G
@@ -218,7 +213,7 @@ test_expect_success 'log --graph with octopus merge with column joining its penu git checkout 5_r && git merge --no-ff 5_s -m 5_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 5_H |\ | *-. 5_G
@@ -257,7 +252,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout 6_1 && git merge --no-ff 6_2 -m 6_I && - check_graph 6_1 6_3 6_5 <<-\EOF + lib_test_check_graph 6_1 6_3 6_5 <<-\EOF * 6_I |\ | | * 6_H
@@ -334,7 +329,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout -b M_7 7_1 && git merge --no-ff 7_2 7_3 -m 7_M4 && - check_graph M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -371,7 +366,7 @@ test_expect_success 'log --graph with multiple tips' ' ' test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' ' - check_graph --graph-lane-limit=2 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=2 M_7 <<-\EOF *-. 7_M4 |\ \ | | * 7_G
@@ -388,7 +383,7 @@ test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' ' ' test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge' ' - check_graph --graph-lane-limit=1 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=1 M_7 <<-\EOF *-~ 7_M4 |\~ | ~ 7_G
@@ -405,7 +400,7 @@ test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge ' test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' ' - check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -441,7 +436,7 @@ test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' ' ' test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows first of 3 parent merge' ' - check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -478,7 +473,7 @@ test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows fir ' test_expect_success 'log --graph --graph-lane-limit=7 check if it shows all 3 parent merge' ' - check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
t/t6016-rev-list-graph-simplify-history.sh +10 -15
@@ -13,11 +13,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh -check_graph () { - cat >expect && - lib_test_cmp_graph --format=%s "$@" -} - test_expect_success 'set up rev-list --graph test' ' # 3 commits on branch A test_commit A1 foo.txt &&
@@ -54,7 +49,7 @@ test_expect_success 'set up rev-list --graph test' ' ' test_expect_success '--graph --all' ' - check_graph --all <<-\EOF + lib_test_check_graph --all <<-\EOF * A7 * A6 |\
@@ -82,7 +77,7 @@ test_expect_success '--graph --all' ' # that undecorated merges are interesting, even with --simplify-by-decoration test_expect_success '--graph --simplify-by-decoration' ' git tag -d A4 && - check_graph --all --simplify-by-decoration <<-\EOF + lib_test_check_graph --all --simplify-by-decoration <<-\EOF * A7 * A6 |\
@@ -114,7 +109,7 @@ test_expect_success 'setup: get rid of decorations on B' ' # Graph with branch B simplified away test_expect_success '--graph --simplify-by-decoration prune branch B' ' - check_graph --simplify-by-decoration --all <<-\EOF + lib_test_check_graph --simplify-by-decoration --all <<-\EOF * A7 * A6 |\
@@ -133,7 +128,7 @@ test_expect_success '--graph --simplify-by-decoration prune branch B' ' ' test_expect_success '--graph --full-history -- bar.txt' ' - check_graph --full-history --all -- bar.txt <<-\EOF + lib_test_check_graph --full-history --all -- bar.txt <<-\EOF * A7 * A6 |\
@@ -148,7 +143,7 @@ test_expect_success '--graph --full-history -- bar.txt' ' ' test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' - check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF + lib_test_check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF * A7 * A6 |\
@@ -161,7 +156,7 @@ test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' ' test_expect_success '--graph -- bar.txt' ' - check_graph --all -- bar.txt <<-\EOF + lib_test_check_graph --all -- bar.txt <<-\EOF * A7 * A5 * A3
@@ -172,7 +167,7 @@ test_expect_success '--graph -- bar.txt' ' ' test_expect_success '--graph --sparse -- bar.txt' ' - check_graph --sparse --all -- bar.txt <<-\EOF + lib_test_check_graph --sparse --all -- bar.txt <<-\EOF * A7 * A6 * A5
@@ -189,7 +184,7 @@ test_expect_success '--graph --sparse -- bar.txt' ' ' test_expect_success '--graph ^C4' ' - check_graph --all ^C4 <<-\EOF + lib_test_check_graph --all ^C4 <<-\EOF * A7 * A6 * A5
@@ -202,7 +197,7 @@ test_expect_success '--graph ^C4' ' ' test_expect_success '--graph ^C3' ' - check_graph --all ^C3 <<-\EOF + lib_test_check_graph --all ^C3 <<-\EOF * A7 * A6 |\
@@ -220,7 +215,7 @@ test_expect_success '--graph ^C3' ' # that important, but this test depends on it. If the ordering ever changes # in the code, we'll need to update this test. test_expect_success '--graph --boundary ^C3' ' - check_graph --boundary --all ^C3 <<-\EOF + lib_test_check_graph --boundary --all ^C3 <<-\EOF * A7 * A6 |\
Signature · 1 line
2.54.0
PATCH v5 2/2 graph: indent visual root in graph
In reply to Pablo SabaterWhen rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This happens because the commits fill the space from left to right and when a visual root ends, its column becomes free for the following commit even if they are not related. Once this happens the unrelated commit is rendered below the visual root. Because there is no special character or way to identify when a visual root is rendered making the graph confusing.
By indenting the visual roots when there are still commits to show the vertical adjacency can be avoided.
Add is_visual_root flag to git_graph making it visible in all graph states, give graph_update() a new function, graph_is_visual_root() to know if the current commit is a visual root and set is_visual_root.
The different handled cases are:
- If a visual root has children: similar to GRAPH_PRE_COMMIT state when octopus merges need space, an edge row needs to be printed to connect the child with the indented visual root. A new state GRAPH_PRE_ROOT is needed to connect the child with the visual root:
* child of the visual root
\ GRAPH_PRE_ROOT
* visual root indented
- If a visual root is child-less we can skip GRAPH_PRE_ROOT state and render the indented commit directly.
* visual root indented
* unrelated commit
- If two or more visual roots are adjacent: by having a lookahead to the next commit that will be rendered, if the next commit is also a visual root and we are on a visual root, meaning two visual root adjacent in the history, the top one can omit the indent, making the one below to indent only once, if there are more adjacent visual commits, the indentation will increase for each adjacent one, cascading.
* visual root
* visual root
* visual root
* last commit
Even if the last commit is a root, because there is nothing that will be rendered below we can omit the indentation on purpose.
The lookahead is not completely reliable, on graphs with filtered parents, the walker when processing the current commit it will simplify its parents by removing the ones that won't be shown, (They have the TREESAME flag when filtering by path for example), but it doesn't act for the grandparents or the next commit if it is unrelated until we move to the next.
For example given
A visual root
B child
C parent of B, visual root FILTERED
D last commit
We would expect
A
B
D
When processing A, for the walker and the information at the renderer, B is still a child of C, as B parent, hasn't been removed yet. This makes cascade to not trigger as the lookahead fails to detect if the next commit will be a visual root.
Once at B, its parent has been removed and has become a visual root, and it just adds its indent to the one left by A. We end up with an extra indent:
A
B
D
The output isn't broken as unrelated commits are successfully separated by indentation, but an indent level should have been avoided.
Create a new test file for graph indentations test called 't4218-log-graph-indentation.sh'.
The filtered parents edge case is documented as a NEEDSWORK on the lookahead function and it has its own 'test_expect_failure' at 't4218'.
[1]: https://lore.kernel.org/git/[email protected]/
--- graph.c | 262 ++++++++++++++++++++++ t/meson.build | 1 + t/t4218-log-graph-indentation.sh | 467 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 730 insertions(+)
graph.c +262 -0
@@ -60,12 +60,23 @@ struct column {* index into column_colors. */ unsigned short color; +/* +* Marks if a commit is a non-first parent of a merge. These columns are +* already visually connected to the merge commit and do not need +* indentation. +* +* The first parent is the one that inherits the column and it can need +* indentation if turns out to be a visual root and there's still +* commits to render. +*/ + unsigned is_merge_parent:1; };enum graph_state {GRAPH_PADDING ,GRAPH_SKIP ,GRAPH_PRE_COMMIT , +GRAPH_PRE_ROOT ,GRAPH_COMMIT ,GRAPH_POST_MERGE ,GRAPH_COLLAPSING
@@ -315,6 +326,48 @@ struct git_graph {* diff_output_prefix_callback(). */ struct strbuf prefix_buf; + +/* +* If a commit is a visual root, we need to indent it to prevent +* unrelated commits from being vertically adjacent to it. +*/ + unsigned is_visual_root:1; + +/* +* Indentation increases for each visual root adjacent to another visual +* root, making visual root commits indentation cascade. +*/ +unsigned int visual_root_depth; + +/* +* When a visual root is adjacent to other visual roots, the first one +* can avoid indentation and the rest cascades, increasing the indentation +* for each one. +*/ + unsigned visual_root_cascade:1; + +/* +* Set when the current commit was already present in graph->columns +* before being processed. +*/ + unsigned commit_in_columns:1; +}; + +struct graph_lookahead_flags { +/* +* Set when there will be a commit after the current one that will be +* rendered. +*/ +unsigned int is_next_visible:1 ; +/* +* Set when the next visible commit is candidate to be a visual root. +*/ +unsigned int is_next_visual_root:1 ; +/* +* Set when the next visible commit will be rendered under the current +* commit. +*/ +unsigned int next_has_column:1 ; };static inline int graph_needs_truncation (struct git_graph *graph,int lane)
@@ -388,6 +441,8 @@ struct git_graph *graph_init(struct rev_info *opt) graph->num_columns =0 ; graph->num_new_columns =0 ; graph->mapping_size =0 ; + graph->visual_root_depth =0 ; + graph->visual_root_cascade =0 ;/* * Start the column color at the maximum value, since we'll * always increment it for the first commit we output.
@@ -561,6 +616,11 @@ static void graph_insert_into_new_columns(struct git_graph *graph, struct commit *commit, int idx) { +/* +* Get the initial merge_layout before it's modified to know if this +* is a merge. +*/ +int initial_merge_layout = graph->merge_layout;int i =graph_find_new_column_by_commit (graph, commit);int mapping_idx;
@@ -572,6 +632,7 @@ static void graph_insert_into_new_columns(struct git_graph *graph, i = graph->num_new_columns++; graph->new_columns[i].commit = commit; graph->new_columns[i].color =graph_find_commit_color (graph, commit); + graph->new_columns[i].is_merge_parent =0 ; }if (graph->num_parents >1 && idx >-1 && graph->merge_layout ==-1 ) {
@@ -610,6 +671,12 @@ static void graph_insert_into_new_columns(struct git_graph *graph, } graph->mapping[mapping_idx] = i; + +/* +* Mark non-first parents of a merge. +*/ +if (graph->num_parents >1 && initial_merge_layout >=0 && idx >-1 ) + graph->new_columns[i].is_merge_parent =1 ; }static void graph_update_columns (struct git_graph *graph)
@@ -701,10 +768,20 @@ static void graph_update_columns(struct git_graph *graph)if (graph->num_parents ==0 ) graph->width +=2 ; }else { +int j;graph_insert_into_new_columns (graph, col_commit,-1 ); +/* +* This column is not the current commit, but we need to +* propagate the flag until the commit is processed. +*/ + j =graph_find_new_column_by_commit (graph, col_commit); +if (j >=0 && graph->columns[i].is_merge_parent) + graph->new_columns[j].is_merge_parent =1 ; } } + graph->commit_in_columns = is_commit_in_columns; +/* * If graph_max_lanes is set, cap the width */
@@ -763,9 +840,135 @@ static int graph_needs_pre_commit_line(struct git_graph *graph) graph->expansion_row <graph_num_expansion_rows (graph); } +/* +* A commit can be a visual root when: +* - It has no parents. +* +* - It has parents but they are all filtered out and +* commit->parents arrives NULL. +* +* - It is not a boundary commit. Boundary commits also have no visible +* parents, but they are not selected as visual roots because they cannot +*. cause the ambiguity of being vertically adjacent because: +* +* 1. A boundary only appears because an included commit is its child. +* Children are always above, and the renderer draws an edge down to +* the boundary from that child. Rather than starting a column like a +* visual root would do, it inherits its child column. +* +* 2. Included commits cannot appear below a boundary. Boundaries are +* ancestors of the exclusion point; if an included commit were an +* ancestor of the boundary it would be excluded and not rendered. +* Boundaries therefore always sink to the bottom. +*/ +static int graph_is_visual_root_candidate (struct commit *c) +{ +return c->parents ==NULL && !(c->object.flags &BOUNDARY ); +} + +static int graph_is_visual_root (struct git_graph *graph, +struct graph_lookahead_flags *flags) +{ +/* +* This must be only called for the current commit as graph contains +* the state for the current commit only. +* +* To check if a commit is a visual root, call graph_is_visual_root_candidate() +* but we won't know if it is really a visual root until we get to the +* next commit state. +* +* The current commit is an actual visual root if it is a candidate and +* the commit is not a non-first parent of a merge. +* +* * +* |\ +* | * <- it is a visual root candidate but it shouldn't be indented +* * because it is already connected by an edge. +* ^ if commit_in_columns && is_merge_parent means the commit +* | was put by a merge and is connected. +* | +* `-------- if !is_next_visible means we're on the last commit, avoid +* indentation unless the one before is a visual root, then +* we need to differentiate from the one above. +* +* If next_has_columns means that the next commit has +* already a column, so it will not be rendered below, the +* current commit has to act as the last commit and omit +* indentation. +*/ +return graph_is_visual_root_candidate (graph->commit) && + !(graph->commit_in_columns && + graph->columns[graph->commit_index].is_merge_parent) && + flags->is_next_visible && + (!flags->next_has_column || graph->visual_root_depth >0 ); +} + +/* +* Iterates the commits queue searching for the next visible commit, once found +* sets visibleness and visual-root flags. +* Knowing if the next commit is also a visual root avoids redundant indentations +* +* NEEDSWORK: The queue is actively being modified by the walker, for each commit +* its parents and itself get simplified and their flags set, but for the next +* unrelated commit or the grandparents they are not simplified yet, which means +* that a commit whose parents are all filtered will not be marked as a visual +* root candidate at the lookahead. +* This causes the lookahead to fail, failing to set the cascade flag to avoid +* redundant indentations. +* See 'test_expect_failure' at t4218-log-graph-indentation.sh. +*/ +static void graph_peek_next_visible (struct git_graph *graph, +struct graph_lookahead_flags *flags) +{ +struct commit_list *cl; + + flags->is_next_visible =0 ; + flags->is_next_visual_root =0 ; + flags->next_has_column =0 ; + +for (cl = graph->revs->commits; cl; cl = cl->next) { +if (get_commit_action (graph->revs, cl->item) != commit_show) +continue ; + flags->is_next_visible =1 ; + flags->next_has_column =graph_find_new_column_by_commit (graph, cl->item) >=0 ; +/* +* We do not need graph->commit_in_columns or is_merge_parent, +* because we only need to know whether the next one might be a +* visual root, affecting the current commit where the cascade +* would have to be set and the first visual root not indented. +* +* It will set next_is_visual_root to true for merge parents that +* graph_is_visual_root() would return false, but if the next is +* a merge parent, the current commit is the child and cannot +* be a visual root and therefore having no effect. +*/ +if (!graph_is_visual_root_candidate (cl->item)) +return ; + +/* +* The next visible commit is a visual root candidate, but +* only set cascade if it's not the last commit to be rendered. +*/ +for (cl = cl->next; cl; cl = cl->next) { +if (get_commit_action (graph->revs, cl->item) != commit_show) +continue ; + flags->is_next_visual_root =1 ; +return ; + } +return ; + } +} + +static int graph_needs_pre_root_line (struct git_graph *graph) +{ +return graph->commit_in_columns && graph->is_visual_root && + graph->num_columns >0 && !graph->visual_root_cascade; +} +void graph_update (struct git_graph *graph,struct commit *commit) {struct commit_list *parent; +struct graph_lookahead_flags flags;/* * Set the new commit
@@ -796,6 +999,23 @@ void graph_update(struct git_graph *graph, struct commit *commit)*/ graph_update_columns (graph); +graph_peek_next_visible (graph, &flags); + + graph->is_visual_root =graph_is_visual_root (graph, &flags); + +if (graph->is_visual_root) { +/* +* If next is a visual root we can omit the indent for the first +* visual root and start cascading. +*/ +if (!graph->visual_root_depth && flags.is_next_visual_root) + graph->visual_root_cascade =1 ; + graph->visual_root_depth++; + }else { + graph->visual_root_depth =0 ; + graph->visual_root_cascade =0 ; + } + graph->expansion_row =0 ;/*
@@ -813,11 +1033,16 @@ void graph_update(struct git_graph *graph, struct commit *commit)* room for it. We need to do this only if there is a branch row * (or more) to the right of this commit. * +* If it is a visual root, we need to print an extra row to +* connect the indentation. +* * If there are less than 3 parents, we can immediately print the * commit line. */ if (graph->state !=GRAPH_PADDING ) graph->state =GRAPH_SKIP ; +else if (graph_needs_pre_root_line (graph)) + graph->state =GRAPH_PRE_ROOT ;else if (graph_needs_pre_commit_line (graph)) graph->state =GRAPH_PRE_COMMIT ;else
@@ -1065,6 +1290,17 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_lineif (col_commit == graph->commit) { seen_this =1 ; +if (graph->is_visual_root) { +int depth = graph->visual_root_depth; +/* +* Each visual column is 2 characters wide. +* Omit the indentation for the first visual +* root in cascade mode. +*/ +int padding = (depth - graph->visual_root_cascade) *2 ; +graph_line_addchars (line,' ' , padding); + graph->width += padding; + }graph_output_commit_char (graph, line);if (graph_needs_truncation (graph, i)) {
@@ -1436,6 +1672,29 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_lgraph_update_state (graph,GRAPH_PADDING ); } +static void graph_output_pre_root_line (struct git_graph *graph,struct graph_line *line) +{ +/* +* This function adds a row before a visual root, to connect the +* branch to the indented commit. It should only be called on a +* visual root. +*/ +assert (graph->is_visual_root); + +for (size_t i =0 ; i < graph->num_columns; i++) { +struct column *col = &graph->columns[i]; +if (col->commit == graph->commit) { +graph_line_addch (line,' ' ); +graph_line_write_column (line, col,'\\' ); + }else { +graph_line_write_column (line, col,'|' ); + } +graph_line_addch (line,' ' ); + } + +graph_update_state (graph,GRAPH_COMMIT ); +} +int graph_next_line (struct git_graph *graph,struct strbuf *sb) {int shown_commit_line =0 ;
@@ -1461,6 +1720,9 @@ int graph_next_line(struct git_graph *graph, struct strbuf *sb)case GRAPH_PRE_COMMIT :graph_output_pre_commit_line (graph, &line);break ; +case GRAPH_PRE_ROOT : +graph_output_pre_root_line (graph, &line); +break ;case GRAPH_COMMIT :graph_output_commit_line (graph, &line); shown_commit_line =1 ;
t/meson.build +1 -0
@@ -576,6 +576,7 @@ integration_tests = [ 't4215-log-skewed-merges.sh', 't4216-log-bloom.sh', 't4217-log-limit.sh', + 't4218-log-graph-indentation.sh', 't4252-am-options.sh', 't4253-am-keep-cr-dos.sh', 't4254-am-corrupt.sh',
t/t4218-log-graph-indentation.sh new file +467 -0
467 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v5 2/2] graph: indent visual root in graph
Pablo Sabater <[email protected]> writes:
[jc: Taylor CC'ed for his expertise and opinion on the quoted part that mucks with commit-graph files during the test]
Quoted 6 lines
t/t4218-log-graph-indentation.sh new file +0
-0
t/t4218-log-graph-indentation.sh line 25
Quoted 10 lines
t/t4218-log-graph-indentation.sh new file +9
-0@@ -0,0 +1,467 @@ +#!/bin/sh +# disable commit-graph topo order to have the graph to render in different +# ways (used in --first-parent tests to have multiple visual roots while a +# column is active at the same time). +unset_commit_graph() { + sane_unset GIT_TEST_COMMIT_GRAPH && + rm -f .git/objects/info/commit-graph && + rm -rf .git/objects/info/commit-graphs +}
I do not quite understand why having commit-graph makes the test result unpredictable here, but wouldn't we have a more stable way to disable use of commit-graph than going into filesystem and muck with the implementation detail like the above?
Thanks.
Re: [PATCH v5 2/2] graph: indent visual root in graph
Quoted 28 lines · Junio C Hamano
Pablo Sabater <[email protected]> writes:
[jc: Taylor CC'ed for his expertise and opinion on the quoted part that mucks with commit-graph files during the test]
Quoted 6 lines
t/t4218-log-graph-indentation.sh new file +0
-0t/t4218-log-graph-indentation.sh line 25
Quoted 10 lines
t/t4218-log-graph-indentation.sh new file +9
-0@@ -0,0 +1,467 @@ +#!/bin/sh +# disable commit-graph topo order to have the graph to render in different +# ways (used in --first-parent tests to have multiple visual roots while a +# column is active at the same time). +unset_commit_graph() { + sane_unset GIT_TEST_COMMIT_GRAPH && + rm -f .git/objects/info/commit-graph && + rm -rf .git/objects/info/commit-graphs +}I do not quite understand why having commit-graph makes the test result unpredictable here, but wouldn't we have a more stable way to disable use of commit-graph than going into filesystem and muck with the implementation detail like the above?
Quoted 1 line
Thanks.
Hi!
It does not make it unpredictable but it makes it not output what I wanted to test, what I wanted to test is having an active column at the same time that visual roots in different cases were being rendered on another column. However having GIT_TEST_COMMIT_GRAPH in the last text for example changes from:
* 41_octopus
| * 43_B | \ | * 43_A | * 42_B | * 42_A
* 41_B
* 41_A
to:
* 41_octopus
* 41_B
\
* 41_A
* 43_B
\
* 43_A
* 42_B
* 42_A
While the output it's ok and the indentation works the excluded but forced to be rendered parents are not being rendered at the same time as an active column is.
On the unset_commit_graph function I had to remove those files because even if it is GIT_TEST_COMMIT_GRAPH unset if there are files from previous tests they still change the output.
Maybe there is a way to get this more cleanly but from what I tried it didn't work as I wanted, sorry.
Thanks,
Pablo.
Re: [PATCH v5 2/2] graph: indent visual root in graph
Quoted 4 lines · Pablo Sabater
It does not make it unpredictable but it makes it not output what I wanted to test, what I wanted to test is having an active column at the same time that visual roots in different cases were being rendered on another column.
Oh, use of commit-graph changes the traversal order, which would affect how the graph is drawn, and there is no way to ensure that we traverse in the same way with or without commit-graph? That's inconvenient. But even without commit-graph, do we guarantee the same traversal order forever? I doubt it. So I suspect that it is a brittle workaround to disable commit-graph in the longer term.
As long as the graph engine shows correct graph no matter what order the commits come out of the revision traversal engine, we won't hurt end-users, but we need our tests to be reproducible, so that is a bit unfortunate.
Anyway, stepping back a bit,
Quoted 11 lines
However having
GIT_TEST_COMMIT_GRAPHin the last
text for example changes from:* 41_octopus
| * 43_B | \ | * 43_A | * 42_B | * 42_A* 41_B
* 41_A
Does the "vertically aligned * on 2nd and later columns do not mean any parent-child relationship" rule no longer apply in this version? IOW, does the above graph show that
- 41_A is a parent of 41_B, which is a parent of 41_octopus
- 42_A is a parent of 42_B, and
- 43_A is a parent of 43_B but is not related to 42_B
? Who are the parents of 41_octopus? It has no relationship with 42_B and 43_B, and unlike what its name suggests, it has only 41_b as its parent (probably with history simplification that makes only these commits shown)?
Quoted 11 lines
to:
* 41_octopus
* 41_B
\
* 41_A
* 43_B
\
* 43_A
* 42_B
* 42_A
And this graph shows the same inter-commit relationship. So both are correctly showing what we want to express, but they show the same information differently, making test_cmp unhappy?
Thanks.
Re: [PATCH v5 2/2] graph: indent visual root in graph
Quoted 8 lines · Junio C Hamano
Quoted 4 lines · Pablo Sabater
It does not make it unpredictable but it makes it not output what I wanted to test, what I wanted to test is having an active column at the same time that visual roots in different cases were being rendered on another column.
Quoted 6 lines
Oh, use of commit-graph changes the traversal order, which would affect how the graph is drawn, and there is no way to ensure that we traverse in the same way with or without commit-graph? That's inconvenient. But even without commit-graph, do we guarantee the same traversal order forever? I doubt it. So I suspect that it is a brittle workaround to disable commit-graph in the longer term.
Hi!
About the traversal order, aren't all the graph tests dependent on the traversal order? If it changed they would all need to be updated because the tests are hardcoded expects of the graph.
I guess it might be more brittle than other graph tests specially because it also depends on removing files, I tried using "git config core.commitGraph false" or "--date-order" but I still get different results and removing the files fixed it. If someone knows a better way of doing it I'm happy to change it.
Quoted 20 lines
As long as the graph engine shows correct graph no matter what order the commits come out of the revision traversal engine, we won't hurt end-users, but we need our tests to be reproducible, so that is a bit unfortunate.
Anyway, stepping back a bit,
Quoted 11 lines
However having
GIT_TEST_COMMIT_GRAPHin the last
text for example changes from:* 41_octopus
| * 43_B | \ | * 43_A | * 42_B | * 42_A* 41_B
* 41_A
Quoted 7 lines
Does the "vertically aligned * on 2nd and later columns do not mean any parent-child relationship" rule no longer apply in this version? IOW, does the above graph show that
- 41_A is a parent of 41_B, which is a parent of 41_octopus
- 42_A is a parent of 42_B, and
- 43_A is a parent of 43_B but is not related to 42_B
Yes, this means that all commits vertically adjacent are related, those who are not related and can cause that ambiguity get indented (43_A).
Quoted 5 lines
? Who are the parents of 41_octopus? It has no relationship with 42_B and 43_B, and unlike what its name suggests, it has only 41_b as its parent (probably with history simplification that makes only these commits shown)?
On this test we are using "--first-parent" which excludes all the parents but the first one, but later we force its excluded parents to be shown.
We exclude 42_* and 43_* branches and then force them to appear as unrelated branches.
Quoted 13 lines
Quoted 12 lines
to:
* 41_octopus
* 41_B
\
* 41_A
* 43_B
\
* 43_A
* 42_B
* 42_A
Quoted 3 lines
And this graph shows the same inter-commit relationship. So both are correctly showing what we want to express, but they show the same information differently, making
test_cmpunhappy?
Yes they show the same information. On the second graph every commit is on the first column (or second if they get indented) but on the first graph we have:
*
| * <- visual root on second column
^
`----- first column remains active
If you tested v3 with this case you would see that it assumes that visual roots only happen to be rendered on the first column, therefore failing to correctly indent those visual roots on the second column, which this test proves that they can appear on other columns.
Back to the test:
* 41_octopus
| * 43_B | \ | * 43_A | * 42_B | * 42_A
* 41_B
* 41_A
43_A is rendered on the second column (first column is active by the 41_* branch) and gets indented to the third one. With commit-graph it would be on the first and get indented to the second, making it the same as more general tests above in "t4218", it is an edge case but shows that indentation works correctly independently where the visual root is.
Quoted 2 lines
Thanks.
Thanks,
Pablo
Re: [PATCH v5 2/2] graph: indent visual root in graph
Quoted 11 lines · Pablo Sabater
Back to the test:
* 41_octopus
| * 43_B | \ | * 43_A | * 42_B | * 42_A* 41_B
* 41_A
Quoted 6 lines
43_A is rendered on the second column (first column is active by the 41_* branch) and gets indented to the third one. With commit-graph it would be on the first and get indented to the second, making it the same as more general tests above in "t4218", it is an edge case but shows that indentation works correctly independently where the visual root is.
Sounds good.
Re: [PATCH v5 2/2] graph: indent visual root in graph
In reply to Pablo SabaterQuoted 17 lines · Pablo Sabater
(quoted diff) +17
-0+/* + * Iterates the commits queue searching for the next visible commit, once found + * sets visibleness and visual-root flags. + * Knowing if the next commit is also a visual root avoids redundant indentations + * + * NEEDSWORK: The queue is actively being modified by the walker, for each commit + * its parents and itself get simplified and their flags set, but for the next + * unrelated commit or the grandparents they are not simplified yet, which means + * that a commit whose parents are all filtered will not be marked as a visual + * root candidate at the lookahead. + * This causes the lookahead to fail, failing to set the cascade flag to avoid + * redundant indentations. + * See 'test_expect_failure' at t4218-log-graph-indentation.sh. + */ +static void graph_peek_next_visible(struct git_graph *graph, + struct graph_lookahead_flags *flags) +{
Review
Quoted 10 lines
(quoted diff) +9
-0+ struct commit_list *cl; + + flags->is_next_visible = 0; + flags->is_next_visual_root = 0; + flags->next_has_column = 0; + + for (cl = graph->revs->commits; cl; cl = cl->next) { + if (get_commit_action(graph->revs, cl->item) != commit_show) + continue;
I have a feeling this may interact badly with the prio-queue introduced by dd4bc01c0a (revision: use priority queue for non-limited streaming walks, 2026-05-27). In that commit, get_revision_1() sucks all of the commits from revs->commits into revs->commit_queue, and then traversal puts the parents into that queue, not the commits list.
So during the traversal, revs->commits does not hold the complete queue anymore. I think it does see _some_ commits, since some get placed directly into revs->commits and then later moved next time get_revision() is called. But if we instrument the code like this:
graph.c +4 -0
@@ -926,6 +926,10 @@ static void graph_peek_next_visible(struct git_graph *graph, flags->is_next_visual_root =0 ; flags->next_has_column =0 ; +warning ("peeking at visible commits: %d in list, %d in queue" , +commit_list_count (graph->revs->commits), + (int )graph->revs->commit_queue.nr); +for (cl = graph->revs->commits; cl; cl = cl->next) {if (get_commit_action (graph->revs, cl->item) != commit_show)continue ;
and run something like:
./git log --graph --oneline -- Makefile
we can see that we're always considering just one commit, while there may be dozens or hundreds in the queue.
I'm not sure what the solution is. This function wants to peek ahead in queue order, possibly through multiple entries. But a heap-based queue inherently only supports peeking at the first entry.
None of the tests seem to fail, but I'm not sure if that's because I'm way off base in my analysis, or there's a gap in the test coverage, or if this case is part of the expect_failure ones mentioned in the comment.
I noticed because I have another topic which drops the revs->commits list entirely (and just always uses the queue), which of course doesn't compile when merged with this (I merge with 'jch' for my daily driver, which now includes this patch).
-Peff
Re: [PATCH v5 2/2] graph: indent visual root in graph
Quoted 60 lines · Jeff King
Quoted 17 lines · Pablo Sabater
(quoted diff) +17
-0+/* + * Iterates the commits queue searching for the next visible commit, once found + * sets visibleness and visual-root flags. + * Knowing if the next commit is also a visual root avoids redundant indentations + * + * NEEDSWORK: The queue is actively being modified by the walker, for each commit + * its parents and itself get simplified and their flags set, but for the next + * unrelated commit or the grandparents they are not simplified yet, which means + * that a commit whose parents are all filtered will not be marked as a visual + * root candidate at the lookahead. + * This causes the lookahead to fail, failing to set the cascade flag to avoid + * redundant indentations. + * See 'test_expect_failure' at t4218-log-graph-indentation.sh. + */ +static void graph_peek_next_visible(struct git_graph *graph, + struct graph_lookahead_flags *flags) +{Review
Quoted 10 lines
(quoted diff) +9
-0+ struct commit_list *cl; + + flags->is_next_visible = 0; + flags->is_next_visual_root = 0; + flags->next_has_column = 0; + + for (cl = graph->revs->commits; cl; cl = cl->next) { + if (get_commit_action(graph->revs, cl->item) != commit_show) + continue;I have a feeling this may interact badly with the prio-queue introduced by
dd4bc01c0a(revision: use priority queue for non-limited streaming walks, 2026-05-27). In that commit,get_revision_1()sucks all of the commits fromrevs->commitsintorevs->commit_queue, and then traversal puts the parents into that queue, not the commits list.So during the traversal,
revs->commitsdoes not hold the complete queue anymore. I think it does see _some_ commits, since some get placed directly intorevs->commitsand then later moved next timeget_revision()is called. But if we instrument the code like this:graph.c +4
-0@@ -926,6 +926,10 @@ static void graph_peek_next_visible(struct git_graph *graph, flags->is_next_visual_root =0 ; flags->next_has_column =0 ; +warning ("peeking at visible commits: %d in list, %d in queue" , +commit_list_count (graph->revs->commits), + (int )graph->revs->commit_queue.nr); +for (cl = graph->revs->commits; cl; cl = cl->next) {if (get_commit_action (graph->revs, cl->item) != commit_show)continue ;and run something like:
Quoted 8 lines
./git log --graph --oneline -- Makefilewe can see that we're always considering just one commit, while there may be dozens or hundreds in the queue.
I'm not sure what the solution is. This function wants to peek ahead in queue order, possibly through multiple entries. But a heap-based queue inherently only supports peeking at the first entry.
Hi Jeff!
Yeah, I haven't read dd4bc01c0a yet but from what you say it prob won't work anymore, I didn't know about that series, about the lookahead I think it could still work with some tweaks, the important part is to set the three lookahead flags.
From what I understood, we can only get the direct next commit, but no more reliably ordered.
The flags should be fine:
- 'is_next_visible' could need to traverse multiple entries, but it doesn't need them to be in order. We just need to know if something will be rendered after.
- 'next_has_column' only needs the first entry.
- 'is_next_visual_root' only needs the first entry to know if it could be a visual root, and also if it is not the last one (but we don't need them to be ordered for this last part).
Should I work with 'next' as a base to have dd4bc01c0a? (Sorry I've just worked with master).
I'll try to make it work but if not, the lookahead works to avoid _redundant_ indentations, but it would still work correctly without it.
Quoted 6 lines
None of the tests seem to fail, but I'm not sure if that's because I'm way off base in my analysis, or there's a gap in the test coverage, or if this case is part of the
expect_failureones mentioned in the comment.
Quoted 6 lines
I noticed because I have another topic which drops the
revs->commitslist entirely (and just always uses the queue), which of course doesn't compile when merged with this (I merge with 'jch' for my daily driver, which now includes this patch).-Peff
Thanks,
Pablo
Re: [PATCH v5 2/2] graph: indent visual root in graph
Quoted 2 lines · Pablo Sabater
Should I work with 'next' as a base to have
dd4bc01c0a? (Sorry I've just worked with master).
As dd4bc01c (revision: use priority queue for non-limited streaming walks, 2026-05-27) is already in 'master', you should be able to work with 'master' that is no stale than 6e148f82 (Merge branch 'kk/streaming-walk-pqueue', 2026-06-16).
Re: [PATCH v5 2/2] graph: indent visual root in graph
In reply to Pablo SabaterQuoted 4 lines · Pablo Sabater
Quoted 3 lines
Quoted 3 lines
(quoted diff) +3
-0+ for (cl = graph->revs->commits; cl; cl = cl->next) { + if (get_commit_action(graph->revs, cl->item) != commit_show) + continue;[...]
Quoted 8 lines
Quoted 3 lines
I'm not sure what the solution is. This function wants to peek ahead in queue order, possibly through multiple entries. But a heap-based queue inherently only supports peeking at the first entry.
Yeah, I haven't read
dd4bc01c0ayet but from what you say it prob won't work anymore, I didn't know about that series, about the lookahead I think it could still work with some tweaks, the important part is to set the three lookahead flags.
Thanks for looking into it. I meant to also cc the Kristofer, the author of dd4bc01c0a, for any thoughts (adding him now).
Quoted 2 lines
From what I understood, we can only get the direct next commit, but no more reliably ordered.
Right. There are other queue implementations that could allow full in-order traversal (e.g., a binary tree), but our prio_queue does not. I suspect performance for other cases would suffer if we switched the underlying data structure.
Quoted 5 lines
The flags should be fine:
- '
is_next_visible' could need to traverse multiple entries, but it doesn't need them to be in order. We just need to know if something will be rendered after.
Yeah, this one seems easy. We are just setting a bit based on whether we'd find any commit to show. So order doesn't matter.
Quoted 1 line
- '
next_has_column' only needs the first entry.
But this was the one I was worried about. Walking the linked list in order will find us the next commit we're going to show, and the result of the flag depends on graph_find_new_column_by_commit(). Is it OK to find _any_ such commit?
(I'm looking at this purely based on reading the existing code, and haven't really thought hard about the problem space).
Quoted 3 lines
- '
is_next_visual_root' only needs the first entry to know if it could be a visual root, and also if it is not the last one (but we don't need them to be ordered for this last part).
This one just iterates looking for any other commit we'll show after the next one. So finding any two entries would be equivalent to the current code (though we only get to this loop if the first one passes the test for graph_is_visual_root_candidate).
So if you say order doesn't matter for checking the column and the visual-root-candidate function, I'm happy to believe you. It makes life much easier. :)
Quoted 2 lines
Should I work with 'next' as a base to have
dd4bc01c0a? (Sorry I've just worked with master).
As Junio noted, that's already in master, so I think you're OK to just base there.
But for future reference, no, you probably don't want to build off of 'next'. If your commit has a dependency on another topic it is best to build directly off of that topic (and note it in the cover letter of the series). That way you do not accidentally depend on other things in 'next' which might not ever make it to 'master' (and would thus hold your topic hostage).
-Peff
Re: [PATCH v5 2/2] graph: indent visual root in graph
Quoted 7 lines · Jeff King
Quoted 2 lines
From what I understood, we can only get the direct next commit, but no more reliably ordered.
Right. There are other queue implementations that could allow full in-order traversal (e.g., a binary tree), but our
prio_queuedoes not. I suspect performance for other cases would suffer if we switched the underlying data structure.
BTW, there's one extra trick here in the iteration: you might see commits in _both_ revs->commits and revs->commit_queue. So you'll have to iterate over both of them (and I guess push the loop body into a function to avoid duplication).
We may eventually settle on having just one queue sturcture, but I think dd4bc01c0a used that to avoid disrupting existing callers.
-Peff
Re: [PATCH v5 2/2] graph: indent visual root in graph
In reply to Jeff KingQuoted 4 lines · Jeff King
Thanks for looking into it. I meant to also cc the Kristofer, the author of
dd4bc01c0a, for any thoughts (adding him now).
Thanks for the CC. I took a look at how this interacts with my change.
dd4bc01c0a doesn't hurt here I think, but future followup changes might. From what I can tell --graph triggers topo_order, so the walk mode is either REV_WALK_TOPO or REV_WALK_LIMITED and the prio_queue change only applies to REV_WALK_STREAMING.
That said, graph_peek_next_visible() reaching directly into revs->commits feels fragile -- especially if we drop revs->commits in the future. One option would be to add a thin abstraction in revision.c that dispatches per walk mode, something like:
int revision_has_more_commits(struct rev_info *revs)
{
if (revs->topo_walk_info)
return revs->topo_walk_info->topo_queue.nr > 0;
return revs->commits != NULL;
}
struct commit *revision_peek_next_commit(struct rev_info *revs)
{
if (revs->topo_walk_info)
return prio_queue_peek(&revs->topo_walk_info->topo_queue);
if (revs->commits)
return revs->commits->item;
return NULL;
}That way graph.c does not need to know which data structure the walker uses, and if the internals change later the API adapts in one place.
This would perhaps be an intermediate safety net -- once we have fully rolled it out, those functions could be removed again.
As for the multi-element peek question, I think I would either opt for draining into a buffer if it's really needed, though when looking at the code here I think multi-element peeking is not truly needed. It seems like the logic just checks if there is at least another element after the peek, but it does not try to read the actual value, so we can just check the queue size instead.
Thanks,
Kristofer
Re: [PATCH v5 2/2] graph: indent visual root in graph
Quoted 6 lines · Kristofer Karlsson
Quoted 4 lines · Jeff King
Thanks for looking into it. I meant to also cc the Kristofer, the author of
dd4bc01c0a, for any thoughts (adding him now).
Quoted 7 lines
Thanks for the CC. I took a look at how this interacts with my change.
dd4bc01c0adoesn't hurt here I think, but future followup changes might. From what I can tell --graph triggerstopo_order, so the walk mode is eitherREV_WALK_TOPOorREV_WALK_LIMITEDand theprio_queuechange only applies toREV_WALK_STREAMING.
I'm not so sure. If I merge 53967f242a (graph: indent visual root in graph, 2026-06-13) into master (so that it has both your commit_queue changes and Pablo's topic), and then apply this:
graph.c +4 -0
@@ -926,6 +926,10 @@ static void graph_peek_next_visible(struct git_graph *graph, flags->is_next_visual_root =0 ; flags->next_has_column =0 ; +warning ("peeking at visible commits: %d in list, %d in queue" , +commit_list_count (graph->revs->commits), + (int )graph->revs->commit_queue.nr); +for (cl = graph->revs->commits; cl; cl = cl->next) {if (get_commit_action (graph->revs, cl->item) != commit_show)continue ;
and run:
./git log --graph -- Makefile
then we always see exactly one commit in the list, but an ever-increasing number in the queue (up to ~4000). We do seem to be in REV_WALK_TOPO mode, so I think we'd never return the commits via get_revision(), but it is weird that we are sticking them in the queue at all.
Looks like that happens via rewrite_parents(), which always writes into commit_queue. I guess it doesn't matter because in topo mode we are always pulling off of the topo_walk_info queue anyway? It does make me wonder if there is a lurking bug around history simplification and --topo-order, though.
Quoted 21 lines
That said,
graph_peek_next_visible()reaching directly intorevs->commitsfeels fragile -- especially if we droprevs->commitsin the future. One option would be to add a thin abstraction inrevision.cthat dispatches per walk mode, something like:int revision_has_more_commits(struct rev_info *revs) { if (revs->topo_walk_info) return revs->topo_walk_info->topo_queue.nr > 0; return revs->commits != NULL; } struct commit *revision_peek_next_commit(struct rev_info *revs) { if (revs->topo_walk_info) return prio_queue_peek(&revs->topo_walk_info->topo_queue); if (revs->commits) return revs->commits->item; return NULL; }
Quoted 3 lines
That way
graph.cdoes not need to know which data structure the walker uses, and if the internals change later the API adapts in one place.
Yeah, I agree some abstraction would help. I think it would have to be full iteration, though; the graph code wants to know if there is any commit that is actually going to be shown, not just a potential single next one. So we at least need to be able to iterate in arbitrary order.
Quoted 6 lines
As for the multi-element peek question, I think I would either opt for draining into a buffer if it's really needed, though when looking at the code here I think multi-element peeking is not truly needed. It seems like the logic just checks if there is at least another element after the peek, but it does not try to read the actual value, so we can just check the queue size instead.
We do look at some characteristics of the commit we find by peeking, but I'm not sure how much it matters if we get the _next_ commit that will be shown, or if any arbitrary commit is OK.
-Peff
Re: [PATCH v5 2/2] graph: indent visual root in graph
Quoted 5 lines · Jeff King
Looks like that happens via
rewrite_parents(), which always writes intocommit_queue. I guess it doesn't matter because in topo mode we are always pulling off of thetopo_walk_infoqueue anyway? It does make me wonder if there is a lurking bug around history simplification and --topo-order, though.
Thanks for the analysis. You are right that rewrite_one() leaks parents into commit_queue that are never consumed in topo mode. I have not explored the graph code very much, so I cannot say how this affects the lookahead.
I am thinking that revs->commits is somewhat multi-purpose -- it serves as initial tips, work queue, topo sort buffer, boundary staging, and reverse output buffer depending on mode and phase. Now that we have two representations (commits and commit_queue) it is both multi-purpose and unclear which one to use. That is not a great situation.
I originally just set out to optimize the prio queue usage and speed up expensive walks, but I think I also need to be a good citizen and help clean up some of the mess that comes with having two separate containers (I am not sure exactly how yet - maybe even adding _more containers but with more semantically clear purpose).
Quoted 10 lines
Quoted 6 lines
As for the multi-element peek question, I think I would either opt for draining into a buffer if it's really needed, though when looking at the code here I think multi-element peeking is not truly needed. It seems like the logic just checks if there is at least another element after the peek, but it does not try to read the actual value, so we can just check the queue size instead.
We do look at some characteristics of the commit we find by peeking, but I'm not sure how much it matters if we get the _next_ commit that will be shown, or if any arbitrary commit is OK.
I am not sure if arbitrary order is valid - I think simply having an intermediate buffer where the filtering has been applied would be sufficient. I think the peeking approach is wrong - peeking into the second element doesn't work since after processing the first element the second element could have changed. I prototyped something locally that uses
a lookahead buffer instead and it seems to work and then we don't need to manually filter on get_commit_action - get_revision_internal will apply the right filtering. Will reply with that finding in the right place though.
Thanks,
Kristofer
Re: [PATCH v5 0/2] graph: indent visual roots in graph
In reply to Pablo SabaterQuoted 65 lines · Pablo Sabater
When rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This series adds indentation to the visual root commits, so they cannot be vertically adjacent anymore making it easier to identify them.
before indentation:
* A
* B1
* B2
* C1
* C2after indentation:
* A
* B1
\
* B2
* C1
* C2Indents the visual root commits that have still commits to show after them, and if they have children it connects them with an edge at a new row.
If there are multiple visual roots adjacent in history, the indentation starts with the second one, avoiding redundant indentation of the first one and cascades after the second.
* A
* B
* C
* D1
* D2This series first commit is a cleanup that brings a common function from t4215 and t6016 to a graph functions file which they both use, so the new test file for indentation, t4218, can use it as well.
The lookahead used to set the cascading and avoid extra indentation is not completely reliable, as the walker goes through the commits it simplifies the history of the current commit and its parents, but it doesn't simplify it for the next unrelated or the grandparents. When the walker simplifies the history, it removes filtered commits from the history and sets its flags. When the next commit is an unrelated commit and its parents will be filtered out, for the lookahead the commit is still a child of, it cannot know that the next commit once simplified (advancing the walker) it will become a visual root. This makes the lookahead fail, failing to set the cascading and starting it with the first visual root, carrying an extra indent for the cascade.
given:
* A unrelated (visual root)
* B child of C
* C visual root WILL BE FILTERED OUT
* D unrelated (visual root)the actual output is:
Quoted 7 lines
* A
* B
* DA test has been added to t4218 and a NEEDSWORK to the lookahead function to document this edge case but I'm not that familiar with
revision.c. Maybe there's a better way to make the lookahead more reliable.
It's slightly disappointing that we couldn't find a way to fix this after all, but at least the bug is non-breaking and the added NEEDSWORK properly documents the issue for someone else to tackle in the future.
Other than that, this version looks fine to me.
Quoted 26 lines
[1]: https://lore.kernel.org/git/[email protected]/
V4 DIFF:
- Fixed test to be shown as expected by unsetting
COMMIT_GRAPHSigned-off-by Pablo Sabater <[email protected]>---
Pablo Sabater (2):
lib-log-graph: movecheck_graphfunction
graph: indent visual root in graphgraph.c | 262 ++++++++++++++++ t/lib-log-graph.sh | 5 + t/meson.build | 1 + t/t4215-log-skewed-merges.sh | 33 +- t/t4218-log-graph-indentation.sh | 467 +++++++++++++++++++++++++++++ t/t6016-rev-list-graph-simplify-history.sh | 25 +- 6 files changed, 759 insertions(+), 34 deletions(-)---
base-commit:3e65291872de10c3f0bf05ea8c24187e7a71ebf0
change-id: 20260612-ps-pre-commit-indent-39ca72816382Best regards,
--
Pablo Sabater <[email protected]>
v6 cover graph: indent visual roots in graph
In reply to Pablo SabaterWhen rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This series adds indentation to the visual root commits, so they cannot be vertically adjacent anymore making it easier to identify them.
before indentation:
* A
* B1
* B2
* C1
* C2
after indentation:
* A
* B1
\
* B2
* C1
* C2
Indents the visual root commits that have still commits to show after them, and if they have children it connects them with an edge at a new row.
If there are multiple visual roots adjacent in history, the indentation starts with the second one, avoiding redundant indentation of the first one and cascades after the second.
* A
* B
* C
* D1
* D2
This series first commit is a cleanup that brings a common function from t4215 and t6016 to a graph functions file which they both use, so the new test file for indentation, t4218, can use it as well.
There are two main limitations to predict if the next commit will be a visual root candidate:
1. The peek only gives us the next entry reliably, we cannot see past it reliably in order.
2. Even if we could peek past in order, its parents might not have been simplified yet, so a future commit that will become a visual root is not detected as a visual root in peek-time.
This causes the cascading to not be set and result in a extra indentation. For example:
Given:
* A unrelated (visual root)
* B child of C
* C visual root WILL BE FILTERED OUT
* D unrelated (visual root)
The actual output is:
* A
* B
* D
But we wanted:
* A
* B
* D
A test has been added to t4218 and a NEEDSWORK to the lookahead function to document this edge case but I'm not that familiar with revision.c. Maybe there's a better way to make the lookahead more reliable.
[1]: https://lore.kernel.org/git/[email protected]/
V5 DIFF:
- Added new commit with lookahead functions to abstract the commit traverse to the graph. Changed the lookahead function from graph to call this new functions.
- Added new test with two unrelated branches with merges.
- Fixed test_expect_failure to have the correct expected output.
- Simplified the NEEDSWORK.
---
Pablo Sabater (3):
lib-log-graph: move check_graph function
revision: add peek functions for lookahead
graph: indent visual root in graph
graph.c | 271 +++++++++++++++++ revision.c | 38 +++ revision.h | 10 + t/lib-log-graph.sh | 5 + t/meson.build | 1 + t/t4215-log-skewed-merges.sh | 33 +- t/t4218-log-graph-indentation.sh | 468 +++++++++++++++++++++++++++++ t/t6016-rev-list-graph-simplify-history.sh | 25 +- 8 files changed, 817 insertions(+), 34 deletions(-)
---
base-commit: 95e20213faefeb95df29277c58ac1980ab68f701
change-id: 20260612-ps-pre-commit-indent-39ca72816382
Best regards,
Signature · 1 line
Pablo Sabater <[email protected]>
PATCH v6 1/3 lib-log-graph: move check_graph function
check_graph is a function shared in the test files t4215 and t6016 used to format the output graph, but instead of being in a file called by both test, the function code is repeated in each file.
Move check_graph to lib-log-graph.sh file which both tests already import graph functions from, renaming it to lib_test_check_graph.
This function is needed for the following commit which includes graph tests in a new file and requires check_graph.
--- t/lib-log-graph.sh | 5 +++++ t/t4215-log-skewed-merges.sh | 33 +++++++++++++----------------- t/t6016-rev-list-graph-simplify-history.sh | 25 +++++++++------------- 3 files changed, 29 insertions(+), 34 deletions(-)
t/lib-log-graph.sh +5 -0
@@ -26,3 +26,8 @@ lib_test_cmp_colored_graph () { test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors && test_cmp expect.colors output.colors } + +lib_test_check_graph () { + cat >expect && + lib_test_cmp_graph --format=%s "$@" +}
t/t4215-log-skewed-merges.sh +14 -19
@@ -5,11 +5,6 @@ test_description='git log --graph of skewed merges' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh -check_graph () { - cat >expect && - lib_test_cmp_graph --format=%s "$@" -} - test_expect_success 'log --graph with merge fusing with its left and right neighbors' ' git checkout --orphan _p && test_commit A &&
@@ -21,7 +16,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh git checkout _p && git merge --no-ff _r -m G && git checkout @^^ && git merge --no-ff _p -m H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * H |\ | * G
@@ -49,7 +44,7 @@ test_expect_success 'log --graph with left-skewed merge' ' git checkout 0_p && git merge --no-ff 0_s -m 0_G && git checkout @^ && git merge --no-ff 0_q 0_r 0_t 0_p -m 0_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF *-----. 0_H |\ \ \ \ | | | | * 0_G
@@ -83,7 +78,7 @@ test_expect_success 'log --graph with nested left-skewed merge' ' git checkout 1_p && git merge --no-ff 1_r -m 1_G && git checkout @^^ && git merge --no-ff 1_p -m 1_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 1_H |\ | * 1_G
@@ -115,7 +110,7 @@ test_expect_success 'log --graph with nested left-skewed merge following normal git checkout -b 2_s @^^ && git merge --no-ff 2_q -m 2_J && git checkout 2_p && git merge --no-ff 2_s -m 2_K && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 2_K |\ | * 2_J
@@ -151,7 +146,7 @@ test_expect_success 'log --graph with nested right-skewed merge following left-s git checkout 3_p && git merge --no-ff 3_r -m 3_H && git checkout @^^ && git merge --no-ff 3_p -m 3_J && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 3_J |\ | * 3_H
@@ -182,7 +177,7 @@ test_expect_success 'log --graph with right-skewed merge following a left-skewed git merge --no-ff 4_p -m 4_G && git checkout @^^ && git merge --no-ff 4_s -m 4_H && - check_graph --date-order <<-\EOF + lib_test_check_graph --date-order <<-\EOF * 4_H |\ | * 4_G
@@ -218,7 +213,7 @@ test_expect_success 'log --graph with octopus merge with column joining its penu git checkout 5_r && git merge --no-ff 5_s -m 5_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 5_H |\ | *-. 5_G
@@ -257,7 +252,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout 6_1 && git merge --no-ff 6_2 -m 6_I && - check_graph 6_1 6_3 6_5 <<-\EOF + lib_test_check_graph 6_1 6_3 6_5 <<-\EOF * 6_I |\ | | * 6_H
@@ -334,7 +329,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout -b M_7 7_1 && git merge --no-ff 7_2 7_3 -m 7_M4 && - check_graph M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -371,7 +366,7 @@ test_expect_success 'log --graph with multiple tips' ' ' test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' ' - check_graph --graph-lane-limit=2 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=2 M_7 <<-\EOF *-. 7_M4 |\ \ | | * 7_G
@@ -388,7 +383,7 @@ test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' ' ' test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge' ' - check_graph --graph-lane-limit=1 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=1 M_7 <<-\EOF *-~ 7_M4 |\~ | ~ 7_G
@@ -405,7 +400,7 @@ test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge ' test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' ' - check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -441,7 +436,7 @@ test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' ' ' test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows first of 3 parent merge' ' - check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -478,7 +473,7 @@ test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows fir ' test_expect_success 'log --graph --graph-lane-limit=7 check if it shows all 3 parent merge' ' - check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
t/t6016-rev-list-graph-simplify-history.sh +10 -15
@@ -13,11 +13,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh -check_graph () { - cat >expect && - lib_test_cmp_graph --format=%s "$@" -} - test_expect_success 'set up rev-list --graph test' ' # 3 commits on branch A test_commit A1 foo.txt &&
@@ -54,7 +49,7 @@ test_expect_success 'set up rev-list --graph test' ' ' test_expect_success '--graph --all' ' - check_graph --all <<-\EOF + lib_test_check_graph --all <<-\EOF * A7 * A6 |\
@@ -82,7 +77,7 @@ test_expect_success '--graph --all' ' # that undecorated merges are interesting, even with --simplify-by-decoration test_expect_success '--graph --simplify-by-decoration' ' git tag -d A4 && - check_graph --all --simplify-by-decoration <<-\EOF + lib_test_check_graph --all --simplify-by-decoration <<-\EOF * A7 * A6 |\
@@ -114,7 +109,7 @@ test_expect_success 'setup: get rid of decorations on B' ' # Graph with branch B simplified away test_expect_success '--graph --simplify-by-decoration prune branch B' ' - check_graph --simplify-by-decoration --all <<-\EOF + lib_test_check_graph --simplify-by-decoration --all <<-\EOF * A7 * A6 |\
@@ -133,7 +128,7 @@ test_expect_success '--graph --simplify-by-decoration prune branch B' ' ' test_expect_success '--graph --full-history -- bar.txt' ' - check_graph --full-history --all -- bar.txt <<-\EOF + lib_test_check_graph --full-history --all -- bar.txt <<-\EOF * A7 * A6 |\
@@ -148,7 +143,7 @@ test_expect_success '--graph --full-history -- bar.txt' ' ' test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' - check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF + lib_test_check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF * A7 * A6 |\
@@ -161,7 +156,7 @@ test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' ' test_expect_success '--graph -- bar.txt' ' - check_graph --all -- bar.txt <<-\EOF + lib_test_check_graph --all -- bar.txt <<-\EOF * A7 * A5 * A3
@@ -172,7 +167,7 @@ test_expect_success '--graph -- bar.txt' ' ' test_expect_success '--graph --sparse -- bar.txt' ' - check_graph --sparse --all -- bar.txt <<-\EOF + lib_test_check_graph --sparse --all -- bar.txt <<-\EOF * A7 * A6 * A5
@@ -189,7 +184,7 @@ test_expect_success '--graph --sparse -- bar.txt' ' ' test_expect_success '--graph ^C4' ' - check_graph --all ^C4 <<-\EOF + lib_test_check_graph --all ^C4 <<-\EOF * A7 * A6 * A5
@@ -202,7 +197,7 @@ test_expect_success '--graph ^C4' ' ' test_expect_success '--graph ^C3' ' - check_graph --all ^C3 <<-\EOF + lib_test_check_graph --all ^C3 <<-\EOF * A7 * A6 |\
@@ -220,7 +215,7 @@ test_expect_success '--graph ^C3' ' # that important, but this test depends on it. If the ordering ever changes # in the code, we'll need to update this test. test_expect_success '--graph --boundary ^C3' ' - check_graph --boundary --all ^C3 <<-\EOF + lib_test_check_graph --boundary --all ^C3 <<-\EOF * A7 * A6 |\
Signature · 1 line
2.54.0
PATCH v6 2/3 revision: add peek functions for lookahead
In reply to Pablo SabaterThe graph code in a subsequent commit needs to be able to look ahead in order to set indentation-related flags.
Using revs->commits is brittle and the data structure that holds the pending commits might change in the future.
Add two functions that abstract this for the graph.
--- revision.c | 38 ++++++++++++++++++++++++++++++++++++++ revision.h | 10 ++++++++++ 2 files changed, 48 insertions(+)
revision.c +38 -0
@@ -3708,6 +3708,44 @@ static unsigned int count_explore_walked;static unsigned int count_indegree_walked;static unsigned int count_topo_walked; +struct commit *revision_peek_next_commit (struct rev_info *revs) +{ +struct topo_walk_info *info = revs->topo_walk_info; + +if (info) +return prio_queue_peek (&info->topo_queue); +if (revs->commits) +return revs->commits->item; + +return NULL ; +} + +int revision_has_commits_after (struct rev_info *revs,int n) +{ +struct topo_walk_info *info = revs->topo_walk_info; + +if (info) { +int visible =0 ; +for (size_t i =0 ; i < info->topo_queue.nr && visible < n; i++) { +struct commit *c = info->topo_queue.array[i].data; +if (get_commit_action (revs, c) == commit_show) + visible++; + } +return visible > n-1 ; + } +if (revs->commits) { +struct commit_list *cl; +int visible =0 ; +for (cl = revs->commits; cl && visible < n; cl = cl->next) { +if (get_commit_action (revs, cl->item) == commit_show) + visible++; + } +return visible > n-1 ; + } + +return 0 ; +} +static void trace2_topo_walk_statistics_atexit (void ) {struct json_writer jw =JSON_WRITER_INIT ;
revision.h +10 -0
@@ -572,4 +572,14 @@ int rewrite_parents(struct rev_info *revs,*/ struct commit_list *get_saved_parents (struct rev_info *revs,const struct commit *commit); +/* +* Peek into revision's next commit without consuming it. +*/ +struct commit *revision_peek_next_commit (struct rev_info *revs); + +/* +* Check if there are n more commits to be shown yet. +*/ +int revision_has_commits_after (struct rev_info *revs,int n); +#endif
Signature · 1 line
2.54.0
Re: [PATCH v6 2/3] revision: add peek functions for lookahead
Quoted 11 lines · Pablo Sabater
The graph code in a subsequent commit needs to be able to look ahead in order to set indentation-related flags.
Using
revs->commitsis brittle and the data structure that holds the pending commits might change in the future.Add two functions that abstract this for the graph.
Helped-by Kristofer Karlsson <[email protected]>Signed-off-by Pablo Sabater <[email protected]>
The email on the trailer is wrong, sorry Kristofer, I'll fix it in the next version.
Regards,
Pablo
Re: [PATCH v6 2/3] revision: add peek functions for lookahead
In reply to Pablo SabaterQuoted 24 lines · Pablo Sabater
The graph code in a subsequent commit needs to be able to look ahead in order to set indentation-related flags.
Using
revs->commitsis brittle and the data structure that holds the pending commits might change in the future.Add two functions that abstract this for the graph.
Helped-by Kristofer Karlsson <[email protected]>Signed-off-by Pablo Sabater <[email protected]>--- revision.c | 38 ++++++++++++++++++++++++++++++++++++++ revision.h | 10 ++++++++++ 2 files changed, 48 insertions(+)revision.c +1
-0@@ -3708,6 +3708,44 @@ static unsigned int count_explore_walked;static unsigned int count_indegree_walked;static unsigned int count_topo_walked; +struct commit *revision_peek_next_commit (struct rev_info *revs)
revision.c static unsigned int count_explore_walked; · line 3721
Quoted 10 lines
revision.c +10
-0+{ +struct topo_walk_info *info = revs->topo_walk_info; + +if (info) +return prio_queue_peek (&info->topo_queue); +if (revs->commits) +return revs->commits->item; + +return NULL ; +}
OK. "If we are doing topo_walk, topo_queue is the priority queue to peek into, otherwise revs->commits list is being used" is a bit too intimate implementation detail I am not comfortable to depend on, but as long as it is contained inside revision.c it should be OK.
Lose the space between the function name and its (parameter list) from this and the next function.
Quoted 15 lines
revision.c +15
-0+int revision_has_commits_after (struct rev_info *revs,int n) +{ +struct topo_walk_info *info = revs->topo_walk_info; + +if (info) { +int visible =0 ; +for (size_t i =0 ; i < info->topo_queue.nr && visible < n; i++) { +struct commit *c = info->topo_queue.array[i].data; +if (get_commit_action (revs, c) == commit_show) + visible++; + } +return visible > n-1 ; + } +if (revs->commits) { +struct commit_list *cl;
revision.c static unsigned int count_explore_walked; · line 3747
Quoted 10 lines
revision.c +10
-0+int visible =0 ; +for (cl = revs->commits; cl && visible < n; cl = cl->next) { +if (get_commit_action (revs, cl->item) == commit_show) + visible++; + } +return visible > n-1 ; + } + +return 0 ; +}
Regarding the use of get_commit_action() here, I wondered if this is safe, because usually get_commit_action() is called only once per commit during history traversal from simplify_commit(), but this patch adds calls to it for all of the remaining commits being processed without consuming them (so get_commit_action() will be called on these commits again later as the history traversal progresses).
If get_commit_action() a pure function without any side effects, this may be safe, but line-log has something with side effect in the function.
I _think_ this is OK, as "--graph" sets .rewrite_parents bit (as well as .topo_order bit) on, which makes want_ancestry() to return true. Which in turn means even if -L is in effect, we will not call line_log_process_ranges_arbitrary_commit() that is the only source of side effect in this function. Somebody needs to sanity check this, but we may want to leave an in-code comment to warn future developers not to call get_commit_action() on random commits outside of the normal history traversal under what condition (namely, -L without rewrite_parents).
Even better, perhaps add
if (revs->line_level_traverse && !want_ancestry(revs))
BUG("do not call this");at the beginning of revision_has_commits_after() function, and describe why in the header file comment for this function below?
Quoted 19 lines
revision.h +10
-0@@ -572,4 +572,14 @@ int rewrite_parents(struct rev_info *revs,*/ struct commit_list *get_saved_parents (struct rev_info *revs,const struct commit *commit); +/* +* Peek into revision's next commit without consuming it. +*/ +struct commit *revision_peek_next_commit (struct rev_info *revs); + +/* +* Check if there are n more commits to be shown yet. +*/ +int revision_has_commits_after (struct rev_info *revs,int n); +#endif
Re: [PATCH v6 2/3] revision: add peek functions for lookahead
Quoted 10 lines · Junio C Hamano
I _think_ this is OK, as "--graph" sets .rewrite_parents bit (as well as .topo_order bit) on, which makes
want_ancestry()to return true. Which in turn means even if -L is in effect, we will not callline_log_process_ranges_arbitrary_commit()that is the only source of side effect in this function. Somebody needs to sanity check this, but we may want to leave an in-code comment to warn future developers not to callget_commit_action()on random commits outside of the normal history traversal under what condition (namely, -L withoutrewrite_parents).
Quoted 7 lines
Even better, perhaps add
if (revs->line_level_traverse && !want_ancestry(revs)) BUG("do not call this");at the beginning of
revision_has_commits_after()function, and describe why in the header file comment for this function below?
Having said all that, in the longer term we might be better off if we fix the line-log code so that get_commit_action() becomes a pure function again.
It might be a very simple change to move the "if we are doing -L and !want_ancestry(), call the line_log_process_ranges_arbitrary_commit()" to simplify_commit() before it calls get_commit_action(), but I haven't thought things through.
[jc: Michael Cc'ed as there are a few topics on line-log recently from him; SZEDER Cc'ed as his 3cb9d2b6 (line-log: more responsive, incremental 'git log -L', 2020-05-11) introduced this side effect there.]
In any case, this is a remote tangent that does not affect how we want to proceed with this series ;-).
Re: [PATCH v6 2/3] revision: add peek functions for lookahead
In reply to Pablo Sabaterrevision.c static unsigned int count_explore_walked; · line 3734
Quoted 12 lines · Pablo Sabater
revision.c +12
-0+int revision_has_commits_after (struct rev_info *revs,int n) +{ +struct topo_walk_info *info = revs->topo_walk_info; + +if (info) { +int visible =0 ; +for (size_t i =0 ; i < info->topo_queue.nr && visible < n; i++) { +struct commit *c = info->topo_queue.array[i].data; +if (get_commit_action (revs, c) == commit_show) + visible++; + } +return visible > n-1 ;
The loop needs to be rethought, perhaps with a better abstraction than ".nr is the number of elements in the queue and we can walk them over as a dense array", using prio_queue_for_each(), once this topic meets the kk/prio-queue-get-put-fusion topic.
I see Kristofer is already on the CC: line. Depending on the done-ness of the topic, we may want to include the topic in the updated base for this topic to resolve semantic conflicts early, or the other way around (i.e., let this topic graduate first and then rebuild the prio-queue topic on top of the updated 'master').
Thanks.
Re: [PATCH v6 2/3] revision: add peek functions for lookahead
In reply to Pablo Sabaterrevision.c static unsigned int count_explore_walked; · line 3734
Quoted 12 lines
revision.c +12
-0+int revision_has_commits_after (struct rev_info *revs,int n) +{ +struct topo_walk_info *info = revs->topo_walk_info; + +if (info) { +int visible =0 ; +for (size_t i =0 ; i < info->topo_queue.nr && visible < n; i++) { +struct commit *c = info->topo_queue.array[i].data; +if (get_commit_action (revs, c) == commit_show) + visible++; + } +return visible > n-1 ;
Nit: I think 'return visible >= n' will be more readable here. As in, more in-line with this function's description (below).
revision.c static unsigned int count_explore_walked; · line 3743
Quoted 8 lines
revision.c +8
-0+if (revs->commits) { +struct commit_list *cl; +int visible =0 ; +for (cl = revs->commits; cl && visible < n; cl = cl->next) { +if (get_commit_action (revs, cl->item) == commit_show) + visible++; + } +return visible > n-1 ;
Same here.
Quoted 13 lines
revision.c +5
-0+ } + +return 0 ; +} +static void trace2_topo_walk_statistics_atexit (void ) {struct json_writer jw =JSON_WRITER_INIT ;revision.h +0
-0
revision.h int rewrite_parents(struct rev_info *revs, · line 581
Quoted 10 lines
revision.h +7
-0@@ -572,4 +572,14 @@ int rewrite_parents(struct rev_info *revs,*/ struct commit_list *get_saved_parents (struct rev_info *revs,const struct commit *commit); +/* +* Peek into revision's next commit without consuming it. +*/ +struct commit *revision_peek_next_commit (struct rev_info *revs); + +/* +* Check if there are n more commits to be shown yet.
Shouldn't this be "n or more"?
Quoted 6 lines
revision.h +2
-1+int revision_has_commits_after (struct rev_info *revs,int n); +#endif --2.54.0
Re: [PATCH v6 2/3] revision: add peek functions for lookahead
In reply to Pablo SabaterQuoted 8 lines · Pablo Sabater
The graph code in a subsequent commit needs to be able to look ahead in order to set indentation-related flags.
Using
revs->commitsis brittle and the data structure that holds the pending commits might change in the future.Add two functions that abstract this for the graph.
The abstraction is a step in the right direction, but I think there is a deeper issue with the peek-based approach. I tried to understand the problem and ended up with an alternative that I think is simpler and also fixes the three test_expect_failure cases in t4218.
revision.c static unsigned int count_explore_walked; · line 3732
Quoted 8 lines
revision.c +7
-0+struct commit *revision_peek_next_commit (struct rev_info *revs) +int revision_has_commits_after (struct rev_info *revs, int n) +{ +for (size_t i =0 ; i < info->topo_queue.nr && visible < n; i++) { +struct commit *c = info->topo_queue.array[i].data; +if (get_commit_action (revs, c) == commit_show) + visible++;
Scanning the pending queue does not work, because it may not contain all relevant entries yet. Processing the first entry in the queue may affect the second entry.
There is also a second problem: commits in the queue have not been through simplify_commit() yet, so their parent lists are still the raw ones. graph_is_visual_root_candidate() checks "parents == NULL", but with a pathspec filter a commit's TREESAME parent might get removed by simplification, turning the commit into a visual root. Peeking at the raw queue misses this, which is the cause of the t4218 test_expect_failure cases.
The solution is to skip peeking entirely and instead call get_revision_internal() to populate a small lookahead buffer - it only needs two slots.
struct git_graph {
// ...
struct commit *lookahead[2];
int lookahead_nr;
}
while (revs->graph->lookahead_nr < 2) {
struct commit *next = get_revision_internal(revs);
if (!next)
break;
graph_push_lookahead(revs->graph, next);
}After prototyping this locally, the three test_expect_failure cases in t4218 went away (though I had to do some minor tweaks to ensure it become fully deterministic by ticking the commit timestamps.
One subtlety worth mentioning: get_revision_internal() sets SHOWN on commits, so lookahead commits are marked SHOWN before graph_update() processes them. This makes graph_is_interesting() think they are already displayed. The fix is a small check in graph_is_interesting() that recognizes commits in the lookahead buffer as interesting regardless of their SHOWN flag.
for (i = 0; i < graph->lookahead_nr; i++)
if (graph->lookahead[i] == commit)
return 1;
// other checks after this ...This approach ultimately removes the need for revision_peek_next_commit() and revision_has_commits_after() entirely - the graph code no longer needs to peek at rev_info internals.
Kristofer
Re: [PATCH v6 2/3] revision: add peek functions for lookahead
Quoted 34 lines · Kristofer Karlsson
The solution is to skip peeking entirely and instead call
get_revision_internal()to populate a small lookahead buffer - it only needs two slots.struct git_graph { // ... struct commit *lookahead[2]; int lookahead_nr; } while (revs->graph->lookahead_nr < 2) { struct commit *next = get_revision_internal(revs); if (!next) break; graph_push_lookahead(revs->graph, next); }After prototyping this locally, the three
test_expect_failurecases in t4218 went away (though I had to do some minor tweaks to ensure it become fully deterministic by ticking the commit timestamps.One subtlety worth mentioning:
get_revision_internal()sets SHOWN on commits, so lookahead commits are marked SHOWN beforegraph_update()processes them. This makesgraph_is_interesting()think they are already displayed. The fix is a small check ingraph_is_interesting()that recognizes commits in the lookahead buffer as interesting regardless of their SHOWN flag.for (i = 0; i < graph->lookahead_nr; i++) if (graph->lookahead[i] == commit) return 1; // other checks after this ...
Quoted 4 lines
This approach ultimately removes the need for
revision_peek_next_commit()andrevision_has_commits_after()entirely - the graph code no longer needs to peek atrev_infointernals.
Sorry I lost track, but I think the message I am responding to is one of the latest messages in the thread. Whose court is the ball in right now?
Thanks.
Re: [PATCH v6 2/3] revision: add peek functions for lookahead
Quoted 37 lines · Junio C Hamano
Quoted 34 lines · Kristofer Karlsson
The solution is to skip peeking entirely and instead call
get_revision_internal()to populate a small lookahead buffer - it only needs two slots.struct git_graph { // ... struct commit *lookahead[2]; int lookahead_nr; } while (revs->graph->lookahead_nr < 2) { struct commit *next = get_revision_internal(revs); if (!next) break; graph_push_lookahead(revs->graph, next); }After prototyping this locally, the three
test_expect_failurecases in t4218 went away (though I had to do some minor tweaks to ensure it become fully deterministic by ticking the commit timestamps.One subtlety worth mentioning:
get_revision_internal()sets SHOWN on commits, so lookahead commits are marked SHOWN beforegraph_update()processes them. This makesgraph_is_interesting()think they are already displayed. The fix is a small check ingraph_is_interesting()that recognizes commits in the lookahead buffer as interesting regardless of their SHOWN flag.for (i = 0; i < graph->lookahead_nr; i++) if (graph->lookahead[i] == commit) return 1; // other checks after this ...
Quoted 8 lines
Quoted 4 lines
This approach ultimately removes the need for
revision_peek_next_commit()andrevision_has_commits_after()entirely - the graph code no longer needs to peek atrev_infointernals.Sorry I lost track, but I think the message I am responding to is one of the latest messages in the thread. Whose court is the ball in right now?
Hi!
It's still mine :).
Sorry I haven't worked on this patch these last days, I tested this morning what Kristofer told me to do, but I didn't finish it. I think I'll have it by tomorrow.
So, the next step is a reroll from me.
Quoted 3 lines
Thanks.
Thanks for the patience,
Pablo.
PATCH v6 3/3 graph: indent visual root in graph
In reply to Pablo SabaterWhen rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This happens because the commits fill the space from left to right and when a visual root ends, its column becomes free for the following commit even if they are not related. Once this happens the unrelated commit is rendered below the visual root. Because there is no special character or way to identify when a visual root is rendered making the graph confusing.
By indenting the visual roots when there are still commits to show the vertical adjacency can be avoided.
Add is_visual_root flag to git_graph making it visible in all graph states, give graph_update() a new function, graph_is_visual_root() to know if the current commit is a visual root and set is_visual_root.
The different handled cases are:
- If a visual root has children: similar to GRAPH_PRE_COMMIT state when octopus merges need space, an edge row needs to be printed to connect the child with the indented visual root. A new state GRAPH_PRE_ROOT is needed to connect the child with the visual root:
* child of the visual root
\ GRAPH_PRE_ROOT
* visual root indented
- If a visual root is child-less we can skip GRAPH_PRE_ROOT state and render the indented commit directly.
* visual root indented
* unrelated commit
- If two or more visual roots are adjacent: by having a lookahead to the next commit that will be rendered, if the next commit is also a visual root and we are on a visual root, meaning two visual root adjacent in the history, the top one can omit the indent, making the one below to indent only once, if there are more adjacent visual commits, the indentation will increase for each adjacent one, cascading.
* visual root
* visual root
* visual root
* last commit
Even if the last commit is a root, because there is nothing that will be rendered below we can omit the indentation on purpose.
There are two main limitations to predict if the next commit will be a visual root candidate:
1. The peek only gives us the next entry reliably, we cannot see past it reliably in order.
2. Even if we could peek past in order, its parents might not have been simplified yet, so a future commit that will become a visual root is not detected as a visual root in peek-time.
This causes the cascading to not be set and result in a extra indentation. For example:
Given:
* A unrelated (visual root)
* B child of C
* C visual root WILL BE FILTERED OUT
* D unrelated (visual root)
The actual output is:
* A
* B
* D
But we wanted:
* A
* B
* D
The output isn't broken as unrelated commits are successfully separated by indentation, but an indent level should have been avoided.
Create a new test file for graph indentations test called 't4218-log-graph-indentation.sh'.
The filtered parents edge case is documented as a NEEDSWORK on the lookahead function and it has its own 'test_expect_failure' at 't4218'.
[1]: https://lore.kernel.org/git/[email protected]/
--- graph.c | 271 +++++++++++++++++++++++ t/meson.build | 1 + t/t4218-log-graph-indentation.sh | 468 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 740 insertions(+)
graph.c +271 -0
@@ -60,12 +60,23 @@ struct column {* index into column_colors. */ unsigned short color; +/* +* Marks if a commit is a non-first parent of a merge. These columns are +* already visually connected to the merge commit and do not need +* indentation. +* +* The first parent is the one that inherits the column and it can need +* indentation if turns out to be a visual root and there's still +* commits to render. +*/ + unsigned is_merge_parent:1; };enum graph_state {GRAPH_PADDING ,GRAPH_SKIP ,GRAPH_PRE_COMMIT , +GRAPH_PRE_ROOT ,GRAPH_COMMIT ,GRAPH_POST_MERGE ,GRAPH_COLLAPSING
@@ -315,6 +326,48 @@ struct git_graph {* diff_output_prefix_callback(). */ struct strbuf prefix_buf; + +/* +* If a commit is a visual root, we need to indent it to prevent +* unrelated commits from being vertically adjacent to it. +*/ + unsigned is_visual_root:1; + +/* +* Indentation increases for each visual root adjacent to another visual +* root, making visual root commits indentation cascade. +*/ +unsigned int visual_root_depth; + +/* +* When a visual root is adjacent to other visual roots, the first one +* can avoid indentation and the rest cascades, increasing the indentation +* for each one. +*/ + unsigned visual_root_cascade:1; + +/* +* Set when the current commit was already present in graph->columns +* before being processed. +*/ + unsigned commit_in_columns:1; +}; + +struct graph_lookahead_flags { +/* +* Set when there will be a commit after the current one that will be +* rendered. +*/ +unsigned int is_next_visible:1 ; +/* +* Set when the next visible commit is candidate to be a visual root. +*/ +unsigned int is_next_visual_root:1 ; +/* +* Set when the next visible commit will be rendered under the current +* commit. +*/ +unsigned int next_has_column:1 ; };static inline int graph_needs_truncation (struct git_graph *graph,int lane)
@@ -388,6 +441,8 @@ struct git_graph *graph_init(struct rev_info *opt) graph->num_columns =0 ; graph->num_new_columns =0 ; graph->mapping_size =0 ; + graph->visual_root_depth =0 ; + graph->visual_root_cascade =0 ;/* * Start the column color at the maximum value, since we'll * always increment it for the first commit we output.
@@ -561,6 +616,11 @@ static void graph_insert_into_new_columns(struct git_graph *graph, struct commit *commit, int idx) { +/* +* Get the initial merge_layout before it's modified to know if this +* is a merge. +*/ +int initial_merge_layout = graph->merge_layout;int i =graph_find_new_column_by_commit (graph, commit);int mapping_idx;
@@ -572,6 +632,7 @@ static void graph_insert_into_new_columns(struct git_graph *graph, i = graph->num_new_columns++; graph->new_columns[i].commit = commit; graph->new_columns[i].color =graph_find_commit_color (graph, commit); + graph->new_columns[i].is_merge_parent =0 ; }if (graph->num_parents >1 && idx >-1 && graph->merge_layout ==-1 ) {
@@ -610,6 +671,12 @@ static void graph_insert_into_new_columns(struct git_graph *graph, } graph->mapping[mapping_idx] = i; + +/* +* Mark non-first parents of a merge. +*/ +if (graph->num_parents >1 && initial_merge_layout >=0 && idx >-1 ) + graph->new_columns[i].is_merge_parent =1 ; }static void graph_update_columns (struct git_graph *graph)
@@ -701,10 +768,20 @@ static void graph_update_columns(struct git_graph *graph)if (graph->num_parents ==0 ) graph->width +=2 ; }else { +int j;graph_insert_into_new_columns (graph, col_commit,-1 ); +/* +* This column is not the current commit, but we need to +* propagate the flag until the commit is processed. +*/ + j =graph_find_new_column_by_commit (graph, col_commit); +if (j >=0 && graph->columns[i].is_merge_parent) + graph->new_columns[j].is_merge_parent =1 ; } } + graph->commit_in_columns = is_commit_in_columns; +/* * If graph_max_lanes is set, cap the width */
@@ -763,9 +840,144 @@ static int graph_needs_pre_commit_line(struct git_graph *graph) graph->expansion_row <graph_num_expansion_rows (graph); } +/* +* A commit can be a visual root when: +* - It has no parents. +* +* - It has parents but they are all filtered out and +* commit->parents arrives NULL. +* +* - It is not a boundary commit. Boundary commits also have no visible +* parents, but they are not selected as visual roots because they cannot +*. cause the ambiguity of being vertically adjacent because: +* +* 1. A boundary only appears because an included commit is its child. +* Children are always above, and the renderer draws an edge down to +* the boundary from that child. Rather than starting a column like a +* visual root would do, it inherits its child column. +* +* 2. Included commits cannot appear below a boundary. Boundaries are +* ancestors of the exclusion point; if an included commit were an +* ancestor of the boundary it would be excluded and not rendered. +* Boundaries therefore always sink to the bottom. +*/ +static int graph_is_visual_root_candidate (struct commit *c) +{ +return c->parents ==NULL && !(c->object.flags &BOUNDARY ); +} + +static int graph_is_visual_root (struct git_graph *graph, +struct graph_lookahead_flags *flags) +{ +/* +* This must be only called for the current commit as graph contains +* the state for the current commit only. +* +* To check if a commit is a visual root, call graph_is_visual_root_candidate() +* but we won't know if it is really a visual root until we get to the +* next commit state. +* +* The current commit is an actual visual root if it is a candidate and +* the commit is not a non-first parent of a merge. +* +* * +* |\ +* | * <- it is a visual root candidate but it shouldn't be indented +* * because it is already connected by an edge. +* ^ if commit_in_columns && is_merge_parent means the commit +* | was put by a merge and is connected. +* | +* `-------- if !is_next_visible means we're on the last commit, avoid +* indentation unless the one before is a visual root, then +* we need to differentiate from the one above. +* +* If next_has_columns means that the next commit has +* already a column, so it will not be rendered below, the +* current commit has to act as the last commit and omit +* indentation. +*/ +return graph_is_visual_root_candidate (graph->commit) && + !(graph->commit_in_columns && + graph->columns[graph->commit_index].is_merge_parent) && + flags->is_next_visible && + (!flags->next_has_column || graph->visual_root_depth >0 ); +} + +/* +* Iterates the commits queue searching for the next visible commit, once found +* sets visibleness and visual-root flags. +* Knowing if the next commit is also a visual root avoids redundant indentations +* +* NEEDSWORK: There are two main limitations to predict if the next commit will be +* a visual root candidate: +* +* 1. The peek only gives us the next entry reliably, we cannot see past it +* reliably in order. +* +* 2. Even if we could peek past in order, its parents might not have been +* simplified yet, so a future commit that will become a visual root is +* not detected as a visual root in peek-time. +* +* This results in a redundant indentation. +* +* See 'test_expect_failure' at t4218-log-graph-indentation.sh. +*/ +static void graph_peek_next_visible (struct git_graph *graph, +struct graph_lookahead_flags *flags) +{ +struct commit *next; + + flags->is_next_visible =0 ; + flags->is_next_visual_root =0 ; + flags->next_has_column =0 ; + + next =revision_peek_next_commit (graph->revs); +if (!next) +return ; + +if (get_commit_action (graph->revs, next) != commit_show) { +/* +* next commit won't be shown but there could be a visible +* commit still. +*/ +if (revision_has_commits_after (graph->revs,1 )) + flags->is_next_visible =1 ; +return ; + } + + flags->is_next_visible =1 ; + flags->next_has_column =graph_find_new_column_by_commit (graph, next) >=0 ; + +if (!graph_is_visual_root_candidate (next)) +return ; +/* +* Next commit is a visual root candidate but we don't want the last +* commit to get indented, check if its not the last visible commit +* +* We do not need graph->commit_in_columns or is_merge_parent, +* because we only need to know whether the next one might be a +* visual root, affecting the current commit where the cascade +* would have to be set and the first visual root not indented. +* +* It will set next_is_visual_root to true for merge parents that +* graph_is_visual_root() would return false, but if the next is +* a merge parent, the current commit is the child and cannot +* be a visual root and therefore having no effect. +*/ +if (revision_has_commits_after (graph->revs,2 )) + flags->is_next_visual_root =1 ; +} + +static int graph_needs_pre_root_line (struct git_graph *graph) +{ +return graph->commit_in_columns && graph->is_visual_root && + graph->num_columns >0 && !graph->visual_root_cascade; +} +void graph_update (struct git_graph *graph,struct commit *commit) {struct commit_list *parent; +struct graph_lookahead_flags flags;/* * Set the new commit
@@ -796,6 +1008,23 @@ void graph_update(struct git_graph *graph, struct commit *commit)*/ graph_update_columns (graph); +graph_peek_next_visible (graph, &flags); + + graph->is_visual_root =graph_is_visual_root (graph, &flags); + +if (graph->is_visual_root) { +/* +* If next is a visual root we can omit the indent for the first +* visual root and start cascading. +*/ +if (!graph->visual_root_depth && flags.is_next_visual_root) + graph->visual_root_cascade =1 ; + graph->visual_root_depth++; + }else { + graph->visual_root_depth =0 ; + graph->visual_root_cascade =0 ; + } + graph->expansion_row =0 ;/*
@@ -813,11 +1042,16 @@ void graph_update(struct git_graph *graph, struct commit *commit)* room for it. We need to do this only if there is a branch row * (or more) to the right of this commit. * +* If it is a visual root, we need to print an extra row to +* connect the indentation. +* * If there are less than 3 parents, we can immediately print the * commit line. */ if (graph->state !=GRAPH_PADDING ) graph->state =GRAPH_SKIP ; +else if (graph_needs_pre_root_line (graph)) + graph->state =GRAPH_PRE_ROOT ;else if (graph_needs_pre_commit_line (graph)) graph->state =GRAPH_PRE_COMMIT ;else
@@ -1065,6 +1299,17 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_lineif (col_commit == graph->commit) { seen_this =1 ; +if (graph->is_visual_root) { +int depth = graph->visual_root_depth; +/* +* Each visual column is 2 characters wide. +* Omit the indentation for the first visual +* root in cascade mode. +*/ +int padding = (depth - graph->visual_root_cascade) *2 ; +graph_line_addchars (line,' ' , padding); + graph->width += padding; + }graph_output_commit_char (graph, line);if (graph_needs_truncation (graph, i)) {
@@ -1436,6 +1681,29 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_lgraph_update_state (graph,GRAPH_PADDING ); } +static void graph_output_pre_root_line (struct git_graph *graph,struct graph_line *line) +{ +/* +* This function adds a row before a visual root, to connect the +* branch to the indented commit. It should only be called on a +* visual root. +*/ +assert (graph->is_visual_root); + +for (size_t i =0 ; i < graph->num_columns; i++) { +struct column *col = &graph->columns[i]; +if (col->commit == graph->commit) { +graph_line_addch (line,' ' ); +graph_line_write_column (line, col,'\\' ); + }else { +graph_line_write_column (line, col,'|' ); + } +graph_line_addch (line,' ' ); + } + +graph_update_state (graph,GRAPH_COMMIT ); +} +int graph_next_line (struct git_graph *graph,struct strbuf *sb) {int shown_commit_line =0 ;
@@ -1461,6 +1729,9 @@ int graph_next_line(struct git_graph *graph, struct strbuf *sb)case GRAPH_PRE_COMMIT :graph_output_pre_commit_line (graph, &line);break ; +case GRAPH_PRE_ROOT : +graph_output_pre_root_line (graph, &line); +break ;case GRAPH_COMMIT :graph_output_commit_line (graph, &line); shown_commit_line =1 ;
t/meson.build +1 -0
@@ -576,6 +576,7 @@ integration_tests = [ 't4215-log-skewed-merges.sh', 't4216-log-bloom.sh', 't4217-log-limit.sh', + 't4218-log-graph-indentation.sh', 't4252-am-options.sh', 't4253-am-keep-cr-dos.sh', 't4254-am-corrupt.sh',
t/t4218-log-graph-indentation.sh new file +468 -0
468 lines not on this page · raw message
Signature · 1 line
2.54.0
v7 cover graph: indent visual roots in graph
In reply to Pablo SabaterWhen rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This series adds indentation to the visual root commits, so they cannot be vertically adjacent anymore making it easier to identify them.
Before indentation:
* A
* B1
* B2
* C1
* C2
After indentation:
* A
* B1
\
* B2
* C1
* C2
Indents the visual root commits that have still commits to show after them, and if they have children it connects them with an edge at a new row.
If there are multiple visual roots adjacent in history, the indentation starts with the second one, avoiding redundant indentation of the first one and cascades after the second.
* A
* B
* C
* D1
* D2
This series first commit is a cleanup that brings a common function from t4215 and t6016 to a graph functions file which they both use, so the new test file for indentation, t4218, can use it as well.
[1]: https://lore.kernel.org/git/[email protected]/
V6 DIFF:
- Replaced the queue peeking with a 2-entry lookahead buffer populated by get_revision_internal() (second commit and graph_peek_next_visible()).
- Changed assert() with BUG() at graph_output_pre_root_line().
---
Pablo Sabater (3):
lib-log-graph: move check_graph function
graph: add a 2 commit buffer for lookahead
graph: indent visual root in graph
graph.c | 282 ++++++++++++++++++ graph.h | 17 ++ revision.c | 17 +- t/lib-log-graph.sh | 5 + t/meson.build | 1 + t/t4215-log-skewed-merges.sh | 33 +-- t/t4218-log-graph-indentation.sh | 453 +++++++++++++++++++++++++++++ t/t6016-rev-list-graph-simplify-history.sh | 25 +- 8 files changed, 798 insertions(+), 35 deletions(-)
---
base-commit: e9019fcafe0040228b8631c30f97ae1adb61bcdc
change-id: 20260612-ps-pre-commit-indent-39ca72816382
Best regards,
Signature · 1 line
Pablo Sabater <[email protected]>
PATCH v7 1/3 lib-log-graph: move check_graph function
check_graph is a function shared in the test files t4215 and t6016 used to format the output graph, but instead of being in a file called by both test, the function code is repeated in each file.
Move check_graph to lib-log-graph.sh file which both tests already import graph functions from, renaming it to lib_test_check_graph.
This function is needed for the following commit which includes graph tests in a new file and requires check_graph.
--- t/lib-log-graph.sh | 5 +++++ t/t4215-log-skewed-merges.sh | 33 +++++++++++++----------------- t/t6016-rev-list-graph-simplify-history.sh | 25 +++++++++------------- 3 files changed, 29 insertions(+), 34 deletions(-)
t/lib-log-graph.sh +5 -0
@@ -26,3 +26,8 @@ lib_test_cmp_colored_graph () { test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors && test_cmp expect.colors output.colors } + +lib_test_check_graph () { + cat >expect && + lib_test_cmp_graph --format=%s "$@" +}
t/t4215-log-skewed-merges.sh +14 -19
@@ -5,11 +5,6 @@ test_description='git log --graph of skewed merges' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh -check_graph () { - cat >expect && - lib_test_cmp_graph --format=%s "$@" -} - test_expect_success 'log --graph with merge fusing with its left and right neighbors' ' git checkout --orphan _p && test_commit A &&
@@ -21,7 +16,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh git checkout _p && git merge --no-ff _r -m G && git checkout @^^ && git merge --no-ff _p -m H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * H |\ | * G
@@ -49,7 +44,7 @@ test_expect_success 'log --graph with left-skewed merge' ' git checkout 0_p && git merge --no-ff 0_s -m 0_G && git checkout @^ && git merge --no-ff 0_q 0_r 0_t 0_p -m 0_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF *-----. 0_H |\ \ \ \ | | | | * 0_G
@@ -83,7 +78,7 @@ test_expect_success 'log --graph with nested left-skewed merge' ' git checkout 1_p && git merge --no-ff 1_r -m 1_G && git checkout @^^ && git merge --no-ff 1_p -m 1_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 1_H |\ | * 1_G
@@ -115,7 +110,7 @@ test_expect_success 'log --graph with nested left-skewed merge following normal git checkout -b 2_s @^^ && git merge --no-ff 2_q -m 2_J && git checkout 2_p && git merge --no-ff 2_s -m 2_K && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 2_K |\ | * 2_J
@@ -151,7 +146,7 @@ test_expect_success 'log --graph with nested right-skewed merge following left-s git checkout 3_p && git merge --no-ff 3_r -m 3_H && git checkout @^^ && git merge --no-ff 3_p -m 3_J && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 3_J |\ | * 3_H
@@ -182,7 +177,7 @@ test_expect_success 'log --graph with right-skewed merge following a left-skewed git merge --no-ff 4_p -m 4_G && git checkout @^^ && git merge --no-ff 4_s -m 4_H && - check_graph --date-order <<-\EOF + lib_test_check_graph --date-order <<-\EOF * 4_H |\ | * 4_G
@@ -218,7 +213,7 @@ test_expect_success 'log --graph with octopus merge with column joining its penu git checkout 5_r && git merge --no-ff 5_s -m 5_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 5_H |\ | *-. 5_G
@@ -257,7 +252,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout 6_1 && git merge --no-ff 6_2 -m 6_I && - check_graph 6_1 6_3 6_5 <<-\EOF + lib_test_check_graph 6_1 6_3 6_5 <<-\EOF * 6_I |\ | | * 6_H
@@ -334,7 +329,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout -b M_7 7_1 && git merge --no-ff 7_2 7_3 -m 7_M4 && - check_graph M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -371,7 +366,7 @@ test_expect_success 'log --graph with multiple tips' ' ' test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' ' - check_graph --graph-lane-limit=2 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=2 M_7 <<-\EOF *-. 7_M4 |\ \ | | * 7_G
@@ -388,7 +383,7 @@ test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' ' ' test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge' ' - check_graph --graph-lane-limit=1 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=1 M_7 <<-\EOF *-~ 7_M4 |\~ | ~ 7_G
@@ -405,7 +400,7 @@ test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge ' test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' ' - check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -441,7 +436,7 @@ test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' ' ' test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows first of 3 parent merge' ' - check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -478,7 +473,7 @@ test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows fir ' test_expect_success 'log --graph --graph-lane-limit=7 check if it shows all 3 parent merge' ' - check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
t/t6016-rev-list-graph-simplify-history.sh +10 -15
@@ -13,11 +13,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh -check_graph () { - cat >expect && - lib_test_cmp_graph --format=%s "$@" -} - test_expect_success 'set up rev-list --graph test' ' # 3 commits on branch A test_commit A1 foo.txt &&
@@ -54,7 +49,7 @@ test_expect_success 'set up rev-list --graph test' ' ' test_expect_success '--graph --all' ' - check_graph --all <<-\EOF + lib_test_check_graph --all <<-\EOF * A7 * A6 |\
@@ -82,7 +77,7 @@ test_expect_success '--graph --all' ' # that undecorated merges are interesting, even with --simplify-by-decoration test_expect_success '--graph --simplify-by-decoration' ' git tag -d A4 && - check_graph --all --simplify-by-decoration <<-\EOF + lib_test_check_graph --all --simplify-by-decoration <<-\EOF * A7 * A6 |\
@@ -114,7 +109,7 @@ test_expect_success 'setup: get rid of decorations on B' ' # Graph with branch B simplified away test_expect_success '--graph --simplify-by-decoration prune branch B' ' - check_graph --simplify-by-decoration --all <<-\EOF + lib_test_check_graph --simplify-by-decoration --all <<-\EOF * A7 * A6 |\
@@ -133,7 +128,7 @@ test_expect_success '--graph --simplify-by-decoration prune branch B' ' ' test_expect_success '--graph --full-history -- bar.txt' ' - check_graph --full-history --all -- bar.txt <<-\EOF + lib_test_check_graph --full-history --all -- bar.txt <<-\EOF * A7 * A6 |\
@@ -148,7 +143,7 @@ test_expect_success '--graph --full-history -- bar.txt' ' ' test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' - check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF + lib_test_check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF * A7 * A6 |\
@@ -161,7 +156,7 @@ test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' ' test_expect_success '--graph -- bar.txt' ' - check_graph --all -- bar.txt <<-\EOF + lib_test_check_graph --all -- bar.txt <<-\EOF * A7 * A5 * A3
@@ -172,7 +167,7 @@ test_expect_success '--graph -- bar.txt' ' ' test_expect_success '--graph --sparse -- bar.txt' ' - check_graph --sparse --all -- bar.txt <<-\EOF + lib_test_check_graph --sparse --all -- bar.txt <<-\EOF * A7 * A6 * A5
@@ -189,7 +184,7 @@ test_expect_success '--graph --sparse -- bar.txt' ' ' test_expect_success '--graph ^C4' ' - check_graph --all ^C4 <<-\EOF + lib_test_check_graph --all ^C4 <<-\EOF * A7 * A6 * A5
@@ -202,7 +197,7 @@ test_expect_success '--graph ^C4' ' ' test_expect_success '--graph ^C3' ' - check_graph --all ^C3 <<-\EOF + lib_test_check_graph --all ^C3 <<-\EOF * A7 * A6 |\
@@ -220,7 +215,7 @@ test_expect_success '--graph ^C3' ' # that important, but this test depends on it. If the ordering ever changes # in the code, we'll need to update this test. test_expect_success '--graph --boundary ^C3' ' - check_graph --boundary --all ^C3 <<-\EOF + lib_test_check_graph --boundary --all ^C3 <<-\EOF * A7 * A6 |\
Signature · 1 line
2.54.0
PATCH v7 2/3 graph: add a 2 commit buffer for lookahead
In reply to Pablo SabaterIn a subsequent commit the graph renderer needs to know if the next commit is a visual root or if it is the last commit to be shown. This requires peeking 2 commits ahead.
Commits are pre-fetched at get_revision_internal() where they are also marked as SHOWN.
Update graph_is_interesting() so it considers commits inside the lookahead as interesting as well.
--- graph.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ graph.h | 17 +++++++++++++++++ revision.c | 17 ++++++++++++++++- 3 files changed, 80 insertions(+), 1 deletion(-)
graph.c +47 -0
@@ -315,6 +315,14 @@ struct git_graph {* diff_output_prefix_callback(). */ struct strbuf prefix_buf; + +/* +* Lookahead buffer: up to 2 pre-fetched commits that will be shown. +* Populated by get_revision() so graph_peek_next_visible() can use +* actual walk results instead of peeking at rev_info internals. +*/ +struct commit *lookahead[2 ]; +int lookahead_nr; };static inline int graph_needs_truncation (struct git_graph *graph,int lane)
@@ -388,6 +396,9 @@ struct git_graph *graph_init(struct rev_info *opt) graph->num_columns =0 ; graph->num_new_columns =0 ; graph->mapping_size =0 ; + graph->lookahead[0 ] =NULL ; + graph->lookahead[1 ] =NULL ; + graph->lookahead_nr =0 ;/* * Start the column color at the maximum value, since we'll * always increment it for the first commit we output.
@@ -456,6 +467,15 @@ static void graph_ensure_capacity(struct git_graph *graph, int num_columns)*/ static int graph_is_interesting (struct git_graph *graph,struct commit *commit) { +/* +* Commits in the lookahead buffer have been pre-fetched by +* get_revision() and will be shown in the future. They already +* have the SHOWN flag set by get_revision_internal(), but the +* graph still needs to treat them as interesting parents. +*/ +for (int i =0 ; i < graph->lookahead_nr; i++) +if (graph->lookahead[i] == commit) +return 1 ;/* * If revs->boundary is set, commits whose children have * been shown are always interesting, even if they have the
@@ -763,6 +783,33 @@ static int graph_needs_pre_commit_line(struct git_graph *graph) graph->expansion_row <graph_num_expansion_rows (graph); } +struct commit *graph_pop_lookahead (struct git_graph *graph) +{ +struct commit *c; + +if (!graph->lookahead_nr) +return NULL ; + + c = graph->lookahead[0 ]; + graph->lookahead[0 ] = graph->lookahead[1 ]; + graph->lookahead[1 ] =NULL ; + graph->lookahead_nr--; +return c; +} + +int graph_get_lookahead_room (struct git_graph *graph) +{ +return 2 - graph->lookahead_nr; +} + +void graph_push_lookahead (struct git_graph *graph,struct commit *c) +{ +if (!graph_get_lookahead_room (graph)) +BUG ("pushing into lookahead buffer when it is already full" ); + + graph->lookahead[graph->lookahead_nr++] = c; +} +void graph_update (struct git_graph *graph,struct commit *commit) {struct commit_list *parent;
graph.h +17 -0
@@ -262,4 +262,21 @@ void graph_show_commit_msg(struct git_graph *graph,FILE *file, struct strbuf const *sb); +/* +* Pop the first commit from the graph's lookahead buffer. +* Returns NULL if the buffer is empty. +*/ +struct commit *graph_pop_lookahead (struct git_graph *graph); + +/* +* Returns how many more commits can be added to the lookahead buffer. +*/ +int graph_get_lookahead_room (struct git_graph *graph); + +/* +* Push a commit into the lookahead buffer. Must only be called when +* graph_lookahead_room() returns > 0. +*/ +void graph_push_lookahead (struct git_graph *graph,struct commit *c); +#endif /* GRAPH_H */
revision.c +16 -1
@@ -4699,12 +4699,27 @@ struct commit *get_revision(struct rev_info *revs)for (p = c->parents; p; p = p->next) p->item->object.flags |=CHILD_SHOWN ; } + }else if (revs->graph) { + c =graph_pop_lookahead (revs->graph); +if (!c) + c =get_revision_internal (revs); + }else { c =get_revision_internal (revs); } -if (c && revs->graph) +if (c && revs->graph) { +if (!revs->max_count_stage && !revs->reverse_output_stage) { +while (graph_get_lookahead_room (revs->graph)) { +struct commit *next =get_revision_internal (revs); +if (!next) +break ; +graph_push_lookahead (revs->graph, next); + } + }graph_update (revs->graph, c); + } +if (!c) {free_saved_parents (revs);commit_list_free (revs->previous_parents);
Signature · 1 line
2.54.0
Re: [PATCH v7 2/3] graph: add a 2 commit buffer for lookahead
Quoted 10 lines · Pablo Sabater
In a subsequent commit the graph renderer needs to know if the next commit is a visual root or if it is the last commit to be shown. This requires peeking 2 commits ahead.
Commits are pre-fetched at
get_revision_internal()where they are also marked as SHOWN.Update
graph_is_interesting()so it considers commits inside the lookahead as interesting as well.
Nit: lookahead -> lookahead buffer.
Quoted 28 lines
Helped-by Kristofer Karlsson <[email protected]>Signed-off-by Pablo Sabater <[email protected]>--- graph.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ graph.h | 17 +++++++++++++++++ revision.c | 17 ++++++++++++++++- 3 files changed, 80 insertions(+), 1 deletion(-)graph.c +8
-0@@ -315,6 +315,14 @@ struct git_graph {* diff_output_prefix_callback(). */ struct strbuf prefix_buf; + +/* +* Lookahead buffer: up to 2 pre-fetched commits that will be shown. +* Populated by get_revision() so graph_peek_next_visible() can use +* actual walk results instead of peeking at rev_info internals. +*/ +struct commit *lookahead[2 ]; +int lookahead_nr; };static inline int graph_needs_truncation (struct git_graph *graph,int lane)
graph.c struct git_graph *graph_init(struct rev_info *opt) · line 400
Quoted 5 lines
graph.c +2
-0@@ -388,6 +396,9 @@ struct git_graph *graph_init(struct rev_info *opt) graph->num_columns =0 ; graph->num_new_columns =0 ; graph->mapping_size =0 ; + graph->lookahead[0 ] =NULL ; + graph->lookahead[1 ] =NULL ;
Style: Manually NULLing out each entry doesn't look quite right to me. Maybe do something like this instead?
memset(graph->lookahead, 0, sizeof(graph->lookahead));
Although for an array of only two elements, manually NULLing is still quite readable and avoids the minor function-call overhead of memset().
Feel free to ignore this if you want.
Quoted 24 lines
graph.c +10
-0+ graph->lookahead_nr =0 ;/* * Start the column color at the maximum value, since we'll * always increment it for the first commit we output. @@ -456,6 +467,15 @@ static void graph_ensure_capacity(struct git_graph *graph, int num_columns)*/ static int graph_is_interesting (struct git_graph *graph,struct commit *commit) { +/* +* Commits in the lookahead buffer have been pre-fetched by +* get_revision() and will be shown in the future. They already +* have the SHOWN flag set by get_revision_internal(), but the +* graph still needs to treat them as interesting parents. +*/ +for (int i =0 ; i < graph->lookahead_nr; i++) +if (graph->lookahead[i] == commit) +return 1 ;/* * If revs->boundary is set, commits whose children have * been shown are always interesting, even if they have the @@ -763,6 +783,33 @@ static int graph_needs_pre_commit_line(struct git_graph *graph) graph->expansion_row <graph_num_expansion_rows (graph); }
graph.c static int graph_needs_pre_commit_line(struct git_graph *graph) · line 795
Quoted 10 lines
graph.c +10
-0+struct commit *graph_pop_lookahead (struct git_graph *graph) +{ +struct commit *c; + +if (!graph->lookahead_nr) +return NULL ; + + c = graph->lookahead[0 ]; + graph->lookahead[0 ] = graph->lookahead[1 ]; + graph->lookahead[1 ] =NULL ;
Do we need to NULL out the retrieved buffer entries? If so, it is worthwhile asserting that the entire buffer is NULLed out in the !graph->lookahead_nr check above.
graph.c static int graph_needs_pre_commit_line(struct git_graph *graph) · line 798
Quoted 3 lines
graph.c +3
-0+ graph->lookahead_nr--; +return c; +}
Not the best engineering practice, but I guess it is fine to constrain the logic to _only_ a 2-entry buffer since that's what we'll always deal with anyway.
graph.c static int graph_needs_pre_commit_line(struct git_graph *graph) · line 802
Quoted 4 lines
graph.c +4
-0+ +int graph_get_lookahead_room (struct git_graph *graph) +{ +return 2 - graph->lookahead_nr;
We should use ARRAY_SIZE(graph->lookahead) instead of hardcoding the value 2.
[snip]
Re: [PATCH v7 2/3] graph: add a 2 commit buffer for lookahead
The hardcoded size-2 lookahead buffer was my suggestion, so I am responding inline with my thoughts although Pablo is the right person for making further changes (if any).
Quoted 3 lines · Chandra Pratap
Do we need to NULL out the retrieved buffer entries? If so, it is worthwhile asserting that the entire buffer is NULLed out in the !graph->lookahead_nr check above.
You're right, it's not technically needed, and there are many places in the repo where stale data remains in buffers, and it would be possible to do that here too. I don't think it matters much in practice though, and NULLing them out would perhaps prevent some accidental reuse on bugs (NULL would crash instead).
As for asserting: rather than checking that empty slots are NULL (which just verifies our own cleanup), it might be more useful to assert that a slot is non-NULL when lookahead_nr says it should be populated, i.e. assert on read rather than on empty. But even that may be overkill for a 2-element internal buffer.
Quoted 3 lines
Not the best engineering practice, but I guess it is fine to constrain the logic to _only_ a 2-entry buffer since that's what we'll always deal with anyway.
I did consider making it a proper ring buffer, but it felt like overkill (and I could not find any other existing ring buffer to piggy-back on in the repo), and the lookahead depth is structurally tied to the algorithm - we only ever need two more elements.
It also helps that this is entirely internal to graph.c. If the buffer were part of a broader API, a less hardcoded approach would be more appropriate indeed.
Quoted 2 lines
We should use
ARRAY_SIZE(graph->lookahead)instead of hardcoding the value 2.
Agreed, that is a nice improvement. What do you think Pablo?
Thanks,
Kristofer
Re: [PATCH v7 2/3] graph: add a 2 commit buffer for lookahead
Quoted 16 lines · Kristofer Karlsson
The hardcoded size-2 lookahead buffer was my suggestion, so I am responding inline with my thoughts although Pablo is the right person for making further changes (if any).
Quoted 3 lines · Chandra Pratap
Do we need to NULL out the retrieved buffer entries? If so, it is worthwhile asserting that the entire buffer is NULLed out in the !graph->lookahead_nr check above.
You're right, it's not technically needed, and there are many places in the repo where stale data remains in buffers, and it would be possible to do that here too. I don't think it matters much in practice though, and NULLing them out would perhaps prevent some accidental reuse on bugs (NULL would crash instead).
Quoted 5 lines
As for asserting: rather than checking that empty slots are NULL (which just verifies our own cleanup), it might be more useful to assert that a slot is non-NULL when
lookahead_nrsays it should be populated, i.e. assert on read rather than on empty. But even that may be overkill for a 2-element internal buffer.
True. But since we're already going through the pains of initializing the buffer and NULLing it upon a pop, I'd much rather go the extra length and verify what we're trying to do, shouldn't be that complicated anyway.
Whether that means checking for NULL here, on a push, or on a read is something I don't feel strongly about, either is fine with me.
Quoted 10 lines
Quoted 3 lines
Not the best engineering practice, but I guess it is fine to constrain the logic to _only_ a 2-entry buffer since that's what we'll always deal with anyway.
I did consider making it a proper ring buffer, but it felt like overkill (and I could not find any other existing ring buffer to piggy-back on in the repo), and the lookahead depth is structurally tied to the algorithm - we only ever need two more elements.
Quoted 3 lines
It also helps that this is entirely internal to
graph.c. If the buffer were part of a broader API, a less hardcoded approach would be more appropriate indeed.
Agreed.
Quoted 7 lines
Quoted 2 lines
We should use
ARRAY_SIZE(graph->lookahead)instead of hardcoding the value 2.Agreed, that is a nice improvement. What do you think Pablo?
Thanks,
Kristofer
Re: [PATCH v7 2/3] graph: add a 2 commit buffer for lookahead
Quoted 12 lines · Chandra Pratap
Quoted 10 lines · Kristofer Karlsson
The hardcoded size-2 lookahead buffer was my suggestion, so I am responding inline with my thoughts although Pablo is the right person for making further changes (if any).
Quoted 3 lines · Chandra Pratap
Do we need to NULL out the retrieved buffer entries? If so, it is worthwhile asserting that the entire buffer is NULLed out in the !graph->lookahead_nr check above.
Quoted 5 lines
Quoted 5 lines
You're right, it's not technically needed, and there are many places in the repo where stale data remains in buffers, and it would be possible to do that here too. I don't think it matters much in practice though, and NULLing them out would perhaps prevent some accidental reuse on bugs (NULL would crash instead).
It is not really needed to NULL because every time we access it (pop or the graph_is_interesting()) we are limited by graph->lookahead_nr, however I thought that it is better to have it NULL.
Imagine that somehow the lookahead_nr is 1 when it should be 0, having NULL would segfault or if it doesn't at least we are sure that graph_is_interesting() won't re-process as interesting a commit left as stale on the buffer. Anyway, this is just speculation. I think it's better to leave it like this.
Quoted 7 lines
Quoted 6 lines
As for asserting: rather than checking that empty slots are NULL (which just verifies our own cleanup), it might be more useful to assert that a slot is non-NULL when
lookahead_nrsays it should be populated, i.e. assert on read rather than on empty. But even that may be overkill for a 2-element internal buffer.
Quoted 6 lines
True. But since we're already going through the pains of initializing the buffer and NULLing it upon a pop, I'd much rather go the extra length and verify what we're trying to do, shouldn't be that complicated anyway.
Whether that means checking for NULL here, on a push, or on a read is something I don't feel strongly about, either is fine with me.
About asserting, I think that the best is, because we are popping, to check the first element only just in case we are in the imaginary scenario that lookahead_nr is lying, but because we pop, we don't really care about what's on the second entry.
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
Not the best engineering practice, but I guess it is fine to constrain the logic to _only_ a 2-entry buffer since that's what we'll always deal with anyway.
I did consider making it a proper ring buffer, but it felt like overkill (and I could not find any other existing ring buffer to piggy-back on in the repo), and the lookahead depth is structurally tied to the algorithm - we only ever need two more elements.
Quoted 10 lines
Quoted 3 lines
It also helps that this is entirely internal to
graph.c. If the buffer were part of a broader API, a less hardcoded approach would be more appropriate indeed.Agreed.
Quoted 4 lines
Quoted 2 lines
We should use
ARRAY_SIZE(graph->lookahead)instead of hardcoding the value 2.Agreed, that is a nice improvement. What do you think Pablo?
Yes, I'll do that on reroll.
Quoted 3 lines
Quoted 3 lines
Thanks,
Kristofer
Not related with this feedback but worth saying:
re-reading what's done on revision.c there is this if line:
Quoted 1 line
if (!revs->max_count_stage && !revs->reverse_output_stage)
Graph is not compatible with --reverse, so the right-side will always be true. About --max-count, I made a few tests and the lookahead behaves the same regardless of the number of commits to be shown (even if capped).
So this whole if block can be dropped and we can try to populate the lookahead buffer always.
Thanks both for the feedback and review,
Pablo.
Re: [PATCH v7 2/3] graph: add a 2 commit buffer for lookahead
Quoted 78 lines · Pablo Sabater
Quoted 12 lines · Chandra Pratap
Quoted 10 lines · Kristofer Karlsson
The hardcoded size-2 lookahead buffer was my suggestion, so I am responding inline with my thoughts although Pablo is the right person for making further changes (if any).
Quoted 3 lines · Chandra Pratap
Do we need to NULL out the retrieved buffer entries? If so, it is worthwhile asserting that the entire buffer is NULLed out in the !graph->lookahead_nr check above.
Quoted 5 lines
Quoted 5 lines
You're right, it's not technically needed, and there are many places in the repo where stale data remains in buffers, and it would be possible to do that here too. I don't think it matters much in practice though, and NULLing them out would perhaps prevent some accidental reuse on bugs (NULL would crash instead).
It is not really needed to NULL because every time we access it (pop or the
graph_is_interesting()) we are limited bygraph->lookahead_nr, however I thought that it is better to have it NULL.Imagine that somehow the
lookahead_nris 1 when it should be 0, having NULL would segfault or if it doesn't at least we are sure thatgraph_is_interesting()won't re-process as interesting a commit left as stale on the buffer. Anyway, this is just speculation. I think it's better to leave it like this.Quoted 7 lines
Quoted 6 lines
As for asserting: rather than checking that empty slots are NULL (which just verifies our own cleanup), it might be more useful to assert that a slot is non-NULL when
lookahead_nrsays it should be populated, i.e. assert on read rather than on empty. But even that may be overkill for a 2-element internal buffer.Quoted 6 lines
True. But since we're already going through the pains of initializing the buffer and NULLing it upon a pop, I'd much rather go the extra length and verify what we're trying to do, shouldn't be that complicated anyway.
Whether that means checking for NULL here, on a push, or on a read is something I don't feel strongly about, either is fine with me.
About asserting, I think that the best is, because we are popping, to check the first element only just in case we are in the imaginary scenario that
lookahead_nris lying, but because we pop, we don't really care about what's on the second entry.Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
Not the best engineering practice, but I guess it is fine to constrain the logic to _only_ a 2-entry buffer since that's what we'll always deal with anyway.
I did consider making it a proper ring buffer, but it felt like overkill (and I could not find any other existing ring buffer to piggy-back on in the repo), and the lookahead depth is structurally tied to the algorithm - we only ever need two more elements.
Quoted 10 lines
Quoted 3 lines
It also helps that this is entirely internal to
graph.c. If the buffer were part of a broader API, a less hardcoded approach would be more appropriate indeed.Agreed.
Quoted 4 lines
Quoted 2 lines
We should use
ARRAY_SIZE(graph->lookahead)instead of hardcoding the value 2.Agreed, that is a nice improvement. What do you think Pablo?
Yes, I'll do that on reroll.
Quoted 3 lines
Quoted 3 lines
Thanks,
Kristofer
Quoted 8 lines
Not related with this feedback but worth saying:
re-reading what's done on
revision.cthere is this if line:Quoted 1 line
if (!revs->max_count_stage && !revs->reverse_output_stage)
Graph is not compatible with --reverse, so the right-side will always be true. About --max-count, I made a few tests and the lookahead behaves the same regardless of the number of commits to be shown (even if capped).
Now that I saw the GitHub CI tests, at t4202 there is a graph option "--max-count-oldest" that makes the !revs->max_count_stage check necessary.
After that everything seems to work, if anything I'll explain it on the cover letter soonly.
Quoted 6 lines
So this whole if block can be dropped and we can try to populate the lookahead buffer always.
Thanks both for the feedback and review,
Pablo.
Regards,
Pablo
PATCH v7 3/3 graph: indent visual root in graph
In reply to Pablo SabaterWhen rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This happens because the commits fill the space from left to right and when a visual root ends, its column becomes free for the following commit even if they are not related. Once this happens the unrelated commit is rendered below the visual root. Because there is no special character or way to identify when a visual root is rendered making the graph confusing.
By indenting the visual roots when there are still commits to show the vertical adjacency can be avoided.
Add is_visual_root flag to git_graph making it visible in all graph states, give graph_update() a new function, graph_is_visual_root() to know if the current commit is a visual root and set is_visual_root.
The different handled cases are:
- If a visual root has children: similar to GRAPH_PRE_COMMIT state when octopus merges need space, an edge row needs to be printed to connect the child with the indented visual root. A new state GRAPH_PRE_ROOT is needed to connect the child with the visual root:
* child of the visual root
\ GRAPH_PRE_ROOT
* visual root indented
- If a visual root is child-less we can skip GRAPH_PRE_ROOT state and render the indented commit directly.
* visual root indented
* unrelated commit
- If two or more visual roots are adjacent: by having a lookahead to the next commit that will be rendered, if the next commit is also a visual root and we are on a visual root, meaning two visual root adjacent in the history, the top one can omit the indent, making the one below to indent only once, if there are more adjacent visual commits, the indentation will increase for each adjacent one, cascading.
* visual root
* visual root
* visual root
* last commit
Even if the last commit is a root, because there is nothing that will be rendered below we can omit the indentation on purpose.
[1]: https://lore.kernel.org/git/[email protected]/
--- graph.c | 235 ++++++++++++++++++++ t/meson.build | 1 + t/t4218-log-graph-indentation.sh | 453 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 689 insertions(+)
graph.c +235 -0
@@ -60,12 +60,23 @@ struct column {* index into column_colors. */ unsigned short color; +/* +* Marks if a commit is a non-first parent of a merge. These columns are +* already visually connected to the merge commit and do not need +* indentation. +* +* The first parent is the one that inherits the column and it can need +* indentation if turns out to be a visual root and there's still +* commits to render. +*/ + unsigned is_merge_parent:1; };enum graph_state {GRAPH_PADDING ,GRAPH_SKIP ,GRAPH_PRE_COMMIT , +GRAPH_PRE_ROOT ,GRAPH_COMMIT ,GRAPH_POST_MERGE ,GRAPH_COLLAPSING
@@ -323,6 +334,51 @@ struct git_graph {*/ struct commit *lookahead[2 ];int lookahead_nr; + +/* +* If a commit is a visual root, we need to indent it to prevent +* unrelated commits from being vertically adjacent to it. +*/ + unsigned is_visual_root:1; + +/* +* Indentation increases for each visual root adjacent to another visual +* root, making visual root commits indentation cascade. +*/ +unsigned int visual_root_depth; + +/* +* When a visual root is adjacent to other visual roots, the first one +* can avoid indentation and the rest cascades, increasing the indentation +* for each one. +*/ + unsigned visual_root_cascade:1; + +/* +* Set when the current commit was already present in graph->columns +* before being processed. +*/ + unsigned commit_in_columns:1; +}; + +struct graph_lookahead_flags { + +/* +* Set when there will be a commit after the current one that will be +* rendered. +*/ +unsigned int is_next_visible:1 ; + +/* +* Set when the next visible commit is candidate to be a visual root. +*/ +unsigned int is_next_visual_root:1 ; + +/* +* Set when the next visible commit will be rendered under the current +* commit. +*/ +unsigned int next_has_column:1 ; };static inline int graph_needs_truncation (struct git_graph *graph,int lane)
@@ -399,6 +455,8 @@ struct git_graph *graph_init(struct rev_info *opt) graph->lookahead[0 ] =NULL ; graph->lookahead[1 ] =NULL ; graph->lookahead_nr =0 ; + graph->visual_root_depth =0 ; + graph->visual_root_cascade =0 ;/* * Start the column color at the maximum value, since we'll * always increment it for the first commit we output.
@@ -581,6 +639,11 @@ static void graph_insert_into_new_columns(struct git_graph *graph, struct commit *commit, int idx) { +/* +* Get the initial merge_layout before it's modified to know if this +* is a merge. +*/ +int initial_merge_layout = graph->merge_layout;int i =graph_find_new_column_by_commit (graph, commit);int mapping_idx;
@@ -592,6 +655,7 @@ static void graph_insert_into_new_columns(struct git_graph *graph, i = graph->num_new_columns++; graph->new_columns[i].commit = commit; graph->new_columns[i].color =graph_find_commit_color (graph, commit); + graph->new_columns[i].is_merge_parent =0 ; }if (graph->num_parents >1 && idx >-1 && graph->merge_layout ==-1 ) {
@@ -630,6 +694,12 @@ static void graph_insert_into_new_columns(struct git_graph *graph, } graph->mapping[mapping_idx] = i; + +/* +* Mark non-first parents of a merge. +*/ +if (graph->num_parents >1 && initial_merge_layout >=0 && idx >-1 ) + graph->new_columns[i].is_merge_parent =1 ; }static void graph_update_columns (struct git_graph *graph)
@@ -721,10 +791,20 @@ static void graph_update_columns(struct git_graph *graph)if (graph->num_parents ==0 ) graph->width +=2 ; }else { +int j;graph_insert_into_new_columns (graph, col_commit,-1 ); +/* +* This column is not the current commit, but we need to +* propagate the flag until the commit is processed. +*/ + j =graph_find_new_column_by_commit (graph, col_commit); +if (j >=0 && graph->columns[i].is_merge_parent) + graph->new_columns[j].is_merge_parent =1 ; } } + graph->commit_in_columns = is_commit_in_columns; +/* * If graph_max_lanes is set, cap the width */
@@ -810,9 +890,104 @@ void graph_push_lookahead(struct git_graph *graph, struct commit *c) graph->lookahead[graph->lookahead_nr++] = c; } +/* +* A commit can be a visual root when: +* +* - It has no parents. +* +* - It has parents but they are all filtered out and +* commit->parents arrives NULL. +* +* - It is not a boundary commit. Boundary commits also have no visible +* parents, but they are not selected as visual roots because they cannot +* cause the ambiguity of being vertically adjacent because: +* +* 1. A boundary only appears because an included commit is its child. +* Children are always above, and the renderer draws an edge down to +* the boundary from that child. Rather than starting a column like a +* visual root would do, it inherits its child column. +* +* 2. Included commits cannot appear below a boundary. Boundaries are +* ancestors of the exclusion point; if an included commit were an +* ancestor of the boundary it would be excluded and not rendered. +* Boundaries therefore always sink to the bottom. +*/ +static int graph_is_visual_root_candidate (struct commit *c) +{ +return c->parents ==NULL && !(c->object.flags &BOUNDARY ); +} + +static int graph_is_visual_root (struct git_graph *graph, +struct graph_lookahead_flags *flags) +{ +/* +* This must be only called for the current commit as graph contains +* the state for the current commit only. +* +* To check if a commit is a visual root, call graph_is_visual_root_candidate() +* but we won't know if it is really a visual root until we get to the +* next commit state. +* +* The current commit is an actual visual root if it is a candidate and +* the commit is not a non-first parent of a merge. +* +* * +* |\ +* | * <- it is a visual root candidate but it shouldn't be indented +* * because it is already connected by an edge. +* ^ if commit_in_columns && is_merge_parent means the commit +* | was put by a merge and is connected. +* | +* `-------- if !is_next_visible means we're on the last commit, avoid +* indentation unless the one before is a visual root, then +* we need to differentiate from the one above. +* +* If next_has_columns means that the next commit has +* already a column, so it will not be rendered below, the +* current commit has to act as the last commit and omit +* indentation. +*/ +return graph_is_visual_root_candidate (graph->commit) && + !(graph->commit_in_columns && + graph->columns[graph->commit_index].is_merge_parent) && + flags->is_next_visible && + (!flags->next_has_column || graph->visual_root_depth >0 ); +} + +/* +* Peeks the next commits via the lookahead buffer and sets the lookahead flags. +*/ +static void graph_peek_next_visible (struct git_graph *graph, +struct graph_lookahead_flags *flags) +{ + flags->is_next_visible =0 ; + flags->is_next_visual_root =0 ; + flags->next_has_column =0 ; + +if (!graph->lookahead_nr) +return ; + + flags->is_next_visible =1 ; + flags->next_has_column = +graph_find_new_column_by_commit (graph, graph->lookahead[0 ]) >=0 ; + +if (!graph_is_visual_root_candidate (graph->lookahead[0 ])) +return ; + +if (graph->lookahead_nr >=2 ) + flags->is_next_visual_root =1 ; +} + +static int graph_needs_pre_root_line (struct git_graph *graph) +{ +return graph->commit_in_columns && graph->is_visual_root && + graph->num_columns >0 && !graph->visual_root_cascade; +} +void graph_update (struct git_graph *graph,struct commit *commit) {struct commit_list *parent; +struct graph_lookahead_flags flags;/* * Set the new commit
@@ -843,6 +1018,23 @@ void graph_update(struct git_graph *graph, struct commit *commit)*/ graph_update_columns (graph); +graph_peek_next_visible (graph, &flags); + + graph->is_visual_root =graph_is_visual_root (graph, &flags); + +if (graph->is_visual_root) { +/* +* If next is a visual root we can omit the indent for the first +* visual root and start cascading. +*/ +if (!graph->visual_root_depth && flags.is_next_visual_root) + graph->visual_root_cascade =1 ; + graph->visual_root_depth++; + }else { + graph->visual_root_depth =0 ; + graph->visual_root_cascade =0 ; + } + graph->expansion_row =0 ;/*
@@ -860,11 +1052,16 @@ void graph_update(struct git_graph *graph, struct commit *commit)* room for it. We need to do this only if there is a branch row * (or more) to the right of this commit. * +* If it is a visual root, we need to print an extra row to +* connect the indentation. +* * If there are less than 3 parents, we can immediately print the * commit line. */ if (graph->state !=GRAPH_PADDING ) graph->state =GRAPH_SKIP ; +else if (graph_needs_pre_root_line (graph)) + graph->state =GRAPH_PRE_ROOT ;else if (graph_needs_pre_commit_line (graph)) graph->state =GRAPH_PRE_COMMIT ;else
@@ -1112,6 +1309,17 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_lineif (col_commit == graph->commit) { seen_this =1 ; +if (graph->is_visual_root) { +int depth = graph->visual_root_depth; +/* +* Each visual column is 2 characters wide. +* Omit the indentation for the first visual +* root in cascade mode. +*/ +int padding = (depth - graph->visual_root_cascade) *2 ; +graph_line_addchars (line,' ' , padding); + graph->width += padding; + }graph_output_commit_char (graph, line);if (graph_needs_truncation (graph, i)) {
@@ -1483,6 +1691,30 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_lgraph_update_state (graph,GRAPH_PADDING ); } +static void graph_output_pre_root_line (struct git_graph *graph,struct graph_line *line) +{ +/* +* This function adds a row before a visual root, to connect the +* branch to the indented commit. It must only be called on a +* visual root. +*/ +if (!graph->is_visual_root) +BUG ("commit must be a visual root to call pre_root_line" ); + +for (size_t i =0 ; i < graph->num_columns; i++) { +struct column *col = &graph->columns[i]; +if (col->commit == graph->commit) { +graph_line_addch (line,' ' ); +graph_line_write_column (line, col,'\\' ); + }else { +graph_line_write_column (line, col,'|' ); + } +graph_line_addch (line,' ' ); + } + +graph_update_state (graph,GRAPH_COMMIT ); +} +int graph_next_line (struct git_graph *graph,struct strbuf *sb) {int shown_commit_line =0 ;
@@ -1508,6 +1740,9 @@ int graph_next_line(struct git_graph *graph, struct strbuf *sb)case GRAPH_PRE_COMMIT :graph_output_pre_commit_line (graph, &line);break ; +case GRAPH_PRE_ROOT : +graph_output_pre_root_line (graph, &line); +break ;case GRAPH_COMMIT :graph_output_commit_line (graph, &line); shown_commit_line =1 ;
t/meson.build +1 -0
@@ -576,6 +576,7 @@ integration_tests = [ 't4215-log-skewed-merges.sh', 't4216-log-bloom.sh', 't4217-log-limit.sh', + 't4218-log-graph-indentation.sh', 't4252-am-options.sh', 't4253-am-keep-cr-dos.sh', 't4254-am-corrupt.sh',
t/t4218-log-graph-indentation.sh new file +453 -0
453 lines not on this page · raw message
Signature · 1 line
2.54.0
v8 cover graph: indent visual roots in graph
In reply to Pablo SabaterWhen rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This series adds indentation to the visual root commits, so they cannot be vertically adjacent anymore making it easier to identify them.
Before indentation:
* A
* B1
* B2
* C1
* C2
After indentation:
* A
* B1
\
* B2
* C1
* C2
Indents the visual root commits that have still commits to show after them, and if they have children it connects them with an edge at a new row.
If there are multiple visual roots adjacent in history, the indentation starts with the second one, avoiding redundant indentation of the first one and cascades after the second.
* A
* B
* C
* D1
* D2
This series first commit is a cleanup that brings a common function from t4215 and t6016 to a graph functions file which they both use, so the new test file for indentation, t4218, can use it as well.
GitHub CI: https://github.com/pabloosabaterr/git/actions/runs/29082267633
[1]: https://lore.kernel.org/git/[email protected]/
V7 DIFF:
- New commit (2nd) "revision: add next_commit_to_show()" I wanted to drop (!revs->max_count_stage && !revs->reverse_output_stage) because --reverse is not compatible with --graph and I wanted the indentation to work with --max-count-oldest. Dropping it broke tests at t4202 because the lookahead buffer was being populated from a different source.
This new commit adds a helper to get the commits for the lookahead from the same source.
- Typos and style.
- Added --max-count and --max-count-oldest tests.
- graph_get_lookahead_room() now uses ARRAY_SIZE() instead of the hardcoded size 2.
- Added an assert on graph_pop_lookahead()
---
Pablo Sabater (4):
lib-log-graph: move check_graph function
revision: add next_commit_to_show()
graph: add a 2 commit buffer for lookahead
graph: indent visual root in graph
graph.c | 286 +++++++++++++++++ graph.h | 17 ++ revision.c | 48 ++- t/lib-log-graph.sh | 5 + t/meson.build | 1 + t/t4215-log-skewed-merges.sh | 33 +- t/t4218-log-graph-indentation.sh | 473 +++++++++++++++++++++++++++++ t/t6016-rev-list-graph-simplify-history.sh | 25 +- 8 files changed, 843 insertions(+), 45 deletions(-)
base-commit: f85a7e662054a7b0d9070e432508831afa214b47
PATCH v8 1/4 lib-log-graph: move check_graph function
check_graph is a function shared in the test files t4215 and t6016 used to format the output graph, but instead of being in a file called by both test, the function code is repeated in each file.
Move check_graph to lib-log-graph.sh file which both tests already import graph functions from, renaming it to lib_test_check_graph.
This function is needed for the following commit which includes graph tests in a new file and requires check_graph.
--- t/lib-log-graph.sh | 5 +++++ t/t4215-log-skewed-merges.sh | 33 +++++++++++++----------------- t/t6016-rev-list-graph-simplify-history.sh | 25 +++++++++------------- 3 files changed, 29 insertions(+), 34 deletions(-)
t/lib-log-graph.sh +5 -0
@@ -26,3 +26,8 @@ lib_test_cmp_colored_graph () { test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors && test_cmp expect.colors output.colors } + +lib_test_check_graph () { + cat >expect && + lib_test_cmp_graph --format=%s "$@" +}
t/t4215-log-skewed-merges.sh +14 -19
@@ -5,11 +5,6 @@ test_description='git log --graph of skewed merges' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh -check_graph () { - cat >expect && - lib_test_cmp_graph --format=%s "$@" -} - test_expect_success 'log --graph with merge fusing with its left and right neighbors' ' git checkout --orphan _p && test_commit A &&
@@ -21,7 +16,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh git checkout _p && git merge --no-ff _r -m G && git checkout @^^ && git merge --no-ff _p -m H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * H |\ | * G
@@ -49,7 +44,7 @@ test_expect_success 'log --graph with left-skewed merge' ' git checkout 0_p && git merge --no-ff 0_s -m 0_G && git checkout @^ && git merge --no-ff 0_q 0_r 0_t 0_p -m 0_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF *-----. 0_H |\ \ \ \ | | | | * 0_G
@@ -83,7 +78,7 @@ test_expect_success 'log --graph with nested left-skewed merge' ' git checkout 1_p && git merge --no-ff 1_r -m 1_G && git checkout @^^ && git merge --no-ff 1_p -m 1_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 1_H |\ | * 1_G
@@ -115,7 +110,7 @@ test_expect_success 'log --graph with nested left-skewed merge following normal git checkout -b 2_s @^^ && git merge --no-ff 2_q -m 2_J && git checkout 2_p && git merge --no-ff 2_s -m 2_K && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 2_K |\ | * 2_J
@@ -151,7 +146,7 @@ test_expect_success 'log --graph with nested right-skewed merge following left-s git checkout 3_p && git merge --no-ff 3_r -m 3_H && git checkout @^^ && git merge --no-ff 3_p -m 3_J && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 3_J |\ | * 3_H
@@ -182,7 +177,7 @@ test_expect_success 'log --graph with right-skewed merge following a left-skewed git merge --no-ff 4_p -m 4_G && git checkout @^^ && git merge --no-ff 4_s -m 4_H && - check_graph --date-order <<-\EOF + lib_test_check_graph --date-order <<-\EOF * 4_H |\ | * 4_G
@@ -218,7 +213,7 @@ test_expect_success 'log --graph with octopus merge with column joining its penu git checkout 5_r && git merge --no-ff 5_s -m 5_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 5_H |\ | *-. 5_G
@@ -257,7 +252,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout 6_1 && git merge --no-ff 6_2 -m 6_I && - check_graph 6_1 6_3 6_5 <<-\EOF + lib_test_check_graph 6_1 6_3 6_5 <<-\EOF * 6_I |\ | | * 6_H
@@ -334,7 +329,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout -b M_7 7_1 && git merge --no-ff 7_2 7_3 -m 7_M4 && - check_graph M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -371,7 +366,7 @@ test_expect_success 'log --graph with multiple tips' ' ' test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' ' - check_graph --graph-lane-limit=2 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=2 M_7 <<-\EOF *-. 7_M4 |\ \ | | * 7_G
@@ -388,7 +383,7 @@ test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' ' ' test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge' ' - check_graph --graph-lane-limit=1 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=1 M_7 <<-\EOF *-~ 7_M4 |\~ | ~ 7_G
@@ -405,7 +400,7 @@ test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge ' test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' ' - check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -441,7 +436,7 @@ test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' ' ' test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows first of 3 parent merge' ' - check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -478,7 +473,7 @@ test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows fir ' test_expect_success 'log --graph --graph-lane-limit=7 check if it shows all 3 parent merge' ' - check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
t/t6016-rev-list-graph-simplify-history.sh +10 -15
@@ -13,11 +13,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh -check_graph () { - cat >expect && - lib_test_cmp_graph --format=%s "$@" -} - test_expect_success 'set up rev-list --graph test' ' # 3 commits on branch A test_commit A1 foo.txt &&
@@ -54,7 +49,7 @@ test_expect_success 'set up rev-list --graph test' ' ' test_expect_success '--graph --all' ' - check_graph --all <<-\EOF + lib_test_check_graph --all <<-\EOF * A7 * A6 |\
@@ -82,7 +77,7 @@ test_expect_success '--graph --all' ' # that undecorated merges are interesting, even with --simplify-by-decoration test_expect_success '--graph --simplify-by-decoration' ' git tag -d A4 && - check_graph --all --simplify-by-decoration <<-\EOF + lib_test_check_graph --all --simplify-by-decoration <<-\EOF * A7 * A6 |\
@@ -114,7 +109,7 @@ test_expect_success 'setup: get rid of decorations on B' ' # Graph with branch B simplified away test_expect_success '--graph --simplify-by-decoration prune branch B' ' - check_graph --simplify-by-decoration --all <<-\EOF + lib_test_check_graph --simplify-by-decoration --all <<-\EOF * A7 * A6 |\
@@ -133,7 +128,7 @@ test_expect_success '--graph --simplify-by-decoration prune branch B' ' ' test_expect_success '--graph --full-history -- bar.txt' ' - check_graph --full-history --all -- bar.txt <<-\EOF + lib_test_check_graph --full-history --all -- bar.txt <<-\EOF * A7 * A6 |\
@@ -148,7 +143,7 @@ test_expect_success '--graph --full-history -- bar.txt' ' ' test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' - check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF + lib_test_check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF * A7 * A6 |\
@@ -161,7 +156,7 @@ test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' ' test_expect_success '--graph -- bar.txt' ' - check_graph --all -- bar.txt <<-\EOF + lib_test_check_graph --all -- bar.txt <<-\EOF * A7 * A5 * A3
@@ -172,7 +167,7 @@ test_expect_success '--graph -- bar.txt' ' ' test_expect_success '--graph --sparse -- bar.txt' ' - check_graph --sparse --all -- bar.txt <<-\EOF + lib_test_check_graph --sparse --all -- bar.txt <<-\EOF * A7 * A6 * A5
@@ -189,7 +184,7 @@ test_expect_success '--graph --sparse -- bar.txt' ' ' test_expect_success '--graph ^C4' ' - check_graph --all ^C4 <<-\EOF + lib_test_check_graph --all ^C4 <<-\EOF * A7 * A6 * A5
@@ -202,7 +197,7 @@ test_expect_success '--graph ^C4' ' ' test_expect_success '--graph ^C3' ' - check_graph --all ^C3 <<-\EOF + lib_test_check_graph --all ^C3 <<-\EOF * A7 * A6 |\
@@ -220,7 +215,7 @@ test_expect_success '--graph ^C3' ' # that important, but this test depends on it. If the ordering ever changes # in the code, we'll need to update this test. test_expect_success '--graph --boundary ^C3' ' - check_graph --boundary --all ^C3 <<-\EOF + lib_test_check_graph --boundary --all ^C3 <<-\EOF * A7 * A6 |\
Signature · 1 line
2.54.0
PATCH v8 2/4 revision: add next_commit_to_show()
In reply to Pablo Sabaterget_revision() gets its commits from two sources depending on the mode:
1. Normally it gets the commits from get_revision_internal().
2. --max-count-oldest which was introduced at bb4ce23284 (revision.c:
implement --max-count-oldest, 2026-05-19) gets the commits by popping from a saved list at revs->commits marking SHOWN and CHILD_SHOWN on each popped commit.
Extract the choice logic into a helper, next_commit_to_show(), which returns the next commit regardless of the source it comes from.
This has no change in behavior. The helper is needed in a subsequent commit that pre-fetches two commits into a buffer for lookahead purposes and needs to pre-fetch from the same source.
The --reverse branch keeps its own pop loop. Using the helper for --reverse would additionally set SHOWN and CHILD_SHOWN which is not desired and a behavior change.
--- revision.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-)
revision.c +24 -12
@@ -4658,12 +4658,34 @@ static void retrieve_oldest_commits(struct rev_info *revs,commit_list_insert (c, queue); } +/* +* Returns the next commit that will be shown, regardless of whether it comes +* directly from the revision walk or from the list saved by the staged output +* of --max-count-oldest. +*/ +static struct commit *next_commit_to_show (struct rev_info *revs) +{ +struct commit *c; +struct commit_list *p; + +if (!revs->max_count_stage) +return get_revision_internal (revs); + + c =pop_commit (&revs->commits); +if (c) { + c->object.flags |=SHOWN ; +if (!(c->object.flags &BOUNDARY )) +for (p = c->parents; p; p = p->next) + p->item->object.flags |=CHILD_SHOWN ; + } +return c; +} +struct commit *get_revision (struct rev_info *revs) {struct commit *c;struct commit_list *reversed;struct commit_list *queue =NULL ; -struct commit_list *p;if (revs->max_count_type ==1 && !revs->max_count_stage) {retrieve_oldest_commits (revs, &queue);
@@ -4693,17 +4715,7 @@ struct commit *get_revision(struct rev_info *revs)return c; } -if (revs->max_count_stage) { - c =pop_commit (&revs->commits); -if (c) { - c->object.flags |=SHOWN ; -if (!(c->object.flags &BOUNDARY )) -for (p = c->parents; p; p = p->next) - p->item->object.flags |=CHILD_SHOWN ; - } - }else { - c =get_revision_internal (revs); - } + c =next_commit_to_show (revs);if (c && revs->graph)graph_update (revs->graph, c);
Signature · 1 line
2.54.0
PATCH v8 3/4 graph: add a 2 commit buffer for lookahead
In reply to Pablo SabaterIn a subsequent commit the graph renderer needs to know if the next commit is a visual root or if it is the last commit to be shown. This requires peeking 2 commits ahead.
Commits are pre-fetched in get_revision() through next_commit_to_show() where they are also marked as SHOWN, regardless the source they come from.
Update graph_is_interesting() so it considers commits inside the lookahead buffer as interesting as well.
--- graph.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ graph.h | 17 +++++++++++++++++ revision.c | 18 ++++++++++++++++-- 3 files changed, 84 insertions(+), 2 deletions(-)
graph.c +51 -0
@@ -315,6 +315,14 @@ struct git_graph {* diff_output_prefix_callback(). */ struct strbuf prefix_buf; + +/* +* Lookahead buffer: up to 2 pre-fetched commits that will be shown. +* Populated by get_revision() so graph_peek_next_visible() can use +* actual walk results instead of peeking at rev_info internals. +*/ +struct commit *lookahead[2 ]; +int lookahead_nr; };static inline int graph_needs_truncation (struct git_graph *graph,int lane)
@@ -388,6 +396,9 @@ struct git_graph *graph_init(struct rev_info *opt) graph->num_columns =0 ; graph->num_new_columns =0 ; graph->mapping_size =0 ; + graph->lookahead[0 ] =NULL ; + graph->lookahead[1 ] =NULL ; + graph->lookahead_nr =0 ;/* * Start the column color at the maximum value, since we'll * always increment it for the first commit we output.
@@ -456,6 +467,15 @@ static void graph_ensure_capacity(struct git_graph *graph, int num_columns)*/ static int graph_is_interesting (struct git_graph *graph,struct commit *commit) { +/* +* Commits in the lookahead buffer have been pre-fetched by +* get_revision() and will be shown in the future. They already have +* the SHOWN flag set when they were pre-fetched but the graph still +* needs to treat them as interesting parents. +*/ +for (int i =0 ; i < graph->lookahead_nr; i++) +if (graph->lookahead[i] == commit) +return 1 ;/* * If revs->boundary is set, commits whose children have * been shown are always interesting, even if they have the
@@ -763,6 +783,37 @@ static int graph_needs_pre_commit_line(struct git_graph *graph) graph->expansion_row <graph_num_expansion_rows (graph); } +struct commit *graph_pop_lookahead (struct git_graph *graph) +{ +struct commit *c; + +if (!graph->lookahead_nr) +return NULL ; + + c = graph->lookahead[0 ]; +if (!c) +BUG ("lookahead buffer has %d entries but the first one is NULL" , + graph->lookahead_nr); + + graph->lookahead[0 ] = graph->lookahead[1 ]; + graph->lookahead[1 ] =NULL ; + graph->lookahead_nr--; +return c; +} + +int graph_get_lookahead_room (struct git_graph *graph) +{ +return (int )ARRAY_SIZE (graph->lookahead) - graph->lookahead_nr; +} + +void graph_push_lookahead (struct git_graph *graph,struct commit *c) +{ +if (!graph_get_lookahead_room (graph)) +BUG ("pushing into lookahead buffer when it is already full" ); + + graph->lookahead[graph->lookahead_nr++] = c; +} +void graph_update (struct git_graph *graph,struct commit *commit) {struct commit_list *parent;
graph.h +17 -0
@@ -262,4 +262,21 @@ void graph_show_commit_msg(struct git_graph *graph,FILE *file, struct strbuf const *sb); +/* +* Pop the first commit from the graph's lookahead buffer. +* Returns NULL if the buffer is empty. +*/ +struct commit *graph_pop_lookahead (struct git_graph *graph); + +/* +* Returns how many more commits can be added to the lookahead buffer. +*/ +int graph_get_lookahead_room (struct git_graph *graph); + +/* +* Push a commit into the lookahead buffer. Must only be called when +* graph_get_lookahead_room() returns > 0. +*/ +void graph_push_lookahead (struct git_graph *graph,struct commit *c); +#endif /* GRAPH_H */
revision.c +16 -2
@@ -4715,10 +4715,24 @@ struct commit *get_revision(struct rev_info *revs)return c; } - c =next_commit_to_show (revs); +if (revs->graph) { + c =graph_pop_lookahead (revs->graph); +if (!c) + c =next_commit_to_show (revs); + }else { + c =next_commit_to_show (revs); + } -if (c && revs->graph) +if (c && revs->graph) { +while (graph_get_lookahead_room (revs->graph)) { +struct commit *next =next_commit_to_show (revs); +if (!next) +break ; +graph_push_lookahead (revs->graph, next); + }graph_update (revs->graph, c); + } +if (!c) {free_saved_parents (revs);commit_list_free (revs->previous_parents);
Signature · 1 line
2.54.0
PATCH v8 4/4 graph: indent visual root in graph
In reply to Pablo SabaterWhen rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This happens because the commits fill the space from left to right and when a visual root ends, its column becomes free for the following commit even if they are not related. Once this happens the unrelated commit is rendered below the visual root. Because there is no special character or way to identify when a visual root is rendered making the graph confusing.
By indenting the visual roots when there are still commits to show the vertical adjacency can be avoided.
Add is_visual_root flag to git_graph making it visible in all graph states, give graph_update() a new function, graph_is_visual_root() to know if the current commit is a visual root and set is_visual_root.
The different handled cases are:
- If a visual root has children: similar to GRAPH_PRE_COMMIT state when octopus merges need space, an edge row needs to be printed to connect the child with the indented visual root. A new state GRAPH_PRE_ROOT is needed to connect the child with the visual root:
* child of the visual root
\ GRAPH_PRE_ROOT
* visual root indented
- If a visual root is child-less we can skip GRAPH_PRE_ROOT state and render the indented commit directly.
* visual root indented
* unrelated commit
- If two or more visual roots are adjacent: by having a lookahead to the next commit that will be rendered, if the next commit is also a visual root and we are on a visual root, meaning two visual root adjacent in the history, the top one can omit the indent, making the one below to indent only once, if there are more adjacent visual commits, the indentation will increase for each adjacent one, cascading.
* visual root
* visual root
* visual root
* last commit
Even if the last commit is a root, because there is nothing that will be rendered below we can omit the indentation on purpose.
[1]: https://lore.kernel.org/git/[email protected]/
--- graph.c | 235 +++++++++++++++++++ t/meson.build | 1 + t/t4218-log-graph-indentation.sh | 473 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 709 insertions(+)
graph.c +235 -0
@@ -60,12 +60,23 @@ struct column {* index into column_colors. */ unsigned short color; +/* +* Marks if a commit is a non-first parent of a merge. These columns are +* already visually connected to the merge commit and do not need +* indentation. +* +* The first parent is the one that inherits the column and it can need +* indentation if turns out to be a visual root and there's still +* commits to render. +*/ + unsigned int is_merge_parent:1; };enum graph_state {GRAPH_PADDING ,GRAPH_SKIP ,GRAPH_PRE_COMMIT , +GRAPH_PRE_ROOT ,GRAPH_COMMIT ,GRAPH_POST_MERGE ,GRAPH_COLLAPSING
@@ -323,6 +334,51 @@ struct git_graph {*/ struct commit *lookahead[2 ];int lookahead_nr; + +/* +* If a commit is a visual root, we need to indent it to prevent +* unrelated commits from being vertically adjacent to it. +*/ + unsigned int is_visual_root:1; + +/* +* Indentation increases for each visual root adjacent to another visual +* root, making visual root commits indentation cascade. +*/ +unsigned int visual_root_depth; + +/* +* When a visual root is adjacent to other visual roots, the first one +* can avoid indentation and the rest cascades, increasing the indentation +* for each one. +*/ + unsigned int visual_root_cascade:1; + +/* +* Set when the current commit was already present in graph->columns +* before being processed. +*/ + unsigned int commit_in_columns:1; +}; + +struct graph_lookahead_flags { + +/* +* Set when there will be a commit after the current one that will be +* rendered. +*/ +unsigned int is_next_visible:1 ; + +/* +* Set when the next visible commit is candidate to be a visual root. +*/ +unsigned int is_next_visual_root:1 ; + +/* +* Set when the next visible commit will be rendered under the current +* commit. +*/ +unsigned int next_has_column:1 ; };static inline int graph_needs_truncation (struct git_graph *graph,int lane)
@@ -399,6 +455,8 @@ struct git_graph *graph_init(struct rev_info *opt) graph->lookahead[0 ] =NULL ; graph->lookahead[1 ] =NULL ; graph->lookahead_nr =0 ; + graph->visual_root_depth =0 ; + graph->visual_root_cascade =0 ;/* * Start the column color at the maximum value, since we'll * always increment it for the first commit we output.
@@ -581,6 +639,11 @@ static void graph_insert_into_new_columns(struct git_graph *graph, struct commit *commit, int idx) { +/* +* Get the initial merge_layout before it's modified to know if this +* is a merge. +*/ +int initial_merge_layout = graph->merge_layout;int i =graph_find_new_column_by_commit (graph, commit);int mapping_idx;
@@ -592,6 +655,7 @@ static void graph_insert_into_new_columns(struct git_graph *graph, i = graph->num_new_columns++; graph->new_columns[i].commit = commit; graph->new_columns[i].color =graph_find_commit_color (graph, commit); + graph->new_columns[i].is_merge_parent =0 ; }if (graph->num_parents >1 && idx >-1 && graph->merge_layout ==-1 ) {
@@ -630,6 +694,12 @@ static void graph_insert_into_new_columns(struct git_graph *graph, } graph->mapping[mapping_idx] = i; + +/* +* Mark non-first parents of a merge. +*/ +if (graph->num_parents >1 && initial_merge_layout >=0 && idx >-1 ) + graph->new_columns[i].is_merge_parent =1 ; }static void graph_update_columns (struct git_graph *graph)
@@ -721,10 +791,20 @@ static void graph_update_columns(struct git_graph *graph)if (graph->num_parents ==0 ) graph->width +=2 ; }else { +int j;graph_insert_into_new_columns (graph, col_commit,-1 ); +/* +* This column is not the current commit, but we need to +* propagate the flag until the commit is processed. +*/ + j =graph_find_new_column_by_commit (graph, col_commit); +if (j >=0 && graph->columns[i].is_merge_parent) + graph->new_columns[j].is_merge_parent =1 ; } } + graph->commit_in_columns = is_commit_in_columns; +/* * If graph_max_lanes is set, cap the width */
@@ -814,9 +894,104 @@ void graph_push_lookahead(struct git_graph *graph, struct commit *c) graph->lookahead[graph->lookahead_nr++] = c; } +/* +* A commit can be a visual root when: +* +* - It has no parents. +* +* - It has parents but they are all filtered out and +* commit->parents arrives NULL. +* +* - It is not a boundary commit. Boundary commits also have no visible +* parents, but they are not selected as visual roots because they cannot +* cause the ambiguity of being vertically adjacent because: +* +* 1. A boundary only appears because an included commit is its child. +* Children are always above, and the renderer draws an edge down to +* the boundary from that child. Rather than starting a column like a +* visual root would do, it inherits its child column. +* +* 2. Included commits cannot appear below a boundary. Boundaries are +* ancestors of the exclusion point; if an included commit were an +* ancestor of the boundary it would be excluded and not rendered. +* Boundaries therefore always sink to the bottom. +*/ +static int graph_is_visual_root_candidate (struct commit *c) +{ +return c->parents ==NULL && !(c->object.flags &BOUNDARY ); +} + +static int graph_is_visual_root (struct git_graph *graph, +struct graph_lookahead_flags *flags) +{ +/* +* This must be only called for the current commit as graph contains +* the state for the current commit only. +* +* To check if a commit is a visual root, call graph_is_visual_root_candidate() +* but we won't know if it is really a visual root until we get to the +* next commit state. +* +* The current commit is an actual visual root if it is a candidate and +* the commit is not a non-first parent of a merge. +* +* * +* |\ +* | * <- it is a visual root candidate but it shouldn't be indented +* * because it is already connected by an edge. +* ^ if commit_in_columns && is_merge_parent means the commit +* | was put by a merge and is connected. +* | +* `-------- if !is_next_visible means we're on the last commit, avoid +* indentation unless the one before is a visual root, then +* we need to differentiate from the one above. +* +* If next_has_columns means that the next commit has +* already a column, so it will not be rendered below, the +* current commit has to act as the last commit and omit +* indentation. +*/ +return graph_is_visual_root_candidate (graph->commit) && + !(graph->commit_in_columns && + graph->columns[graph->commit_index].is_merge_parent) && + flags->is_next_visible && + (!flags->next_has_column || graph->visual_root_depth >0 ); +} + +/* +* Peeks the next commits via the lookahead buffer and sets the lookahead flags. +*/ +static void graph_peek_next_visible (struct git_graph *graph, +struct graph_lookahead_flags *flags) +{ + flags->is_next_visible =0 ; + flags->is_next_visual_root =0 ; + flags->next_has_column =0 ; + +if (!graph->lookahead_nr) +return ; + + flags->is_next_visible =1 ; + flags->next_has_column = +graph_find_new_column_by_commit (graph, graph->lookahead[0 ]) >=0 ; + +if (!graph_is_visual_root_candidate (graph->lookahead[0 ])) +return ; + +if (graph->lookahead_nr >=2 ) + flags->is_next_visual_root =1 ; +} + +static int graph_needs_pre_root_line (struct git_graph *graph) +{ +return graph->commit_in_columns && graph->is_visual_root && + graph->num_columns >0 && !graph->visual_root_cascade; +} +void graph_update (struct git_graph *graph,struct commit *commit) {struct commit_list *parent; +struct graph_lookahead_flags flags;/* * Set the new commit
@@ -847,6 +1022,23 @@ void graph_update(struct git_graph *graph, struct commit *commit)*/ graph_update_columns (graph); +graph_peek_next_visible (graph, &flags); + + graph->is_visual_root =graph_is_visual_root (graph, &flags); + +if (graph->is_visual_root) { +/* +* If next is a visual root we can omit the indent for the first +* visual root and start cascading. +*/ +if (!graph->visual_root_depth && flags.is_next_visual_root) + graph->visual_root_cascade =1 ; + graph->visual_root_depth++; + }else { + graph->visual_root_depth =0 ; + graph->visual_root_cascade =0 ; + } + graph->expansion_row =0 ;/*
@@ -864,11 +1056,16 @@ void graph_update(struct git_graph *graph, struct commit *commit)* room for it. We need to do this only if there is a branch row * (or more) to the right of this commit. * +* If it is a visual root, we need to print an extra row to +* connect the indentation. +* * If there are less than 3 parents, we can immediately print the * commit line. */ if (graph->state !=GRAPH_PADDING ) graph->state =GRAPH_SKIP ; +else if (graph_needs_pre_root_line (graph)) + graph->state =GRAPH_PRE_ROOT ;else if (graph_needs_pre_commit_line (graph)) graph->state =GRAPH_PRE_COMMIT ;else
@@ -1116,6 +1313,17 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_lineif (col_commit == graph->commit) { seen_this =1 ; +if (graph->is_visual_root) { +int depth = graph->visual_root_depth; +/* +* Each visual column is 2 characters wide. +* Omit the indentation for the first visual +* root in cascade mode. +*/ +int padding = (depth - graph->visual_root_cascade) *2 ; +graph_line_addchars (line,' ' , padding); + graph->width += padding; + }graph_output_commit_char (graph, line);if (graph_needs_truncation (graph, i)) {
@@ -1487,6 +1695,30 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_lgraph_update_state (graph,GRAPH_PADDING ); } +static void graph_output_pre_root_line (struct git_graph *graph,struct graph_line *line) +{ +/* +* This function adds a row before a visual root, to connect the +* branch to the indented commit. It must only be called on a +* visual root. +*/ +if (!graph->is_visual_root) +BUG ("commit must be a visual root to call pre_root_line" ); + +for (int i =0 ; i < graph->num_columns; i++) { +struct column *col = &graph->columns[i]; +if (col->commit == graph->commit) { +graph_line_addch (line,' ' ); +graph_line_write_column (line, col,'\\' ); + }else { +graph_line_write_column (line, col,'|' ); + } +graph_line_addch (line,' ' ); + } + +graph_update_state (graph,GRAPH_COMMIT ); +} +int graph_next_line (struct git_graph *graph,struct strbuf *sb) {int shown_commit_line =0 ;
@@ -1512,6 +1744,9 @@ int graph_next_line(struct git_graph *graph, struct strbuf *sb)case GRAPH_PRE_COMMIT :graph_output_pre_commit_line (graph, &line);break ; +case GRAPH_PRE_ROOT : +graph_output_pre_root_line (graph, &line); +break ;case GRAPH_COMMIT :graph_output_commit_line (graph, &line); shown_commit_line =1 ;
t/meson.build +1 -0
@@ -577,6 +577,7 @@ integration_tests = [ 't4215-log-skewed-merges.sh', 't4216-log-bloom.sh', 't4217-log-limit.sh', + 't4218-log-graph-indentation.sh', 't4219-log-follow-merge.sh', 't4252-am-options.sh', 't4253-am-keep-cr-dos.sh',
t/t4218-log-graph-indentation.sh new file +473 -0
473 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v8 4/4] graph: indent visual root in graph
Quoted 58 lines · Pablo Sabater
When rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This happens because the commits fill the space from left to right and when a visual root ends, its column becomes free for the following commit even if they are not related. Once this happens the unrelated commit is rendered below the visual root. Because there is no special character or way to identify when a visual root is rendered making the graph confusing.
By indenting the visual roots when there are still commits to show the vertical adjacency can be avoided.
Add
is_visual_rootflag togit_graphmaking it visible in all graph states, givegraph_update()a new function,graph_is_visual_root()to know if the current commit is a visual root and setis_visual_root.
The different handled cases are:- If a visual root has children: similar to
GRAPH_PRE_COMMITstate when octopus merges need space, an edge row needs to be printed to connect the child with the indented visual root. A new stateGRAPH_PRE_ROOTis needed to connect the child with the visual root:* child of the visual root
\GRAPH_PRE_ROOT
* visual root indented- If a visual root is child-less we can skip
GRAPH_PRE_ROOTstate and render the indented commit directly.* visual root indented
* unrelated commit- If two or more visual roots are adjacent: by having a lookahead to the next commit that will be rendered, if the next commit is also a visual root and we are on a visual root, meaning two visual root adjacent in the history, the top one can omit the indent, making the one below to indent only once, if there are more adjacent visual commits, the indentation will increase for each adjacent one, cascading.
* visual root
* visual root
* visual root
* last commitEven if the last commit is a root, because there is nothing that will be rendered below we can omit the indentation on purpose.
[1]: https://lore.kernel.org/git/[email protected]/
Helped-by Kristofer Karlsson <[email protected]>Mentored-by Karthik Nayak <[email protected]>Mentored-by Chandra Pratap <[email protected]>Signed-off-by Pablo Sabater <[email protected]>
Quoted 5 lines
--- graph.c | 235 +++++++++++++++++++ t/meson.build | 1 + t/t4218-log-graph-indentation.sh | 473 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 709 insertions(+)
This doesn't seem to work for every visual root e.g.
git log --graph --oneline --author="Mirko Faina"
The visual roots are not indented.
Quoted 16 lines
graph.c +16
-0+/* +* A commit can be a visual root when: +* +* - It has no parents. +* +* - It has parents but they are all filtered out and +* commit->parents arrives NULL. +* +* - It is not a boundary commit. Boundary commits also have no visible +* parents, but they are not selected as visual roots because they cannot +* cause the ambiguity of being vertically adjacent because: +* +* 1. A boundary only appears because an included commit is its child. +* Children are always above, and the renderer draws an edge down to +* the boundary from that child. Rather than starting a column like a +* visual root would do, it inherits its child column.
graph.c void graph_push_lookahead(struct git_graph *graph, struct commit *c) · line 922
Quoted 10 lines
graph.c +10
-0+* +* 2. Included commits cannot appear below a boundary. Boundaries are +* ancestors of the exclusion point; if an included commit were an +* ancestor of the boundary it would be excluded and not rendered. +* Boundaries therefore always sink to the bottom. +*/ +static int graph_is_visual_root_candidate (struct commit *c) +{ +return c->parents ==NULL && !(c->object.flags &BOUNDARY ); +}
I suspect this behaviour is due to these assumptions being too strict.
When we use the --author option the parents are not filtered out, so it doesn't return NULL desipte being a visual root. We realize it is a visual root only on the next commit, but once we are on the next commit we can't indent as we have already printed this commit.
We realize only on the next commit after hitting simplify_commit(), it calls get_commit_action() and checks if should keep the commit based on the regex we provided. If the regex is not matched the commit is just ignored (we do not filter parents based on regex when we expand a topo walk).
At least that's what I gather, if anyone can confirm this...
Re: [PATCH v8 4/4] graph: indent visual root in graph
Quoted 106 lines · Mirko Faina
Quoted 58 lines · Pablo Sabater
When rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This happens because the commits fill the space from left to right and when a visual root ends, its column becomes free for the following commit even if they are not related. Once this happens the unrelated commit is rendered below the visual root. Because there is no special character or way to identify when a visual root is rendered making the graph confusing.
By indenting the visual roots when there are still commits to show the vertical adjacency can be avoided.
Add
is_visual_rootflag togit_graphmaking it visible in all graph states, givegraph_update()a new function,graph_is_visual_root()to know if the current commit is a visual root and setis_visual_root.
The different handled cases are:- If a visual root has children: similar to
GRAPH_PRE_COMMITstate when octopus merges need space, an edge row needs to be printed to connect the child with the indented visual root. A new stateGRAPH_PRE_ROOTis needed to connect the child with the visual root:* child of the visual root
\GRAPH_PRE_ROOT
* visual root indented- If a visual root is child-less we can skip
GRAPH_PRE_ROOTstate and render the indented commit directly.* visual root indented
* unrelated commit- If two or more visual roots are adjacent: by having a lookahead to the next commit that will be rendered, if the next commit is also a visual root and we are on a visual root, meaning two visual root adjacent in the history, the top one can omit the indent, making the one below to indent only once, if there are more adjacent visual commits, the indentation will increase for each adjacent one, cascading.
* visual root
* visual root
* visual root
* last commitEven if the last commit is a root, because there is nothing that will be rendered below we can omit the indentation on purpose.
[1]: https://lore.kernel.org/git/[email protected]/
Helped-by Kristofer Karlsson <[email protected]>Mentored-by Karthik Nayak <[email protected]>Mentored-by Chandra Pratap <[email protected]>Signed-off-by Pablo Sabater <[email protected]>Quoted 5 lines
--- graph.c | 235 +++++++++++++++++++ t/meson.build | 1 + t/t4218-log-graph-indentation.sh | 473 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 709 insertions(+)This doesn't seem to work for every visual root e.g.
git log --graph --oneline --author="Mirko Faina"The visual roots are not indented.
Quoted 16 lines
graph.c +16
-0+/* +* A commit can be a visual root when: +* +* - It has no parents. +* +* - It has parents but they are all filtered out and +* commit->parents arrives NULL. +* +* - It is not a boundary commit. Boundary commits also have no visible +* parents, but they are not selected as visual roots because they cannot +* cause the ambiguity of being vertically adjacent because: +* +* 1. A boundary only appears because an included commit is its child. +* Children are always above, and the renderer draws an edge down to +* the boundary from that child. Rather than starting a column like a +* visual root would do, it inherits its child column. graph.c void graph_push_lookahead(struct git_graph *graph, struct commit *c) · line 922
Quoted 10 lines
graph.c +10
-0+* +* 2. Included commits cannot appear below a boundary. Boundaries are +* ancestors of the exclusion point; if an included commit were an +* ancestor of the boundary it would be excluded and not rendered. +* Boundaries therefore always sink to the bottom. +*/ +static int graph_is_visual_root_candidate (struct commit *c) +{ +return c->parents ==NULL && !(c->object.flags &BOUNDARY ); +}I suspect this behaviour is due to these assumptions being too strict.
When we use the --author option the parents are not filtered out, so it doesn't return NULL desipte being a visual root. We realize it is a visual root only on the next commit, but once we are on the next commit we can't indent as we have already printed this commit.
Quoted 7 lines
We realize only on the next commit after hitting
simplify_commit(), it callsget_commit_action()and checks if should keep the commit based on the regex we provided. If the regex is not matched the commit is just ignored (we do not filter parents based on regex when we expand a topo walk).At least that's what I gather, if anyone can confirm this...
Hi!
Yes, I just tried with the same:
git log --graph --oneline --author="Mirko Faina"
And no indentation sadly, if when we use --author the parents are not excluded then the c->parents is not enough.
I think that it should be fine if we iterate each parent and call graph_is_interesting() that also calls get_commit_action() as a fallback.
Something like:
graph_is_visual_root_candidate():
/* We keep ignoring boundary commits */
if (c->object.flags & BOUNDARY)
return 0;
/* Check the parents if they are not excluded because of options like
--author */
for (p = c->parents; p; p = p->next)
if(graph_is_interesting(graph, p->item))
return 0;return 1;
I haven't tried yet though, but if --author has this problem, probably other options like --grep would likely fail too because of the same reason.
Thanks for the feedback,
Pablo
v9 cover graph: indent visual roots in graph
In reply to Pablo SabaterWhen rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This series adds indentation to the visual root commits, so they cannot be vertically adjacent anymore making it easier to identify them.
Before indentation:
* A
* B1
* B2
* C1
* C2
After indentation:
* A
* B1
\
* B2
* C1
* C2
Indents the visual root commits that have still commits to show after them, and if they have children it connects them with an edge at a new row.
If there are multiple visual roots adjacent in history, the indentation starts with the second one, avoiding redundant indentation of the first one and cascades after the second.
* A
* B
* C
* D1
* D2
This series first commit is a cleanup that brings a common function from t4215 and t6016 to a graph functions file which they both use, so the new test file for indentation, t4218, can use it as well.
GitHub CI: https://github.com/pabloosabaterr/git/actions/runs/29154333559
[1]: https://lore.kernel.org/git/[email protected]/
V8 DIFF:
- Checking if the parents of a commit are NULL is not enough to know if the commit is a visual root due to options that filter the commit parents but they do not remove them (--author, --grep, etc). At graph_is_visual_root_candidate(), iterate the parents and call graph_is_interesting() for each of them to know whether they will be shown or not.
- Add a --author and a --grep test.
---
Pablo Sabater (4):
lib-log-graph: move check_graph function
revision: add next_commit_to_show()
graph: add a 2 commit buffer for lookahead
graph: indent visual root in graph
graph.c | 295 +++++++++++++++++ graph.h | 17 + revision.c | 48 ++- t/lib-log-graph.sh | 5 + t/meson.build | 1 + t/t4215-log-skewed-merges.sh | 33 +- t/t4218-log-graph-indentation.sh | 514 +++++++++++++++++++++++++++++ t/t6016-rev-list-graph-simplify-history.sh | 25 +- 8 files changed, 893 insertions(+), 45 deletions(-)
Range-diff versus v8:
1: ce4f6419c2 = 1: 22ab444372 lib-log-graph: move check_graph function
2: 8c7326745e = 2: ebb88c8b29 revision: add next_commit_to_show()
3: f2e895c72b = 3: 0705ee321e graph: add a 2 commit buffer for lookahead
4: 90d5d22344 ! 4: fa2e60fb3f graph: indent visual root in graph
@@ graph.c: void graph_push_lookahead(struct git_graph *graph, struct commit *c)
+ * - It has parents but they are all filtered out and
+ * commit->parents arrives NULL.
+ *
++ * - Its parents are uninteresting.
++ *
+ * - It is not a boundary commit. Boundary commits also have no visible
+ * parents, but they are not selected as visual roots because they cannot
+ * cause the ambiguity of being vertically adjacent because:
@@ graph.c: void graph_push_lookahead(struct git_graph *graph, struct commit *c)
+ * ancestor of the boundary it would be excluded and not rendered.
+ * Boundaries therefore always sink to the bottom.
+ */
-+static int graph_is_visual_root_candidate(struct commit *c)
++static int graph_is_visual_root_candidate(struct commit *c, struct git_graph *graph)
+{
-+ return c->parents == NULL && !(c->object.flags & BOUNDARY);
++ struct commit_list *p;
++
++ if (c->object.flags & BOUNDARY)
++ return 0;
++ for (p = c->parents; p; p = p->next)
++ if (graph_is_interesting(graph, p->item))
++ return 0;
++ return 1;
+}
+
+static int graph_is_visual_root(struct git_graph *graph,
@@ graph.c: void graph_push_lookahead(struct git_graph *graph, struct commit *c)
+ * current commit has to act as the last commit and omit
+ * indentation.
+ */
-+ return graph_is_visual_root_candidate(graph->commit) &&
++ return graph_is_visual_root_candidate(graph->commit, graph) &&
+ !(graph->commit_in_columns &&
+ graph->columns[graph->commit_index].is_merge_parent) &&
+ flags->is_next_visible &&
@@ graph.c: void graph_push_lookahead(struct git_graph *graph, struct commit *c)
+ flags->next_has_column =
+ graph_find_new_column_by_commit(graph, graph->lookahead[0]) >= 0;
+
-+ if (!graph_is_visual_root_candidate(graph->lookahead[0]))
++ if (!graph_is_visual_root_candidate(graph->lookahead[0], graph))
+ return;
+
+ if (graph->lookahead_nr >= 2)
@@ t/t4218-log-graph-indentation.sh (new)
+ EOF
+'
+
++# when the graph commits are filtered with regex options like --author, the
++# commit parents do not come NULL so it is needed to check if the parents are
++# interesting.
++test_expect_success '--author skipped parent makes a visual root' '
++ create_orphan _55 &&
++ test_tick &&
++ git commit --allow-empty -m 55_A &&
++ create_orphan _54 &&
++ test_tick &&
++ git commit --allow-empty --author="Other <[email protected]>" -m 54_A &&
++ test_tick &&
++ git commit --allow-empty -m 54_B &&
++ test_tick &&
++ git commit --allow-empty -m 54_C &&
++ lib_test_check_graph --author="A U Thor" _54 _55 <<-\EOF
++ * 54_C
++ \
++ * 54_B
++ * 55_A
++ EOF
++'
++
++test_expect_success '--grep skipped parent makes a visual root' '
++ create_orphan _57 &&
++ test_tick &&
++ git commit --allow-empty -m 57_keep_A &&
++ create_orphan _56 &&
++ test_tick &&
++ git commit --allow-empty -m 56_skip &&
++ test_tick &&
++ git commit --allow-empty -m 56_keep_A &&
++ test_tick &&
++ git commit --allow-empty -m 56_keep_B &&
++ lib_test_check_graph --grep=keep _56 _57 <<-\EOF
++ * 56_keep_B
++ \
++ * 56_keep_A
++ * 57_keep_A
++ EOF
++'
++
+test_done---
base-commit: f85a7e662054a7b0d9070e432508831afa214b47
PATCH v9 1/4 lib-log-graph: move check_graph function
check_graph is a function shared in the test files t4215 and t6016 used to format the output graph, but instead of being in a file called by both test, the function code is repeated in each file.
Move check_graph to lib-log-graph.sh file which both tests already import graph functions from, renaming it to lib_test_check_graph.
This function is needed for the following commit which includes graph tests in a new file and requires check_graph.
--- t/lib-log-graph.sh | 5 +++++ t/t4215-log-skewed-merges.sh | 33 +++++++++++++----------------- t/t6016-rev-list-graph-simplify-history.sh | 25 +++++++++------------- 3 files changed, 29 insertions(+), 34 deletions(-)
t/lib-log-graph.sh +5 -0
@@ -26,3 +26,8 @@ lib_test_cmp_colored_graph () { test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors && test_cmp expect.colors output.colors } + +lib_test_check_graph () { + cat >expect && + lib_test_cmp_graph --format=%s "$@" +}
t/t4215-log-skewed-merges.sh +14 -19
@@ -5,11 +5,6 @@ test_description='git log --graph of skewed merges' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh -check_graph () { - cat >expect && - lib_test_cmp_graph --format=%s "$@" -} - test_expect_success 'log --graph with merge fusing with its left and right neighbors' ' git checkout --orphan _p && test_commit A &&
@@ -21,7 +16,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh git checkout _p && git merge --no-ff _r -m G && git checkout @^^ && git merge --no-ff _p -m H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * H |\ | * G
@@ -49,7 +44,7 @@ test_expect_success 'log --graph with left-skewed merge' ' git checkout 0_p && git merge --no-ff 0_s -m 0_G && git checkout @^ && git merge --no-ff 0_q 0_r 0_t 0_p -m 0_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF *-----. 0_H |\ \ \ \ | | | | * 0_G
@@ -83,7 +78,7 @@ test_expect_success 'log --graph with nested left-skewed merge' ' git checkout 1_p && git merge --no-ff 1_r -m 1_G && git checkout @^^ && git merge --no-ff 1_p -m 1_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 1_H |\ | * 1_G
@@ -115,7 +110,7 @@ test_expect_success 'log --graph with nested left-skewed merge following normal git checkout -b 2_s @^^ && git merge --no-ff 2_q -m 2_J && git checkout 2_p && git merge --no-ff 2_s -m 2_K && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 2_K |\ | * 2_J
@@ -151,7 +146,7 @@ test_expect_success 'log --graph with nested right-skewed merge following left-s git checkout 3_p && git merge --no-ff 3_r -m 3_H && git checkout @^^ && git merge --no-ff 3_p -m 3_J && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 3_J |\ | * 3_H
@@ -182,7 +177,7 @@ test_expect_success 'log --graph with right-skewed merge following a left-skewed git merge --no-ff 4_p -m 4_G && git checkout @^^ && git merge --no-ff 4_s -m 4_H && - check_graph --date-order <<-\EOF + lib_test_check_graph --date-order <<-\EOF * 4_H |\ | * 4_G
@@ -218,7 +213,7 @@ test_expect_success 'log --graph with octopus merge with column joining its penu git checkout 5_r && git merge --no-ff 5_s -m 5_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 5_H |\ | *-. 5_G
@@ -257,7 +252,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout 6_1 && git merge --no-ff 6_2 -m 6_I && - check_graph 6_1 6_3 6_5 <<-\EOF + lib_test_check_graph 6_1 6_3 6_5 <<-\EOF * 6_I |\ | | * 6_H
@@ -334,7 +329,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout -b M_7 7_1 && git merge --no-ff 7_2 7_3 -m 7_M4 && - check_graph M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -371,7 +366,7 @@ test_expect_success 'log --graph with multiple tips' ' ' test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' ' - check_graph --graph-lane-limit=2 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=2 M_7 <<-\EOF *-. 7_M4 |\ \ | | * 7_G
@@ -388,7 +383,7 @@ test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' ' ' test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge' ' - check_graph --graph-lane-limit=1 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=1 M_7 <<-\EOF *-~ 7_M4 |\~ | ~ 7_G
@@ -405,7 +400,7 @@ test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge ' test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' ' - check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -441,7 +436,7 @@ test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' ' ' test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows first of 3 parent merge' ' - check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -478,7 +473,7 @@ test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows fir ' test_expect_success 'log --graph --graph-lane-limit=7 check if it shows all 3 parent merge' ' - check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
t/t6016-rev-list-graph-simplify-history.sh +10 -15
@@ -13,11 +13,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh -check_graph () { - cat >expect && - lib_test_cmp_graph --format=%s "$@" -} - test_expect_success 'set up rev-list --graph test' ' # 3 commits on branch A test_commit A1 foo.txt &&
@@ -54,7 +49,7 @@ test_expect_success 'set up rev-list --graph test' ' ' test_expect_success '--graph --all' ' - check_graph --all <<-\EOF + lib_test_check_graph --all <<-\EOF * A7 * A6 |\
@@ -82,7 +77,7 @@ test_expect_success '--graph --all' ' # that undecorated merges are interesting, even with --simplify-by-decoration test_expect_success '--graph --simplify-by-decoration' ' git tag -d A4 && - check_graph --all --simplify-by-decoration <<-\EOF + lib_test_check_graph --all --simplify-by-decoration <<-\EOF * A7 * A6 |\
@@ -114,7 +109,7 @@ test_expect_success 'setup: get rid of decorations on B' ' # Graph with branch B simplified away test_expect_success '--graph --simplify-by-decoration prune branch B' ' - check_graph --simplify-by-decoration --all <<-\EOF + lib_test_check_graph --simplify-by-decoration --all <<-\EOF * A7 * A6 |\
@@ -133,7 +128,7 @@ test_expect_success '--graph --simplify-by-decoration prune branch B' ' ' test_expect_success '--graph --full-history -- bar.txt' ' - check_graph --full-history --all -- bar.txt <<-\EOF + lib_test_check_graph --full-history --all -- bar.txt <<-\EOF * A7 * A6 |\
@@ -148,7 +143,7 @@ test_expect_success '--graph --full-history -- bar.txt' ' ' test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' - check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF + lib_test_check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF * A7 * A6 |\
@@ -161,7 +156,7 @@ test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' ' test_expect_success '--graph -- bar.txt' ' - check_graph --all -- bar.txt <<-\EOF + lib_test_check_graph --all -- bar.txt <<-\EOF * A7 * A5 * A3
@@ -172,7 +167,7 @@ test_expect_success '--graph -- bar.txt' ' ' test_expect_success '--graph --sparse -- bar.txt' ' - check_graph --sparse --all -- bar.txt <<-\EOF + lib_test_check_graph --sparse --all -- bar.txt <<-\EOF * A7 * A6 * A5
@@ -189,7 +184,7 @@ test_expect_success '--graph --sparse -- bar.txt' ' ' test_expect_success '--graph ^C4' ' - check_graph --all ^C4 <<-\EOF + lib_test_check_graph --all ^C4 <<-\EOF * A7 * A6 * A5
@@ -202,7 +197,7 @@ test_expect_success '--graph ^C4' ' ' test_expect_success '--graph ^C3' ' - check_graph --all ^C3 <<-\EOF + lib_test_check_graph --all ^C3 <<-\EOF * A7 * A6 |\
@@ -220,7 +215,7 @@ test_expect_success '--graph ^C3' ' # that important, but this test depends on it. If the ordering ever changes # in the code, we'll need to update this test. test_expect_success '--graph --boundary ^C3' ' - check_graph --boundary --all ^C3 <<-\EOF + lib_test_check_graph --boundary --all ^C3 <<-\EOF * A7 * A6 |\
Signature · 1 line
2.54.0
PATCH v9 2/4 revision: add next_commit_to_show()
In reply to Pablo Sabaterget_revision() gets its commits from two sources depending on the mode:
1. Normally it gets the commits from get_revision_internal().
2. --max-count-oldest which was introduced at bb4ce23284 (revision.c:
implement --max-count-oldest, 2026-05-19) gets the commits by popping from a saved list at revs->commits marking SHOWN and CHILD_SHOWN on each popped commit.
Extract the choice logic into a helper, next_commit_to_show(), which returns the next commit regardless of the source it comes from.
This has no change in behavior. The helper is needed in a subsequent commit that pre-fetches two commits into a buffer for lookahead purposes and needs to pre-fetch from the same source.
The --reverse branch keeps its own pop loop. Using the helper for --reverse would additionally set SHOWN and CHILD_SHOWN which is not desired and a behavior change.
--- revision.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-)
revision.c +24 -12
@@ -4658,12 +4658,34 @@ static void retrieve_oldest_commits(struct rev_info *revs,commit_list_insert (c, queue); } +/* +* Returns the next commit that will be shown, regardless of whether it comes +* directly from the revision walk or from the list saved by the staged output +* of --max-count-oldest. +*/ +static struct commit *next_commit_to_show (struct rev_info *revs) +{ +struct commit *c; +struct commit_list *p; + +if (!revs->max_count_stage) +return get_revision_internal (revs); + + c =pop_commit (&revs->commits); +if (c) { + c->object.flags |=SHOWN ; +if (!(c->object.flags &BOUNDARY )) +for (p = c->parents; p; p = p->next) + p->item->object.flags |=CHILD_SHOWN ; + } +return c; +} +struct commit *get_revision (struct rev_info *revs) {struct commit *c;struct commit_list *reversed;struct commit_list *queue =NULL ; -struct commit_list *p;if (revs->max_count_type ==1 && !revs->max_count_stage) {retrieve_oldest_commits (revs, &queue);
@@ -4693,17 +4715,7 @@ struct commit *get_revision(struct rev_info *revs)return c; } -if (revs->max_count_stage) { - c =pop_commit (&revs->commits); -if (c) { - c->object.flags |=SHOWN ; -if (!(c->object.flags &BOUNDARY )) -for (p = c->parents; p; p = p->next) - p->item->object.flags |=CHILD_SHOWN ; - } - }else { - c =get_revision_internal (revs); - } + c =next_commit_to_show (revs);if (c && revs->graph)graph_update (revs->graph, c);
Signature · 1 line
2.54.0
PATCH v9 3/4 graph: add a 2 commit buffer for lookahead
In reply to Pablo SabaterIn a subsequent commit the graph renderer needs to know if the next commit is a visual root or if it is the last commit to be shown. This requires peeking 2 commits ahead.
Commits are pre-fetched in get_revision() through next_commit_to_show() where they are also marked as SHOWN, regardless the source they come from.
Update graph_is_interesting() so it considers commits inside the lookahead buffer as interesting as well.
--- graph.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ graph.h | 17 +++++++++++++++++ revision.c | 18 ++++++++++++++++-- 3 files changed, 84 insertions(+), 2 deletions(-)
graph.c +51 -0
@@ -315,6 +315,14 @@ struct git_graph {* diff_output_prefix_callback(). */ struct strbuf prefix_buf; + +/* +* Lookahead buffer: up to 2 pre-fetched commits that will be shown. +* Populated by get_revision() so graph_peek_next_visible() can use +* actual walk results instead of peeking at rev_info internals. +*/ +struct commit *lookahead[2 ]; +int lookahead_nr; };static inline int graph_needs_truncation (struct git_graph *graph,int lane)
@@ -388,6 +396,9 @@ struct git_graph *graph_init(struct rev_info *opt) graph->num_columns =0 ; graph->num_new_columns =0 ; graph->mapping_size =0 ; + graph->lookahead[0 ] =NULL ; + graph->lookahead[1 ] =NULL ; + graph->lookahead_nr =0 ;/* * Start the column color at the maximum value, since we'll * always increment it for the first commit we output.
@@ -456,6 +467,15 @@ static void graph_ensure_capacity(struct git_graph *graph, int num_columns)*/ static int graph_is_interesting (struct git_graph *graph,struct commit *commit) { +/* +* Commits in the lookahead buffer have been pre-fetched by +* get_revision() and will be shown in the future. They already have +* the SHOWN flag set when they were pre-fetched but the graph still +* needs to treat them as interesting parents. +*/ +for (int i =0 ; i < graph->lookahead_nr; i++) +if (graph->lookahead[i] == commit) +return 1 ;/* * If revs->boundary is set, commits whose children have * been shown are always interesting, even if they have the
@@ -763,6 +783,37 @@ static int graph_needs_pre_commit_line(struct git_graph *graph) graph->expansion_row <graph_num_expansion_rows (graph); } +struct commit *graph_pop_lookahead (struct git_graph *graph) +{ +struct commit *c; + +if (!graph->lookahead_nr) +return NULL ; + + c = graph->lookahead[0 ]; +if (!c) +BUG ("lookahead buffer has %d entries but the first one is NULL" , + graph->lookahead_nr); + + graph->lookahead[0 ] = graph->lookahead[1 ]; + graph->lookahead[1 ] =NULL ; + graph->lookahead_nr--; +return c; +} + +int graph_get_lookahead_room (struct git_graph *graph) +{ +return (int )ARRAY_SIZE (graph->lookahead) - graph->lookahead_nr; +} + +void graph_push_lookahead (struct git_graph *graph,struct commit *c) +{ +if (!graph_get_lookahead_room (graph)) +BUG ("pushing into lookahead buffer when it is already full" ); + + graph->lookahead[graph->lookahead_nr++] = c; +} +void graph_update (struct git_graph *graph,struct commit *commit) {struct commit_list *parent;
graph.h +17 -0
@@ -262,4 +262,21 @@ void graph_show_commit_msg(struct git_graph *graph,FILE *file, struct strbuf const *sb); +/* +* Pop the first commit from the graph's lookahead buffer. +* Returns NULL if the buffer is empty. +*/ +struct commit *graph_pop_lookahead (struct git_graph *graph); + +/* +* Returns how many more commits can be added to the lookahead buffer. +*/ +int graph_get_lookahead_room (struct git_graph *graph); + +/* +* Push a commit into the lookahead buffer. Must only be called when +* graph_get_lookahead_room() returns > 0. +*/ +void graph_push_lookahead (struct git_graph *graph,struct commit *c); +#endif /* GRAPH_H */
revision.c +16 -2
@@ -4715,10 +4715,24 @@ struct commit *get_revision(struct rev_info *revs)return c; } - c =next_commit_to_show (revs); +if (revs->graph) { + c =graph_pop_lookahead (revs->graph); +if (!c) + c =next_commit_to_show (revs); + }else { + c =next_commit_to_show (revs); + } -if (c && revs->graph) +if (c && revs->graph) { +while (graph_get_lookahead_room (revs->graph)) { +struct commit *next =next_commit_to_show (revs); +if (!next) +break ; +graph_push_lookahead (revs->graph, next); + }graph_update (revs->graph, c); + } +if (!c) {free_saved_parents (revs);commit_list_free (revs->previous_parents);
Signature · 1 line
2.54.0
PATCH v9 4/4 graph: indent visual root in graph
In reply to Pablo SabaterWhen rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This happens because the commits fill the space from left to right and when a visual root ends, its column becomes free for the following commit even if they are not related. Once this happens the unrelated commit is rendered below the visual root. Because there is no special character or way to identify when a visual root is rendered making the graph confusing.
By indenting the visual roots when there are still commits to show the vertical adjacency can be avoided.
Add is_visual_root flag to git_graph making it visible in all graph states, give graph_update() a new function, graph_is_visual_root() to know if the current commit is a visual root and set is_visual_root.
The different handled cases are:
- If a visual root has children: similar to GRAPH_PRE_COMMIT state when octopus merges need space, an edge row needs to be printed to connect the child with the indented visual root. A new state GRAPH_PRE_ROOT is needed to connect the child with the visual root:
* child of the visual root
\ GRAPH_PRE_ROOT
* visual root indented
- If a visual root is child-less we can skip GRAPH_PRE_ROOT state and render the indented commit directly.
* visual root indented
* unrelated commit
- If two or more visual roots are adjacent: by having a lookahead to the next commit that will be rendered, if the next commit is also a visual root and we are on a visual root, meaning two visual root adjacent in the history, the top one can omit the indent, making the one below to indent only once, if there are more adjacent visual commits, the indentation will increase for each adjacent one, cascading.
* visual root
* visual root
* visual root
* last commit
Even if the last commit is a root, because there is nothing that will be rendered below we can omit the indentation on purpose.
[1]: https://lore.kernel.org/git/[email protected]/
--- graph.c | 244 +++++++++++++++++++ t/meson.build | 1 + t/t4218-log-graph-indentation.sh | 514 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 759 insertions(+)
graph.c +244 -0
@@ -60,12 +60,23 @@ struct column {* index into column_colors. */ unsigned short color; +/* +* Marks if a commit is a non-first parent of a merge. These columns are +* already visually connected to the merge commit and do not need +* indentation. +* +* The first parent is the one that inherits the column and it can need +* indentation if turns out to be a visual root and there's still +* commits to render. +*/ + unsigned int is_merge_parent:1; };enum graph_state {GRAPH_PADDING ,GRAPH_SKIP ,GRAPH_PRE_COMMIT , +GRAPH_PRE_ROOT ,GRAPH_COMMIT ,GRAPH_POST_MERGE ,GRAPH_COLLAPSING
@@ -323,6 +334,51 @@ struct git_graph {*/ struct commit *lookahead[2 ];int lookahead_nr; + +/* +* If a commit is a visual root, we need to indent it to prevent +* unrelated commits from being vertically adjacent to it. +*/ + unsigned int is_visual_root:1; + +/* +* Indentation increases for each visual root adjacent to another visual +* root, making visual root commits indentation cascade. +*/ +unsigned int visual_root_depth; + +/* +* When a visual root is adjacent to other visual roots, the first one +* can avoid indentation and the rest cascades, increasing the indentation +* for each one. +*/ + unsigned int visual_root_cascade:1; + +/* +* Set when the current commit was already present in graph->columns +* before being processed. +*/ + unsigned int commit_in_columns:1; +}; + +struct graph_lookahead_flags { + +/* +* Set when there will be a commit after the current one that will be +* rendered. +*/ +unsigned int is_next_visible:1 ; + +/* +* Set when the next visible commit is candidate to be a visual root. +*/ +unsigned int is_next_visual_root:1 ; + +/* +* Set when the next visible commit will be rendered under the current +* commit. +*/ +unsigned int next_has_column:1 ; };static inline int graph_needs_truncation (struct git_graph *graph,int lane)
@@ -399,6 +455,8 @@ struct git_graph *graph_init(struct rev_info *opt) graph->lookahead[0 ] =NULL ; graph->lookahead[1 ] =NULL ; graph->lookahead_nr =0 ; + graph->visual_root_depth =0 ; + graph->visual_root_cascade =0 ;/* * Start the column color at the maximum value, since we'll * always increment it for the first commit we output.
@@ -581,6 +639,11 @@ static void graph_insert_into_new_columns(struct git_graph *graph, struct commit *commit, int idx) { +/* +* Get the initial merge_layout before it's modified to know if this +* is a merge. +*/ +int initial_merge_layout = graph->merge_layout;int i =graph_find_new_column_by_commit (graph, commit);int mapping_idx;
@@ -592,6 +655,7 @@ static void graph_insert_into_new_columns(struct git_graph *graph, i = graph->num_new_columns++; graph->new_columns[i].commit = commit; graph->new_columns[i].color =graph_find_commit_color (graph, commit); + graph->new_columns[i].is_merge_parent =0 ; }if (graph->num_parents >1 && idx >-1 && graph->merge_layout ==-1 ) {
@@ -630,6 +694,12 @@ static void graph_insert_into_new_columns(struct git_graph *graph, } graph->mapping[mapping_idx] = i; + +/* +* Mark non-first parents of a merge. +*/ +if (graph->num_parents >1 && initial_merge_layout >=0 && idx >-1 ) + graph->new_columns[i].is_merge_parent =1 ; }static void graph_update_columns (struct git_graph *graph)
@@ -721,10 +791,20 @@ static void graph_update_columns(struct git_graph *graph)if (graph->num_parents ==0 ) graph->width +=2 ; }else { +int j;graph_insert_into_new_columns (graph, col_commit,-1 ); +/* +* This column is not the current commit, but we need to +* propagate the flag until the commit is processed. +*/ + j =graph_find_new_column_by_commit (graph, col_commit); +if (j >=0 && graph->columns[i].is_merge_parent) + graph->new_columns[j].is_merge_parent =1 ; } } + graph->commit_in_columns = is_commit_in_columns; +/* * If graph_max_lanes is set, cap the width */
@@ -814,9 +894,113 @@ void graph_push_lookahead(struct git_graph *graph, struct commit *c) graph->lookahead[graph->lookahead_nr++] = c; } +/* +* A commit can be a visual root when: +* +* - It has no parents. +* +* - It has parents but they are all filtered out and +* commit->parents arrives NULL. +* +* - Its parents are uninteresting. +* +* - It is not a boundary commit. Boundary commits also have no visible +* parents, but they are not selected as visual roots because they cannot +* cause the ambiguity of being vertically adjacent because: +* +* 1. A boundary only appears because an included commit is its child. +* Children are always above, and the renderer draws an edge down to +* the boundary from that child. Rather than starting a column like a +* visual root would do, it inherits its child column. +* +* 2. Included commits cannot appear below a boundary. Boundaries are +* ancestors of the exclusion point; if an included commit were an +* ancestor of the boundary it would be excluded and not rendered. +* Boundaries therefore always sink to the bottom. +*/ +static int graph_is_visual_root_candidate (struct commit *c,struct git_graph *graph) +{ +struct commit_list *p; + +if (c->object.flags &BOUNDARY ) +return 0 ; +for (p = c->parents; p; p = p->next) +if (graph_is_interesting (graph, p->item)) +return 0 ; +return 1 ; +} + +static int graph_is_visual_root (struct git_graph *graph, +struct graph_lookahead_flags *flags) +{ +/* +* This must be only called for the current commit as graph contains +* the state for the current commit only. +* +* To check if a commit is a visual root, call graph_is_visual_root_candidate() +* but we won't know if it is really a visual root until we get to the +* next commit state. +* +* The current commit is an actual visual root if it is a candidate and +* the commit is not a non-first parent of a merge. +* +* * +* |\ +* | * <- it is a visual root candidate but it shouldn't be indented +* * because it is already connected by an edge. +* ^ if commit_in_columns && is_merge_parent means the commit +* | was put by a merge and is connected. +* | +* `-------- if !is_next_visible means we're on the last commit, avoid +* indentation unless the one before is a visual root, then +* we need to differentiate from the one above. +* +* If next_has_columns means that the next commit has +* already a column, so it will not be rendered below, the +* current commit has to act as the last commit and omit +* indentation. +*/ +return graph_is_visual_root_candidate (graph->commit, graph) && + !(graph->commit_in_columns && + graph->columns[graph->commit_index].is_merge_parent) && + flags->is_next_visible && + (!flags->next_has_column || graph->visual_root_depth >0 ); +} + +/* +* Peeks the next commits via the lookahead buffer and sets the lookahead flags. +*/ +static void graph_peek_next_visible (struct git_graph *graph, +struct graph_lookahead_flags *flags) +{ + flags->is_next_visible =0 ; + flags->is_next_visual_root =0 ; + flags->next_has_column =0 ; + +if (!graph->lookahead_nr) +return ; + + flags->is_next_visible =1 ; + flags->next_has_column = +graph_find_new_column_by_commit (graph, graph->lookahead[0 ]) >=0 ; + +if (!graph_is_visual_root_candidate (graph->lookahead[0 ], graph)) +return ; + +if (graph->lookahead_nr >=2 ) + flags->is_next_visual_root =1 ; +} + +static int graph_needs_pre_root_line (struct git_graph *graph) +{ +return graph->commit_in_columns && graph->is_visual_root && + graph->num_columns >0 && !graph->visual_root_cascade; +} +void graph_update (struct git_graph *graph,struct commit *commit) {struct commit_list *parent; +struct graph_lookahead_flags flags;/* * Set the new commit
@@ -847,6 +1031,23 @@ void graph_update(struct git_graph *graph, struct commit *commit)*/ graph_update_columns (graph); +graph_peek_next_visible (graph, &flags); + + graph->is_visual_root =graph_is_visual_root (graph, &flags); + +if (graph->is_visual_root) { +/* +* If next is a visual root we can omit the indent for the first +* visual root and start cascading. +*/ +if (!graph->visual_root_depth && flags.is_next_visual_root) + graph->visual_root_cascade =1 ; + graph->visual_root_depth++; + }else { + graph->visual_root_depth =0 ; + graph->visual_root_cascade =0 ; + } + graph->expansion_row =0 ;/*
@@ -864,11 +1065,16 @@ void graph_update(struct git_graph *graph, struct commit *commit)* room for it. We need to do this only if there is a branch row * (or more) to the right of this commit. * +* If it is a visual root, we need to print an extra row to +* connect the indentation. +* * If there are less than 3 parents, we can immediately print the * commit line. */ if (graph->state !=GRAPH_PADDING ) graph->state =GRAPH_SKIP ; +else if (graph_needs_pre_root_line (graph)) + graph->state =GRAPH_PRE_ROOT ;else if (graph_needs_pre_commit_line (graph)) graph->state =GRAPH_PRE_COMMIT ;else
@@ -1116,6 +1322,17 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_lineif (col_commit == graph->commit) { seen_this =1 ; +if (graph->is_visual_root) { +int depth = graph->visual_root_depth; +/* +* Each visual column is 2 characters wide. +* Omit the indentation for the first visual +* root in cascade mode. +*/ +int padding = (depth - graph->visual_root_cascade) *2 ; +graph_line_addchars (line,' ' , padding); + graph->width += padding; + }graph_output_commit_char (graph, line);if (graph_needs_truncation (graph, i)) {
@@ -1487,6 +1704,30 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_lgraph_update_state (graph,GRAPH_PADDING ); } +static void graph_output_pre_root_line (struct git_graph *graph,struct graph_line *line) +{ +/* +* This function adds a row before a visual root, to connect the +* branch to the indented commit. It must only be called on a +* visual root. +*/ +if (!graph->is_visual_root) +BUG ("commit must be a visual root to call pre_root_line" ); + +for (int i =0 ; i < graph->num_columns; i++) { +struct column *col = &graph->columns[i]; +if (col->commit == graph->commit) { +graph_line_addch (line,' ' ); +graph_line_write_column (line, col,'\\' ); + }else { +graph_line_write_column (line, col,'|' ); + } +graph_line_addch (line,' ' ); + } + +graph_update_state (graph,GRAPH_COMMIT ); +} +int graph_next_line (struct git_graph *graph,struct strbuf *sb) {int shown_commit_line =0 ;
@@ -1512,6 +1753,9 @@ int graph_next_line(struct git_graph *graph, struct strbuf *sb)case GRAPH_PRE_COMMIT :graph_output_pre_commit_line (graph, &line);break ; +case GRAPH_PRE_ROOT : +graph_output_pre_root_line (graph, &line); +break ;case GRAPH_COMMIT :graph_output_commit_line (graph, &line); shown_commit_line =1 ;
t/meson.build +1 -0
@@ -577,6 +577,7 @@ integration_tests = [ 't4215-log-skewed-merges.sh', 't4216-log-bloom.sh', 't4217-log-limit.sh', + 't4218-log-graph-indentation.sh', 't4219-log-follow-merge.sh', 't4252-am-options.sh', 't4253-am-keep-cr-dos.sh',
t/t4218-log-graph-indentation.sh new file +514 -0
514 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v9 0/4] graph: indent visual roots in graph
In reply to Pablo SabaterQuoted 68 lines · Pablo Sabater
When rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This series adds indentation to the visual root commits, so they cannot be vertically adjacent anymore making it easier to identify them.
Before indentation:
* A
* B1
* B2
* C1
* C2After indentation:
* A
* B1
\
* B2
* C1
* C2Indents the visual root commits that have still commits to show after them, and if they have children it connects them with an edge at a new row.
If there are multiple visual roots adjacent in history, the indentation starts with the second one, avoiding redundant indentation of the first one and cascades after the second.
* A
* B
* C
* D1
* D2This series first commit is a cleanup that brings a common function from t4215 and t6016 to a graph functions file which they both use, so the new test file for indentation, t4218, can use it as well.
GitHub CI: https://github.com/pabloosabaterr/git/actions/runs/29154333559
[1]: https://lore.kernel.org/git/[email protected]/
V8 DIFF:
- Checking if the parents of a commit are NULL is not enough to know if the commit is a visual root due to options that filter the commit parents but they do not remove them (--author, --grep, etc). At
graph_is_visual_root_candidate(), iterate the parents and callgraph_is_interesting()for each of them to know whether they will be shown or not.
- Add a --author and a --grep test.Signed-off-by Pablo Sabater <[email protected]>---
Pablo Sabater (4):
lib-log-graph: movecheck_graphfunction
revision: addnext_commit_to_show()
graph: add a 2 commit buffer for lookahead
graph: indent visual root in graph
Quoted 9 lines
graph.c | 295 +++++++++++++++++ graph.h | 17 + revision.c | 48 ++- t/lib-log-graph.sh | 5 + t/meson.build | 1 + t/t4215-log-skewed-merges.sh | 33 +- t/t4218-log-graph-indentation.sh | 514 +++++++++++++++++++++++++++++ t/t6016-rev-list-graph-simplify-history.sh | 25 +- 8 files changed, 893 insertions(+), 45 deletions(-)
Sorry, I know I'm a bit late to the discussion regarding the design, but, could we maybe have two different code paths for printing graphs? Having the old one as a default and this new one only when we're using --oneline (well, --format=reference would benefit too)? As it is now if I have multiple one-patch series in sequence the entries are unnecessarily indented.
Thanks
Re: [PATCH v9 0/4] graph: indent visual roots in graph
Quoted 10 lines · Mirko Faina
Quoted 9 lines · Pablo Sabater
When rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This series adds indentation to the visual root commits, so they cannot be vertically adjacent anymore making it easier to identify them.
[snip]
Quoted 9 lines
Sorry, I know I'm a bit late to the discussion regarding the design, but, could we maybe have two different code paths for printing graphs? Having the old one as a default and this new one only when we're using --oneline (well, --format=reference would benefit too)? As it is now if I have multiple one-patch series in sequence the entries are unnecessarily indented.
Thanks
No worries :)
Well, I thought that it could become annoying given the scenario of having too many visual roots one after the other. But I didn't have a clear way of having that scenario without forcing it.
I think that this solves an ambiguity so it should be the default option and someone who doesn't want the indentation has to explicitly unset it maybe with something like '--no-graph-indent'.
Apart from having an option to disable indentation.
We could have the cascading to have a limit or make it zig-zag:
instead of:
A
B
C
D
We could do:
A
B
C
D
This would have its own edge cases like:
A
B
C <- if we zig-zag here C and D become ambiguous, currently we are
D indenting only the last commits (visual roots) here we would have
D to chose between continuing cascading or indenting the first of D.
I'm not so sure if I like the zig-zag solution because we need to think again if it causes an ambiguity, but I wanted to mention it.
I think we need some more opinions about the design.
Thanks,
Pablo
Re: [PATCH v9 0/4] graph: indent visual roots in graph
Quoted 3 lines · Pablo Sabater
I think that this solves an ambiguity so it should be the default option and someone who doesn't want the indentation has to explicitly unset it maybe with something like '--no-graph-indent'.
The reason I prefer the current way of printing as the default is because the ambiguity arises only when each commit occupies exactly one line. In any other case we can clearly see the edges connecting the vertices. I'd rather have --oneline imply what would be --graph-indent instead of having to pass --no-graph-indent on any other format different from --oneline or --format=reference.
Quoted 26 lines
Apart from having an option to disable indentation.
We could have the cascading to have a limit or make it zig-zag:
instead of:
A
B
C
DWe could do:
A
B
C
DThis would have its own edge cases like:
A
B
C <- if we zig-zag here C and D become ambiguous, currently we are
D indenting only the last commits (visual roots) here we would have
D to chose between continuing cascading or indenting the first of D.
Quoted 4 lines
I'm not so sure if I like the zig-zag solution because we need to think again if it causes an ambiguity, but I wanted to mention it.
I think we need some more opinions about the design.
I don't dislike the the current solution but I can see it degenerating if someone contributes a lot of one-patch series.
Maybe you could indent commits that are both head and tail up to two levels and then on the third go back to the beginning of the line. That way you kind of have a zig-zag but without ambiguity. You'd only have to add a counter to keep track of the level of indentation.
Re: [PATCH v9 0/4] graph: indent visual roots in graph
Quoted 6 lines · Mirko Faina
Quoted 3 lines · Pablo Sabater
I think that this solves an ambiguity so it should be the default option and someone who doesn't want the indentation has to explicitly unset it maybe with something like '--no-graph-indent'.
Quoted 6 lines
The reason I prefer the current way of printing as the default is because the ambiguity arises only when each commit occupies exactly one line. In any other case we can clearly see the edges connecting the vertices. I'd rather have --oneline imply what would be --graph-indent instead of having to pass --no-graph-indent on any other format different from --oneline or --format=reference.
Tying graph-drawing logic to specific formatting flags could introduce inconsistencies. For example, if a user relies on a custom format like --format="%h %s", the output is functionally single-line and suffers from the exact same ambiguity, but it would miss the fix.
Even in multi-line formats, relying on the absence of a '|' character to spot unrelated commits requires active effort. Indentation provides an immediate visual cue that breaks the vertical lineage, which is helpful regardless of the commit message length.
I agree with Pablo: for users who strictly want the old behavior, an opt-out flag keeps the graph logic decoupled from the formatting logic.
Quoted 31 lines
Quoted 26 lines
Apart from having an option to disable indentation.
We could have the cascading to have a limit or make it zig-zag:
instead of:
A
B
C
DWe could do:
A
B
C
DThis would have its own edge cases like:
A
B
C <- if we zig-zag here C and D become ambiguous, currently we are
D indenting only the last commits (visual roots) here we would have
D to chose between continuing cascading or indenting the first of D.Quoted 4 lines
I'm not so sure if I like the zig-zag solution because we need to think again if it causes an ambiguity, but I wanted to mention it.
I think we need some more opinions about the design.
Quoted 7 lines
I don't dislike the the current solution but I can see it degenerating if someone contributes a lot of one-patch series.
Maybe you could indent commits that are both head and tail up to two levels and then on the third go back to the beginning of the line. That way you kind of have a zig-zag but without ambiguity. You'd only have to add a counter to keep track of the level of indentation.
Not sure about this. A zig-zag pattern visually mimics branching and merging, which makes unrelated commits look like a complex merge topology.
I also have a feeling that this will end up recreating the exact ambiguity this patch series is trying to fix.
Re: [PATCH v9 0/4] graph: indent visual roots in graph
Quoted 5 lines · Chandra Pratap
Tying graph-drawing logic to specific formatting flags could introduce inconsistencies. For example, if a user relies on a custom format like --format="%h %s", the output is functionally single-line and suffers from the exact same ambiguity, but it would miss the fix.
Quoted 7 lines
Even in multi-line formats, relying on the absence of a '|' character to spot unrelated commits requires active effort. Indentation provides an immediate visual cue that breaks the vertical lineage, which is helpful regardless of the commit message length.
I agree with Pablo: for users who strictly want the old behavior, an opt-out flag keeps the graph logic decoupled from the formatting logic.
In that case, together with --[no]-graph-indent, a configuration variable like "graph.indent" could be introduced to reduce the usage of --[no]-graph-indent for those that would like to retain the old behaviour for most formats.
Quoted 39 lines
Quoted 31 lines
Quoted 26 lines
Apart from having an option to disable indentation.
We could have the cascading to have a limit or make it zig-zag:
instead of:
A
B
C
DWe could do:
A
B
C
DThis would have its own edge cases like:
A
B
C <- if we zig-zag here C and D become ambiguous, currently we are
D indenting only the last commits (visual roots) here we would have
D to chose between continuing cascading or indenting the first of D.Quoted 4 lines
I'm not so sure if I like the zig-zag solution because we need to think again if it causes an ambiguity, but I wanted to mention it.
I think we need some more opinions about the design.
Quoted 7 lines
I don't dislike the the current solution but I can see it degenerating if someone contributes a lot of one-patch series.
Maybe you could indent commits that are both head and tail up to two levels and then on the third go back to the beginning of the line. That way you kind of have a zig-zag but without ambiguity. You'd only have to add a counter to keep track of the level of indentation.
Quoted 5 lines
Not sure about this. A zig-zag pattern visually mimics branching and merging, which makes unrelated commits look like a complex merge topology.
I also have a feeling that this will end up recreating the exact ambiguity this patch series is trying to fix.
While a zig-zag pattern might be ambiguous, what I proposed is a little different.
What I proposed is effectively a wrapping for anything that goes beyond two levels of indentation. I don't think it would look anything like a fork/merge pattern.
* A
* B
* C
* D
* E
* F
The difference between two indentation levels and no indentation is very noticeble, I don't think anyone confused this. This would fix the staircase pattern on adjacent one-patch series.
Re: [PATCH v9 0/4] graph: indent visual roots in graph
Quoted 3 lines · Mirko Faina
The difference between two indentation levels and no indentation is very noticeble, I don't think anyone confused this. This would fix the staircase pattern on adjacent one-patch series.
Sorry, meant to write, "I don't think anyone would be confused by this".
Re: [PATCH v9 0/4] graph: indent visual roots in graph
In reply to Mirko FainaQuoted 78 lines · Mirko Faina
Quoted 5 lines · Chandra Pratap
Tying graph-drawing logic to specific formatting flags could introduce inconsistencies. For example, if a user relies on a custom format like --format="%h %s", the output is functionally single-line and suffers from the exact same ambiguity, but it would miss the fix.
Quoted 7 lines
Even in multi-line formats, relying on the absence of a '|' character to spot unrelated commits requires active effort. Indentation provides an immediate visual cue that breaks the vertical lineage, which is helpful regardless of the commit message length.
I agree with Pablo: for users who strictly want the old behavior, an opt-out flag keeps the graph logic decoupled from the formatting logic.
In that case, together with --[no]-graph-indent, a configuration variable like "graph.indent" could be introduced to reduce the usage of --[no]-graph-indent for those that would like to retain the old behaviour for most formats.
Quoted 39 lines
Quoted 31 lines
Quoted 26 lines
Apart from having an option to disable indentation.
We could have the cascading to have a limit or make it zig-zag:
instead of:
A
B
C
DWe could do:
A
B
C
DThis would have its own edge cases like:
A
B
C <- if we zig-zag here C and D become ambiguous, currently we are
D indenting only the last commits (visual roots) here we would have
D to chose between continuing cascading or indenting the first of D.Quoted 4 lines
I'm not so sure if I like the zig-zag solution because we need to think again if it causes an ambiguity, but I wanted to mention it.
I think we need some more opinions about the design.
Quoted 7 lines
I don't dislike the the current solution but I can see it degenerating if someone contributes a lot of one-patch series.
Maybe you could indent commits that are both head and tail up to two levels and then on the third go back to the beginning of the line. That way you kind of have a zig-zag but without ambiguity. You'd only have to add a counter to keep track of the level of indentation.
Quoted 5 lines
Not sure about this. A zig-zag pattern visually mimics branching and merging, which makes unrelated commits look like a complex merge topology.
I also have a feeling that this will end up recreating the exact ambiguity this patch series is trying to fix.
While a zig-zag pattern might be ambiguous, what I proposed is a little different.
What I proposed is effectively a wrapping for anything that goes beyond two levels of indentation. I don't think it would look anything like a fork/merge pattern.
* A
* B
* C
* D
* E
* F
Quoted 3 lines
The difference between two indentation levels and no indentation is very noticeble, I don't think anyone confused this. This would fix the staircase pattern on adjacent one-patch series.
I agree that having an infinite stair is not a good solution. the 3 column wrap looks reasonable.
I see two cases with this wrap:
1. No conflict case:
A
B
C
D
E
F
No ambiguity, this would be the ideal case.
2. Ambiguity:
If it happens that the visual number on visual roots meet the condition (number_of_visual_roots % 3 == 0) and the next commit is NOT a visual root this would happen:
A
B
C
D
E
E
Which would be ambiguous. The solution is to check with the lookahead buffer that we have since patch 3 if the next is a visual root, if it's not we indent D anyway:
A
B
C
D
E
E
Which I find the pyramid effect uncomfortable.
What about capping at 4 columns?
1.
A
B
C
D
E
F
G
H
2.
A
B
C
D
E
F
F
I prefer the 4 column wrap because it looks more abrupt and IMO shows better that the commits are unrelated.
What do you think?
Also, about the no-opt option "--no-graph-indent" is still wanted regardless of the final design that we choose?
Thanks,
Pablo
Re: [PATCH v9 0/4] graph: indent visual roots in graph
Quoted 48 lines · Pablo Sabater
2. Ambiguity:
If it happens that the visual number on visual roots meet the condition (
number_of_visual_roots% 3 == 0) and the next commit is NOT a visual root this would happen:A
B
C
D
E
EWhich would be ambiguous. The solution is to check with the lookahead buffer that we have since patch 3 if the next is a visual root, if it's not we indent D anyway:
A
B
C
D
E
EWhich I find the pyramid effect uncomfortable.
What about capping at 4 columns?1.
A
B
C
D
E
F
G
H2.
A
B
C
D
E
F
F
Quoted 4 lines
I prefer the 4 column wrap because it looks more abrupt and IMO shows better that the commits are unrelated.
What do you think?
I agree, warpping beyond three levels instead of two would resolve this ambiguity.
Quoted 2 lines
Also, about the no-opt option "--no-graph-indent" is still wanted regardless of the final design that we choose?
Yes, I personally wouldn't want indentation on non-oneline formats.
Thank you.
Re: [PATCH v9 0/4] graph: indent visual roots in graph
In reply to Pablo Sabater[snip]
Quoted 64 lines
I agree that having an infinite stair is not a good solution. the 3 column wrap looks reasonable.
I see two cases with this wrap:
1. No conflict case:
A
B
C
D
E
FNo ambiguity, this would be the ideal case.
2. Ambiguity:
If it happens that the visual number on visual roots meet the condition (
number_of_visual_roots% 3 == 0) and the next commit is NOT a visual root this would happen:A
B
C
D
E
EWhich would be ambiguous. The solution is to check with the lookahead buffer that we have since patch 3 if the next is a visual root, if it's not we indent D anyway:
A
B
C
D
E
EWhich I find the pyramid effect uncomfortable.
What about capping at 4 columns?1.
A
B
C
D
E
F
G
H2.
A
B
C
D
E
F
F
Quoted 4 lines
I prefer the 4 column wrap because it looks more abrupt and IMO shows better that the commits are unrelated.
What do you think?
I agree with Mirko, the 4-column wrap looks like a reasonable compromise.
Quoted 2 lines
Also, about the no-opt option "--no-graph-indent" is still wanted regardless of the final design that we choose?
I feel indifferent about this personally, but there are clearly people who have a use-case for such a flag.
Let us add an explicit opt-out flag: --no-graph-indent alongside a configuration
variable: graph.indent, log.graphIndent, or something similar.
A heads up: I think it would best to add these changes as two new commits to the series.
Thanks,
Chandra.
v10 cover graph: indent visual roots in graph
In reply to Pablo SabaterWhen rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This series adds indentation to the visual root commits, so they cannot be vertically adjacent anymore making it easier to identify them.
Before indentation:
* A
* B1
* B2
* C1
* C2
After indentation:
* A
* B1
\
* B2
* C1
* C2
Indents the visual root commits that have still commits to show after them, and if they have children it connects them with an edge at a new row.
If there are multiple visual roots adjacent in history, the indentation starts with the second one, avoiding redundant indentation of the first one and cascades after the second.
* A
* B
* C
* D
* E
* F
* G
* H
* I
* J1
* J2
The indentation wraps after cascading columns and when wrapping back to the initial column if the next commit is a non-visual-root commit, force the indentation one extra level.
Series explanation:
- Cleanup to bring a common function from t4215 and t6016 that will be used in t4218.
- Logic extraction of the chose of from where the commit source comes from.
- Add a buffer for lookahead purposes.
- Principal commit. Implement the logic to get the visual roots indented.
- Make visual root cascading wrap after 4 columns
- Add --[no-]graph-indent and log.graphIndent options.
GitHub CI: https://github.com/pabloosabaterr/git/actions/runs/29241054418
[1]: https://lore.kernel.org/git/[email protected]/
V9 DIFF:
- visual roots cascading now wrap after 4 columns. This was introduced into a new commit to make reviewing easier because the Main one is already big and has gone through multiple rounds already.
- Made a new graph_read_config() function where the calls to repo_config_get_*() live to leave graph_init() simpler.
- Added --[no-]graph-indent and log.graphIndent options so a user can set his preferences about the graph indentation.
---
Pablo Sabater (7):
lib-log-graph: move check_graph function
revision: add next_commit_to_show()
graph: add a 2 commit buffer for lookahead
graph: indent visual root in graph
graph: wrap cascading commits after 4 columns
graph: move config reading into graph_read_config()
graph: add --[no-]graph-indent and log.graphIndent
Documentation/config/log.adoc | 4 + Documentation/rev-list-options.adoc | 8 + graph.c | 332 +++++++++++++++- graph.h | 17 + revision.c | 57 ++- revision.h | 2 + t/lib-log-graph.sh | 5 + t/meson.build | 1 + t/t4215-log-skewed-merges.sh | 33 +- t/t4218-log-graph-indentation.sh | 595 +++++++++++++++++++++++++++++ t/t6016-rev-list-graph-simplify-history.sh | 25 +- 11 files changed, 1031 insertions(+), 48 deletions(-)
Range-diff versus v9:
1: 22ab444372 = 1: 9541b410b7 lib-log-graph: move check_graph function 2: ebb88c8b29 = 2: 4f8fb2cc1d revision: add next_commit_to_show() 3: 0705ee321e = 3: b50574bbe1 graph: add a 2 commit buffer for lookahead 4: fa2e60fb3f = 4: fc3a8253fd graph: indent visual root in graph -: ---------- > 5: 204aae5061 graph: wrap cascading commits after 4 columns -: ---------- > 6: 1b42ed86a1 graph: move config reading into graph_read_config() -: ---------- > 7: 737331b68d graph: add --[no-]graph-indent and log.graphIndent
---
base-commit: f60db8d575adb79761d363e026fb49bddf330c73
PATCH v10 1/7 lib-log-graph: move check_graph function
check_graph is a function shared in the test files t4215 and t6016 used to format the output graph, but instead of being in a file called by both test, the function code is repeated in each file.
Move check_graph to lib-log-graph.sh file which both tests already import graph functions from, renaming it to lib_test_check_graph.
This function is needed for the following commit which includes graph tests in a new file and requires check_graph.
--- t/lib-log-graph.sh | 5 +++++ t/t4215-log-skewed-merges.sh | 33 +++++++++++++----------------- t/t6016-rev-list-graph-simplify-history.sh | 25 +++++++++------------- 3 files changed, 29 insertions(+), 34 deletions(-)
t/lib-log-graph.sh +5 -0
@@ -26,3 +26,8 @@ lib_test_cmp_colored_graph () { test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors && test_cmp expect.colors output.colors } + +lib_test_check_graph () { + cat >expect && + lib_test_cmp_graph --format=%s "$@" +}
t/t4215-log-skewed-merges.sh +14 -19
@@ -5,11 +5,6 @@ test_description='git log --graph of skewed merges' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh -check_graph () { - cat >expect && - lib_test_cmp_graph --format=%s "$@" -} - test_expect_success 'log --graph with merge fusing with its left and right neighbors' ' git checkout --orphan _p && test_commit A &&
@@ -21,7 +16,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh git checkout _p && git merge --no-ff _r -m G && git checkout @^^ && git merge --no-ff _p -m H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * H |\ | * G
@@ -49,7 +44,7 @@ test_expect_success 'log --graph with left-skewed merge' ' git checkout 0_p && git merge --no-ff 0_s -m 0_G && git checkout @^ && git merge --no-ff 0_q 0_r 0_t 0_p -m 0_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF *-----. 0_H |\ \ \ \ | | | | * 0_G
@@ -83,7 +78,7 @@ test_expect_success 'log --graph with nested left-skewed merge' ' git checkout 1_p && git merge --no-ff 1_r -m 1_G && git checkout @^^ && git merge --no-ff 1_p -m 1_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 1_H |\ | * 1_G
@@ -115,7 +110,7 @@ test_expect_success 'log --graph with nested left-skewed merge following normal git checkout -b 2_s @^^ && git merge --no-ff 2_q -m 2_J && git checkout 2_p && git merge --no-ff 2_s -m 2_K && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 2_K |\ | * 2_J
@@ -151,7 +146,7 @@ test_expect_success 'log --graph with nested right-skewed merge following left-s git checkout 3_p && git merge --no-ff 3_r -m 3_H && git checkout @^^ && git merge --no-ff 3_p -m 3_J && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 3_J |\ | * 3_H
@@ -182,7 +177,7 @@ test_expect_success 'log --graph with right-skewed merge following a left-skewed git merge --no-ff 4_p -m 4_G && git checkout @^^ && git merge --no-ff 4_s -m 4_H && - check_graph --date-order <<-\EOF + lib_test_check_graph --date-order <<-\EOF * 4_H |\ | * 4_G
@@ -218,7 +213,7 @@ test_expect_success 'log --graph with octopus merge with column joining its penu git checkout 5_r && git merge --no-ff 5_s -m 5_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 5_H |\ | *-. 5_G
@@ -257,7 +252,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout 6_1 && git merge --no-ff 6_2 -m 6_I && - check_graph 6_1 6_3 6_5 <<-\EOF + lib_test_check_graph 6_1 6_3 6_5 <<-\EOF * 6_I |\ | | * 6_H
@@ -334,7 +329,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout -b M_7 7_1 && git merge --no-ff 7_2 7_3 -m 7_M4 && - check_graph M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -371,7 +366,7 @@ test_expect_success 'log --graph with multiple tips' ' ' test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' ' - check_graph --graph-lane-limit=2 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=2 M_7 <<-\EOF *-. 7_M4 |\ \ | | * 7_G
@@ -388,7 +383,7 @@ test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' ' ' test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge' ' - check_graph --graph-lane-limit=1 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=1 M_7 <<-\EOF *-~ 7_M4 |\~ | ~ 7_G
@@ -405,7 +400,7 @@ test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge ' test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' ' - check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -441,7 +436,7 @@ test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' ' ' test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows first of 3 parent merge' ' - check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -478,7 +473,7 @@ test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows fir ' test_expect_success 'log --graph --graph-lane-limit=7 check if it shows all 3 parent merge' ' - check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
t/t6016-rev-list-graph-simplify-history.sh +10 -15
@@ -13,11 +13,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh -check_graph () { - cat >expect && - lib_test_cmp_graph --format=%s "$@" -} - test_expect_success 'set up rev-list --graph test' ' # 3 commits on branch A test_commit A1 foo.txt &&
@@ -54,7 +49,7 @@ test_expect_success 'set up rev-list --graph test' ' ' test_expect_success '--graph --all' ' - check_graph --all <<-\EOF + lib_test_check_graph --all <<-\EOF * A7 * A6 |\
@@ -82,7 +77,7 @@ test_expect_success '--graph --all' ' # that undecorated merges are interesting, even with --simplify-by-decoration test_expect_success '--graph --simplify-by-decoration' ' git tag -d A4 && - check_graph --all --simplify-by-decoration <<-\EOF + lib_test_check_graph --all --simplify-by-decoration <<-\EOF * A7 * A6 |\
@@ -114,7 +109,7 @@ test_expect_success 'setup: get rid of decorations on B' ' # Graph with branch B simplified away test_expect_success '--graph --simplify-by-decoration prune branch B' ' - check_graph --simplify-by-decoration --all <<-\EOF + lib_test_check_graph --simplify-by-decoration --all <<-\EOF * A7 * A6 |\
@@ -133,7 +128,7 @@ test_expect_success '--graph --simplify-by-decoration prune branch B' ' ' test_expect_success '--graph --full-history -- bar.txt' ' - check_graph --full-history --all -- bar.txt <<-\EOF + lib_test_check_graph --full-history --all -- bar.txt <<-\EOF * A7 * A6 |\
@@ -148,7 +143,7 @@ test_expect_success '--graph --full-history -- bar.txt' ' ' test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' - check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF + lib_test_check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF * A7 * A6 |\
@@ -161,7 +156,7 @@ test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' ' test_expect_success '--graph -- bar.txt' ' - check_graph --all -- bar.txt <<-\EOF + lib_test_check_graph --all -- bar.txt <<-\EOF * A7 * A5 * A3
@@ -172,7 +167,7 @@ test_expect_success '--graph -- bar.txt' ' ' test_expect_success '--graph --sparse -- bar.txt' ' - check_graph --sparse --all -- bar.txt <<-\EOF + lib_test_check_graph --sparse --all -- bar.txt <<-\EOF * A7 * A6 * A5
@@ -189,7 +184,7 @@ test_expect_success '--graph --sparse -- bar.txt' ' ' test_expect_success '--graph ^C4' ' - check_graph --all ^C4 <<-\EOF + lib_test_check_graph --all ^C4 <<-\EOF * A7 * A6 * A5
@@ -202,7 +197,7 @@ test_expect_success '--graph ^C4' ' ' test_expect_success '--graph ^C3' ' - check_graph --all ^C3 <<-\EOF + lib_test_check_graph --all ^C3 <<-\EOF * A7 * A6 |\
@@ -220,7 +215,7 @@ test_expect_success '--graph ^C3' ' # that important, but this test depends on it. If the ordering ever changes # in the code, we'll need to update this test. test_expect_success '--graph --boundary ^C3' ' - check_graph --boundary --all ^C3 <<-\EOF + lib_test_check_graph --boundary --all ^C3 <<-\EOF * A7 * A6 |\
Signature · 1 line
2.54.0
PATCH v10 2/7 revision: add next_commit_to_show()
In reply to Pablo Sabaterget_revision() gets its commits from two sources depending on the mode:
1. Normally it gets the commits from get_revision_internal().
2. --max-count-oldest which was introduced at bb4ce23284 (revision.c:
implement --max-count-oldest, 2026-05-19) gets the commits by popping from a saved list at revs->commits marking SHOWN and CHILD_SHOWN on each popped commit.
Extract the choice logic into a helper, next_commit_to_show(), which returns the next commit regardless of the source it comes from.
This has no change in behavior. The helper is needed in a subsequent commit that pre-fetches two commits into a buffer for lookahead purposes and needs to pre-fetch from the same source.
The --reverse branch keeps its own pop loop. Using the helper for --reverse would additionally set SHOWN and CHILD_SHOWN which is not desired and a behavior change.
--- revision.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-)
revision.c +24 -12
@@ -4658,12 +4658,34 @@ static void retrieve_oldest_commits(struct rev_info *revs,commit_list_insert (c, queue); } +/* +* Returns the next commit that will be shown, regardless of whether it comes +* directly from the revision walk or from the list saved by the staged output +* of --max-count-oldest. +*/ +static struct commit *next_commit_to_show (struct rev_info *revs) +{ +struct commit *c; +struct commit_list *p; + +if (!revs->max_count_stage) +return get_revision_internal (revs); + + c =pop_commit (&revs->commits); +if (c) { + c->object.flags |=SHOWN ; +if (!(c->object.flags &BOUNDARY )) +for (p = c->parents; p; p = p->next) + p->item->object.flags |=CHILD_SHOWN ; + } +return c; +} +struct commit *get_revision (struct rev_info *revs) {struct commit *c;struct commit_list *reversed;struct commit_list *queue =NULL ; -struct commit_list *p;if (revs->max_count_type ==1 && !revs->max_count_stage) {retrieve_oldest_commits (revs, &queue);
@@ -4693,17 +4715,7 @@ struct commit *get_revision(struct rev_info *revs)return c; } -if (revs->max_count_stage) { - c =pop_commit (&revs->commits); -if (c) { - c->object.flags |=SHOWN ; -if (!(c->object.flags &BOUNDARY )) -for (p = c->parents; p; p = p->next) - p->item->object.flags |=CHILD_SHOWN ; - } - }else { - c =get_revision_internal (revs); - } + c =next_commit_to_show (revs);if (c && revs->graph)graph_update (revs->graph, c);
Signature · 1 line
2.54.0
PATCH v10 3/7 graph: add a 2 commit buffer for lookahead
In reply to Pablo SabaterIn a subsequent commit the graph renderer needs to know if the next commit is a visual root or if it is the last commit to be shown. This requires peeking 2 commits ahead.
Commits are pre-fetched in get_revision() through next_commit_to_show() where they are also marked as SHOWN, regardless the source they come from.
Update graph_is_interesting() so it considers commits inside the lookahead buffer as interesting as well.
--- graph.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ graph.h | 17 +++++++++++++++++ revision.c | 18 ++++++++++++++++-- 3 files changed, 84 insertions(+), 2 deletions(-)
graph.c +51 -0
@@ -315,6 +315,14 @@ struct git_graph {* diff_output_prefix_callback(). */ struct strbuf prefix_buf; + +/* +* Lookahead buffer: up to 2 pre-fetched commits that will be shown. +* Populated by get_revision() so graph_peek_next_visible() can use +* actual walk results instead of peeking at rev_info internals. +*/ +struct commit *lookahead[2 ]; +int lookahead_nr; };static inline int graph_needs_truncation (struct git_graph *graph,int lane)
@@ -388,6 +396,9 @@ struct git_graph *graph_init(struct rev_info *opt) graph->num_columns =0 ; graph->num_new_columns =0 ; graph->mapping_size =0 ; + graph->lookahead[0 ] =NULL ; + graph->lookahead[1 ] =NULL ; + graph->lookahead_nr =0 ;/* * Start the column color at the maximum value, since we'll * always increment it for the first commit we output.
@@ -456,6 +467,15 @@ static void graph_ensure_capacity(struct git_graph *graph, int num_columns)*/ static int graph_is_interesting (struct git_graph *graph,struct commit *commit) { +/* +* Commits in the lookahead buffer have been pre-fetched by +* get_revision() and will be shown in the future. They already have +* the SHOWN flag set when they were pre-fetched but the graph still +* needs to treat them as interesting parents. +*/ +for (int i =0 ; i < graph->lookahead_nr; i++) +if (graph->lookahead[i] == commit) +return 1 ;/* * If revs->boundary is set, commits whose children have * been shown are always interesting, even if they have the
@@ -763,6 +783,37 @@ static int graph_needs_pre_commit_line(struct git_graph *graph) graph->expansion_row <graph_num_expansion_rows (graph); } +struct commit *graph_pop_lookahead (struct git_graph *graph) +{ +struct commit *c; + +if (!graph->lookahead_nr) +return NULL ; + + c = graph->lookahead[0 ]; +if (!c) +BUG ("lookahead buffer has %d entries but the first one is NULL" , + graph->lookahead_nr); + + graph->lookahead[0 ] = graph->lookahead[1 ]; + graph->lookahead[1 ] =NULL ; + graph->lookahead_nr--; +return c; +} + +int graph_get_lookahead_room (struct git_graph *graph) +{ +return (int )ARRAY_SIZE (graph->lookahead) - graph->lookahead_nr; +} + +void graph_push_lookahead (struct git_graph *graph,struct commit *c) +{ +if (!graph_get_lookahead_room (graph)) +BUG ("pushing into lookahead buffer when it is already full" ); + + graph->lookahead[graph->lookahead_nr++] = c; +} +void graph_update (struct git_graph *graph,struct commit *commit) {struct commit_list *parent;
graph.h +17 -0
@@ -262,4 +262,21 @@ void graph_show_commit_msg(struct git_graph *graph,FILE *file, struct strbuf const *sb); +/* +* Pop the first commit from the graph's lookahead buffer. +* Returns NULL if the buffer is empty. +*/ +struct commit *graph_pop_lookahead (struct git_graph *graph); + +/* +* Returns how many more commits can be added to the lookahead buffer. +*/ +int graph_get_lookahead_room (struct git_graph *graph); + +/* +* Push a commit into the lookahead buffer. Must only be called when +* graph_get_lookahead_room() returns > 0. +*/ +void graph_push_lookahead (struct git_graph *graph,struct commit *c); +#endif /* GRAPH_H */
revision.c +16 -2
@@ -4715,10 +4715,24 @@ struct commit *get_revision(struct rev_info *revs)return c; } - c =next_commit_to_show (revs); +if (revs->graph) { + c =graph_pop_lookahead (revs->graph); +if (!c) + c =next_commit_to_show (revs); + }else { + c =next_commit_to_show (revs); + } -if (c && revs->graph) +if (c && revs->graph) { +while (graph_get_lookahead_room (revs->graph)) { +struct commit *next =next_commit_to_show (revs); +if (!next) +break ; +graph_push_lookahead (revs->graph, next); + }graph_update (revs->graph, c); + } +if (!c) {free_saved_parents (revs);commit_list_free (revs->previous_parents);
Signature · 1 line
2.54.0
PATCH v10 4/7 graph: indent visual root in graph
In reply to Pablo SabaterWhen rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This happens because the commits fill the space from left to right and when a visual root ends, its column becomes free for the following commit even if they are not related. Once this happens the unrelated commit is rendered below the visual root. Because there is no special character or way to identify when a visual root is rendered making the graph confusing.
By indenting the visual roots when there are still commits to show the vertical adjacency can be avoided.
Add is_visual_root flag to git_graph making it visible in all graph states, give graph_update() a new function, graph_is_visual_root() to know if the current commit is a visual root and set is_visual_root.
The different handled cases are:
- If a visual root has children: similar to GRAPH_PRE_COMMIT state when octopus merges need space, an edge row needs to be printed to connect the child with the indented visual root. A new state GRAPH_PRE_ROOT is needed to connect the child with the visual root:
* child of the visual root
\ GRAPH_PRE_ROOT
* visual root indented
- If a visual root is child-less we can skip GRAPH_PRE_ROOT state and render the indented commit directly.
* visual root indented
* unrelated commit
- If two or more visual roots are adjacent: by having a lookahead to the next commit that will be rendered, if the next commit is also a visual root and we are on a visual root, meaning two visual root adjacent in the history, the top one can omit the indent, making the one below to indent only once, if there are more adjacent visual commits, the indentation will increase for each adjacent one, cascading.
* visual root
* visual root
* visual root
* last commit
Even if the last commit is a root, because there is nothing that will be rendered below we can omit the indentation on purpose.
[1]: https://lore.kernel.org/git/[email protected]/
--- graph.c | 244 +++++++++++++++++++ t/meson.build | 1 + t/t4218-log-graph-indentation.sh | 514 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 759 insertions(+)
graph.c +244 -0
@@ -60,12 +60,23 @@ struct column {* index into column_colors. */ unsigned short color; +/* +* Marks if a commit is a non-first parent of a merge. These columns are +* already visually connected to the merge commit and do not need +* indentation. +* +* The first parent is the one that inherits the column and it can need +* indentation if turns out to be a visual root and there's still +* commits to render. +*/ + unsigned int is_merge_parent:1; };enum graph_state {GRAPH_PADDING ,GRAPH_SKIP ,GRAPH_PRE_COMMIT , +GRAPH_PRE_ROOT ,GRAPH_COMMIT ,GRAPH_POST_MERGE ,GRAPH_COLLAPSING
@@ -323,6 +334,51 @@ struct git_graph {*/ struct commit *lookahead[2 ];int lookahead_nr; + +/* +* If a commit is a visual root, we need to indent it to prevent +* unrelated commits from being vertically adjacent to it. +*/ + unsigned int is_visual_root:1; + +/* +* Indentation increases for each visual root adjacent to another visual +* root, making visual root commits indentation cascade. +*/ +unsigned int visual_root_depth; + +/* +* When a visual root is adjacent to other visual roots, the first one +* can avoid indentation and the rest cascades, increasing the indentation +* for each one. +*/ + unsigned int visual_root_cascade:1; + +/* +* Set when the current commit was already present in graph->columns +* before being processed. +*/ + unsigned int commit_in_columns:1; +}; + +struct graph_lookahead_flags { + +/* +* Set when there will be a commit after the current one that will be +* rendered. +*/ +unsigned int is_next_visible:1 ; + +/* +* Set when the next visible commit is candidate to be a visual root. +*/ +unsigned int is_next_visual_root:1 ; + +/* +* Set when the next visible commit will be rendered under the current +* commit. +*/ +unsigned int next_has_column:1 ; };static inline int graph_needs_truncation (struct git_graph *graph,int lane)
@@ -399,6 +455,8 @@ struct git_graph *graph_init(struct rev_info *opt) graph->lookahead[0 ] =NULL ; graph->lookahead[1 ] =NULL ; graph->lookahead_nr =0 ; + graph->visual_root_depth =0 ; + graph->visual_root_cascade =0 ;/* * Start the column color at the maximum value, since we'll * always increment it for the first commit we output.
@@ -581,6 +639,11 @@ static void graph_insert_into_new_columns(struct git_graph *graph, struct commit *commit, int idx) { +/* +* Get the initial merge_layout before it's modified to know if this +* is a merge. +*/ +int initial_merge_layout = graph->merge_layout;int i =graph_find_new_column_by_commit (graph, commit);int mapping_idx;
@@ -592,6 +655,7 @@ static void graph_insert_into_new_columns(struct git_graph *graph, i = graph->num_new_columns++; graph->new_columns[i].commit = commit; graph->new_columns[i].color =graph_find_commit_color (graph, commit); + graph->new_columns[i].is_merge_parent =0 ; }if (graph->num_parents >1 && idx >-1 && graph->merge_layout ==-1 ) {
@@ -630,6 +694,12 @@ static void graph_insert_into_new_columns(struct git_graph *graph, } graph->mapping[mapping_idx] = i; + +/* +* Mark non-first parents of a merge. +*/ +if (graph->num_parents >1 && initial_merge_layout >=0 && idx >-1 ) + graph->new_columns[i].is_merge_parent =1 ; }static void graph_update_columns (struct git_graph *graph)
@@ -721,10 +791,20 @@ static void graph_update_columns(struct git_graph *graph)if (graph->num_parents ==0 ) graph->width +=2 ; }else { +int j;graph_insert_into_new_columns (graph, col_commit,-1 ); +/* +* This column is not the current commit, but we need to +* propagate the flag until the commit is processed. +*/ + j =graph_find_new_column_by_commit (graph, col_commit); +if (j >=0 && graph->columns[i].is_merge_parent) + graph->new_columns[j].is_merge_parent =1 ; } } + graph->commit_in_columns = is_commit_in_columns; +/* * If graph_max_lanes is set, cap the width */
@@ -814,9 +894,113 @@ void graph_push_lookahead(struct git_graph *graph, struct commit *c) graph->lookahead[graph->lookahead_nr++] = c; } +/* +* A commit can be a visual root when: +* +* - It has no parents. +* +* - It has parents but they are all filtered out and +* commit->parents arrives NULL. +* +* - Its parents are uninteresting. +* +* - It is not a boundary commit. Boundary commits also have no visible +* parents, but they are not selected as visual roots because they cannot +* cause the ambiguity of being vertically adjacent because: +* +* 1. A boundary only appears because an included commit is its child. +* Children are always above, and the renderer draws an edge down to +* the boundary from that child. Rather than starting a column like a +* visual root would do, it inherits its child column. +* +* 2. Included commits cannot appear below a boundary. Boundaries are +* ancestors of the exclusion point; if an included commit were an +* ancestor of the boundary it would be excluded and not rendered. +* Boundaries therefore always sink to the bottom. +*/ +static int graph_is_visual_root_candidate (struct commit *c,struct git_graph *graph) +{ +struct commit_list *p; + +if (c->object.flags &BOUNDARY ) +return 0 ; +for (p = c->parents; p; p = p->next) +if (graph_is_interesting (graph, p->item)) +return 0 ; +return 1 ; +} + +static int graph_is_visual_root (struct git_graph *graph, +struct graph_lookahead_flags *flags) +{ +/* +* This must be only called for the current commit as graph contains +* the state for the current commit only. +* +* To check if a commit is a visual root, call graph_is_visual_root_candidate() +* but we won't know if it is really a visual root until we get to the +* next commit state. +* +* The current commit is an actual visual root if it is a candidate and +* the commit is not a non-first parent of a merge. +* +* * +* |\ +* | * <- it is a visual root candidate but it shouldn't be indented +* * because it is already connected by an edge. +* ^ if commit_in_columns && is_merge_parent means the commit +* | was put by a merge and is connected. +* | +* `-------- if !is_next_visible means we're on the last commit, avoid +* indentation unless the one before is a visual root, then +* we need to differentiate from the one above. +* +* If next_has_columns means that the next commit has +* already a column, so it will not be rendered below, the +* current commit has to act as the last commit and omit +* indentation. +*/ +return graph_is_visual_root_candidate (graph->commit, graph) && + !(graph->commit_in_columns && + graph->columns[graph->commit_index].is_merge_parent) && + flags->is_next_visible && + (!flags->next_has_column || graph->visual_root_depth >0 ); +} + +/* +* Peeks the next commits via the lookahead buffer and sets the lookahead flags. +*/ +static void graph_peek_next_visible (struct git_graph *graph, +struct graph_lookahead_flags *flags) +{ + flags->is_next_visible =0 ; + flags->is_next_visual_root =0 ; + flags->next_has_column =0 ; + +if (!graph->lookahead_nr) +return ; + + flags->is_next_visible =1 ; + flags->next_has_column = +graph_find_new_column_by_commit (graph, graph->lookahead[0 ]) >=0 ; + +if (!graph_is_visual_root_candidate (graph->lookahead[0 ], graph)) +return ; + +if (graph->lookahead_nr >=2 ) + flags->is_next_visual_root =1 ; +} + +static int graph_needs_pre_root_line (struct git_graph *graph) +{ +return graph->commit_in_columns && graph->is_visual_root && + graph->num_columns >0 && !graph->visual_root_cascade; +} +void graph_update (struct git_graph *graph,struct commit *commit) {struct commit_list *parent; +struct graph_lookahead_flags flags;/* * Set the new commit
@@ -847,6 +1031,23 @@ void graph_update(struct git_graph *graph, struct commit *commit)*/ graph_update_columns (graph); +graph_peek_next_visible (graph, &flags); + + graph->is_visual_root =graph_is_visual_root (graph, &flags); + +if (graph->is_visual_root) { +/* +* If next is a visual root we can omit the indent for the first +* visual root and start cascading. +*/ +if (!graph->visual_root_depth && flags.is_next_visual_root) + graph->visual_root_cascade =1 ; + graph->visual_root_depth++; + }else { + graph->visual_root_depth =0 ; + graph->visual_root_cascade =0 ; + } + graph->expansion_row =0 ;/*
@@ -864,11 +1065,16 @@ void graph_update(struct git_graph *graph, struct commit *commit)* room for it. We need to do this only if there is a branch row * (or more) to the right of this commit. * +* If it is a visual root, we need to print an extra row to +* connect the indentation. +* * If there are less than 3 parents, we can immediately print the * commit line. */ if (graph->state !=GRAPH_PADDING ) graph->state =GRAPH_SKIP ; +else if (graph_needs_pre_root_line (graph)) + graph->state =GRAPH_PRE_ROOT ;else if (graph_needs_pre_commit_line (graph)) graph->state =GRAPH_PRE_COMMIT ;else
@@ -1116,6 +1322,17 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_lineif (col_commit == graph->commit) { seen_this =1 ; +if (graph->is_visual_root) { +int depth = graph->visual_root_depth; +/* +* Each visual column is 2 characters wide. +* Omit the indentation for the first visual +* root in cascade mode. +*/ +int padding = (depth - graph->visual_root_cascade) *2 ; +graph_line_addchars (line,' ' , padding); + graph->width += padding; + }graph_output_commit_char (graph, line);if (graph_needs_truncation (graph, i)) {
@@ -1487,6 +1704,30 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_lgraph_update_state (graph,GRAPH_PADDING ); } +static void graph_output_pre_root_line (struct git_graph *graph,struct graph_line *line) +{ +/* +* This function adds a row before a visual root, to connect the +* branch to the indented commit. It must only be called on a +* visual root. +*/ +if (!graph->is_visual_root) +BUG ("commit must be a visual root to call pre_root_line" ); + +for (int i =0 ; i < graph->num_columns; i++) { +struct column *col = &graph->columns[i]; +if (col->commit == graph->commit) { +graph_line_addch (line,' ' ); +graph_line_write_column (line, col,'\\' ); + }else { +graph_line_write_column (line, col,'|' ); + } +graph_line_addch (line,' ' ); + } + +graph_update_state (graph,GRAPH_COMMIT ); +} +int graph_next_line (struct git_graph *graph,struct strbuf *sb) {int shown_commit_line =0 ;
@@ -1512,6 +1753,9 @@ int graph_next_line(struct git_graph *graph, struct strbuf *sb)case GRAPH_PRE_COMMIT :graph_output_pre_commit_line (graph, &line);break ; +case GRAPH_PRE_ROOT : +graph_output_pre_root_line (graph, &line); +break ;case GRAPH_COMMIT :graph_output_commit_line (graph, &line); shown_commit_line =1 ;
t/meson.build +1 -0
@@ -577,6 +577,7 @@ integration_tests = [ 't4215-log-skewed-merges.sh', 't4216-log-bloom.sh', 't4217-log-limit.sh', + 't4218-log-graph-indentation.sh', 't4219-log-follow-merge.sh', 't4252-am-options.sh', 't4253-am-keep-cr-dos.sh',
t/t4218-log-graph-indentation.sh new file +514 -0
514 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v10 5/7 graph: wrap cascading commits after 4 columns
In reply to Pablo SabaterCurrently the visual root commits in a graph cascade indefinitely until a commit which is not a visual root or the last commit appears. On filters like --author where one author might contribute mostly on single patches this can become a visual issue.
Make the cascading wrap after 4 columns.
There are two possible cases of the wrap:
1. No ambiguity:
* A
* B
* C
* D
* E
* F
2. Ambiguous conflict:
If F happens to not be a visual root and E gets wrapped back to the initial column then E and F would be vertically adjacent. The solution is to forcefully indent E one level:
* A
* B
* C
* D
* E
* F
* F
The magic number 4 comes as the minimum number of columns to wrap where the output shows clearly the commits are unrelated and doesn't cause too much "pyramid" effects
--- graph.c | 22 +++++++++++++++++++++- t/t4218-log-graph-indentation.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-)
graph.c +21 -1
@@ -1042,6 +1042,23 @@ void graph_update(struct git_graph *graph, struct commit *commit)*/ if (!graph->visual_root_depth && flags.is_next_visual_root) graph->visual_root_cascade =1 ; + +/* +* We wrap the cascading at a max of four columns at most, after +* that we wrap it back to the initial column. +* +* This could cause ambiguity in case of the next commit not +* being a visual root and be at the initial column after the +* first wrap. +* +* In case of being a non-visual-root the next, stop the +* cascading to get the commit indented. +*/ +if (!flags.is_next_visual_root && + graph->visual_root_depth && + !(graph->visual_root_depth %4 )) + graph->visual_root_cascade =0 ; + graph->visual_root_depth++; }else { graph->visual_root_depth =0 ;
@@ -1328,8 +1345,11 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line* Each visual column is 2 characters wide. * Omit the indentation for the first visual * root in cascade mode. +* +* Have a max of 4 columns when cascading, after +* that wrap it and repeat. */ -int padding = (depth - graph->visual_root_cascade) *2 ; +int padding = ((depth - graph->visual_root_cascade) %4 ) *2 ;graph_line_addchars (line,' ' , padding); graph->width += padding; }
t/t4218-log-graph-indentation.sh +29 -0
@@ -511,4 +511,33 @@ test_expect_success '--grep skipped parent makes a visual root' ' EOF ' +# The cascading wraps after 4 columns and when wraping (column % 4 == 0) if the +# next is a non visual-root, force indentation to avoid an ambiguous graph +# (commit 59_A is forcefully indented) +test_expect_success 'visual root cascading gets wrapped after 4 columns' ' + create_orphan _58 && test_commit 58_A && test_commit 58_B && + create_orphan _59 && test_commit 59_A && + create_orphan _60 && test_commit 60_A && + create_orphan _61 && test_commit 61_A && + create_orphan _62 && test_commit 62_A && + create_orphan _63 && test_commit 63_A && + create_orphan _64 && test_commit 64_A && + create_orphan _65 && test_commit 65_A && + create_orphan _66 && test_commit 66_A && + create_orphan _67 && test_commit 67_A && + lib_test_check_graph _58 _59 _60 _61 _62 _63 _64 _65 _66 _67 <<-\EOF + * 67_A + * 66_A + * 65_A + * 64_A + * 63_A + * 62_A + * 61_A + * 60_A + * 59_A + * 58_B + * 58_A + EOF +' + test_done
Signature · 1 line
2.54.0
PATCH v10 6/7 graph: move config reading into graph_read_config()
In reply to Pablo SabaterMove the repo_config_get_string() call out of graph_init() and into graph_read_config(). This simplifies graph_init() and provides a function for future graph-related config opt.
This commit is a preparatory commit for a subsequent one.
--- graph.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
graph.c +9 -4
@@ -417,13 +417,11 @@ void graph_setup_line_prefix(struct diff_options *diffopt) diffopt->output_prefix = diff_output_prefix_callback; } -struct git_graph *graph_init (struct rev_info *opt) +static void graph_read_config (struct rev_info *revs) { -struct git_graph *graph =xmalloc (sizeof (struct git_graph )); -if (!column_colors) {char *string; -if (repo_config_get_string (opt->repo,"log.graphcolors" , &string)) { +if (repo_config_get_string (revs->repo,"log.graphcolors" , &string)) {/* not configured -- use default */ graph_set_column_colors (column_colors_ansi, column_colors_ansi_max);
@@ -437,6 +435,13 @@ struct git_graph *graph_init(struct rev_info *opt) custom_colors.nr - 1); } } +} + +struct git_graph *graph_init (struct rev_info *opt) +{ +struct git_graph *graph =xmalloc (sizeof (struct git_graph )); + +graph_read_config (opt); graph->commit =NULL ; graph->revs = opt;
Signature · 1 line
2.54.0
PATCH v10 7/7 graph: add --[no-]graph-indent and log.graphIndent
In reply to Pablo SabaterSome users may prefer to not have graph indentation.
Add "log.graphIndent" config variable to graph_read_config() to read the default preference. By default is graph indentation is true.
Add --graph-indent and --no-graph-indent options to overwrite the default preference.
--- Documentation/config/log.adoc | 4 +++ Documentation/rev-list-options.adoc | 8 ++++++ graph.c | 10 +++++-- revision.c | 9 +++++++ revision.h | 2 ++ t/t4218-log-graph-indentation.sh | 52 +++++++++++++++++++++++++++++++++++++ 6 files changed, 83 insertions(+), 2 deletions(-)
Documentation/config/log.adoc +4 -0
@@ -59,6 +59,10 @@ This is the same as the `--decorate` option of the `git log`. A list of colors, separated by commas, that can be used to draw history lines in `git log --graph`. +`log.graphIndent`:: + If `true`, indent visual roots when rendering the graphs with `--graph`. + Set true by default. It can be overriden with `--[no-]graph-indent`. + `log.showRoot`:: If true, the initial commit will be shown as a big creation event. This is equivalent to a diff against an empty tree.
Documentation/rev-list-options.adoc +8 -0
@@ -1269,6 +1269,14 @@ This implies the `--topo-order` option by default, but the By default it is set to 0 (no limit), zero and negative values are ignored and treated as no limit. +`--no-graph-indent`:: +`--graph-indent`:: + When used with `--graph`, indent visual roots (commits with no parents + or whose parents are not shown) to differentiate them from commits that + are vertically adjacent but unrelated. Enabled by default. Use + `--no-graph-indent` to disable or set `graph.indent` to set a deafault + preference. + ifdef::git-rev-list[] `--count`:: Print a number stating how many commits would have been
graph.c +8 -2
@@ -419,6 +419,8 @@ void graph_setup_line_prefix(struct diff_options *diffopt)static void graph_read_config (struct rev_info *revs) { +int val; +if (!column_colors) {char *string;if (repo_config_get_string (revs->repo,"log.graphcolors" , &string)) {
@@ -435,6 +437,9 @@ static void graph_read_config(struct rev_info *revs) custom_colors.nr - 1); } } + +if (!repo_config_get_bool (revs->repo,"log.graphIndent" , &val)) + revs->no_graph_indent = !val; }struct git_graph *graph_init (struct rev_info *opt)
@@ -999,7 +1004,8 @@ static void graph_peek_next_visible(struct git_graph *graph,static int graph_needs_pre_root_line (struct git_graph *graph) {return graph->commit_in_columns && graph->is_visual_root && - graph->num_columns >0 && !graph->visual_root_cascade; + graph->num_columns >0 && !graph->visual_root_cascade && + !graph->revs->no_graph_indent; }void graph_update (struct git_graph *graph,struct commit *commit)
@@ -1344,7 +1350,7 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_lineif (col_commit == graph->commit) { seen_this =1 ; -if (graph->is_visual_root) { +if (graph->is_visual_root && !graph->revs->no_graph_indent) {int depth = graph->visual_root_depth;/* * Each visual column is 2 characters wide.
revision.c +9 -0
@@ -2627,6 +2627,12 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->graph =NULL ; }else if (skip_prefix (arg,"--graph-lane-limit=" , &optarg)) { revs->graph_max_lanes =parse_count (optarg); + }else if (!strcmp (arg,"--graph-indent" )) { + revs->no_graph_indent =0 ; + revs->graph_indent_set =1 ; + }else if (!strcmp (arg,"--no-graph-indent" )) { + revs->no_graph_indent =1 ; + revs->graph_indent_set =1 ; }else if (!strcmp (arg,"--encode-email-headers" )) { revs->encode_email_headers =1 ; }else if (!strcmp (arg,"--no-encode-email-headers" )) {
@@ -3201,6 +3207,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct sif (revs->graph_max_lanes >0 && !revs->graph)die (_ ("the option '%s' requires '%s'" ),"--graph-lane-limit" ,"--graph" ); +if (revs->graph_indent_set >0 && !revs->graph) +die (_ ("the option '%s' requires '%s'" ),"--[no-]graph-indent" ,"--graph" ); +if (!revs->reflog_info && revs->grep_filter.use_reflog_filter)die (_ ("the option '%s' requires '%s'" ),"--grep-reflog" ,"--walk-reflogs" );
revision.h +2 -0
@@ -314,6 +314,8 @@ struct rev_info {/* Display history graph */ struct git_graph *graph;int graph_max_lanes; +int no_graph_indent; +unsigned int graph_indent_set;/* special limits */ int skip_count;
t/t4218-log-graph-indentation.sh +52 -0
56 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v10 7/7] graph: add --[no-]graph-indent and log.graphIndent
Quoted 17 lines · Pablo Sabater
Some users may prefer to not have graph indentation.
Add "log.graphIndent" config variable to
graph_read_config()to read the default preference. By default is graph indentation is true.Add --graph-indent and --no-graph-indent options to overwrite the default preference.
Signed-off-by Pablo Sabater <[email protected]>--- Documentation/config/log.adoc | 4 +++ Documentation/rev-list-options.adoc | 8 ++++++ graph.c | 10 +++++-- revision.c | 9 +++++++ revision.h | 2 ++ t/t4218-log-graph-indentation.sh | 52 +++++++++++++++++++++++++++++++++++++ 6 files changed, 83 insertions(+), 2 deletions(-)
[snip]
revision.h struct rev_info { · line 318
Quoted 10 lines
revision.h +2
-0@@ -314,6 +314,8 @@ struct rev_info {/* Display history graph */ struct git_graph *graph;int graph_max_lanes; +int no_graph_indent; +unsigned int graph_indent_set;
These are both boolean values and could be set to be 1 bit wide.
Other than that LGTM.
Thank you for the changes.
Re: [PATCH v10 7/7] graph: add --[no-]graph-indent and log.graphIndent
Quoted 21 lines · Mirko Faina
Quoted 17 lines · Pablo Sabater
Some users may prefer to not have graph indentation.
Add "log.graphIndent" config variable to
graph_read_config()to read the default preference. By default is graph indentation is true.Add --graph-indent and --no-graph-indent options to overwrite the default preference.
Signed-off-by Pablo Sabater <[email protected]>--- Documentation/config/log.adoc | 4 +++ Documentation/rev-list-options.adoc | 8 ++++++ graph.c | 10 +++++-- revision.c | 9 +++++++ revision.h | 2 ++ t/t4218-log-graph-indentation.sh | 52 +++++++++++++++++++++++++++++++++++++ 6 files changed, 83 insertions(+), 2 deletions(-)[snip]
Quoted 12 lines
revision.h struct rev_info { · line 318
Quoted 10 lines
revision.h +2
-0@@ -314,6 +314,8 @@ struct rev_info {/* Display history graph */ struct git_graph *graph;int graph_max_lanes; +int no_graph_indent; +unsigned int graph_indent_set;These are both boolean values and could be set to be 1 bit wide.
True, I'll change it.
Quoted 4 lines
Other than that LGTM.
Thank you for the changes.
Thanks,
Pablo
v11 cover graph: indent visual roots in graph
In reply to Pablo SabaterWhen rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This series adds indentation to the visual root commits, so they cannot be vertically adjacent anymore making it easier to identify them.
Before indentation:
* A
* B1
* B2
* C1
* C2
After indentation:
* A
* B1
\
* B2
* C1
* C2
Indents the visual root commits that have still commits to show after them, and if they have children it connects them with an edge at a new row.
If there are multiple visual roots adjacent in history, the indentation starts with the second one, avoiding redundant indentation of the first one and cascades after the second.
* A
* B
* C
* D
* E
* F
* G
* H
* I
* J1
* J2
The indentation wraps after cascading columns and when wrapping back to the initial column if the next commit is a non-visual-root commit, force the indentation one extra level.
Series explanation:
- Cleanup to bring a common function from t4215 and t6016 that will be used in t4218.
- Logic extraction of the chose of from where the commit source comes from.
- Add a buffer for lookahead purposes.
- Principal commit. Implement the logic to get the visual roots indented.
- Make visual root cascading wrap after 4 columns
- Add --[no-]graph-indent and log.graphIndent options.
GitHub CI: https://github.com/pabloosabaterr/git/actions/runs/29266560903
[1]: https://lore.kernel.org/git/[email protected]/
V9 DIFF:
- Changed boolean variables to be bit fields.
---
Pablo Sabater (7):
lib-log-graph: move check_graph function
revision: add next_commit_to_show()
graph: add a 2 commit buffer for lookahead
graph: indent visual root in graph
graph: wrap cascading commits after 4 columns
graph: move config reading into graph_read_config()
graph: add --[no-]graph-indent and log.graphIndent
Documentation/config/log.adoc | 4 + Documentation/rev-list-options.adoc | 8 + graph.c | 332 +++++++++++++++- graph.h | 17 + revision.c | 57 ++- revision.h | 2 + t/lib-log-graph.sh | 5 + t/meson.build | 1 + t/t4215-log-skewed-merges.sh | 33 +- t/t4218-log-graph-indentation.sh | 595 +++++++++++++++++++++++++++++ t/t6016-rev-list-graph-simplify-history.sh | 25 +- 11 files changed, 1031 insertions(+), 48 deletions(-)
Range-diff versus v10:
1: 9541b410b7 = 1: dd0bb0d215 lib-log-graph: move check_graph function
2: 4f8fb2cc1d = 2: 07e239533d revision: add next_commit_to_show()
3: b50574bbe1 = 3: 4d71f674a1 graph: add a 2 commit buffer for lookahead
4: fc3a8253fd = 4: 48ad2562f0 graph: indent visual root in graph
5: 204aae5061 = 5: 45be69d11b graph: wrap cascading commits after 4 columns
6: 1b42ed86a1 = 6: 8ce53ae21b graph: move config reading into graph_read_config()
7: 737331b68d ! 7: c1fa81022e graph: add --[no-]graph-indent and log.graphIndent
@@ revision.h: struct rev_info {
/* Display history graph */
struct git_graph *graph;
int graph_max_lanes;
-+ int no_graph_indent;
-+ unsigned int graph_indent_set;
++ unsigned int no_graph_indent:1;
++ unsigned int graph_indent_set:1;
/* special limits */
int skip_count;---
base-commit: f60db8d575adb79761d363e026fb49bddf330c73
PATCH v11 1/7 lib-log-graph: move check_graph function
check_graph is a function shared in the test files t4215 and t6016 used to format the output graph, but instead of being in a file called by both test, the function code is repeated in each file.
Move check_graph to lib-log-graph.sh file which both tests already import graph functions from, renaming it to lib_test_check_graph.
This function is needed for the following commit which includes graph tests in a new file and requires check_graph.
--- t/lib-log-graph.sh | 5 +++++ t/t4215-log-skewed-merges.sh | 33 +++++++++++++----------------- t/t6016-rev-list-graph-simplify-history.sh | 25 +++++++++------------- 3 files changed, 29 insertions(+), 34 deletions(-)
t/lib-log-graph.sh +5 -0
@@ -26,3 +26,8 @@ lib_test_cmp_colored_graph () { test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors && test_cmp expect.colors output.colors } + +lib_test_check_graph () { + cat >expect && + lib_test_cmp_graph --format=%s "$@" +}
t/t4215-log-skewed-merges.sh +14 -19
@@ -5,11 +5,6 @@ test_description='git log --graph of skewed merges' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh -check_graph () { - cat >expect && - lib_test_cmp_graph --format=%s "$@" -} - test_expect_success 'log --graph with merge fusing with its left and right neighbors' ' git checkout --orphan _p && test_commit A &&
@@ -21,7 +16,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh git checkout _p && git merge --no-ff _r -m G && git checkout @^^ && git merge --no-ff _p -m H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * H |\ | * G
@@ -49,7 +44,7 @@ test_expect_success 'log --graph with left-skewed merge' ' git checkout 0_p && git merge --no-ff 0_s -m 0_G && git checkout @^ && git merge --no-ff 0_q 0_r 0_t 0_p -m 0_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF *-----. 0_H |\ \ \ \ | | | | * 0_G
@@ -83,7 +78,7 @@ test_expect_success 'log --graph with nested left-skewed merge' ' git checkout 1_p && git merge --no-ff 1_r -m 1_G && git checkout @^^ && git merge --no-ff 1_p -m 1_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 1_H |\ | * 1_G
@@ -115,7 +110,7 @@ test_expect_success 'log --graph with nested left-skewed merge following normal git checkout -b 2_s @^^ && git merge --no-ff 2_q -m 2_J && git checkout 2_p && git merge --no-ff 2_s -m 2_K && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 2_K |\ | * 2_J
@@ -151,7 +146,7 @@ test_expect_success 'log --graph with nested right-skewed merge following left-s git checkout 3_p && git merge --no-ff 3_r -m 3_H && git checkout @^^ && git merge --no-ff 3_p -m 3_J && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 3_J |\ | * 3_H
@@ -182,7 +177,7 @@ test_expect_success 'log --graph with right-skewed merge following a left-skewed git merge --no-ff 4_p -m 4_G && git checkout @^^ && git merge --no-ff 4_s -m 4_H && - check_graph --date-order <<-\EOF + lib_test_check_graph --date-order <<-\EOF * 4_H |\ | * 4_G
@@ -218,7 +213,7 @@ test_expect_success 'log --graph with octopus merge with column joining its penu git checkout 5_r && git merge --no-ff 5_s -m 5_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 5_H |\ | *-. 5_G
@@ -257,7 +252,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout 6_1 && git merge --no-ff 6_2 -m 6_I && - check_graph 6_1 6_3 6_5 <<-\EOF + lib_test_check_graph 6_1 6_3 6_5 <<-\EOF * 6_I |\ | | * 6_H
@@ -334,7 +329,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout -b M_7 7_1 && git merge --no-ff 7_2 7_3 -m 7_M4 && - check_graph M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -371,7 +366,7 @@ test_expect_success 'log --graph with multiple tips' ' ' test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' ' - check_graph --graph-lane-limit=2 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=2 M_7 <<-\EOF *-. 7_M4 |\ \ | | * 7_G
@@ -388,7 +383,7 @@ test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' ' ' test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge' ' - check_graph --graph-lane-limit=1 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=1 M_7 <<-\EOF *-~ 7_M4 |\~ | ~ 7_G
@@ -405,7 +400,7 @@ test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge ' test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' ' - check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -441,7 +436,7 @@ test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' ' ' test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows first of 3 parent merge' ' - check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -478,7 +473,7 @@ test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows fir ' test_expect_success 'log --graph --graph-lane-limit=7 check if it shows all 3 parent merge' ' - check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
t/t6016-rev-list-graph-simplify-history.sh +10 -15
@@ -13,11 +13,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh -check_graph () { - cat >expect && - lib_test_cmp_graph --format=%s "$@" -} - test_expect_success 'set up rev-list --graph test' ' # 3 commits on branch A test_commit A1 foo.txt &&
@@ -54,7 +49,7 @@ test_expect_success 'set up rev-list --graph test' ' ' test_expect_success '--graph --all' ' - check_graph --all <<-\EOF + lib_test_check_graph --all <<-\EOF * A7 * A6 |\
@@ -82,7 +77,7 @@ test_expect_success '--graph --all' ' # that undecorated merges are interesting, even with --simplify-by-decoration test_expect_success '--graph --simplify-by-decoration' ' git tag -d A4 && - check_graph --all --simplify-by-decoration <<-\EOF + lib_test_check_graph --all --simplify-by-decoration <<-\EOF * A7 * A6 |\
@@ -114,7 +109,7 @@ test_expect_success 'setup: get rid of decorations on B' ' # Graph with branch B simplified away test_expect_success '--graph --simplify-by-decoration prune branch B' ' - check_graph --simplify-by-decoration --all <<-\EOF + lib_test_check_graph --simplify-by-decoration --all <<-\EOF * A7 * A6 |\
@@ -133,7 +128,7 @@ test_expect_success '--graph --simplify-by-decoration prune branch B' ' ' test_expect_success '--graph --full-history -- bar.txt' ' - check_graph --full-history --all -- bar.txt <<-\EOF + lib_test_check_graph --full-history --all -- bar.txt <<-\EOF * A7 * A6 |\
@@ -148,7 +143,7 @@ test_expect_success '--graph --full-history -- bar.txt' ' ' test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' - check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF + lib_test_check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF * A7 * A6 |\
@@ -161,7 +156,7 @@ test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' ' test_expect_success '--graph -- bar.txt' ' - check_graph --all -- bar.txt <<-\EOF + lib_test_check_graph --all -- bar.txt <<-\EOF * A7 * A5 * A3
@@ -172,7 +167,7 @@ test_expect_success '--graph -- bar.txt' ' ' test_expect_success '--graph --sparse -- bar.txt' ' - check_graph --sparse --all -- bar.txt <<-\EOF + lib_test_check_graph --sparse --all -- bar.txt <<-\EOF * A7 * A6 * A5
@@ -189,7 +184,7 @@ test_expect_success '--graph --sparse -- bar.txt' ' ' test_expect_success '--graph ^C4' ' - check_graph --all ^C4 <<-\EOF + lib_test_check_graph --all ^C4 <<-\EOF * A7 * A6 * A5
@@ -202,7 +197,7 @@ test_expect_success '--graph ^C4' ' ' test_expect_success '--graph ^C3' ' - check_graph --all ^C3 <<-\EOF + lib_test_check_graph --all ^C3 <<-\EOF * A7 * A6 |\
@@ -220,7 +215,7 @@ test_expect_success '--graph ^C3' ' # that important, but this test depends on it. If the ordering ever changes # in the code, we'll need to update this test. test_expect_success '--graph --boundary ^C3' ' - check_graph --boundary --all ^C3 <<-\EOF + lib_test_check_graph --boundary --all ^C3 <<-\EOF * A7 * A6 |\
Signature · 1 line
2.54.0
PATCH v11 2/7 revision: add next_commit_to_show()
In reply to Pablo Sabaterget_revision() gets its commits from two sources depending on the mode:
1. Normally it gets the commits from get_revision_internal().
2. --max-count-oldest which was introduced at bb4ce23284 (revision.c:
implement --max-count-oldest, 2026-05-19) gets the commits by popping from a saved list at revs->commits marking SHOWN and CHILD_SHOWN on each popped commit.
Extract the choice logic into a helper, next_commit_to_show(), which returns the next commit regardless of the source it comes from.
This has no change in behavior. The helper is needed in a subsequent commit that pre-fetches two commits into a buffer for lookahead purposes and needs to pre-fetch from the same source.
The --reverse branch keeps its own pop loop. Using the helper for --reverse would additionally set SHOWN and CHILD_SHOWN which is not desired and a behavior change.
--- revision.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-)
revision.c +24 -12
@@ -4658,12 +4658,34 @@ static void retrieve_oldest_commits(struct rev_info *revs,commit_list_insert (c, queue); } +/* +* Returns the next commit that will be shown, regardless of whether it comes +* directly from the revision walk or from the list saved by the staged output +* of --max-count-oldest. +*/ +static struct commit *next_commit_to_show (struct rev_info *revs) +{ +struct commit *c; +struct commit_list *p; + +if (!revs->max_count_stage) +return get_revision_internal (revs); + + c =pop_commit (&revs->commits); +if (c) { + c->object.flags |=SHOWN ; +if (!(c->object.flags &BOUNDARY )) +for (p = c->parents; p; p = p->next) + p->item->object.flags |=CHILD_SHOWN ; + } +return c; +} +struct commit *get_revision (struct rev_info *revs) {struct commit *c;struct commit_list *reversed;struct commit_list *queue =NULL ; -struct commit_list *p;if (revs->max_count_type ==1 && !revs->max_count_stage) {retrieve_oldest_commits (revs, &queue);
@@ -4693,17 +4715,7 @@ struct commit *get_revision(struct rev_info *revs)return c; } -if (revs->max_count_stage) { - c =pop_commit (&revs->commits); -if (c) { - c->object.flags |=SHOWN ; -if (!(c->object.flags &BOUNDARY )) -for (p = c->parents; p; p = p->next) - p->item->object.flags |=CHILD_SHOWN ; - } - }else { - c =get_revision_internal (revs); - } + c =next_commit_to_show (revs);if (c && revs->graph)graph_update (revs->graph, c);
Signature · 1 line
2.54.0
PATCH v11 3/7 graph: add a 2 commit buffer for lookahead
In reply to Pablo SabaterIn a subsequent commit the graph renderer needs to know if the next commit is a visual root or if it is the last commit to be shown. This requires peeking 2 commits ahead.
Commits are pre-fetched in get_revision() through next_commit_to_show() where they are also marked as SHOWN, regardless the source they come from.
Update graph_is_interesting() so it considers commits inside the lookahead buffer as interesting as well.
--- graph.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ graph.h | 17 +++++++++++++++++ revision.c | 18 ++++++++++++++++-- 3 files changed, 84 insertions(+), 2 deletions(-)
graph.c +51 -0
@@ -315,6 +315,14 @@ struct git_graph {* diff_output_prefix_callback(). */ struct strbuf prefix_buf; + +/* +* Lookahead buffer: up to 2 pre-fetched commits that will be shown. +* Populated by get_revision() so graph_peek_next_visible() can use +* actual walk results instead of peeking at rev_info internals. +*/ +struct commit *lookahead[2 ]; +int lookahead_nr; };static inline int graph_needs_truncation (struct git_graph *graph,int lane)
@@ -388,6 +396,9 @@ struct git_graph *graph_init(struct rev_info *opt) graph->num_columns =0 ; graph->num_new_columns =0 ; graph->mapping_size =0 ; + graph->lookahead[0 ] =NULL ; + graph->lookahead[1 ] =NULL ; + graph->lookahead_nr =0 ;/* * Start the column color at the maximum value, since we'll * always increment it for the first commit we output.
@@ -456,6 +467,15 @@ static void graph_ensure_capacity(struct git_graph *graph, int num_columns)*/ static int graph_is_interesting (struct git_graph *graph,struct commit *commit) { +/* +* Commits in the lookahead buffer have been pre-fetched by +* get_revision() and will be shown in the future. They already have +* the SHOWN flag set when they were pre-fetched but the graph still +* needs to treat them as interesting parents. +*/ +for (int i =0 ; i < graph->lookahead_nr; i++) +if (graph->lookahead[i] == commit) +return 1 ;/* * If revs->boundary is set, commits whose children have * been shown are always interesting, even if they have the
@@ -763,6 +783,37 @@ static int graph_needs_pre_commit_line(struct git_graph *graph) graph->expansion_row <graph_num_expansion_rows (graph); } +struct commit *graph_pop_lookahead (struct git_graph *graph) +{ +struct commit *c; + +if (!graph->lookahead_nr) +return NULL ; + + c = graph->lookahead[0 ]; +if (!c) +BUG ("lookahead buffer has %d entries but the first one is NULL" , + graph->lookahead_nr); + + graph->lookahead[0 ] = graph->lookahead[1 ]; + graph->lookahead[1 ] =NULL ; + graph->lookahead_nr--; +return c; +} + +int graph_get_lookahead_room (struct git_graph *graph) +{ +return (int )ARRAY_SIZE (graph->lookahead) - graph->lookahead_nr; +} + +void graph_push_lookahead (struct git_graph *graph,struct commit *c) +{ +if (!graph_get_lookahead_room (graph)) +BUG ("pushing into lookahead buffer when it is already full" ); + + graph->lookahead[graph->lookahead_nr++] = c; +} +void graph_update (struct git_graph *graph,struct commit *commit) {struct commit_list *parent;
graph.h +17 -0
@@ -262,4 +262,21 @@ void graph_show_commit_msg(struct git_graph *graph,FILE *file, struct strbuf const *sb); +/* +* Pop the first commit from the graph's lookahead buffer. +* Returns NULL if the buffer is empty. +*/ +struct commit *graph_pop_lookahead (struct git_graph *graph); + +/* +* Returns how many more commits can be added to the lookahead buffer. +*/ +int graph_get_lookahead_room (struct git_graph *graph); + +/* +* Push a commit into the lookahead buffer. Must only be called when +* graph_get_lookahead_room() returns > 0. +*/ +void graph_push_lookahead (struct git_graph *graph,struct commit *c); +#endif /* GRAPH_H */
revision.c +16 -2
@@ -4715,10 +4715,24 @@ struct commit *get_revision(struct rev_info *revs)return c; } - c =next_commit_to_show (revs); +if (revs->graph) { + c =graph_pop_lookahead (revs->graph); +if (!c) + c =next_commit_to_show (revs); + }else { + c =next_commit_to_show (revs); + } -if (c && revs->graph) +if (c && revs->graph) { +while (graph_get_lookahead_room (revs->graph)) { +struct commit *next =next_commit_to_show (revs); +if (!next) +break ; +graph_push_lookahead (revs->graph, next); + }graph_update (revs->graph, c); + } +if (!c) {free_saved_parents (revs);commit_list_free (revs->previous_parents);
Signature · 1 line
2.54.0
PATCH v11 4/7 graph: indent visual root in graph
In reply to Pablo SabaterWhen rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This happens because the commits fill the space from left to right and when a visual root ends, its column becomes free for the following commit even if they are not related. Once this happens the unrelated commit is rendered below the visual root. Because there is no special character or way to identify when a visual root is rendered making the graph confusing.
By indenting the visual roots when there are still commits to show the vertical adjacency can be avoided.
Add is_visual_root flag to git_graph making it visible in all graph states, give graph_update() a new function, graph_is_visual_root() to know if the current commit is a visual root and set is_visual_root.
The different handled cases are:
- If a visual root has children: similar to GRAPH_PRE_COMMIT state when octopus merges need space, an edge row needs to be printed to connect the child with the indented visual root. A new state GRAPH_PRE_ROOT is needed to connect the child with the visual root:
* child of the visual root
\ GRAPH_PRE_ROOT
* visual root indented
- If a visual root is child-less we can skip GRAPH_PRE_ROOT state and render the indented commit directly.
* visual root indented
* unrelated commit
- If two or more visual roots are adjacent: by having a lookahead to the next commit that will be rendered, if the next commit is also a visual root and we are on a visual root, meaning two visual root adjacent in the history, the top one can omit the indent, making the one below to indent only once, if there are more adjacent visual commits, the indentation will increase for each adjacent one, cascading.
* visual root
* visual root
* visual root
* last commit
Even if the last commit is a root, because there is nothing that will be rendered below we can omit the indentation on purpose.
[1]: https://lore.kernel.org/git/[email protected]/
--- graph.c | 244 +++++++++++++++++++ t/meson.build | 1 + t/t4218-log-graph-indentation.sh | 514 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 759 insertions(+)
graph.c +244 -0
@@ -60,12 +60,23 @@ struct column {* index into column_colors. */ unsigned short color; +/* +* Marks if a commit is a non-first parent of a merge. These columns are +* already visually connected to the merge commit and do not need +* indentation. +* +* The first parent is the one that inherits the column and it can need +* indentation if turns out to be a visual root and there's still +* commits to render. +*/ + unsigned int is_merge_parent:1; };enum graph_state {GRAPH_PADDING ,GRAPH_SKIP ,GRAPH_PRE_COMMIT , +GRAPH_PRE_ROOT ,GRAPH_COMMIT ,GRAPH_POST_MERGE ,GRAPH_COLLAPSING
@@ -323,6 +334,51 @@ struct git_graph {*/ struct commit *lookahead[2 ];int lookahead_nr; + +/* +* If a commit is a visual root, we need to indent it to prevent +* unrelated commits from being vertically adjacent to it. +*/ + unsigned int is_visual_root:1; + +/* +* Indentation increases for each visual root adjacent to another visual +* root, making visual root commits indentation cascade. +*/ +unsigned int visual_root_depth; + +/* +* When a visual root is adjacent to other visual roots, the first one +* can avoid indentation and the rest cascades, increasing the indentation +* for each one. +*/ + unsigned int visual_root_cascade:1; + +/* +* Set when the current commit was already present in graph->columns +* before being processed. +*/ + unsigned int commit_in_columns:1; +}; + +struct graph_lookahead_flags { + +/* +* Set when there will be a commit after the current one that will be +* rendered. +*/ +unsigned int is_next_visible:1 ; + +/* +* Set when the next visible commit is candidate to be a visual root. +*/ +unsigned int is_next_visual_root:1 ; + +/* +* Set when the next visible commit will be rendered under the current +* commit. +*/ +unsigned int next_has_column:1 ; };static inline int graph_needs_truncation (struct git_graph *graph,int lane)
@@ -399,6 +455,8 @@ struct git_graph *graph_init(struct rev_info *opt) graph->lookahead[0 ] =NULL ; graph->lookahead[1 ] =NULL ; graph->lookahead_nr =0 ; + graph->visual_root_depth =0 ; + graph->visual_root_cascade =0 ;/* * Start the column color at the maximum value, since we'll * always increment it for the first commit we output.
@@ -581,6 +639,11 @@ static void graph_insert_into_new_columns(struct git_graph *graph, struct commit *commit, int idx) { +/* +* Get the initial merge_layout before it's modified to know if this +* is a merge. +*/ +int initial_merge_layout = graph->merge_layout;int i =graph_find_new_column_by_commit (graph, commit);int mapping_idx;
@@ -592,6 +655,7 @@ static void graph_insert_into_new_columns(struct git_graph *graph, i = graph->num_new_columns++; graph->new_columns[i].commit = commit; graph->new_columns[i].color =graph_find_commit_color (graph, commit); + graph->new_columns[i].is_merge_parent =0 ; }if (graph->num_parents >1 && idx >-1 && graph->merge_layout ==-1 ) {
@@ -630,6 +694,12 @@ static void graph_insert_into_new_columns(struct git_graph *graph, } graph->mapping[mapping_idx] = i; + +/* +* Mark non-first parents of a merge. +*/ +if (graph->num_parents >1 && initial_merge_layout >=0 && idx >-1 ) + graph->new_columns[i].is_merge_parent =1 ; }static void graph_update_columns (struct git_graph *graph)
@@ -721,10 +791,20 @@ static void graph_update_columns(struct git_graph *graph)if (graph->num_parents ==0 ) graph->width +=2 ; }else { +int j;graph_insert_into_new_columns (graph, col_commit,-1 ); +/* +* This column is not the current commit, but we need to +* propagate the flag until the commit is processed. +*/ + j =graph_find_new_column_by_commit (graph, col_commit); +if (j >=0 && graph->columns[i].is_merge_parent) + graph->new_columns[j].is_merge_parent =1 ; } } + graph->commit_in_columns = is_commit_in_columns; +/* * If graph_max_lanes is set, cap the width */
@@ -814,9 +894,113 @@ void graph_push_lookahead(struct git_graph *graph, struct commit *c) graph->lookahead[graph->lookahead_nr++] = c; } +/* +* A commit can be a visual root when: +* +* - It has no parents. +* +* - It has parents but they are all filtered out and +* commit->parents arrives NULL. +* +* - Its parents are uninteresting. +* +* - It is not a boundary commit. Boundary commits also have no visible +* parents, but they are not selected as visual roots because they cannot +* cause the ambiguity of being vertically adjacent because: +* +* 1. A boundary only appears because an included commit is its child. +* Children are always above, and the renderer draws an edge down to +* the boundary from that child. Rather than starting a column like a +* visual root would do, it inherits its child column. +* +* 2. Included commits cannot appear below a boundary. Boundaries are +* ancestors of the exclusion point; if an included commit were an +* ancestor of the boundary it would be excluded and not rendered. +* Boundaries therefore always sink to the bottom. +*/ +static int graph_is_visual_root_candidate (struct commit *c,struct git_graph *graph) +{ +struct commit_list *p; + +if (c->object.flags &BOUNDARY ) +return 0 ; +for (p = c->parents; p; p = p->next) +if (graph_is_interesting (graph, p->item)) +return 0 ; +return 1 ; +} + +static int graph_is_visual_root (struct git_graph *graph, +struct graph_lookahead_flags *flags) +{ +/* +* This must be only called for the current commit as graph contains +* the state for the current commit only. +* +* To check if a commit is a visual root, call graph_is_visual_root_candidate() +* but we won't know if it is really a visual root until we get to the +* next commit state. +* +* The current commit is an actual visual root if it is a candidate and +* the commit is not a non-first parent of a merge. +* +* * +* |\ +* | * <- it is a visual root candidate but it shouldn't be indented +* * because it is already connected by an edge. +* ^ if commit_in_columns && is_merge_parent means the commit +* | was put by a merge and is connected. +* | +* `-------- if !is_next_visible means we're on the last commit, avoid +* indentation unless the one before is a visual root, then +* we need to differentiate from the one above. +* +* If next_has_columns means that the next commit has +* already a column, so it will not be rendered below, the +* current commit has to act as the last commit and omit +* indentation. +*/ +return graph_is_visual_root_candidate (graph->commit, graph) && + !(graph->commit_in_columns && + graph->columns[graph->commit_index].is_merge_parent) && + flags->is_next_visible && + (!flags->next_has_column || graph->visual_root_depth >0 ); +} + +/* +* Peeks the next commits via the lookahead buffer and sets the lookahead flags. +*/ +static void graph_peek_next_visible (struct git_graph *graph, +struct graph_lookahead_flags *flags) +{ + flags->is_next_visible =0 ; + flags->is_next_visual_root =0 ; + flags->next_has_column =0 ; + +if (!graph->lookahead_nr) +return ; + + flags->is_next_visible =1 ; + flags->next_has_column = +graph_find_new_column_by_commit (graph, graph->lookahead[0 ]) >=0 ; + +if (!graph_is_visual_root_candidate (graph->lookahead[0 ], graph)) +return ; + +if (graph->lookahead_nr >=2 ) + flags->is_next_visual_root =1 ; +} + +static int graph_needs_pre_root_line (struct git_graph *graph) +{ +return graph->commit_in_columns && graph->is_visual_root && + graph->num_columns >0 && !graph->visual_root_cascade; +} +void graph_update (struct git_graph *graph,struct commit *commit) {struct commit_list *parent; +struct graph_lookahead_flags flags;/* * Set the new commit
@@ -847,6 +1031,23 @@ void graph_update(struct git_graph *graph, struct commit *commit)*/ graph_update_columns (graph); +graph_peek_next_visible (graph, &flags); + + graph->is_visual_root =graph_is_visual_root (graph, &flags); + +if (graph->is_visual_root) { +/* +* If next is a visual root we can omit the indent for the first +* visual root and start cascading. +*/ +if (!graph->visual_root_depth && flags.is_next_visual_root) + graph->visual_root_cascade =1 ; + graph->visual_root_depth++; + }else { + graph->visual_root_depth =0 ; + graph->visual_root_cascade =0 ; + } + graph->expansion_row =0 ;/*
@@ -864,11 +1065,16 @@ void graph_update(struct git_graph *graph, struct commit *commit)* room for it. We need to do this only if there is a branch row * (or more) to the right of this commit. * +* If it is a visual root, we need to print an extra row to +* connect the indentation. +* * If there are less than 3 parents, we can immediately print the * commit line. */ if (graph->state !=GRAPH_PADDING ) graph->state =GRAPH_SKIP ; +else if (graph_needs_pre_root_line (graph)) + graph->state =GRAPH_PRE_ROOT ;else if (graph_needs_pre_commit_line (graph)) graph->state =GRAPH_PRE_COMMIT ;else
@@ -1116,6 +1322,17 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_lineif (col_commit == graph->commit) { seen_this =1 ; +if (graph->is_visual_root) { +int depth = graph->visual_root_depth; +/* +* Each visual column is 2 characters wide. +* Omit the indentation for the first visual +* root in cascade mode. +*/ +int padding = (depth - graph->visual_root_cascade) *2 ; +graph_line_addchars (line,' ' , padding); + graph->width += padding; + }graph_output_commit_char (graph, line);if (graph_needs_truncation (graph, i)) {
@@ -1487,6 +1704,30 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_lgraph_update_state (graph,GRAPH_PADDING ); } +static void graph_output_pre_root_line (struct git_graph *graph,struct graph_line *line) +{ +/* +* This function adds a row before a visual root, to connect the +* branch to the indented commit. It must only be called on a +* visual root. +*/ +if (!graph->is_visual_root) +BUG ("commit must be a visual root to call pre_root_line" ); + +for (int i =0 ; i < graph->num_columns; i++) { +struct column *col = &graph->columns[i]; +if (col->commit == graph->commit) { +graph_line_addch (line,' ' ); +graph_line_write_column (line, col,'\\' ); + }else { +graph_line_write_column (line, col,'|' ); + } +graph_line_addch (line,' ' ); + } + +graph_update_state (graph,GRAPH_COMMIT ); +} +int graph_next_line (struct git_graph *graph,struct strbuf *sb) {int shown_commit_line =0 ;
@@ -1512,6 +1753,9 @@ int graph_next_line(struct git_graph *graph, struct strbuf *sb)case GRAPH_PRE_COMMIT :graph_output_pre_commit_line (graph, &line);break ; +case GRAPH_PRE_ROOT : +graph_output_pre_root_line (graph, &line); +break ;case GRAPH_COMMIT :graph_output_commit_line (graph, &line); shown_commit_line =1 ;
t/meson.build +1 -0
@@ -577,6 +577,7 @@ integration_tests = [ 't4215-log-skewed-merges.sh', 't4216-log-bloom.sh', 't4217-log-limit.sh', + 't4218-log-graph-indentation.sh', 't4219-log-follow-merge.sh', 't4252-am-options.sh', 't4253-am-keep-cr-dos.sh',
t/t4218-log-graph-indentation.sh new file +514 -0
514 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v11 5/7 graph: wrap cascading commits after 4 columns
In reply to Pablo SabaterCurrently the visual root commits in a graph cascade indefinitely until a commit which is not a visual root or the last commit appears. On filters like --author where one author might contribute mostly on single patches this can become a visual issue.
Make the cascading wrap after 4 columns.
There are two possible cases of the wrap:
1. No ambiguity:
* A
* B
* C
* D
* E
* F
2. Ambiguous conflict:
If F happens to not be a visual root and E gets wrapped back to the initial column then E and F would be vertically adjacent. The solution is to forcefully indent E one level:
* A
* B
* C
* D
* E
* F
* F
The magic number 4 comes as the minimum number of columns to wrap where the output shows clearly the commits are unrelated and doesn't cause too much "pyramid" effects
--- graph.c | 22 +++++++++++++++++++++- t/t4218-log-graph-indentation.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-)
graph.c +21 -1
@@ -1042,6 +1042,23 @@ void graph_update(struct git_graph *graph, struct commit *commit)*/ if (!graph->visual_root_depth && flags.is_next_visual_root) graph->visual_root_cascade =1 ; + +/* +* We wrap the cascading at a max of four columns at most, after +* that we wrap it back to the initial column. +* +* This could cause ambiguity in case of the next commit not +* being a visual root and be at the initial column after the +* first wrap. +* +* In case of being a non-visual-root the next, stop the +* cascading to get the commit indented. +*/ +if (!flags.is_next_visual_root && + graph->visual_root_depth && + !(graph->visual_root_depth %4 )) + graph->visual_root_cascade =0 ; + graph->visual_root_depth++; }else { graph->visual_root_depth =0 ;
@@ -1328,8 +1345,11 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line* Each visual column is 2 characters wide. * Omit the indentation for the first visual * root in cascade mode. +* +* Have a max of 4 columns when cascading, after +* that wrap it and repeat. */ -int padding = (depth - graph->visual_root_cascade) *2 ; +int padding = ((depth - graph->visual_root_cascade) %4 ) *2 ;graph_line_addchars (line,' ' , padding); graph->width += padding; }
t/t4218-log-graph-indentation.sh +29 -0
@@ -511,4 +511,33 @@ test_expect_success '--grep skipped parent makes a visual root' ' EOF ' +# The cascading wraps after 4 columns and when wraping (column % 4 == 0) if the +# next is a non visual-root, force indentation to avoid an ambiguous graph +# (commit 59_A is forcefully indented) +test_expect_success 'visual root cascading gets wrapped after 4 columns' ' + create_orphan _58 && test_commit 58_A && test_commit 58_B && + create_orphan _59 && test_commit 59_A && + create_orphan _60 && test_commit 60_A && + create_orphan _61 && test_commit 61_A && + create_orphan _62 && test_commit 62_A && + create_orphan _63 && test_commit 63_A && + create_orphan _64 && test_commit 64_A && + create_orphan _65 && test_commit 65_A && + create_orphan _66 && test_commit 66_A && + create_orphan _67 && test_commit 67_A && + lib_test_check_graph _58 _59 _60 _61 _62 _63 _64 _65 _66 _67 <<-\EOF + * 67_A + * 66_A + * 65_A + * 64_A + * 63_A + * 62_A + * 61_A + * 60_A + * 59_A + * 58_B + * 58_A + EOF +' + test_done
Signature · 1 line
2.54.0
PATCH v11 6/7 graph: move config reading into graph_read_config()
In reply to Pablo SabaterMove the repo_config_get_string() call out of graph_init() and into graph_read_config(). This simplifies graph_init() and provides a function for future graph-related config opt.
This commit is a preparatory commit for a subsequent one.
--- graph.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
graph.c +9 -4
@@ -417,13 +417,11 @@ void graph_setup_line_prefix(struct diff_options *diffopt) diffopt->output_prefix = diff_output_prefix_callback; } -struct git_graph *graph_init (struct rev_info *opt) +static void graph_read_config (struct rev_info *revs) { -struct git_graph *graph =xmalloc (sizeof (struct git_graph )); -if (!column_colors) {char *string; -if (repo_config_get_string (opt->repo,"log.graphcolors" , &string)) { +if (repo_config_get_string (revs->repo,"log.graphcolors" , &string)) {/* not configured -- use default */ graph_set_column_colors (column_colors_ansi, column_colors_ansi_max);
@@ -437,6 +435,13 @@ struct git_graph *graph_init(struct rev_info *opt) custom_colors.nr - 1); } } +} + +struct git_graph *graph_init (struct rev_info *opt) +{ +struct git_graph *graph =xmalloc (sizeof (struct git_graph )); + +graph_read_config (opt); graph->commit =NULL ; graph->revs = opt;
Signature · 1 line
2.54.0
PATCH v11 7/7 graph: add --[no-]graph-indent and log.graphIndent
In reply to Pablo SabaterSome users may prefer to not have graph indentation.
Add "log.graphIndent" config variable to graph_read_config() to read the default preference. By default is graph indentation is true.
Add --graph-indent and --no-graph-indent options to overwrite the default preference.
--- Documentation/config/log.adoc | 4 +++ Documentation/rev-list-options.adoc | 8 ++++++ graph.c | 10 +++++-- revision.c | 9 +++++++ revision.h | 2 ++ t/t4218-log-graph-indentation.sh | 52 +++++++++++++++++++++++++++++++++++++ 6 files changed, 83 insertions(+), 2 deletions(-)
Documentation/config/log.adoc +4 -0
@@ -59,6 +59,10 @@ This is the same as the `--decorate` option of the `git log`. A list of colors, separated by commas, that can be used to draw history lines in `git log --graph`. +`log.graphIndent`:: + If `true`, indent visual roots when rendering the graphs with `--graph`. + Set true by default. It can be overriden with `--[no-]graph-indent`. + `log.showRoot`:: If true, the initial commit will be shown as a big creation event. This is equivalent to a diff against an empty tree.
Documentation/rev-list-options.adoc +8 -0
@@ -1269,6 +1269,14 @@ This implies the `--topo-order` option by default, but the By default it is set to 0 (no limit), zero and negative values are ignored and treated as no limit. +`--no-graph-indent`:: +`--graph-indent`:: + When used with `--graph`, indent visual roots (commits with no parents + or whose parents are not shown) to differentiate them from commits that + are vertically adjacent but unrelated. Enabled by default. Use + `--no-graph-indent` to disable or set `graph.indent` to set a deafault + preference. + ifdef::git-rev-list[] `--count`:: Print a number stating how many commits would have been
graph.c +8 -2
@@ -419,6 +419,8 @@ void graph_setup_line_prefix(struct diff_options *diffopt)static void graph_read_config (struct rev_info *revs) { +int val; +if (!column_colors) {char *string;if (repo_config_get_string (revs->repo,"log.graphcolors" , &string)) {
@@ -435,6 +437,9 @@ static void graph_read_config(struct rev_info *revs) custom_colors.nr - 1); } } + +if (!repo_config_get_bool (revs->repo,"log.graphIndent" , &val)) + revs->no_graph_indent = !val; }struct git_graph *graph_init (struct rev_info *opt)
@@ -999,7 +1004,8 @@ static void graph_peek_next_visible(struct git_graph *graph,static int graph_needs_pre_root_line (struct git_graph *graph) {return graph->commit_in_columns && graph->is_visual_root && - graph->num_columns >0 && !graph->visual_root_cascade; + graph->num_columns >0 && !graph->visual_root_cascade && + !graph->revs->no_graph_indent; }void graph_update (struct git_graph *graph,struct commit *commit)
@@ -1344,7 +1350,7 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_lineif (col_commit == graph->commit) { seen_this =1 ; -if (graph->is_visual_root) { +if (graph->is_visual_root && !graph->revs->no_graph_indent) {int depth = graph->visual_root_depth;/* * Each visual column is 2 characters wide.
revision.c +9 -0
@@ -2627,6 +2627,12 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->graph =NULL ; }else if (skip_prefix (arg,"--graph-lane-limit=" , &optarg)) { revs->graph_max_lanes =parse_count (optarg); + }else if (!strcmp (arg,"--graph-indent" )) { + revs->no_graph_indent =0 ; + revs->graph_indent_set =1 ; + }else if (!strcmp (arg,"--no-graph-indent" )) { + revs->no_graph_indent =1 ; + revs->graph_indent_set =1 ; }else if (!strcmp (arg,"--encode-email-headers" )) { revs->encode_email_headers =1 ; }else if (!strcmp (arg,"--no-encode-email-headers" )) {
@@ -3201,6 +3207,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct sif (revs->graph_max_lanes >0 && !revs->graph)die (_ ("the option '%s' requires '%s'" ),"--graph-lane-limit" ,"--graph" ); +if (revs->graph_indent_set >0 && !revs->graph) +die (_ ("the option '%s' requires '%s'" ),"--[no-]graph-indent" ,"--graph" ); +if (!revs->reflog_info && revs->grep_filter.use_reflog_filter)die (_ ("the option '%s' requires '%s'" ),"--grep-reflog" ,"--walk-reflogs" );
revision.h +2 -0
@@ -314,6 +314,8 @@ struct rev_info {/* Display history graph */ struct git_graph *graph;int graph_max_lanes; + unsigned int no_graph_indent:1; + unsigned int graph_indent_set:1;/* special limits */ int skip_count;
t/t4218-log-graph-indentation.sh +52 -0
56 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v11 7/7] graph: add --[no-]graph-indent and log.graphIndent
Quoted 39 lines · Pablo Sabater
Some users may prefer to not have graph indentation.
Add "log.graphIndent" config variable to
graph_read_config()to read the default preference. By default is graph indentation is true.Add --graph-indent and --no-graph-indent options to overwrite the default preference.
Signed-off-by Pablo Sabater <[email protected]>--- Documentation/config/log.adoc | 4 +++ Documentation/rev-list-options.adoc | 8 ++++++ graph.c | 10 +++++-- revision.c | 9 +++++++ revision.h | 2 ++ t/t4218-log-graph-indentation.sh | 52 +++++++++++++++++++++++++++++++++++++ 6 files changed, 83 insertions(+), 2 deletions(-)Documentation/config/log.adoc +4
-0@@ -59,6 +59,10 @@ This is the same as the `--decorate` option of the `git log`. A list of colors, separated by commas, that can be used to draw history lines in `git log --graph`. +`log.graphIndent`:: + If `true`, indent visual roots when rendering the graphs with `--graph`. + Set true by default. It can be overriden with `--[no-]graph-indent`. + `log.showRoot`:: If true, the initial commit will be shown as a big creation event. This is equivalent to a diff against an empty tree.Documentation/rev-list-options.adoc +0
-0
Documentation/rev-list-options.adoc This implies the `--topo-order` option by default, but the · line 1277
Quoted 9 lines
Documentation/rev-list-options.adoc +6
-0@@ -1269,6 +1269,14 @@ This implies the `--topo-order` option by default, but the By default it is set to 0 (no limit), zero and negative values are ignored and treated as no limit. +`--no-graph-indent`:: +`--graph-indent`:: + When used with `--graph`, indent visual roots (commits with no parents + or whose parents are not shown) to differentiate them from commits that + are vertically adjacent but unrelated. Enabled by default. Use + `--no-graph-indent` to disable or set `graph.indent` to set a deafault
s/deafault/default
Also, I think you meant log.graphIndent instead of graph.indent here.
[snip]
Quoted 41 lines
Documentation/rev-list-options.adoc +41
-0+test_expect_success '--no-graph-indent disables indentation' ' + lib_test_check_graph --no-graph-indent _58 _59 _60 _61 _62 _63 _64 _65 _66 _67 <<-\EOF + * 67_A + * 66_A + * 65_A + * 64_A + * 63_A + * 62_A + * 61_A + * 60_A + * 59_A + * 58_B + * 58_A + EOF +' + +test_expect_success 'log.graphIndent config disables indentation' ' + test_config log.graphIndent false && + lib_test_check_graph _58 _59 _60 _61 _62 _63 _64 _65 _66 _67 <<-\EOF + * 67_A + * 66_A + * 65_A + * 64_A + * 63_A + * 62_A + * 61_A + * 60_A + * 59_A + * 58_B + * 58_A + EOF +' + +test_expect_success '--graph-indent forces indentation when graph.indent is unset' ' + test_config log.graphIndent false && + lib_test_check_graph --graph-indent _58 _59 _60 _61 _62 _63 _64 _65 _66 _67 <<-\EOF + * 67_A + * 66_A + * 65_A + * 64_A + * 63_A
Documentation/rev-list-options.adoc This implies the `--topo-order` option by default, but the
Quoted 10 lines
Documentation/rev-list-options.adoc +10
-0+ * 62_A + * 61_A + * 60_A + * 59_A + * 58_B + * 58_A + EOF +' + +# graph.indent true and no --option is the default state.
Same thing here.
Re: [PATCH v11 7/7] graph: add --[no-]graph-indent and log.graphIndent
Quoted 52 lines · Chandra Pratap
Quoted 39 lines · Pablo Sabater
Some users may prefer to not have graph indentation.
Add "log.graphIndent" config variable to
graph_read_config()to read the default preference. By default is graph indentation is true.Add --graph-indent and --no-graph-indent options to overwrite the default preference.
Signed-off-by Pablo Sabater <[email protected]>--- Documentation/config/log.adoc | 4 +++ Documentation/rev-list-options.adoc | 8 ++++++ graph.c | 10 +++++-- revision.c | 9 +++++++ revision.h | 2 ++ t/t4218-log-graph-indentation.sh | 52 +++++++++++++++++++++++++++++++++++++ 6 files changed, 83 insertions(+), 2 deletions(-)Documentation/config/log.adoc +4
-0@@ -59,6 +59,10 @@ This is the same as the `--decorate` option of the `git log`. A list of colors, separated by commas, that can be used to draw history lines in `git log --graph`. +`log.graphIndent`:: + If `true`, indent visual roots when rendering the graphs with `--graph`. + Set true by default. It can be overriden with `--[no-]graph-indent`. + `log.showRoot`:: If true, the initial commit will be shown as a big creation event. This is equivalent to a diff against an empty tree.Documentation/rev-list-options.adoc +0
-0Documentation/rev-list-options.adoc This implies the `--topo-order` option by default, but the · line 1277
Quoted 9 lines
Documentation/rev-list-options.adoc +6
-0@@ -1269,6 +1269,14 @@ This implies the `--topo-order` option by default, but the By default it is set to 0 (no limit), zero and negative values are ignored and treated as no limit. +`--no-graph-indent`:: +`--graph-indent`:: + When used with `--graph`, indent visual roots (commits with no parents + or whose parents are not shown) to differentiate them from commits that + are vertically adjacent but unrelated. Enabled by default. Use + `--no-graph-indent` to disable or set `graph.indent` to set a deafaults/deafault/default
Quoted 1 line
Also, I think you meant log.graphIndent instead of graph.indent here.
Yes, thanks, I'll fix it.
Quoted 47 lines
[snip]
Quoted 45 lines
Documentation/rev-list-options.adoc +45
-0+test_expect_success '--no-graph-indent disables indentation' ' + lib_test_check_graph --no-graph-indent _58 _59 _60 _61 _62 _63 _64 _65 _66 _67 <<-\EOF + * 67_A + * 66_A + * 65_A + * 64_A + * 63_A + * 62_A + * 61_A + * 60_A + * 59_A + * 58_B + * 58_A + EOF +' + +test_expect_success 'log.graphIndent config disables indentation' ' + test_config log.graphIndent false && + lib_test_check_graph _58 _59 _60 _61 _62 _63 _64 _65 _66 _67 <<-\EOF + * 67_A + * 66_A + * 65_A + * 64_A + * 63_A + * 62_A + * 61_A + * 60_A + * 59_A + * 58_B + * 58_A + EOF +' + +test_expect_success '--graph-indent forces indentation when graph.indent is unset' ' + test_config log.graphIndent false && + lib_test_check_graph --graph-indent _58 _59 _60 _61 _62 _63 _64 _65 _66 _67 <<-\EOF + * 67_A + * 66_A + * 65_A + * 64_A + * 63_A + * 62_A + * 61_A + * 60_A + * 59_A
Quoted 8 lines
Documentation/rev-list-options.adoc
Quoted 6 lines
Documentation/rev-list-options.adoc +6
-0+ * 58_B + * 58_A + EOF +' + +# graph.indent true and no --option is the default state.Same thing here.
Will fix it.
Thanks for the review,
Pablo
Re: [PATCH v11 0/7] graph: indent visual roots in graph
In reply to Pablo SabaterQuoted 3 lines · Pablo Sabater
V9 DIFF:
- Changed boolean variables to be bit fields.
v11???
Quoted 10 lines
7:
737331b68d! 7:c1fa81022egraph: add --[no-]graph-indent and log.graphIndent@@ revision.h: struct rev_info { /* Display history graph */ struct git_graph *graph; int graph_max_lanes; -+ int no_graph_indent; -+ unsigned int graph_indent_set; ++ unsigned int no_graph_indent:1; ++ unsigned int graph_indent_set:1;
OK. References to these occur primarily in a boolean context, and all assignments to them are either 0 or 1.
graph.c:442: revs->no_graph_indent = !val;
graph.c:1008: !graph->revs->no_graph_indent;
graph.c:1353: if (graph->is_visual_root && !graph->revs->no_graph_indent) {
revision.c:2630: revs->no_graph_indent = 0;
revision.c:2631: revs->graph_indent_set = 1;
revision.c:2633: revs->no_graph_indent = 1;
revision.c:2634: revs->graph_indent_set = 1;
revision.c:3209: if (revs->graph_indent_set > 0 && !revs->graph)
You may want to rewrite the last conditional check to:
if (revs->graph_indent_set && !revs->graph)
This avoids confusing readers into thinking the member can be set to 2 or greater.
Thanks.
Re: [PATCH v11 0/7] graph: indent visual roots in graph
Quoted 8 lines · Junio C Hamano
Quoted 3 lines · Pablo Sabater
V9 DIFF:
- Changed boolean variables to be bit fields.
v11???
My bad, I updated it manually and I forgot to.
Quoted 23 lines
Quoted 10 lines
7:
737331b68d! 7:c1fa81022egraph: add --[no-]graph-indent and log.graphIndent@@ revision.h: struct rev_info { /* Display history graph */ struct git_graph *graph; int graph_max_lanes; -+ int no_graph_indent; -+ unsigned int graph_indent_set; ++ unsigned int no_graph_indent:1; ++ unsigned int graph_indent_set:1;OK. References to these occur primarily in a boolean context, and all assignments to them are either 0 or 1.
graph.c:442:
revs->no_graph_indent= !val;
graph.c:1008: !graph->revs->no_graph_indent;
graph.c:1353: if (graph->is_visual_root&& !graph->revs->no_graph_indent) {
revision.c:2630:revs->no_graph_indent= 0;
revision.c:2631:revs->graph_indent_set= 1;
revision.c:2633:revs->no_graph_indent= 1;
revision.c:2634:revs->graph_indent_set= 1;
revision.c:3209: if (revs->graph_indent_set> 0 && !revs->graph)
Quoted 6 lines
You may want to rewrite the last conditional check to:
if (revs->graph_indent_set && !revs->graph)This avoids confusing readers into thinking the member can be set to 2 or greater.
I'll do that. Thanks.
Quoted 2 lines
Thanks.
Regards,
Pablo.
v12 cover graph: indent visual roots in graph
In reply to Pablo SabaterWhen rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This series adds indentation to the visual root commits, so they cannot be vertically adjacent anymore making it easier to identify them.
Before indentation:
* A
* B1
* B2
* C1
* C2
After indentation:
* A
* B1
\
* B2
* C1
* C2
Indents the visual root commits that have still commits to show after them, and if they have children it connects them with an edge at a new row.
If there are multiple visual roots adjacent in history, the indentation starts with the second one, avoiding redundant indentation of the first one and cascades after the second.
* A
* B
* C
* D
* E
* F
* G
* H
* I
* J1
* J2
The indentation wraps after cascading columns and when wrapping back to the initial column if the next commit is a non-visual-root commit, force the indentation one extra level.
Series explanation:
1. Cleanup to bring a common function from t4215 and t6016 that will be used in t4218.
2. Logic extraction of the chose of from where the commit source comes from.
3. Add a buffer for lookahead purposes.
4. Principal commit. Implement the logic to get the visual roots indented.
5. Make visual root cascading wrap after 4 columns
6. Add --[no-]graph-indent and log.graphIndent options.
GitHub CI: https://github.com/pabloosabaterr/git/actions/runs/29331144667
[1]: https://lore.kernel.org/git/[email protected]/
V11 DIFF:
- Changed the check that required graph, to not confuse because it is a boolean value.
- Typos
---
Pablo Sabater (7):
lib-log-graph: move check_graph function
revision: add next_commit_to_show()
graph: add a 2 commit buffer for lookahead
graph: indent visual root in graph
graph: wrap cascading commits after 4 columns
graph: move config reading into graph_read_config()
graph: add --[no-]graph-indent and log.graphIndent
Documentation/config/log.adoc | 4 + Documentation/rev-list-options.adoc | 8 + graph.c | 332 +++++++++++++++- graph.h | 17 + revision.c | 57 ++- revision.h | 2 + t/lib-log-graph.sh | 5 + t/meson.build | 1 + t/t4215-log-skewed-merges.sh | 33 +- t/t4218-log-graph-indentation.sh | 596 +++++++++++++++++++++++++++++ t/t6016-rev-list-graph-simplify-history.sh | 25 +- 11 files changed, 1032 insertions(+), 48 deletions(-)
Range-diff versus v11:
1: dd0bb0d215 = 1: d754392142 lib-log-graph: move check_graph function
2: 07e239533d = 2: c93c2c0771 revision: add next_commit_to_show()
3: 4d71f674a1 = 3: 70fe612ae1 graph: add a 2 commit buffer for lookahead
4: 48ad2562f0 = 4: e1ac06c4ea graph: indent visual root in graph
5: 45be69d11b = 5: ce52b41527 graph: wrap cascading commits after 4 columns
6: 8ce53ae21b = 6: 9b7bb2cebc graph: move config reading into graph_read_config()
7: c1fa81022e ! 7: 13e830725f graph: add --[no-]graph-indent and log.graphIndent
@@ Documentation/rev-list-options.adoc: This implies the `--topo-order` option by d
+ When used with `--graph`, indent visual roots (commits with no parents
+ or whose parents are not shown) to differentiate them from commits that
+ are vertically adjacent but unrelated. Enabled by default. Use
-+ `--no-graph-indent` to disable or set `graph.indent` to set a deafault
-+ preference.
++ `--no-graph-indent` to disable or set `log.graphIndent` to set a
++ default preference.
+
ifdef::git-rev-list[]
`--count`::
@@ revision.c: int setup_revisions(int argc, const char **argv, struct rev_info *re
if (revs->graph_max_lanes > 0 && !revs->graph)
die(_("the option '%s' requires '%s'"), "--graph-lane-limit", "--graph");
-+ if (revs->graph_indent_set > 0 && !revs->graph)
++ if (revs->graph_indent_set && !revs->graph)
+ die(_("the option '%s' requires '%s'"), "--[no-]graph-indent", "--graph");
+
if (!revs->reflog_info && revs->grep_filter.use_reflog_filter)
@@ t/t4218-log-graph-indentation.sh: test_expect_success 'visual root cascading get
+ EOF
+'
+
-+# graph.indent true and no --option is the default state.
++# log.graphIndent unset and no --option (which activates graph indentation) is
++# the default state.
+
test_done---
base-commit: f60db8d575adb79761d363e026fb49bddf330c73
PATCH v12 1/7 lib-log-graph: move check_graph function
check_graph is a function shared in the test files t4215 and t6016 used to format the output graph, but instead of being in a file called by both test, the function code is repeated in each file.
Move check_graph to lib-log-graph.sh file which both tests already import graph functions from, renaming it to lib_test_check_graph.
This function is needed for the following commit which includes graph tests in a new file and requires check_graph.
--- t/lib-log-graph.sh | 5 +++++ t/t4215-log-skewed-merges.sh | 33 +++++++++++++----------------- t/t6016-rev-list-graph-simplify-history.sh | 25 +++++++++------------- 3 files changed, 29 insertions(+), 34 deletions(-)
t/lib-log-graph.sh +5 -0
@@ -26,3 +26,8 @@ lib_test_cmp_colored_graph () { test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors && test_cmp expect.colors output.colors } + +lib_test_check_graph () { + cat >expect && + lib_test_cmp_graph --format=%s "$@" +}
t/t4215-log-skewed-merges.sh +14 -19
@@ -5,11 +5,6 @@ test_description='git log --graph of skewed merges' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh -check_graph () { - cat >expect && - lib_test_cmp_graph --format=%s "$@" -} - test_expect_success 'log --graph with merge fusing with its left and right neighbors' ' git checkout --orphan _p && test_commit A &&
@@ -21,7 +16,7 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh git checkout _p && git merge --no-ff _r -m G && git checkout @^^ && git merge --no-ff _p -m H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * H |\ | * G
@@ -49,7 +44,7 @@ test_expect_success 'log --graph with left-skewed merge' ' git checkout 0_p && git merge --no-ff 0_s -m 0_G && git checkout @^ && git merge --no-ff 0_q 0_r 0_t 0_p -m 0_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF *-----. 0_H |\ \ \ \ | | | | * 0_G
@@ -83,7 +78,7 @@ test_expect_success 'log --graph with nested left-skewed merge' ' git checkout 1_p && git merge --no-ff 1_r -m 1_G && git checkout @^^ && git merge --no-ff 1_p -m 1_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 1_H |\ | * 1_G
@@ -115,7 +110,7 @@ test_expect_success 'log --graph with nested left-skewed merge following normal git checkout -b 2_s @^^ && git merge --no-ff 2_q -m 2_J && git checkout 2_p && git merge --no-ff 2_s -m 2_K && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 2_K |\ | * 2_J
@@ -151,7 +146,7 @@ test_expect_success 'log --graph with nested right-skewed merge following left-s git checkout 3_p && git merge --no-ff 3_r -m 3_H && git checkout @^^ && git merge --no-ff 3_p -m 3_J && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 3_J |\ | * 3_H
@@ -182,7 +177,7 @@ test_expect_success 'log --graph with right-skewed merge following a left-skewed git merge --no-ff 4_p -m 4_G && git checkout @^^ && git merge --no-ff 4_s -m 4_H && - check_graph --date-order <<-\EOF + lib_test_check_graph --date-order <<-\EOF * 4_H |\ | * 4_G
@@ -218,7 +213,7 @@ test_expect_success 'log --graph with octopus merge with column joining its penu git checkout 5_r && git merge --no-ff 5_s -m 5_H && - check_graph <<-\EOF + lib_test_check_graph <<-\EOF * 5_H |\ | *-. 5_G
@@ -257,7 +252,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout 6_1 && git merge --no-ff 6_2 -m 6_I && - check_graph 6_1 6_3 6_5 <<-\EOF + lib_test_check_graph 6_1 6_3 6_5 <<-\EOF * 6_I |\ | | * 6_H
@@ -334,7 +329,7 @@ test_expect_success 'log --graph with multiple tips' ' git checkout -b M_7 7_1 && git merge --no-ff 7_2 7_3 -m 7_M4 && - check_graph M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -371,7 +366,7 @@ test_expect_success 'log --graph with multiple tips' ' ' test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' ' - check_graph --graph-lane-limit=2 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=2 M_7 <<-\EOF *-. 7_M4 |\ \ | | * 7_G
@@ -388,7 +383,7 @@ test_expect_success 'log --graph --graph-lane-limit=2 limited to two lanes' ' ' test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge' ' - check_graph --graph-lane-limit=1 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=1 M_7 <<-\EOF *-~ 7_M4 |\~ | ~ 7_G
@@ -405,7 +400,7 @@ test_expect_success 'log --graph --graph-lane-limit=1 truncate mid octopus merge ' test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' ' - check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=3 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -441,7 +436,7 @@ test_expect_success 'log --graph --graph-lane-limit=3 limited to three lanes' ' ' test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows first of 3 parent merge' ' - check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=6 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
@@ -478,7 +473,7 @@ test_expect_success 'log --graph --graph-lane-limit=6 check if it only shows fir ' test_expect_success 'log --graph --graph-lane-limit=7 check if it shows all 3 parent merge' ' - check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF + lib_test_check_graph --graph-lane-limit=7 M_1 M_3 M_5 M_7 <<-\EOF * 7_M1 |\ | | * 7_M2
t/t6016-rev-list-graph-simplify-history.sh +10 -15
@@ -13,11 +13,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh . "$TEST_DIRECTORY"/lib-log-graph.sh -check_graph () { - cat >expect && - lib_test_cmp_graph --format=%s "$@" -} - test_expect_success 'set up rev-list --graph test' ' # 3 commits on branch A test_commit A1 foo.txt &&
@@ -54,7 +49,7 @@ test_expect_success 'set up rev-list --graph test' ' ' test_expect_success '--graph --all' ' - check_graph --all <<-\EOF + lib_test_check_graph --all <<-\EOF * A7 * A6 |\
@@ -82,7 +77,7 @@ test_expect_success '--graph --all' ' # that undecorated merges are interesting, even with --simplify-by-decoration test_expect_success '--graph --simplify-by-decoration' ' git tag -d A4 && - check_graph --all --simplify-by-decoration <<-\EOF + lib_test_check_graph --all --simplify-by-decoration <<-\EOF * A7 * A6 |\
@@ -114,7 +109,7 @@ test_expect_success 'setup: get rid of decorations on B' ' # Graph with branch B simplified away test_expect_success '--graph --simplify-by-decoration prune branch B' ' - check_graph --simplify-by-decoration --all <<-\EOF + lib_test_check_graph --simplify-by-decoration --all <<-\EOF * A7 * A6 |\
@@ -133,7 +128,7 @@ test_expect_success '--graph --simplify-by-decoration prune branch B' ' ' test_expect_success '--graph --full-history -- bar.txt' ' - check_graph --full-history --all -- bar.txt <<-\EOF + lib_test_check_graph --full-history --all -- bar.txt <<-\EOF * A7 * A6 |\
@@ -148,7 +143,7 @@ test_expect_success '--graph --full-history -- bar.txt' ' ' test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' - check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF + lib_test_check_graph --full-history --simplify-merges --all -- bar.txt <<-\EOF * A7 * A6 |\
@@ -161,7 +156,7 @@ test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' ' test_expect_success '--graph -- bar.txt' ' - check_graph --all -- bar.txt <<-\EOF + lib_test_check_graph --all -- bar.txt <<-\EOF * A7 * A5 * A3
@@ -172,7 +167,7 @@ test_expect_success '--graph -- bar.txt' ' ' test_expect_success '--graph --sparse -- bar.txt' ' - check_graph --sparse --all -- bar.txt <<-\EOF + lib_test_check_graph --sparse --all -- bar.txt <<-\EOF * A7 * A6 * A5
@@ -189,7 +184,7 @@ test_expect_success '--graph --sparse -- bar.txt' ' ' test_expect_success '--graph ^C4' ' - check_graph --all ^C4 <<-\EOF + lib_test_check_graph --all ^C4 <<-\EOF * A7 * A6 * A5
@@ -202,7 +197,7 @@ test_expect_success '--graph ^C4' ' ' test_expect_success '--graph ^C3' ' - check_graph --all ^C3 <<-\EOF + lib_test_check_graph --all ^C3 <<-\EOF * A7 * A6 |\
@@ -220,7 +215,7 @@ test_expect_success '--graph ^C3' ' # that important, but this test depends on it. If the ordering ever changes # in the code, we'll need to update this test. test_expect_success '--graph --boundary ^C3' ' - check_graph --boundary --all ^C3 <<-\EOF + lib_test_check_graph --boundary --all ^C3 <<-\EOF * A7 * A6 |\
Signature · 1 line
2.54.0
PATCH v12 2/7 revision: add next_commit_to_show()
In reply to Pablo Sabaterget_revision() gets its commits from two sources depending on the mode:
1. Normally it gets the commits from get_revision_internal().
2. --max-count-oldest which was introduced at bb4ce23284 (revision.c:
implement --max-count-oldest, 2026-05-19) gets the commits by popping from a saved list at revs->commits marking SHOWN and CHILD_SHOWN on each popped commit.
Extract the choice logic into a helper, next_commit_to_show(), which returns the next commit regardless of the source it comes from.
This has no change in behavior. The helper is needed in a subsequent commit that pre-fetches two commits into a buffer for lookahead purposes and needs to pre-fetch from the same source.
The --reverse branch keeps its own pop loop. Using the helper for --reverse would additionally set SHOWN and CHILD_SHOWN which is not desired and a behavior change.
--- revision.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-)
revision.c +24 -12
@@ -4658,12 +4658,34 @@ static void retrieve_oldest_commits(struct rev_info *revs,commit_list_insert (c, queue); } +/* +* Returns the next commit that will be shown, regardless of whether it comes +* directly from the revision walk or from the list saved by the staged output +* of --max-count-oldest. +*/ +static struct commit *next_commit_to_show (struct rev_info *revs) +{ +struct commit *c; +struct commit_list *p; + +if (!revs->max_count_stage) +return get_revision_internal (revs); + + c =pop_commit (&revs->commits); +if (c) { + c->object.flags |=SHOWN ; +if (!(c->object.flags &BOUNDARY )) +for (p = c->parents; p; p = p->next) + p->item->object.flags |=CHILD_SHOWN ; + } +return c; +} +struct commit *get_revision (struct rev_info *revs) {struct commit *c;struct commit_list *reversed;struct commit_list *queue =NULL ; -struct commit_list *p;if (revs->max_count_type ==1 && !revs->max_count_stage) {retrieve_oldest_commits (revs, &queue);
@@ -4693,17 +4715,7 @@ struct commit *get_revision(struct rev_info *revs)return c; } -if (revs->max_count_stage) { - c =pop_commit (&revs->commits); -if (c) { - c->object.flags |=SHOWN ; -if (!(c->object.flags &BOUNDARY )) -for (p = c->parents; p; p = p->next) - p->item->object.flags |=CHILD_SHOWN ; - } - }else { - c =get_revision_internal (revs); - } + c =next_commit_to_show (revs);if (c && revs->graph)graph_update (revs->graph, c);
Signature · 1 line
2.54.0
PATCH v12 3/7 graph: add a 2 commit buffer for lookahead
In reply to Pablo SabaterIn a subsequent commit the graph renderer needs to know if the next commit is a visual root or if it is the last commit to be shown. This requires peeking 2 commits ahead.
Commits are pre-fetched in get_revision() through next_commit_to_show() where they are also marked as SHOWN, regardless the source they come from.
Update graph_is_interesting() so it considers commits inside the lookahead buffer as interesting as well.
--- graph.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ graph.h | 17 +++++++++++++++++ revision.c | 18 ++++++++++++++++-- 3 files changed, 84 insertions(+), 2 deletions(-)
graph.c +51 -0
@@ -315,6 +315,14 @@ struct git_graph {* diff_output_prefix_callback(). */ struct strbuf prefix_buf; + +/* +* Lookahead buffer: up to 2 pre-fetched commits that will be shown. +* Populated by get_revision() so graph_peek_next_visible() can use +* actual walk results instead of peeking at rev_info internals. +*/ +struct commit *lookahead[2 ]; +int lookahead_nr; };static inline int graph_needs_truncation (struct git_graph *graph,int lane)
@@ -388,6 +396,9 @@ struct git_graph *graph_init(struct rev_info *opt) graph->num_columns =0 ; graph->num_new_columns =0 ; graph->mapping_size =0 ; + graph->lookahead[0 ] =NULL ; + graph->lookahead[1 ] =NULL ; + graph->lookahead_nr =0 ;/* * Start the column color at the maximum value, since we'll * always increment it for the first commit we output.
@@ -456,6 +467,15 @@ static void graph_ensure_capacity(struct git_graph *graph, int num_columns)*/ static int graph_is_interesting (struct git_graph *graph,struct commit *commit) { +/* +* Commits in the lookahead buffer have been pre-fetched by +* get_revision() and will be shown in the future. They already have +* the SHOWN flag set when they were pre-fetched but the graph still +* needs to treat them as interesting parents. +*/ +for (int i =0 ; i < graph->lookahead_nr; i++) +if (graph->lookahead[i] == commit) +return 1 ;/* * If revs->boundary is set, commits whose children have * been shown are always interesting, even if they have the
@@ -763,6 +783,37 @@ static int graph_needs_pre_commit_line(struct git_graph *graph) graph->expansion_row <graph_num_expansion_rows (graph); } +struct commit *graph_pop_lookahead (struct git_graph *graph) +{ +struct commit *c; + +if (!graph->lookahead_nr) +return NULL ; + + c = graph->lookahead[0 ]; +if (!c) +BUG ("lookahead buffer has %d entries but the first one is NULL" , + graph->lookahead_nr); + + graph->lookahead[0 ] = graph->lookahead[1 ]; + graph->lookahead[1 ] =NULL ; + graph->lookahead_nr--; +return c; +} + +int graph_get_lookahead_room (struct git_graph *graph) +{ +return (int )ARRAY_SIZE (graph->lookahead) - graph->lookahead_nr; +} + +void graph_push_lookahead (struct git_graph *graph,struct commit *c) +{ +if (!graph_get_lookahead_room (graph)) +BUG ("pushing into lookahead buffer when it is already full" ); + + graph->lookahead[graph->lookahead_nr++] = c; +} +void graph_update (struct git_graph *graph,struct commit *commit) {struct commit_list *parent;
graph.h +17 -0
@@ -262,4 +262,21 @@ void graph_show_commit_msg(struct git_graph *graph,FILE *file, struct strbuf const *sb); +/* +* Pop the first commit from the graph's lookahead buffer. +* Returns NULL if the buffer is empty. +*/ +struct commit *graph_pop_lookahead (struct git_graph *graph); + +/* +* Returns how many more commits can be added to the lookahead buffer. +*/ +int graph_get_lookahead_room (struct git_graph *graph); + +/* +* Push a commit into the lookahead buffer. Must only be called when +* graph_get_lookahead_room() returns > 0. +*/ +void graph_push_lookahead (struct git_graph *graph,struct commit *c); +#endif /* GRAPH_H */
revision.c +16 -2
@@ -4715,10 +4715,24 @@ struct commit *get_revision(struct rev_info *revs)return c; } - c =next_commit_to_show (revs); +if (revs->graph) { + c =graph_pop_lookahead (revs->graph); +if (!c) + c =next_commit_to_show (revs); + }else { + c =next_commit_to_show (revs); + } -if (c && revs->graph) +if (c && revs->graph) { +while (graph_get_lookahead_room (revs->graph)) { +struct commit *next =next_commit_to_show (revs); +if (!next) +break ; +graph_push_lookahead (revs->graph, next); + }graph_update (revs->graph, c); + } +if (!c) {free_saved_parents (revs);commit_list_free (revs->previous_parents);
Signature · 1 line
2.54.0
PATCH v12 4/7 graph: indent visual root in graph
In reply to Pablo SabaterWhen rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This happens because the commits fill the space from left to right and when a visual root ends, its column becomes free for the following commit even if they are not related. Once this happens the unrelated commit is rendered below the visual root. Because there is no special character or way to identify when a visual root is rendered making the graph confusing.
By indenting the visual roots when there are still commits to show the vertical adjacency can be avoided.
Add is_visual_root flag to git_graph making it visible in all graph states, give graph_update() a new function, graph_is_visual_root() to know if the current commit is a visual root and set is_visual_root.
The different handled cases are:
- If a visual root has children: similar to GRAPH_PRE_COMMIT state when octopus merges need space, an edge row needs to be printed to connect the child with the indented visual root. A new state GRAPH_PRE_ROOT is needed to connect the child with the visual root:
* child of the visual root
\ GRAPH_PRE_ROOT
* visual root indented
- If a visual root is child-less we can skip GRAPH_PRE_ROOT state and render the indented commit directly.
* visual root indented
* unrelated commit
- If two or more visual roots are adjacent: by having a lookahead to the next commit that will be rendered, if the next commit is also a visual root and we are on a visual root, meaning two visual root adjacent in the history, the top one can omit the indent, making the one below to indent only once, if there are more adjacent visual commits, the indentation will increase for each adjacent one, cascading.
* visual root
* visual root
* visual root
* last commit
Even if the last commit is a root, because there is nothing that will be rendered below we can omit the indentation on purpose.
[1]: https://lore.kernel.org/git/[email protected]/
--- graph.c | 244 +++++++++++++++++++ t/meson.build | 1 + t/t4218-log-graph-indentation.sh | 514 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 759 insertions(+)
graph.c +244 -0
@@ -60,12 +60,23 @@ struct column {* index into column_colors. */ unsigned short color; +/* +* Marks if a commit is a non-first parent of a merge. These columns are +* already visually connected to the merge commit and do not need +* indentation. +* +* The first parent is the one that inherits the column and it can need +* indentation if turns out to be a visual root and there's still +* commits to render. +*/ + unsigned int is_merge_parent:1; };enum graph_state {GRAPH_PADDING ,GRAPH_SKIP ,GRAPH_PRE_COMMIT , +GRAPH_PRE_ROOT ,GRAPH_COMMIT ,GRAPH_POST_MERGE ,GRAPH_COLLAPSING
@@ -323,6 +334,51 @@ struct git_graph {*/ struct commit *lookahead[2 ];int lookahead_nr; + +/* +* If a commit is a visual root, we need to indent it to prevent +* unrelated commits from being vertically adjacent to it. +*/ + unsigned int is_visual_root:1; + +/* +* Indentation increases for each visual root adjacent to another visual +* root, making visual root commits indentation cascade. +*/ +unsigned int visual_root_depth; + +/* +* When a visual root is adjacent to other visual roots, the first one +* can avoid indentation and the rest cascades, increasing the indentation +* for each one. +*/ + unsigned int visual_root_cascade:1; + +/* +* Set when the current commit was already present in graph->columns +* before being processed. +*/ + unsigned int commit_in_columns:1; +}; + +struct graph_lookahead_flags { + +/* +* Set when there will be a commit after the current one that will be +* rendered. +*/ +unsigned int is_next_visible:1 ; + +/* +* Set when the next visible commit is candidate to be a visual root. +*/ +unsigned int is_next_visual_root:1 ; + +/* +* Set when the next visible commit will be rendered under the current +* commit. +*/ +unsigned int next_has_column:1 ; };static inline int graph_needs_truncation (struct git_graph *graph,int lane)
@@ -399,6 +455,8 @@ struct git_graph *graph_init(struct rev_info *opt) graph->lookahead[0 ] =NULL ; graph->lookahead[1 ] =NULL ; graph->lookahead_nr =0 ; + graph->visual_root_depth =0 ; + graph->visual_root_cascade =0 ;/* * Start the column color at the maximum value, since we'll * always increment it for the first commit we output.
@@ -581,6 +639,11 @@ static void graph_insert_into_new_columns(struct git_graph *graph, struct commit *commit, int idx) { +/* +* Get the initial merge_layout before it's modified to know if this +* is a merge. +*/ +int initial_merge_layout = graph->merge_layout;int i =graph_find_new_column_by_commit (graph, commit);int mapping_idx;
@@ -592,6 +655,7 @@ static void graph_insert_into_new_columns(struct git_graph *graph, i = graph->num_new_columns++; graph->new_columns[i].commit = commit; graph->new_columns[i].color =graph_find_commit_color (graph, commit); + graph->new_columns[i].is_merge_parent =0 ; }if (graph->num_parents >1 && idx >-1 && graph->merge_layout ==-1 ) {
@@ -630,6 +694,12 @@ static void graph_insert_into_new_columns(struct git_graph *graph, } graph->mapping[mapping_idx] = i; + +/* +* Mark non-first parents of a merge. +*/ +if (graph->num_parents >1 && initial_merge_layout >=0 && idx >-1 ) + graph->new_columns[i].is_merge_parent =1 ; }static void graph_update_columns (struct git_graph *graph)
@@ -721,10 +791,20 @@ static void graph_update_columns(struct git_graph *graph)if (graph->num_parents ==0 ) graph->width +=2 ; }else { +int j;graph_insert_into_new_columns (graph, col_commit,-1 ); +/* +* This column is not the current commit, but we need to +* propagate the flag until the commit is processed. +*/ + j =graph_find_new_column_by_commit (graph, col_commit); +if (j >=0 && graph->columns[i].is_merge_parent) + graph->new_columns[j].is_merge_parent =1 ; } } + graph->commit_in_columns = is_commit_in_columns; +/* * If graph_max_lanes is set, cap the width */
@@ -814,9 +894,113 @@ void graph_push_lookahead(struct git_graph *graph, struct commit *c) graph->lookahead[graph->lookahead_nr++] = c; } +/* +* A commit can be a visual root when: +* +* - It has no parents. +* +* - It has parents but they are all filtered out and +* commit->parents arrives NULL. +* +* - Its parents are uninteresting. +* +* - It is not a boundary commit. Boundary commits also have no visible +* parents, but they are not selected as visual roots because they cannot +* cause the ambiguity of being vertically adjacent because: +* +* 1. A boundary only appears because an included commit is its child. +* Children are always above, and the renderer draws an edge down to +* the boundary from that child. Rather than starting a column like a +* visual root would do, it inherits its child column. +* +* 2. Included commits cannot appear below a boundary. Boundaries are +* ancestors of the exclusion point; if an included commit were an +* ancestor of the boundary it would be excluded and not rendered. +* Boundaries therefore always sink to the bottom. +*/ +static int graph_is_visual_root_candidate (struct commit *c,struct git_graph *graph) +{ +struct commit_list *p; + +if (c->object.flags &BOUNDARY ) +return 0 ; +for (p = c->parents; p; p = p->next) +if (graph_is_interesting (graph, p->item)) +return 0 ; +return 1 ; +} + +static int graph_is_visual_root (struct git_graph *graph, +struct graph_lookahead_flags *flags) +{ +/* +* This must be only called for the current commit as graph contains +* the state for the current commit only. +* +* To check if a commit is a visual root, call graph_is_visual_root_candidate() +* but we won't know if it is really a visual root until we get to the +* next commit state. +* +* The current commit is an actual visual root if it is a candidate and +* the commit is not a non-first parent of a merge. +* +* * +* |\ +* | * <- it is a visual root candidate but it shouldn't be indented +* * because it is already connected by an edge. +* ^ if commit_in_columns && is_merge_parent means the commit +* | was put by a merge and is connected. +* | +* `-------- if !is_next_visible means we're on the last commit, avoid +* indentation unless the one before is a visual root, then +* we need to differentiate from the one above. +* +* If next_has_columns means that the next commit has +* already a column, so it will not be rendered below, the +* current commit has to act as the last commit and omit +* indentation. +*/ +return graph_is_visual_root_candidate (graph->commit, graph) && + !(graph->commit_in_columns && + graph->columns[graph->commit_index].is_merge_parent) && + flags->is_next_visible && + (!flags->next_has_column || graph->visual_root_depth >0 ); +} + +/* +* Peeks the next commits via the lookahead buffer and sets the lookahead flags. +*/ +static void graph_peek_next_visible (struct git_graph *graph, +struct graph_lookahead_flags *flags) +{ + flags->is_next_visible =0 ; + flags->is_next_visual_root =0 ; + flags->next_has_column =0 ; + +if (!graph->lookahead_nr) +return ; + + flags->is_next_visible =1 ; + flags->next_has_column = +graph_find_new_column_by_commit (graph, graph->lookahead[0 ]) >=0 ; + +if (!graph_is_visual_root_candidate (graph->lookahead[0 ], graph)) +return ; + +if (graph->lookahead_nr >=2 ) + flags->is_next_visual_root =1 ; +} + +static int graph_needs_pre_root_line (struct git_graph *graph) +{ +return graph->commit_in_columns && graph->is_visual_root && + graph->num_columns >0 && !graph->visual_root_cascade; +} +void graph_update (struct git_graph *graph,struct commit *commit) {struct commit_list *parent; +struct graph_lookahead_flags flags;/* * Set the new commit
@@ -847,6 +1031,23 @@ void graph_update(struct git_graph *graph, struct commit *commit)*/ graph_update_columns (graph); +graph_peek_next_visible (graph, &flags); + + graph->is_visual_root =graph_is_visual_root (graph, &flags); + +if (graph->is_visual_root) { +/* +* If next is a visual root we can omit the indent for the first +* visual root and start cascading. +*/ +if (!graph->visual_root_depth && flags.is_next_visual_root) + graph->visual_root_cascade =1 ; + graph->visual_root_depth++; + }else { + graph->visual_root_depth =0 ; + graph->visual_root_cascade =0 ; + } + graph->expansion_row =0 ;/*
@@ -864,11 +1065,16 @@ void graph_update(struct git_graph *graph, struct commit *commit)* room for it. We need to do this only if there is a branch row * (or more) to the right of this commit. * +* If it is a visual root, we need to print an extra row to +* connect the indentation. +* * If there are less than 3 parents, we can immediately print the * commit line. */ if (graph->state !=GRAPH_PADDING ) graph->state =GRAPH_SKIP ; +else if (graph_needs_pre_root_line (graph)) + graph->state =GRAPH_PRE_ROOT ;else if (graph_needs_pre_commit_line (graph)) graph->state =GRAPH_PRE_COMMIT ;else
@@ -1116,6 +1322,17 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_lineif (col_commit == graph->commit) { seen_this =1 ; +if (graph->is_visual_root) { +int depth = graph->visual_root_depth; +/* +* Each visual column is 2 characters wide. +* Omit the indentation for the first visual +* root in cascade mode. +*/ +int padding = (depth - graph->visual_root_cascade) *2 ; +graph_line_addchars (line,' ' , padding); + graph->width += padding; + }graph_output_commit_char (graph, line);if (graph_needs_truncation (graph, i)) {
@@ -1487,6 +1704,30 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_lgraph_update_state (graph,GRAPH_PADDING ); } +static void graph_output_pre_root_line (struct git_graph *graph,struct graph_line *line) +{ +/* +* This function adds a row before a visual root, to connect the +* branch to the indented commit. It must only be called on a +* visual root. +*/ +if (!graph->is_visual_root) +BUG ("commit must be a visual root to call pre_root_line" ); + +for (int i =0 ; i < graph->num_columns; i++) { +struct column *col = &graph->columns[i]; +if (col->commit == graph->commit) { +graph_line_addch (line,' ' ); +graph_line_write_column (line, col,'\\' ); + }else { +graph_line_write_column (line, col,'|' ); + } +graph_line_addch (line,' ' ); + } + +graph_update_state (graph,GRAPH_COMMIT ); +} +int graph_next_line (struct git_graph *graph,struct strbuf *sb) {int shown_commit_line =0 ;
@@ -1512,6 +1753,9 @@ int graph_next_line(struct git_graph *graph, struct strbuf *sb)case GRAPH_PRE_COMMIT :graph_output_pre_commit_line (graph, &line);break ; +case GRAPH_PRE_ROOT : +graph_output_pre_root_line (graph, &line); +break ;case GRAPH_COMMIT :graph_output_commit_line (graph, &line); shown_commit_line =1 ;
t/meson.build +1 -0
@@ -577,6 +577,7 @@ integration_tests = [ 't4215-log-skewed-merges.sh', 't4216-log-bloom.sh', 't4217-log-limit.sh', + 't4218-log-graph-indentation.sh', 't4219-log-follow-merge.sh', 't4252-am-options.sh', 't4253-am-keep-cr-dos.sh',
t/t4218-log-graph-indentation.sh new file +514 -0
514 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v12 5/7 graph: wrap cascading commits after 4 columns
In reply to Pablo SabaterCurrently the visual root commits in a graph cascade indefinitely until a commit which is not a visual root or the last commit appears. On filters like --author where one author might contribute mostly on single patches this can become a visual issue.
Make the cascading wrap after 4 columns.
There are two possible cases of the wrap:
1. No ambiguity:
* A
* B
* C
* D
* E
* F
2. Ambiguous conflict:
If F happens to not be a visual root and E gets wrapped back to the initial column then E and F would be vertically adjacent. The solution is to forcefully indent E one level:
* A
* B
* C
* D
* E
* F
* F
The magic number 4 comes as the minimum number of columns to wrap where the output shows clearly the commits are unrelated and doesn't cause too much "pyramid" effects
--- graph.c | 22 +++++++++++++++++++++- t/t4218-log-graph-indentation.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-)
graph.c +21 -1
@@ -1042,6 +1042,23 @@ void graph_update(struct git_graph *graph, struct commit *commit)*/ if (!graph->visual_root_depth && flags.is_next_visual_root) graph->visual_root_cascade =1 ; + +/* +* We wrap the cascading at a max of four columns at most, after +* that we wrap it back to the initial column. +* +* This could cause ambiguity in case of the next commit not +* being a visual root and be at the initial column after the +* first wrap. +* +* In case of being a non-visual-root the next, stop the +* cascading to get the commit indented. +*/ +if (!flags.is_next_visual_root && + graph->visual_root_depth && + !(graph->visual_root_depth %4 )) + graph->visual_root_cascade =0 ; + graph->visual_root_depth++; }else { graph->visual_root_depth =0 ;
@@ -1328,8 +1345,11 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line* Each visual column is 2 characters wide. * Omit the indentation for the first visual * root in cascade mode. +* +* Have a max of 4 columns when cascading, after +* that wrap it and repeat. */ -int padding = (depth - graph->visual_root_cascade) *2 ; +int padding = ((depth - graph->visual_root_cascade) %4 ) *2 ;graph_line_addchars (line,' ' , padding); graph->width += padding; }
t/t4218-log-graph-indentation.sh +29 -0
@@ -511,4 +511,33 @@ test_expect_success '--grep skipped parent makes a visual root' ' EOF ' +# The cascading wraps after 4 columns and when wraping (column % 4 == 0) if the +# next is a non visual-root, force indentation to avoid an ambiguous graph +# (commit 59_A is forcefully indented) +test_expect_success 'visual root cascading gets wrapped after 4 columns' ' + create_orphan _58 && test_commit 58_A && test_commit 58_B && + create_orphan _59 && test_commit 59_A && + create_orphan _60 && test_commit 60_A && + create_orphan _61 && test_commit 61_A && + create_orphan _62 && test_commit 62_A && + create_orphan _63 && test_commit 63_A && + create_orphan _64 && test_commit 64_A && + create_orphan _65 && test_commit 65_A && + create_orphan _66 && test_commit 66_A && + create_orphan _67 && test_commit 67_A && + lib_test_check_graph _58 _59 _60 _61 _62 _63 _64 _65 _66 _67 <<-\EOF + * 67_A + * 66_A + * 65_A + * 64_A + * 63_A + * 62_A + * 61_A + * 60_A + * 59_A + * 58_B + * 58_A + EOF +' + test_done
Signature · 1 line
2.54.0
PATCH v12 6/7 graph: move config reading into graph_read_config()
In reply to Pablo SabaterMove the repo_config_get_string() call out of graph_init() and into graph_read_config(). This simplifies graph_init() and provides a function for future graph-related config opt.
This commit is a preparatory commit for a subsequent one.
--- graph.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
graph.c +9 -4
@@ -417,13 +417,11 @@ void graph_setup_line_prefix(struct diff_options *diffopt) diffopt->output_prefix = diff_output_prefix_callback; } -struct git_graph *graph_init (struct rev_info *opt) +static void graph_read_config (struct rev_info *revs) { -struct git_graph *graph =xmalloc (sizeof (struct git_graph )); -if (!column_colors) {char *string; -if (repo_config_get_string (opt->repo,"log.graphcolors" , &string)) { +if (repo_config_get_string (revs->repo,"log.graphcolors" , &string)) {/* not configured -- use default */ graph_set_column_colors (column_colors_ansi, column_colors_ansi_max);
@@ -437,6 +435,13 @@ struct git_graph *graph_init(struct rev_info *opt) custom_colors.nr - 1); } } +} + +struct git_graph *graph_init (struct rev_info *opt) +{ +struct git_graph *graph =xmalloc (sizeof (struct git_graph )); + +graph_read_config (opt); graph->commit =NULL ; graph->revs = opt;
Signature · 1 line
2.54.0
PATCH v12 7/7 graph: add --[no-]graph-indent and log.graphIndent
In reply to Pablo SabaterSome users may prefer to not have graph indentation.
Add "log.graphIndent" config variable to graph_read_config() to read the default preference. By default is graph indentation is true.
Add --graph-indent and --no-graph-indent options to overwrite the default preference.
--- Documentation/config/log.adoc | 4 +++ Documentation/rev-list-options.adoc | 8 ++++++ graph.c | 10 +++++-- revision.c | 9 +++++++ revision.h | 2 ++ t/t4218-log-graph-indentation.sh | 53 +++++++++++++++++++++++++++++++++++++ 6 files changed, 84 insertions(+), 2 deletions(-)
Documentation/config/log.adoc +4 -0
@@ -59,6 +59,10 @@ This is the same as the `--decorate` option of the `git log`. A list of colors, separated by commas, that can be used to draw history lines in `git log --graph`. +`log.graphIndent`:: + If `true`, indent visual roots when rendering the graphs with `--graph`. + Set true by default. It can be overriden with `--[no-]graph-indent`. + `log.showRoot`:: If true, the initial commit will be shown as a big creation event. This is equivalent to a diff against an empty tree.
Documentation/rev-list-options.adoc +8 -0
@@ -1269,6 +1269,14 @@ This implies the `--topo-order` option by default, but the By default it is set to 0 (no limit), zero and negative values are ignored and treated as no limit. +`--no-graph-indent`:: +`--graph-indent`:: + When used with `--graph`, indent visual roots (commits with no parents + or whose parents are not shown) to differentiate them from commits that + are vertically adjacent but unrelated. Enabled by default. Use + `--no-graph-indent` to disable or set `log.graphIndent` to set a + default preference. + ifdef::git-rev-list[] `--count`:: Print a number stating how many commits would have been
graph.c +8 -2
@@ -419,6 +419,8 @@ void graph_setup_line_prefix(struct diff_options *diffopt)static void graph_read_config (struct rev_info *revs) { +int val; +if (!column_colors) {char *string;if (repo_config_get_string (revs->repo,"log.graphcolors" , &string)) {
@@ -435,6 +437,9 @@ static void graph_read_config(struct rev_info *revs) custom_colors.nr - 1); } } + +if (!repo_config_get_bool (revs->repo,"log.graphIndent" , &val)) + revs->no_graph_indent = !val; }struct git_graph *graph_init (struct rev_info *opt)
@@ -999,7 +1004,8 @@ static void graph_peek_next_visible(struct git_graph *graph,static int graph_needs_pre_root_line (struct git_graph *graph) {return graph->commit_in_columns && graph->is_visual_root && - graph->num_columns >0 && !graph->visual_root_cascade; + graph->num_columns >0 && !graph->visual_root_cascade && + !graph->revs->no_graph_indent; }void graph_update (struct git_graph *graph,struct commit *commit)
@@ -1344,7 +1350,7 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_lineif (col_commit == graph->commit) { seen_this =1 ; -if (graph->is_visual_root) { +if (graph->is_visual_root && !graph->revs->no_graph_indent) {int depth = graph->visual_root_depth;/* * Each visual column is 2 characters wide.
revision.c +9 -0
@@ -2627,6 +2627,12 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->graph =NULL ; }else if (skip_prefix (arg,"--graph-lane-limit=" , &optarg)) { revs->graph_max_lanes =parse_count (optarg); + }else if (!strcmp (arg,"--graph-indent" )) { + revs->no_graph_indent =0 ; + revs->graph_indent_set =1 ; + }else if (!strcmp (arg,"--no-graph-indent" )) { + revs->no_graph_indent =1 ; + revs->graph_indent_set =1 ; }else if (!strcmp (arg,"--encode-email-headers" )) { revs->encode_email_headers =1 ; }else if (!strcmp (arg,"--no-encode-email-headers" )) {
@@ -3201,6 +3207,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct sif (revs->graph_max_lanes >0 && !revs->graph)die (_ ("the option '%s' requires '%s'" ),"--graph-lane-limit" ,"--graph" ); +if (revs->graph_indent_set && !revs->graph) +die (_ ("the option '%s' requires '%s'" ),"--[no-]graph-indent" ,"--graph" ); +if (!revs->reflog_info && revs->grep_filter.use_reflog_filter)die (_ ("the option '%s' requires '%s'" ),"--grep-reflog" ,"--walk-reflogs" );
revision.h +2 -0
@@ -314,6 +314,8 @@ struct rev_info {/* Display history graph */ struct git_graph *graph;int graph_max_lanes; + unsigned int no_graph_indent:1; + unsigned int graph_indent_set:1;/* special limits */ int skip_count;
t/t4218-log-graph-indentation.sh +53 -0
57 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v12 0/7] graph: indent visual roots in graph
In reply to Pablo SabaterQuoted 143 lines · Pablo Sabater
When rendering a graph, if the history contains multiple "visual roots", actual roots or commits that look like roots (i.e. have their parents filtered out) can end up being vertically adjacent to unrelated commits, falsely appearing to be related.
A fix for this issue was already attempted [1] a while ago.
This series adds indentation to the visual root commits, so they cannot be vertically adjacent anymore making it easier to identify them.
Before indentation:
* A
* B1
* B2
* C1
* C2After indentation:
* A
* B1
\
* B2
* C1
* C2Indents the visual root commits that have still commits to show after them, and if they have children it connects them with an edge at a new row.
If there are multiple visual roots adjacent in history, the indentation starts with the second one, avoiding redundant indentation of the first one and cascades after the second.
* A
* B
* C
* D
* E
* F
* G
* H
* I
* J1
* J2The indentation wraps after cascading columns and when wrapping back to the initial column if the next commit is a non-visual-root commit, force the indentation one extra level.
Series explanation:
1. Cleanup to bring a common function from t4215 and t6016 that will be used in t4218.
2. Logic extraction of the chose of from where the commit source comes from.
3. Add a buffer for lookahead purposes.
4. Principal commit. Implement the logic to get the visual roots indented.
5. Make visual root cascading wrap after 4 columns
6. Add --[no-]graph-indent and log.graphIndent options.
GitHub CI: https://github.com/pabloosabaterr/git/actions/runs/29331144667
[1]: https://lore.kernel.org/git/[email protected]/
V11 DIFF:
- Changed the check that required graph, to not confuse because it is a boolean value.
- Typos
Signed-off-by Pablo Sabater <[email protected]>---
Pablo Sabater (7):
lib-log-graph: movecheck_graphfunction
revision: addnext_commit_to_show()
graph: add a 2 commit buffer for lookahead
graph: indent visual root in graph
graph: wrap cascading commits after 4 columns
graph: move config reading intograph_read_config()
graph: add --[no-]graph-indent and log.graphIndentDocumentation/config/log.adoc | 4 + Documentation/rev-list-options.adoc | 8 + graph.c | 332 +++++++++++++++- graph.h | 17 + revision.c | 57 ++- revision.h | 2 + t/lib-log-graph.sh | 5 + t/meson.build | 1 + t/t4215-log-skewed-merges.sh | 33 +- t/t4218-log-graph-indentation.sh | 596 +++++++++++++++++++++++++++++ t/t6016-rev-list-graph-simplify-history.sh | 25 +- 11 files changed, 1032 insertions(+), 48 deletions(-)Range-diff versus v11:
1: dd0bb0d215 = 1: d754392142 lib-log-graph: move check_graph function 2: 07e239533d = 2: c93c2c0771 revision: add next_commit_to_show() 3: 4d71f674a1 = 3: 70fe612ae1 graph: add a 2 commit buffer for lookahead 4: 48ad2562f0 = 4: e1ac06c4ea graph: indent visual root in graph 5: 45be69d11b = 5: ce52b41527 graph: wrap cascading commits after 4 columns 6: 8ce53ae21b = 6: 9b7bb2cebc graph: move config reading into graph_read_config() 7: c1fa81022e ! 7: 13e830725f graph: add --[no-]graph-indent and log.graphIndent@@
Documentation/rev-list-options.adoc: This implies the--topo-orderoption by d
+ When used with--graph, indent visual roots (commits with no parents
+ or whose parents are not shown) to differentiate them from commits that
+ are vertically adjacent but unrelated. Enabled by default. Use
-+--no-graph-indentto disable or setgraph.indentto set a deafault -+ preference.
++--no-graph-indentto disable or setlog.graphIndentto set a
++ default preference.
+
ifdef::git-rev-list[]
--count::
@@revision.c: int setup_revisions(int argc, const char **argv, structrev_info*re
if (revs->graph_max_lanes> 0 && !revs->graph)
die(_("the option '%s' requires '%s'"), "--graph-lane-limit", "--graph");-+ if (
revs->graph_indent_set> 0 && !revs->graph)
++ if (revs->graph_indent_set&& !revs->graph)
+die(_("the option '%s' requires '%s'"), "--[no-]graph-indent", "--graph");
+
if (!revs->reflog_info &&revs->grep_filter.use_reflog_filter)
@@t/t4218-log-graph-indentation.sh:test_expect_success'visual root cascading get
+ EOF
+'
+
-+# graph.indent true and no --option is the default state.
++# log.graphIndent unset and no --option (which activates graph indentation) is ++# the default state.
+
test_done
Quoted 2 lines
---
base-commit:f60db8d575adb79761d363e026fb49bddf330c73
This version looks fine to me.
Thanks,
Chandra.
Hi Pablo
Quoted 14 lines · Pablo Sabater
When having a history with multiple root commits and drawing the history near the roots, the graphing engine renders the commit one below the other, seeming that they are related, which makes the graph confusing.
This issue was reported by Junio at:
https://lore.kernel.org/git/[email protected]/e.g.:
* root-B
* child-A2
* child-A1
* root-A
Quoted 7 lines
[...]
* root-B
* child-A2
/
* child-A1
* root-A
I'm rather late to the party here, but personally I find the indentation a bit confusing, it would be clearer to me if we had a blank line after a root commit
* root-B
* child-A2
* child-A1
* root-A
It takes the same amount of vertical space but keeps the children of root-A together.
Thanks
Phillip
Quoted 58 lines
This is done by adding a
is_placeholderflag to the columns, the root commit is actually there but marked as a placeholdere.g.:
* root-B
(B) * child-A2
/
* child-A1
* root-A(B) would be root-B column with the placeholder flag active.
Then teaching the rendering function to print a padding ' ' when meeting a placeholder column outputs the second example.
There could also be the case where there are multiple roots
without the patch:
* A root
* B root
* C root
* D1 child
* D rootwith the patch, the indentation cascades:
* A root
* B root
* C root
* D1 child
_ /
/
/
* D rootthe _ / might look weird but that's how the collapsing rendering does it for big gaps, this case being from the 4th column to the 0th column. Another patch could change the collapsing rendering for placeholders ? I haven't done it to keep it minimal, but a follow up could make it to be straight '/'. This would make it bigger but easier for the eye to follow. IMO is not worth it, but opinions are welcome.
The patch also adds tests for different cases like a root preceding multiple parents merges and the examples above.
There could be some edge cases still so any testing is very welcome.
Pablo Sabater (1):
graph: add indentation for commits preceded by a rootgraph.c | 68 ++++++++++++++++-- t/t4215-log-skewed-merges.sh | 136 +++++++++++++++++++++++++++++++++++ 2 files changed, 198 insertions(+), 6 deletions(-)base-commit:
256554692df0685b45e60778b08802b720880c50