1
0
mirror of https://github.com/git/git.git synced 2024-09-29 05:01:36 +02:00

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>
This commit is contained in:
Derrick Stolee 2020-10-09 20:53:52 +00:00 committed by Junio C Hamano
parent 150f11574b
commit 85102ac71b
3 changed files with 10 additions and 2 deletions

@ -39,7 +39,9 @@ COMMANDS
--------
'write'::
Write a commit-graph file based on the commits found in packfiles.
Write a commit-graph file based on the commits found in packfiles. If
the config option `core.commitGraph` is disabled, then this command will
output a warning, then return success without writing a commit-graph file.
+
With the `--stdin-packs` option, generate the new commit graph by
walking objects only in the specified pack-indexes. (Cannot be combined

@ -2062,6 +2062,11 @@ int write_commit_graph(struct object_directory *odb,
int res = 0;
int replace = 0;
prepare_repo_settings(the_repository);
if (!the_repository->settings.core_commit_graph) {
warning(_("attempting to write a commit-graph, but 'core.commitGraph' is disabled"));
return 0;
}
if (!commit_graph_compatible(the_repository))
return 0;

@ -440,8 +440,9 @@ test_expect_success '--split=replace with partial Bloom data' '
test_expect_success 'prevent regression for duplicate commits across layers' '
git init dup &&
git -C dup config core.commitGraph false &&
git -C dup commit --allow-empty -m one &&
git -C dup -c core.commitGraph=false commit-graph write --split=no-merge --reachable 2>err &&
test_i18ngrep "attempting to write a commit-graph" err &&
git -C dup commit-graph write --split=no-merge --reachable &&
git -C dup commit --allow-empty -m two &&
git -C dup commit-graph write --split=no-merge --reachable &&