@matheusbsbs / matheus-bagliano / commits / 85102ac71b
Fork 0

commit-graph: don't write commit-graph when disabled

The core.commitGraph config setting can be set to 'false' to prevent parsing commits from the commit-graph file(s). This causes an issue when trying to write with "--split" which needs to distinguish between commits that are in the existing commit-graph layers and commits that are not. The existing mechanism uses parse_commit() and follows by checking if there is a 'graph_pos' that shows the commit was parsed from the commit-graph file. When core.commitGraph=false, we do not parse the commits from the commit-graph and 'graph_pos' indicates that no commits are in the existing file. The --split logic moves forward creating a new layer on top that holds all reachable commits, then possibly merges down into those layers, resulting in duplicate commits. The previous change makes that merging process more robust to such a situation in case it happens in the written commit-graph data. The easy answer here is to avoid writing a commit-graph if reading the commit-graph is disabled. Since the resulting commit-graph will would not be read by subsequent Git processes. This is more natural than forcing core.commitGraph to be true for the 'write' process. Reported-by: Thomas Braun <thomas.braun@virtuell-zuhause.de> Helped-by: Jeff King <peff@peff.net> Helped-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Oct 9, 2020 at 20:53 UTC 85102ac71b98466eaa2b9b5a568c3a1de736202d
3 files changed +10 -2
Documentation/git-commit-graph.txt
+3 -1
@@ -39,7 +39,9 @@ COMMANDS
39 --------
40 'write'::
41
42 -Write a commit-graph file based on the commits found in packfiles.
42 +Write a commit-graph file based on the commits found in packfiles. If
43 +the config option `core.commitGraph` is disabled, then this command will
44 +output a warning, then return success without writing a commit-graph file.
45 +
46 With the `--stdin-packs` option, generate the new commit graph by
47 walking objects only in the specified pack-indexes. (Cannot be combined
commit-graph.c
+5
@@ -2062,6 +2062,11 @@ int write_commit_graph(struct object_directory *odb,
2062 int res = 0;
2063 int replace = 0;
2064
2065 + prepare_repo_settings(the_repository);
2066 + if (!the_repository->settings.core_commit_graph) {
2067 + warning(_("attempting to write a commit-graph, but 'core.commitGraph' is disabled"));
2068 + return 0;
2069 + }
2070 if (!commit_graph_compatible(the_repository))
2071 return 0;
2072
t/t5324-split-commit-graph.sh
+2 -1
@@ -440,8 +440,9 @@ test_expect_success '--split=replace with partial Bloom data' '
440
441 test_expect_success 'prevent regression for duplicate commits across layers' '
442 git init dup &&
443 - git -C dup config core.commitGraph false &&
443 git -C dup commit --allow-empty -m one &&
444 + git -C dup -c core.commitGraph=false commit-graph write --split=no-merge --reachable 2>err &&
445 + test_i18ngrep "attempting to write a commit-graph" err &&
446 git -C dup commit-graph write --split=no-merge --reachable &&
447 git -C dup commit --allow-empty -m two &&
448 git -C dup commit-graph write --split=no-merge --reachable &&