git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 17, 2021, 22:56 UTC
Message-ID
<xmqqsg6zkwa8.fsf@gitster.c.googlers.com>
In-Reply-To
<20210117110337.429994-3-kmarek@pdinc.us>
Kyle Marek <kmarek@pdinc.us> 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 <kmarek@pdinc.us>
> ---
Show 17 quoted lines
> 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.

Show 8 quoted lines
> @@ -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
Previous: Kyle MarekNext: Junio C Hamano
Message 24 of 29 in “add a blank line when a commit has no parent in log output?”
  1. Jason PyeronJan 14, 2021
  2. Philippe BlainJan 14, 2021
  3. Jason PyeronJan 14, 2021
  4. 0/2 Option to modify revision mark for root commitsKyle Marek, Jan 17, 2021
  5. 1/2 revision: Denote root commits with '#'Kyle Marek, Jan 17, 2021
  6. Junio C HamanoJan 17, 2021
  7. Kyle MarekJan 18, 2021
  8. Junio C HamanoJan 18, 2021
  9. Junio C HamanoJan 18, 2021
  10. Kyle MarekJan 19, 2021
  11. Junio C HamanoJan 19, 2021
  12. Kyle MarekJan 20, 2021
  13. Junio C HamanoJan 20, 2021
  14. Jason PyeronJan 20, 2021
  15. Junio C HamanoJan 20, 2021
  16. Jason PyeronJan 20, 2021
  17. Junio C HamanoJan 23, 2021
  18. Jason PyeronJan 23, 2021
  19. Junio C HamanoJan 23, 2021
  20. Jason PyeronJan 24, 2021
  21. Junio C HamanoJan 25, 2021
  22. Junio C HamanoJan 17, 2021
  23. 2/2 revision: implement --show-linear-break for --graphKyle Marek, Jan 17, 2021
  24. Junio C HamanoJan 17, 2021
  25. Junio C HamanoJan 18, 2021
  26. Kyle MarekJan 18, 2021
  27. Junio C HamanoJan 18, 2021
  28. Kyle MarekJan 19, 2021
  29. Junio C HamanoJan 15, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.