Skip to content

Commit a217810

Browse files
peffgitster
authored andcommitted
index-pack: downgrade twice-resolved REF_DELTA to die()
When we're resolving a REF_DELTA, we compare-and-swap its type from REF_DELTA to whatever real type the base object has, as discussed in ab791dd (index-pack: fix race condition with duplicate bases, 2014-08-29). If the old type wasn't a REF_DELTA, we consider that a BUG(). But as discussed in that commit, we might see this case whenever we try to resolve an object twice, which may happen because we have multiple copies of the base object. So this isn't a bug at all, but rather a sign that the input pack is broken. And indeed, this case is triggered already in t5309.5 and t5309.6, which create packs with delta cycles and duplicate bases. But we never noticed because those tests are marked expect_failure. Those tests were added by b2ef3d9 (test index-pack on packs with recoverable delta cycles, 2013-08-23), which was leaving the door open for cases that we theoretically _could_ handle. And when we see an already-resolved object like this, in theory we could keep going after confirming that the previously resolved child->real_type matches base->obj->real_type. But: - enforcing the "only resolve once" rule here saves us from an infinite loop in other parts of the code. If we keep going, then the delta cycle in t5309.5 causes us to loop infinitely, as find_ref_delta_children() doesn't realize which objects have already been resolved. So there would be more changes needed to make this case work, and in the meantime we'd be worse off. - any pack that triggers this is broken anyway. It either has a duplicate base object, or it has a cycle which causes us to bring in a duplicate via --fix-thin. In either case, we'd end up rejecting the pack in write_idx_file(), which also detects duplicates. So the tests have little value in documenting what we _could_ be doing (and have been neglected for 6+ years). Let's switch them to confirming that we handle this case cleanly (and switch out the BUG() for a more informative die() so that we do so). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b6d4d82 commit a217810

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

builtin/index-pack.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,9 @@ static struct base_data *find_unresolved_deltas_1(struct base_data *base,
10031003

10041004
if (!compare_and_swap_type(&child->real_type, OBJ_REF_DELTA,
10051005
base->obj->real_type))
1006-
BUG("child->real_type != OBJ_REF_DELTA");
1006+
die("REF_DELTA at offset %"PRIuMAX" already resolved (duplicate base %s?)",
1007+
(uintmax_t)child->idx.offset,
1008+
oid_to_hex(&base->obj->idx.oid));
10071009

10081010
resolve_delta(child, base, result);
10091011
if (base->ref_first == base->ref_last && base->ofs_last == -1)

t/t5309-pack-delta-cycles.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ test_expect_success 'index-pack detects REF_DELTA cycles' '
6262
test_must_fail git index-pack --fix-thin --stdin <cycle.pack
6363
'
6464

65-
test_expect_failure 'failover to an object in another pack' '
65+
test_expect_success 'failover to an object in another pack' '
6666
clear_packs &&
6767
git index-pack --stdin <ab.pack &&
68-
git index-pack --stdin --fix-thin <cycle.pack
68+
test_must_fail git index-pack --stdin --fix-thin <cycle.pack
6969
'
7070

71-
test_expect_failure 'failover to a duplicate object in the same pack' '
71+
test_expect_success 'failover to a duplicate object in the same pack' '
7272
clear_packs &&
7373
{
7474
pack_header 3 &&
@@ -77,7 +77,7 @@ test_expect_failure 'failover to a duplicate object in the same pack' '
7777
pack_obj $A
7878
} >recoverable.pack &&
7979
pack_trailer recoverable.pack &&
80-
git index-pack --fix-thin --stdin <recoverable.pack
80+
test_must_fail git index-pack --fix-thin --stdin <recoverable.pack
8181
'
8282

8383
test_done

0 commit comments

Comments
 (0)