]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/pack-objects.c: ignore missing links with --stdin-packs
authorTaylor Blau <me@ttaylorr.com>
Fri, 19 Mar 2021 15:40:52 +0000 (11:40 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 19 Mar 2021 18:19:29 +0000 (11:19 -0700)
When 'git pack-objects --stdin-packs' encounters a commit in a pack, it
marks it as a starting point of a best-effort reachability traversal
that is used to populate the name-hash of the objects listed in the
given packs.

The traversal expects that it should be able to walk the ancestors of
all commits in a pack without issue. Ordinarily this is the case, but it
is possible to having missing parents from an unreachable part of the
repository. In that case, we'd consider any missing objects in the
unreachable portion of the graph to be junk.

This should be handled gracefully: since the traversal is best-effort
(i.e., we don't strictly need to fill in all of the name-hash fields),
we should simply ignore any missing links.

This patch does that (by setting the 'ignore_missing_links' bit on the
rev_info struct), and ensures we don't regress in the future by adding a
test which demonstrates this case.

It is a little over-eager, since it will also ignore missing links in
reachable parts of the packs (which would indicate a corrupted
repository), but '--stdin-packs' is explicitly *not* about reachability.
So this step isn't making anything worse for a repository which contains
packs missing reachable objects (since we never drop objects with
'--stdin-packs').

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/pack-objects.c
t/t5300-pack-object.sh

index 8cb32763b7d30f9633a0d30a4624ad0f0c1426d4..f513138513f0cc06b03b815c89ede19e4f435d6b 100644 (file)
@@ -3122,6 +3122,7 @@ static void read_packs_list_from_stdin(void)
        revs.blob_objects = 1;
        revs.tree_objects = 1;
        revs.tag_objects = 1;
+       revs.ignore_missing_links = 1;
 
        while (strbuf_getline(&buf, stdin) != EOF) {
                if (!buf.len)
index 7138a54595061a057d8f9fbdffae1dfcf8c14bb7..ab509e8c382a2a6bf49f29c50f2745b4f58b5166 100755 (executable)
@@ -629,4 +629,42 @@ test_expect_success '--stdin-packs with loose objects' '
        )
 '
 
+test_expect_success '--stdin-packs with broken links' '
+       (
+               cd stdin-packs &&
+
+               # make an unreachable object with a bogus parent
+               git cat-file -p HEAD >commit &&
+               sed "s/$(git rev-parse HEAD^)/$(test_oid zero)/" <commit |
+               git hash-object -w -t commit --stdin >in &&
+
+               git pack-objects .git/objects/pack/pack-D <in &&
+
+               PACK_A="$(basename .git/objects/pack/pack-A-*.pack)" &&
+               PACK_B="$(basename .git/objects/pack/pack-B-*.pack)" &&
+               PACK_C="$(basename .git/objects/pack/pack-C-*.pack)" &&
+               PACK_D="$(basename .git/objects/pack/pack-D-*.pack)" &&
+
+               git pack-objects test3 --stdin-packs --unpacked <<-EOF &&
+               $PACK_A
+               ^$PACK_B
+               $PACK_C
+               $PACK_D
+               EOF
+
+               (
+                       git show-index <$(ls .git/objects/pack/pack-A-*.idx) &&
+                       git show-index <$(ls .git/objects/pack/pack-C-*.idx) &&
+                       git show-index <$(ls .git/objects/pack/pack-D-*.idx) &&
+                       git rev-list --objects --no-object-names \
+                               refs/tags/C..refs/tags/D
+               ) >expect.raw &&
+               git show-index <$(ls test3-*.idx) >actual.raw &&
+
+               cut -d" " -f2 <expect.raw | sort >expect &&
+               cut -d" " -f2 <actual.raw | sort >actual &&
+               test_cmp expect actual
+       )
+'
+
 test_done