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

[PATCH v2] log: add --nonlinear-barrier to help see non-linear history

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Mar 17, 2014, 12:51 UTC
Message-ID
<1395060676-23144-1-git-send-email-pclouds@gmail.com>
In-Reply-To
<1391867417-979-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 v2 renames the option name to --nonlinear-barrier and fixes using it
 with --dense. Best used with --no-merges to see patch series.
 Documentation/rev-list-options.txt |  7 ++++++
 log-tree.c                         |  4 +++
 revision.c                         | 51 +++++++++++++++++++++++++++++++++++---
 revision.h                         |  6 +++++
 4 files changed, 65 insertions(+), 3 deletions(-)
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index 03533af..435aa2d 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -750,6 +750,13 @@ This enables parent rewriting, see 'History Simplification' below.
 This implies the `--topo-order` option by default, but the
 `--date-order` option may also be specified.
 
+--nonlinear-barrier[=<barrier>]::
+	When --graph is not used, all history branches are flatten and
+	could be hard to see that the two consecutive commits 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.
+
 ifdef::git-rev-list[]
 --count::
 	Print a number stating how many commits would have been
diff --git a/log-tree.c b/log-tree.c
index 08970bf..17862f6 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -805,12 +805,16 @@ 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)
+		printf("\n%s\n", opt->break_bar);
 	shown = log_tree_diff(opt, commit, &log);
 	if (!shown && opt->loginfo && opt->always_show_header) {
 		log.parent = NULL;
 		show_log(opt);
 		shown = 1;
 	}
+	if (opt->track_linear && !opt->linear && opt->reverse_output_stage)
+		printf("\n%s\n", opt->break_bar);
 	opt->loginfo = NULL;
 	maybe_flush_or_die(stdout, "stdout");
 	return shown;
diff --git a/revision.c b/revision.c
index a68fde6..0a4849e 100644
--- a/revision.c
+++ b/revision.c
@@ -1832,6 +1832,12 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 		revs->notes_opt.use_default_notes = 1;
 	} else if (!strcmp(arg, "--show-signature")) {
 		revs->show_signature = 1;
+	} else if (!strcmp(arg, "--nonlinear-barrier")) {
+		revs->track_linear = 1;
+		revs->break_bar = "                    ..........";
+	} else if (starts_with(arg, "--nonlinear-barrier=")) {
+		revs->track_linear = 1;
+		revs->break_bar = xstrdup(arg + 20);
 	} else if (starts_with(arg, "--show-notes=") ||
 		   starts_with(arg, "--notes=")) {
 		struct strbuf buf = STRBUF_INIT;
@@ -2897,6 +2903,32 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
 	return action;
 }
 
+define_commit_slab(saved_linear, int);
+
+static void track_linear(struct rev_info *revs, struct commit *commit)
+{
+	struct commit_list *p = revs->previous_parents;
+
+	if (p) {
+		int got_parent = 0;
+		for (; p && !got_parent; p = p->next)
+			got_parent = !hashcmp(p->item->object.sha1,
+					      commit->object.sha1);
+		revs->linear = got_parent;
+		free_commit_list(revs->previous_parents);
+	} else
+		revs->linear = 1;
+	if (revs->reverse) {
+		if (!revs->saved_linear_slab) {
+			revs->saved_linear_slab = xmalloc(sizeof(struct saved_linear));
+			init_saved_linear(revs->saved_linear_slab);
+		}
+
+		*saved_linear_at(revs->saved_linear_slab, commit) = revs->linear;
+	}
+	revs->previous_parents = copy_commit_list(commit->parents);
+}
+
 static struct commit *get_revision_1(struct rev_info *revs)
 {
 	if (!revs->commits)
@@ -2936,6 +2968,8 @@ static struct commit *get_revision_1(struct rev_info *revs)
 			die("Failed to simplify parents of commit %s",
 			    sha1_to_hex(commit->object.sha1));
 		default:
+			if (revs->track_linear)
+				track_linear(revs, commit);
 			return commit;
 		}
 	} while (revs->commits);
@@ -3102,14 +3136,25 @@ struct commit *get_revision(struct rev_info *revs)
 		revs->reverse_output_stage = 1;
 	}
 
-	if (revs->reverse_output_stage)
-		return pop_commit(&revs->commits);
+	if (revs->reverse_output_stage) {
+		c = pop_commit(&revs->commits);
+		if (revs->track_linear)
+			revs->linear = *saved_linear_at(revs->saved_linear_slab, c);
+		return c;
+	}
 
 	c = get_revision_internal(revs);
 	if (c && revs->graph)
 		graph_update(revs->graph, c);
-	if (!c)
+	if (!c) {
 		free_saved_parents(revs);
+		if (revs->saved_linear_slab)
+			clear_saved_linear(revs->saved_linear_slab);
+		if (revs->previous_parents) {
+			free_commit_list(revs->previous_parents);
+			revs->previous_parents = NULL;
+		}
+	}
 	return c;
 }
 
diff --git a/revision.h b/revision.h
index 88967d6..bffdc15 100644
--- a/revision.h
+++ b/revision.h
@@ -134,6 +134,7 @@ struct rev_info {
 			use_terminator:1,
 			missing_newline:1,
 			date_mode_explicit:1,
+			track_linear:1,
 			preserve_subject:1;
 	unsigned int	disable_stdin:1;
 	unsigned int	leak_pending:1;
@@ -195,6 +196,11 @@ struct rev_info {
 
 	/* copies of the parent lists, for --full-diff display */
 	struct saved_parents *saved_parents_slab;
+
+	struct commit_list *previous_parents;
+	struct saved_linear *saved_linear_slab;
+	char *break_bar;
+	unsigned int linear;
 };
 
 extern int ref_excluded(struct string_list *, const char *path);
-- 
1.9.0.40.gaa8c3ea
Previous: Nguyễn Thái Ngọc DuyNext: Eric Sunshine
Message 8 of 19 in “Confusing git log --- First time bug submission please advise on best practices”
  1. Francis StephensFeb 6, 2014
  2. Vincent van RavesteijnFeb 6, 2014
  3. David KastrupFeb 6, 2014
  4. Francis StephensFeb 7, 2014
  5. Duy NguyenFeb 7, 2014
  6. demerphqFeb 7, 2014
  7. log: add --show-linear-break to help see non-linear historyNguyễn Thái Ngọc Duy, Feb 8, 2014
  8. log: add --nonlinear-barrier to help see non-linear historyNguyễn Thái Ngọc Duy, Mar 17, 2014
  9. Eric SunshineMar 17, 2014
  10. Junio C HamanoMar 17, 2014
  11. Duy NguyenMar 18, 2014
  12. Junio C HamanoMar 18, 2014
  13. 1/2 object.h: centralize object flag allocationNguyễn Thái Ngọc Duy, Mar 20, 2014
  14. 2/2 log: add --show-linear-break to help see non-linear historyNguyễn Thái Ngọc Duy, Mar 20, 2014
  15. Junio C HamanoMar 20, 2014
  16. Duy NguyenMar 21, 2014
  17. 1/2 object.h: centralize object flag allocationNguyễn Thái Ngọc Duy, Mar 25, 2014
  18. 2/2 log: add --show-linear-break to help see non-linear historyNguyễn Thái Ngọc Duy, Mar 25, 2014
  19. Junio C HamanoMar 25, 2014

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.