add a blank line when a commit has no parent in log output?

7 messages, 4 authors, 2021-01-17 · open the first message on its own page

add a blank line when a commit has no parent in log output?

From: Jason Pyeron <hidden>
Date: 2021-01-14 18:31:10

Take this git log --format="%C(auto) %h% ad%d% s%C(green)% aE" --graph --date=short

| | | *  5505e019c2 2014-07-09 initial xxxxxx@xxxx
| | | *  3e658f4085 2019-09-10 (wiki/wip-citest, origin/wip-citest) Added defau
| | | *  ad148aafe6 2019-09-10 Added default CI/CD Jenkinsfile (from f7daf088)

One might assume 5505e019c2 and 3e658f4085 are related. But git cat-file -p 5505e019c2
tree 546c6b71f01e7fd086c8adb832518240b71a9075
author sam swindell <xxxxxx@xxxx> 1404878701 -0400
committer sam swindell <xxxxxx@xxxx> 1404878701 -0400

initial


Is there a way to have it look like:

| | | *  5505e019c2 2014-07-09 initial xxxxxx@xxxx
| | |
| | | *  3e658f4085 2019-09-10 (wiki/wip-citest, origin/wip-citest) Added defau
| | | *  ad148aafe6 2019-09-10 Added default CI/CD Jenkinsfile (from f7daf088)

Or 

| | | #  5505e019c2 2014-07-09 initial xxxxxx@xxxx
| | | *  3e658f4085 2019-09-10 (wiki/wip-citest, origin/wip-citest) Added defau
| | | *  ad148aafe6 2019-09-10 Added default CI/CD Jenkinsfile (from f7daf088)

Respectfully,

Jason Pyeron


--
Jason Pyeron  | Architect
PD Inc        |
10 w 24th St  |
Baltimore, MD |
 
.mil: jason.j.pyeron.ctr...
.com: jpyeron@pdinc.us
tel : 202-741-9397


Re: add a blank line when a commit has no parent in log output?

From: Philippe Blain <hidden>
Date: 2021-01-14 19:30:27

Hi Jason,

Le 2021-01-14 à 13:30, Jason Pyeron a écrit :
Take this git log --format="%C(auto) %h% ad%d% s%C(green)% aE" --graph --date=short

| | | *  5505e019c2 2014-07-09 initial xxxxxx@xxxx
| | | *  3e658f4085 2019-09-10 (wiki/wip-citest, origin/wip-citest) Added defau
| | | *  ad148aafe6 2019-09-10 Added default CI/CD Jenkinsfile (from f7daf088)

One might assume 5505e019c2 and 3e658f4085 are related. But git cat-file -p 5505e019c2
tree 546c6b71f01e7fd086c8adb832518240b71a9075
author sam swindell <xxxxxx@xxxx> 1404878701 -0400
committer sam swindell <xxxxxx@xxxx> 1404878701 -0400

initial


Is there a way to have it look like:

| | | *  5505e019c2 2014-07-09 initial xxxxxx@xxxx
| | |
| | | *  3e658f4085 2019-09-10 (wiki/wip-citest, origin/wip-citest) Added defau
| | | *  ad148aafe6 2019-09-10 Added default CI/CD Jenkinsfile (from f7daf088)

Or

| | | #  5505e019c2 2014-07-09 initial xxxxxx@xxxx
| | | *  3e658f4085 2019-09-10 (wiki/wip-citest, origin/wip-citest) Added defau
| | | *  ad148aafe6 2019-09-10 Added default CI/CD Jenkinsfile (from f7daf088)
If you remove '--graph', then you can add '--show-linear-break' [1]. Unfortunately
these two options do not work together. I think your suggestion to have the '*'
be changed to '#' for root commit is a great idea.

In the mean time, I use this trick:

     git log --date=short --format='%C(auto) %h% [%<(2,trunc)%p] ad%d% s%C(green)% aE'

This adds the abbreviated parent hashes (%p) but truncated to 2 characters ([2], [3]). So
the brackets will be empty for root commits.

Cheers,

Philippe.


[1] https://git-scm.com/docs/git-log#Documentation/git-log.txt---show-linear-breakltbarriergt
[2] https://git-scm.com/docs/git-log#Documentation/git-log.txt-empem
[3] https://git-scm.com/docs/git-log#Documentation/git-log.txt-emltltNgttruncltruncmtruncem

RE: add a blank line when a commit has no parent in log output?

From: Jason Pyeron <hidden>
Date: 2021-01-14 20:45:37

Kyle:

Need you to whip up a patch (back port it to current Cygwin git too), see below. It will help with cleaning up Cresaptown branches. Or if you think Watson can do it, give it to him.
-----Original Message-----
From: Philippe Blain <redacted>
Sent: Thursday, January 14, 2021 2:29 PM
To: git@vger.kernel.org; Jason Pyeron <redacted>
Subject: Re: add a blank line when a commit has no parent in log output?

Hi Jason,

Le 2021-01-14 à 13:30, Jason Pyeron a écrit :
quoted
Take this git log --format="%C(auto) %h% ad%d% s%C(green)% aE" --graph --date=short

| | | *  5505e019c2 2014-07-09 initial xxxxxx@xxxx
| | | *  3e658f4085 2019-09-10 (wiki/wip-citest, origin/wip-citest) Added defau
| | | *  ad148aafe6 2019-09-10 Added default CI/CD Jenkinsfile (from f7daf088)

One might assume 5505e019c2 and 3e658f4085 are related. But git cat-file -p 5505e019c2
tree 546c6b71f01e7fd086c8adb832518240b71a9075
author sam swindell <xxxxxx@xxxx> 1404878701 -0400
committer sam swindell <xxxxxx@xxxx> 1404878701 -0400

initial


Is there a way to have it look like:

| | | *  5505e019c2 2014-07-09 initial xxxxxx@xxxx
| | |
| | | *  3e658f4085 2019-09-10 (wiki/wip-citest, origin/wip-citest) Added defau
| | | *  ad148aafe6 2019-09-10 Added default CI/CD Jenkinsfile (from f7daf088)

Or

| | | #  5505e019c2 2014-07-09 initial xxxxxx@xxxx
| | | *  3e658f4085 2019-09-10 (wiki/wip-citest, origin/wip-citest) Added defau
| | | *  ad148aafe6 2019-09-10 Added default CI/CD Jenkinsfile (from f7daf088)
If you remove '--graph', then you can add '--show-linear-break' [1]. Unfortunately
these two options do not work together. I think your suggestion to have the '*'
be changed to '#' for root commit is a great idea.
Patch description

When --graph is used

--show-linear-break converts the * to a #

--show-linear-break=x converts the * to a x
In the mean time, I use this trick:

     git log --date=short --format='%C(auto) %h% [%<(2,trunc)%p] ad%d% s%C(green)% aE'

This adds the abbreviated parent hashes (%p) but truncated to 2 characters ([2], [3]). So
the brackets will be empty for root commits.

Cheers,

Philippe.


[1] https://git-scm.com/docs/git-log#Documentation/git-log.txt---show-linear-breakltbarriergt
[2] https://git-scm.com/docs/git-log#Documentation/git-log.txt-empem
[3] https://git-scm.com/docs/git-log#Documentation/git-log.txt-emltltNgttruncltruncmtruncem

[PATCH 0/2] Option to modify revision mark for root commits

From: Kyle Marek <hidden>
Date: 2021-01-17 12:07:08

This patch series allows --show-linear-break to be used with --graph,
allowing for the revision mark to be changed for root commits.

Feel free to squash away PATCH 1, or maybe even discard PATCH 2.

Jason: tested against Cygwin x86_64/release/git/git-2.30.0-1-src.tar.xz

Note: PATCH 2 revision.c:2410 makes a second copy of optarg. This may
not be necessary.

Background:

The use case is --graph --oneline with unrelated histories. For example,
in a hypothetical repository with an orphaned "prebuilt" branch
containing builds of the master branch, the history may look like:

kmarek@kyle-ppc64le /tmp/somerepo
$ git log --graph --all --oneline
* 02190b6 (prebuilt) add aarch64
* 7b873f6 add x86_64
* 26cc783 add ppc64le
* 5b7186e (HEAD -> master) add Makefile
* ea69093 implement cmdline parsing
* a65df8a add main.c
* 7727eb3 Initial commit

At first sight, the above log implies that 26cc783's parent is 5b7186e,
or that master is an ancestor to prebuilt, but 26cc783 is the start of a
new history:

kmarek@kyle-ppc64le /tmp/somerepo
$ git log --graph --oneline master
* 5b7186e (HEAD -> master) add Makefile
* ea69093 implement cmdline parsing
* a65df8a add main.c
* 7727eb3 Initial commit

kmarek@kyle-ppc64le /tmp/somerepo
$ git log --graph --oneline prebuilt
* 02190b6 (prebuilt) add aarch64
* 7b873f6 add x86_64
* 26cc783 add ppc64le

To identify the start of a new history:

kmarek@kyle-ppc64le /tmp/somerepo
$ git log --graph --all --oneline --show-linear-break
* 02190b6 (prebuilt) add aarch64
* 7b873f6 add x86_64
# 26cc783 add ppc64le
* 5b7186e (HEAD -> master) add Makefile
* ea69093 implement cmdline parsing
* a65df8a add main.c
# 7727eb3 Initial commit

kmarek@kyle-ppc64le /tmp/somerepo
$ git log --graph --all --oneline --show-linear-break=I
* 02190b6 (prebuilt) add aarch64
* 7b873f6 add x86_64
I 26cc783 add ppc64le
* 5b7186e (HEAD -> master) add Makefile
* ea69093 implement cmdline parsing
* a65df8a add main.c
I 7727eb3 Initial commit

Kyle Marek (2):
  revision: Denote root commits with '#'
  revision: implement --show-linear-break for --graph

 Documentation/rev-list-options.txt |  7 +++++++
 log-tree.c                         |  2 +-
 revision.c                         | 10 ++++++----
 revision.h                         |  1 +
 4 files changed, 15 insertions(+), 5 deletions(-)

-- 
2.29.2

[PATCH 1/2] revision: Denote root commits with '#'

From: Kyle Marek <hidden>
Date: 2021-01-17 12:07:03

This aids in identifying where an unrelated branch history starts when
using `git log --graph --oneline --all`

Signed-off-by: Kyle Marek <redacted>
---
 revision.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/revision.c b/revision.c
index 9dff845bed..8556923de8 100644
--- a/revision.c
+++ b/revision.c
@@ -4191,9 +4191,11 @@ const char *get_revision_mark(const struct rev_info *revs, const struct commit *
 			return "<";
 		else
 			return ">";
-	} else if (revs->graph)
+	} else if (revs->graph) {
+		if (!commit->parents)
+			return "#";
 		return "*";
-	else if (revs->cherry_mark)
+	} else if (revs->cherry_mark)
 		return "+";
 	return "";
 }
-- 
2.29.2

[PATCH 2/2] revision: implement --show-linear-break for --graph

From: Kyle Marek <hidden>
Date: 2021-01-17 12:07:30

where <barrier> sets rev_info.break_revision_mark, the revision mark
used for root commits.

Signed-off-by: Kyle Marek <redacted>
---
 Documentation/rev-list-options.txt | 7 +++++++
 log-tree.c                         | 2 +-
 revision.c                         | 8 ++++----
 revision.h                         | 1 +
 4 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index 002379056a..93adb77c19 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -1104,6 +1104,13 @@ This implies the `--topo-order` option by default, but the
 	do not belong to a linear branch. This option puts a barrier
 	in between them in that case. If `<barrier>` is specified, it
 	is the string that will be shown instead of the default one.
++
+When --graph is used with --oneline, there is usually no vertical
+space between commits, so the graph edge is not drawn. This can make
+it hard to see that a history may end at one commit, while an
+unrelated history starts at the next commit. This option changes the
+revision mark for root commits. If `<barrier>` is specified, it is
+used as the new revision mark instead of the default one.
 
 ifdef::git-rev-list[]
 --count::
diff --git a/log-tree.c b/log-tree.c
index fd0dde97ec..f62300e404 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -962,7 +962,7 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)
 	if (opt->line_level_traverse)
 		return line_log_print(opt, commit);
 
-	if (opt->track_linear && !opt->linear && !opt->reverse_output_stage)
+	if (!opt->graph && opt->track_linear && !opt->linear && !opt->reverse_output_stage)
 		fprintf(opt->diffopt.file, "\n%s\n", opt->break_bar);
 	shown = log_tree_diff(opt, commit, &log);
 	if (!shown && opt->loginfo && opt->always_show_header) {
diff --git a/revision.c b/revision.c
index 8556923de8..51deab2326 100644
--- a/revision.c
+++ b/revision.c
@@ -2402,10 +2402,12 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 		revs->show_signature = 0;
 	} else if (!strcmp(arg, "--show-linear-break")) {
 		revs->break_bar = "                    ..........";
+		revs->break_revision_mark = "#";
 		revs->track_linear = 1;
 		revs->track_first_time = 1;
 	} else if (skip_prefix(arg, "--show-linear-break=", &optarg)) {
 		revs->break_bar = xstrdup(optarg);
+		revs->break_revision_mark = xstrdup(optarg);
 		revs->track_linear = 1;
 		revs->track_first_time = 1;
 	} else if (skip_prefix(arg, "--show-notes=", &optarg) ||
@@ -2530,8 +2532,6 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 			unkv[(*unkc)++] = arg;
 		return opts;
 	}
-	if (revs->graph && revs->track_linear)
-		die("--show-linear-break and --graph are incompatible");
 
 	return 1;
 }
@@ -4192,8 +4192,8 @@ const char *get_revision_mark(const struct rev_info *revs, const struct commit *
 		else
 			return ">";
 	} else if (revs->graph) {
-		if (!commit->parents)
-			return "#";
+		if (revs->break_revision_mark && !commit->parents)
+			return revs->break_revision_mark;
 		return "*";
 	} else if (revs->cherry_mark)
 		return "+";
diff --git a/revision.h b/revision.h
index 086ff10280..83b2ecef56 100644
--- a/revision.h
+++ b/revision.h
@@ -297,6 +297,7 @@ struct rev_info {
 
 	struct commit_list *previous_parents;
 	const char *break_bar;
+	const char *break_revision_mark;
 
 	struct revision_sources *sources;
 
-- 
2.29.2

Re: [PATCH 2/2] revision: implement --show-linear-break for --graph

From: Junio C Hamano <hidden>
Date: 2021-01-17 22:57:17

Kyle Marek [off-list ref] writes:
where <barrier> sets rev_info.break_revision_mark, the revision mark
used for root commits.
Please make sure that the body of the proposed log message begins
with a full sentence, not as a continuation of a sentence that the
title started (as a consequence, the title must be understandable
without the help of the beginning part of the body, too).
Signed-off-by: Kyle Marek <redacted>
---
quoted hunk
diff --git a/revision.c b/revision.c
index 8556923de8..51deab2326 100644
--- a/revision.c
+++ b/revision.c
@@ -2402,10 +2402,12 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 		revs->show_signature = 0;
 	} else if (!strcmp(arg, "--show-linear-break")) {
 		revs->break_bar = "                    ..........";
+		revs->break_revision_mark = "#";
 		revs->track_linear = 1;
 		revs->track_first_time = 1;
 	} else if (skip_prefix(arg, "--show-linear-break=", &optarg)) {
 		revs->break_bar = xstrdup(optarg);
+		revs->break_revision_mark = xstrdup(optarg);
 		revs->track_linear = 1;
 		revs->track_first_time = 1;
 	} else if (skip_prefix(arg, "--show-notes=", &optarg) ||
In other words, revs->break_revision_mark is left NULL unless
--show-linear-break is given.
quoted hunk
@@ -4192,8 +4192,8 @@ const char *get_revision_mark(const struct rev_info *revs, const struct commit *
 		else
 			return ">";
 	} else if (revs->graph) {
-		if (!commit->parents)
-			return "#";
+		if (revs->break_revision_mark && !commit->parents)
+			return revs->break_revision_mark;
And that causes this to break.  Now "--graph" alone won't show '#'
for the root commits, despite that is what [1/2] wanted to do.

Here is a fix-up, plus some minimum tests.  

The part to teach left-right codepath to show L/R is a fix-up to
[1/2], not to this step.  You might want to change them to some
left/right punctuation letters, like () or [].

The other hunks in revision.c are fixes to step [2/2].

I didn't test a custom --show-linear-break='My break line' in the
attachedtest, so that it can be squashed into your [1/2] to test the
feature that step adds.  You should be able to add tests for that
feature in this step [2/2] on top.

I still am skeptical that spending 3 more letters to denote roots is
worth it, though.

 revision.c                   |  11 ++--
 t/t6020-rev-list-boundary.sh | 132 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 138 insertions(+), 5 deletions(-)
diff --git c/revision.c w/revision.c
index 33fbef5c08..55521c53af 100644
--- c/revision.c
+++ w/revision.c
@@ -2402,7 +2402,6 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 		revs->show_signature = 0;
 	} else if (!strcmp(arg, "--show-linear-break")) {
 		revs->break_bar = "                    ..........";
-		revs->break_revision_mark = "#";
 		revs->track_linear = 1;
 		revs->track_first_time = 1;
 	} else if (skip_prefix(arg, "--show-linear-break=", &optarg)) {
@@ -4219,12 +4218,14 @@ const char *get_revision_mark(const struct rev_info *revs, const struct commit *
 		return "=";
 	else if (!revs || revs->left_right) {
 		if (commit->object.flags & SYMMETRIC_LEFT)
-			return "<";
+			return commit->parents ? "<" : "L";
 		else
-			return ">";
+			return commit->parents ? ">" : "R";
 	} else if (revs->graph) {
-		if (revs->break_revision_mark && !commit->parents)
-			return revs->break_revision_mark;
+		if (!commit->parents)
+			return (revs->break_revision_mark 
+				? revs->break_revision_mark
+				: "#");
 		return "*";
 	} else if (revs->cherry_mark)
 		return "+";
diff --git c/t/t6020-rev-list-boundary.sh w/t/t6020-rev-list-boundary.sh
new file mode 100755
index 0000000000..35614e9baf
--- /dev/null
+++ w/t/t6020-rev-list-boundary.sh
@@ -0,0 +1,132 @@
+#!/bin/sh
+
+test_description='rev-list/log boundary and root'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+	test_commit A &&
+	test_commit B &&
+	git reset --hard A &&
+	test_commit C &&
+
+	git checkout --orphan side &&
+	git rm -fr . &&
+	test_commit X &&
+	test_commit Y &&
+
+	test_tick && git merge --allow-unrelated-histories -m "M" B &&
+	test_tick && git merge -m "N" C &&
+	test_commit Z
+'
+
+test_expect_success 'log with boundary' '
+	git log --graph --boundary --format='%s' ^A ^X Z >actual &&
+	sed -e "s/Q$//" >expect <<-\EOF &&
+	* Z
+	*   N
+	|\  Q
+	| * C
+	* |   M
+	|\ \  Q
+	| * | B
+	| |/  Q
+	* | Y
+	o | X
+	 /  Q
+	o A
+	EOF
+	test_cmp expect actual
+'
+
+test_expect_success 'log --left-right with symmetric boundary' '
+	git log --graph --left-right --boundary --format='%s' B...C >actual &&
+	sed -e "s/Q$//" >expect <<-\EOF &&
+	> C
+	| < B
+	|/  Q
+	o A
+	EOF
+	test_cmp expect actual
+'
+
+test_expect_success 'log --left-right with asymmetric boundary' '
+	git log --graph --left-right --boundary --format='%s' ^A ^X Z >actual &&
+	sed -e "s/Q$//" >expect <<-\EOF &&
+	> Z
+	>   N
+	|\  Q
+	| > C
+	> |   M
+	|\ \  Q
+	| > | B
+	| |/  Q
+	> | Y
+	o | X
+	 /  Q
+	o A
+	EOF
+	test_cmp expect actual
+'
+
+test_expect_success 'log down to root' '
+	git log --graph --format='%s' Z >actual &&
+	sed -e "s/Q$//" >expect <<-\EOF &&
+	* Z
+	*   N
+	|\  Q
+	| * C
+	* |   M
+	|\ \  Q
+	| * | B
+	| |/  Q
+	| # A
+	* Y
+	# X
+	EOF
+	test_cmp expect actual
+'
+
+test_expect_success 'log down to root' '
+	git log --graph --format='%s' B Y >actual &&
+	sed -e "s/Q$//" >expect <<-\EOF &&
+	* Y
+	# X
+	* B
+	# A
+	EOF
+	test_cmp expect actual
+'
+
+test_expect_success 'log that happens to show root' '
+	git log --graph -3 --format='%s' B Y >actual &&
+	sed -e "s/Q$//" >expect <<-\EOF &&
+	* Y
+	# X
+	* B
+	EOF
+	test_cmp expect actual
+'
+
+test_expect_success 'log --left-right down to root' '
+	git log --graph --left-right --format='%s' B...Y >actual &&
+	sed -e "s/Q$//" >expect <<-\EOF &&
+	> Y
+	R X
+	< B
+	L A
+	EOF
+	test_cmp expect actual
+'
+
+test_expect_success 'log --left-right that happens to show root' '
+	git log --graph -3 --left-right --format='%s' B...Y >actual &&
+	sed -e "s/Q$//" >expect <<-\EOF &&
+	> Y
+	R X
+	< B
+	EOF
+	test_cmp expect actual
+'
+
+test_done
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help