summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--commit-graph.c16
-rwxr-xr-xt/t5324-split-commit-graph.sh25
2 files changed, 38 insertions, 3 deletions
diff --git a/commit-graph.c b/commit-graph.c
index 1af68c297d..d3e2ee4bf2 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1911,7 +1911,7 @@ static int commit_compare(const void *_a, const void *_b)
static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
{
- uint32_t i;
+ uint32_t i, dedup_i = 0;
if (ctx->report_progress)
ctx->progress = start_delayed_progress(
@@ -1926,17 +1926,27 @@ static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
if (i && oideq(&ctx->commits.list[i - 1]->object.oid,
&ctx->commits.list[i]->object.oid)) {
- die(_("unexpected duplicate commit id %s"),
- oid_to_hex(&ctx->commits.list[i]->object.oid));
+ /*
+ * Silently ignore duplicates. These were likely
+ * created due to a commit appearing in multiple
+ * layers of the chain, which is unexpected but
+ * not invalid. We should make sure there is a
+ * unique copy in the new layer.
+ */
} else {
unsigned int num_parents;
+ ctx->commits.list[dedup_i] = ctx->commits.list[i];
+ dedup_i++;
+
num_parents = commit_list_count(ctx->commits.list[i]->parents);
if (num_parents > 2)
ctx->num_extra_edges += num_parents - 1;
}
}
+ ctx->commits.nr = dedup_i;
+
stop_progress(&ctx->progress);
}
diff --git a/t/t5324-split-commit-graph.sh b/t/t5324-split-commit-graph.sh
index 269d0964a3..82f22c8c44 100755
--- a/t/t5324-split-commit-graph.sh
+++ b/t/t5324-split-commit-graph.sh
@@ -425,4 +425,29 @@ done <<\EOF
0600 -r--------
EOF
+test_expect_success '--split=replace with partial Bloom data' '
+ rm -rf $graphdir $infodir/commit-graph &&
+ git reset --hard commits/3 &&
+ git rev-list -1 HEAD~2 >a &&
+ git rev-list -1 HEAD~1 >b &&
+ git commit-graph write --split=no-merge --stdin-commits --changed-paths <a &&
+ git commit-graph write --split=no-merge --stdin-commits <b &&
+ git commit-graph write --split=replace --stdin-commits --changed-paths <c &&
+ ls $graphdir/graph-*.graph >graph-files &&
+ test_line_count = 1 graph-files &&
+ verify_chain_files_exist $graphdir
+'
+
+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 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 &&
+ git -C dup commit --allow-empty -m three &&
+ git -C dup commit-graph write --split --reachable &&
+ git -C dup commit-graph verify
+'
+
test_done