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

[PATCH 3/7] builtin/commit-graph.c: introduce split strategy 'no-merge'

From
Taylor Blau <me@ttaylorr.com>
Date
Apr 14, 2020, 04:04 UTC
Message-ID
<2741858596ce9cd48aa0e3d126310435166d37ab.1586836700.git.me@ttaylorr.com>
In-Reply-To
<cover.1586836700.git.me@ttaylorr.com>

In the previous commit, we laid the groundwork for supporting different splitting strategies. In this commit, we introduce the first splitting strategy: 'no-merge'.

Passing '--split=no-merge' is useful for callers which wish to write a new incremental commit-graph, but do not want to spend effort condensing the incremental chain [1]. Previously, this was possible by passing '--size-multiple=0', but this no longer the case following 63020f175f (commit-graph: prefer default size_mult when given zero, 2020-01-02).

When '--split=no-merge' is given, the commit-graph machinery will never condense an existing chain, and it will always write a new incremental.

[1]: This might occur when, for example, a server administrator running some program after each push may want to ensure that each job runs proportional in time to the size of the push, and does not "jump" when the commit-graph machinery decides to trigger a merge.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 Documentation/git-commit-graph.txt |  5 +++++
 builtin/commit-graph.c             |  7 ++++++-
 commit-graph.c                     | 19 ++++++++++++-------
 commit-graph.h                     |  3 ++-
 t/t5324-split-commit-graph.sh      | 11 +++++++++++
 5 files changed, 36 insertions(+), 9 deletions(-)
diff --git a/Documentation/git-commit-graph.txt b/Documentation/git-commit-graph.txt
index 10d757c5cc..a4c4a641e5 100644
--- a/Documentation/git-commit-graph.txt
+++ b/Documentation/git-commit-graph.txt
@@ -63,6 +63,11 @@ chain of multiple commit-graph files stored in
 strategy and other splitting options. The new commits not already in the
 commit-graph are added in a new "tip" file. This file is merged with the
 existing file if the following merge conditions are met:
+* If `--split=no-merge` is specified, a merge is never performed, and
+the remaining options are ignored. A bare `--split` defers to the
+remaining options. (Note that merging a chain of commit graphs replaces
+the existing chain with a length-1 chain where the first and only
+incremental holds the entire graph).
 +
 * If `--size-multiple=<X>` is not specified, let `X` equal 2. If the new
 tip file would have `N` commits and the previous tip has `M` commits and
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 342094fc77..42182ed71c 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -121,11 +121,16 @@ static struct split_commit_graph_opts split_opts;
 static int write_option_parse_split(const struct option *opt, const char *arg,
 				    int unset)
 {
+	enum commit_graph_split_flags *flags = opt->value;
+
 	opts.split = 1;
 	if (!arg)
 		return 0;
 
-	die(_("unrecognized --split argument, %s"), arg);
+	if (!strcmp(arg, "no-merge"))
+		*flags = COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED;
+	else
+		die(_("unrecognized --split argument, %s"), arg);
 
 	return 0;
 }
diff --git a/commit-graph.c b/commit-graph.c
index f013a84e29..af3fe20bb5 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1529,6 +1529,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
 {
 	struct commit_graph *g;
 	uint32_t num_commits;
+	enum commit_graph_split_flags flags = COMMIT_GRAPH_SPLIT_UNSPECIFIED;
 	uint32_t i;
 
 	int max_commits = 0;
@@ -1539,21 +1540,25 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
 
 		if (ctx->split_opts->size_multiple)
 			size_mult = ctx->split_opts->size_multiple;
+
+		flags = ctx->split_opts->flags;
 	}
 
 	g = ctx->r->objects->commit_graph;
 	num_commits = ctx->commits.nr;
 	ctx->num_commit_graphs_after = ctx->num_commit_graphs_before + 1;
 
-	while (g && (g->num_commits <= size_mult * num_commits ||
-		    (max_commits && num_commits > max_commits))) {
-		if (g->odb != ctx->odb)
-			break;
+	if (flags != COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED) {
+		while (g && (g->num_commits <= size_mult * num_commits ||
+			    (max_commits && num_commits > max_commits))) {
+			if (g->odb != ctx->odb)
+				break;
 
-		num_commits += g->num_commits;
-		g = g->base_graph;
+			num_commits += g->num_commits;
+			g = g->base_graph;
 
-		ctx->num_commit_graphs_after--;
+			ctx->num_commit_graphs_after--;
+		}
 	}
 
 	ctx->new_base_graph = g;
diff --git a/commit-graph.h b/commit-graph.h
index e799008ff4..8752afb88d 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -83,7 +83,8 @@ enum commit_graph_write_flags {
 };
 
 enum commit_graph_split_flags {
-	COMMIT_GRAPH_SPLIT_UNSPECIFIED = 0
+	COMMIT_GRAPH_SPLIT_UNSPECIFIED      = 0,
+	COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED = 1
 };
 
 struct split_commit_graph_opts {
diff --git a/t/t5324-split-commit-graph.sh b/t/t5324-split-commit-graph.sh
index 53b2e6b455..1438d63f24 100755
--- a/t/t5324-split-commit-graph.sh
+++ b/t/t5324-split-commit-graph.sh
@@ -351,4 +351,15 @@ test_expect_success 'split across alternate where alternate is not split' '
 	test_cmp commit-graph .git/objects/info/commit-graph
 '
 
+test_expect_success '--split=no-merge always writes an incremental' '
+	test_when_finished rm -rf a b &&
+	rm -rf $graphdir $infodir/commit-graph &&
+	git reset --hard commits/2 &&
+	git rev-list HEAD~1 >a &&
+	git rev-list HEAD >b &&
+	git commit-graph write --split --stdin-commits <a &&
+	git commit-graph write --split=no-merge --stdin-commits <b &&
+	test_line_count = 2 $graphdir/commit-graph-chain
+'
+
 test_done
-- 
2.26.0.106.g9fadedd637
Previous: Taylor BlauNext: Taylor Blau
Message 4 of 19 in “commit-graph: split strategies, '--[no-]check-oids'”
  1. 0/7 commit-graph: split strategies, '--[no-]check-oids'Taylor Blau, Apr 14, 2020
  2. 1/7 t/helper/test-read-graph.c: support commit-graph chainsTaylor Blau, Apr 14, 2020
  3. 2/7 builtin/commit-graph.c: support for '--split[=<strategy>]'Taylor Blau, Apr 14, 2020
  4. 3/7 builtin/commit-graph.c: introduce split strategy 'no-merge'Taylor Blau, Apr 14, 2020
  5. 4/7 builtin/commit-graph.c: introduce split strategy 'replace'Taylor Blau, Apr 14, 2020
  6. 5/7 oidset: introduce 'oidset_size'Taylor Blau, Apr 14, 2020
  7. 6/7 commit-graph.h: replace 'commit_hex' with 'commits'Taylor Blau, Apr 14, 2020
  8. 7/7 commit-graph.c: introduce '--[no-]check-oids'Taylor Blau, Apr 14, 2020
  9. Taylor BlauApr 15, 2020
  10. Taylor BlauApr 15, 2020
  11. SZEDER GáborApr 22, 2020
  12. Taylor BlauApr 22, 2020
  13. SZEDER GáborApr 24, 2020
  14. Taylor BlauMay 1, 2020
  15. Jeff KingMay 3, 2020
  16. Junio C HamanoMay 3, 2020
  17. Jeff KingMay 4, 2020
  18. Junio C HamanoMay 4, 2020
  19. Taylor BlauMay 4, 2020

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.