]> git.ipfire.org Git - thirdparty/git.git/commitdiff
graph: add --[no-]graph-indent and log.graphIndent
authorPablo Sabater <pabloosabaterr@gmail.com>
Tue, 14 Jul 2026 12:09:38 +0000 (14:09 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 14 Jul 2026 14:32:51 +0000 (07:32 -0700)
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>
Documentation/config/log.adoc
Documentation/rev-list-options.adoc
graph.c
revision.c
revision.h
t/t4218-log-graph-indentation.sh

index 757a7be196ab38a3a3c8a9a8946b05d83fb8bfb7..f7dfce69b5f95ec93f23fc217e4273559404a544 100644 (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.
index eaee6ee8399c574d0a123b0eecba4b6b66422da4..fd831f0ec647442b7003aab1c0cfc991ce9b9b33 100644 (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
diff --git a/graph.c b/graph.c
index c14be934a05d4f53c38b3520a9d0ebcdb11e3811..28bef1b88f5a7a04b026621500890d6f1e04f564 100644 (file)
--- a/graph.c
+++ b/graph.c
@@ -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.
index 258c3cf782894bbc7fdfeb90d51c5896872baa10..37f7ea45d131333676274d14ca0bc0931c5783fa 100644 (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");
 
index 569b3fa1cb5a339e2b9c2fbfa6318e6ad9f7073c..acf6d06b24126c7a70a8e42f6846d0105ccf8d9a 100644 (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;
index d4c850c0d46e9b043f3b3a616af01ae07c91e644..24dc9b497d9dbc040fd67a62ea9f12056c5cfd6d 100755 (executable)
@@ -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