# [PATCH] graph.c: log.showRootMark to indicate root commits

3 messages from 2018-04-01 to 2018-04-02. Participants: Lyubomyr Shaydariv, Junio C Hamano.
Thread: https://gitlist.dev/t/48195

## Lyubomyr Shaydariv, 2018-04-01 20:57

Subject: [PATCH] graph.c: log.showRootMark to indicate root commits
Message-ID: <0102016283000c69-b09d1499-8a50-45a7-9f41-01be648398bc-000000@eu-west-1.amazonses.com>
URL: https://gitlist.dev/e/0102016283000c69-b09d1499-8a50-45a7-9f41-01be648398bc-000000%40eu-west-1.amazonses.com

```
When log.showRootMark is set, root commits are marked with
the at sign (@).

When log.showRootMark is not set, root commits are marked with
the asterisk sign (*). This is the default behavior.

Signed-off-by: Lyubomyr Shaydariv <lsh.dev@ukr.net>
---
 Documentation/config.txt  |  5 +++++
 Documentation/git-log.txt |  5 +++++
 graph.c                   | 20 ++++++++++++++++++++
 t/t4202-log.sh            | 16 ++++++++++++++++
 4 files changed, 46 insertions(+)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 4e0cff87f62f5..0a32357e3c625 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2254,6 +2254,11 @@ log.showRoot::
 	Tools like linkgit:git-log[1] or linkgit:git-whatchanged[1], which
 	normally hide the root commit will now show it. True by default.
 
+log.showRootMark::
+	If true, the initial commit in `git log --graph` will be marked
+	with the at sign (`@`). Otherwise the initial commit will be
+	marked with the default asterisk sign (`*`). False by default.
+
 log.showSignature::
 	If true, makes linkgit:git-log[1], linkgit:git-show[1], and
 	linkgit:git-whatchanged[1] assume `--show-signature`.
diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
index 5437f8b0f0e66..7f5436231b6d7 100644
--- a/Documentation/git-log.txt
+++ b/Documentation/git-log.txt
@@ -205,6 +205,11 @@ log.showRoot::
 	`git log -p` output would be shown without a diff attached.
 	The default is `true`.
 
+log.showRootMark::
+	If true, the initial commit in `git log --graph` will be marked
+	with the at sign (`@`). Otherwise the initial commit will be
+	marked with the default asterisk sign (`*`). False by default.
+
 log.showSignature::
 	If `true`, `git log` and related commands will act as if the
 	`--show-signature` option was passed to them.
diff --git a/graph.c b/graph.c
index e1f6d3bddb38a..d14ffec7a975c 100644
--- a/graph.c
+++ b/graph.c
@@ -80,6 +80,7 @@ static void graph_show_line_prefix(const struct diff_options *diffopt)
 
 static const char **column_colors;
 static unsigned short column_colors_max;
+static int show_root_mark;
 
 static void parse_graph_colors_config(struct argv_array *colors, const char *string)
 {
@@ -256,6 +257,16 @@ void graph_setup_line_prefix(struct diff_options *diffopt)
 }
 
 
+static int git_graph_config(const char *var, const char *value, void *cb)
+{
+	if (!strcmp(var, "log.showrootmark")) {
+		show_root_mark = git_config_bool(var, value);
+		return 0;
+	}
+
+	return git_default_config(var, value, cb);
+}
+
 struct git_graph *graph_init(struct rev_info *opt)
 {
 	struct git_graph *graph = xmalloc(sizeof(struct git_graph));
@@ -276,6 +287,7 @@ struct git_graph *graph_init(struct rev_info *opt)
 						custom_colors.argc - 1);
 		}
 	}
+	git_config(git_graph_config, NULL);
 
 	graph->commit = NULL;
 	graph->revs = opt;
@@ -835,6 +847,14 @@ static void graph_output_commit_char(struct git_graph *graph, struct strbuf *sb)
 		return;
 	}
 
+	/*
+	 * If the commit has no parents, it's a root commit
+	 */
+	if (show_root_mark && !graph->num_parents) {
+		strbuf_addch(sb, '@');
+		return;
+	}
+
 	/*
 	 * get_revision_mark() handles all other cases without assert()
 	 */
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index 25b1f8cc73bc3..350e35264362f 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -455,6 +455,22 @@ test_expect_success 'simple log --graph' '
 	test_cmp expect actual
 '
 
+cat > expect <<EOF
+* Second
+* sixth
+* fifth
+* fourth
+* third
+* second
+@ initial
+EOF
+
+test_expect_success 'simple log --graph' '
+	test_config log.showRootMark true &&
+	git log --graph --pretty=tformat:%s >actual &&
+	test_cmp expect actual
+'
+
 cat > expect <<EOF
 123 * Second
 123 * sixth

--
https://github.com/git/git/pull/478

```

## Junio C Hamano, 2018-04-02 17:57

Subject: Re: [PATCH] graph.c: log.showRootMark to indicate root commits
Message-ID: <xmqqk1tpze1x.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqqk1tpze1x.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <0102016283000c69-b09d1499-8a50-45a7-9f41-01be648398bc-000000@eu-west-1.amazonses.com>

```
Lyubomyr Shaydariv <lsh.dev@ukr.net> writes:

> When log.showRootMark is set, root commits are marked with
> the at sign (@).
>
> When log.showRootMark is not set, root commits are marked with
> the asterisk sign (*). This is the default behavior.
>
> Signed-off-by: Lyubomyr Shaydariv <lsh.dev@ukr.net>
> ---

So the idea is when you have a history like this:

    R1--A---B
              \
    R2--C---D---M

to show "git log --oneline --graph D B" like

        * B
        * A
        @ R1
        * D
        * C
        @ R2

because you cannot tell that between R1 and D there is no
parent-child relationship otherwise?

One downside of that approach is that it is not clear how this
feature should interact with --left-right.  I do not think there is
a clean way to do that, unless you come up with a pair of symbols,
not just a single '@'.

Another way to show that there is no parent-child relationship
between R1 and D is to show it like this instead:

        * B
        * A
         \
          * R1
        * D
        * C
        * R2

and that would work well with --left-right automatically (as you
would just do the same thing as you would to a normal asterisk).

```

## Junio C Hamano, 2018-04-02 18:13

Subject: Re: [PATCH] graph.c: log.showRootMark to indicate root commits
Message-ID: <xmqqfu4dzdax.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqqfu4dzdax.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <xmqqk1tpze1x.fsf@gitster-ct.c.googlers.com>

```
Junio C Hamano <gitster@pobox.com> writes:

> Lyubomyr Shaydariv <lsh.dev@ukr.net> writes:
>
>> When log.showRootMark is set, root commits are marked with
>> the at sign (@).
>>
>> When log.showRootMark is not set, root commits are marked with
>> the asterisk sign (*). This is the default behavior.
>>
>> Signed-off-by: Lyubomyr Shaydariv <lsh.dev@ukr.net>
>> ---
>
> So the idea is when you have a history like this:
> ...
> and that would work well with --left-right automatically (as you
> would just do the same thing as you would to a normal asterisk).

There was some discussion a while back on making root commits more
apparent in the graph view, e.g.

https://public-inbox.org/git/1382717268-21884-1-git-send-email-milton.soares.filho@gmail.com/


```
