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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux