Skip to content

Commit 6afc679

Browse files
ttaylorrgitster
authored andcommitted
midx-write: include packs above custom incremental base
The previous commit made '--base' take effect on the normal incremental write path, which exposed an existing assumption in our helper function `should_include_pack()`, which is that any pack already present in `ctx->m` was skipped. That is only correct for non-incremental writes. For incremental writes, `ctx->base_midx` is the boundary that should be excluded from the new layer. If the caller selects an older base, or no base at all, then packs from layers above that base have to be included in the detached layer so that its bitmap has reachability closure. Teach `should_include_pack()` to choose the MIDX used for pack exclusion based on whether or not we are performing an incremental write. When doing so, use `ctx->base_midx`, and use `ctx->m` otherwise. The t5334 cases from the previous commit can now be marked as successful. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 8e519b8 commit 6afc679

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

midx-write.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,17 @@ static uint32_t midx_pack_perm(struct write_midx_context *ctx,
133133
static int should_include_pack(const struct write_midx_context *ctx,
134134
const char *file_name)
135135
{
136+
struct multi_pack_index *m = ctx->m;
136137
/*
137-
* Note that at most one of ctx->m and ctx->to_include are set,
138+
* When writing incrementally, ctx->m may contain layers above
139+
* the selected base MIDX, which must be included in the new
140+
* layer.
141+
*/
142+
if (ctx->incremental)
143+
m = ctx->base_midx;
144+
145+
/*
146+
* Note that at most one of m and ctx->to_include are set,
138147
* so we are testing midx_contains_pack() and
139148
* string_list_has_string() independently (guarded by the
140149
* appropriate NULL checks).
@@ -148,10 +157,7 @@ static int should_include_pack(const struct write_midx_context *ctx,
148157
* should be performed independently (likely checking
149158
* to_include before the existing MIDX).
150159
*/
151-
if (ctx->m && midx_contains_pack(ctx->m, file_name))
152-
return 0;
153-
else if (ctx->base_midx && midx_contains_pack(ctx->base_midx,
154-
file_name))
160+
if (m && midx_contains_pack(m, file_name))
155161
return 0;
156162
else if (ctx->to_include &&
157163
!string_list_has_string(ctx->to_include, file_name))

t/t5334-incremental-multi-pack-index.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ test_expect_success 'write MIDX layer with --base without --no-write-chain-file'
119119
test_grep "cannot use --base without --no-write-chain-file" err
120120
'
121121

122-
test_expect_failure 'write MIDX layer with --base=none and --no-write-chain-file' '
122+
test_expect_success 'write MIDX layer with --base=none and --no-write-chain-file' '
123123
test_commit base-none &&
124124
git repack -d &&
125125
@@ -136,7 +136,7 @@ test_expect_failure 'write MIDX layer with --base=none and --no-write-chain-file
136136
cp "$midx_chain.bak" "$midx_chain"
137137
'
138138

139-
test_expect_failure 'write MIDX layer with --base=<hash> and --no-write-chain-file' '
139+
test_expect_success 'write MIDX layer with --base=<hash> and --no-write-chain-file' '
140140
test_commit base-hash &&
141141
git repack -d &&
142142

0 commit comments

Comments
 (0)