graph: add --[no-]graph-indent and log.graphIndent

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 <pabloosabaterr@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Pablo Sabater
2026-07-14 14:09:38 +02:00
committed by Junio C Hamano
parent f3a03302ad
commit e9b5720bef
6 changed files with 84 additions and 2 deletions

View File

@@ -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.

View File

@@ -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

10
graph.c
View File

@@ -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_line
if (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.

View File

@@ -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 s
if (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");

View File

@@ -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;

View File

@@ -540,4 +540,57 @@ test_expect_success 'visual root cascading gets wrapped after 4 columns' '
EOF
'
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
* 58_B
* 58_A
EOF
'
# log.graphIndent unset and no --option (which activates graph indentation) is
# the default state.
test_done