revision.c: ignore broken tags with ignore_missing_links

When peeling a tag for prepare_revision_walk(), we do not respect the ignore_missing_links flag. This can lead to a bogus error when pack-objects walks the possibly-broken unreachable-but-recent part of the object graph. The other link-following all happens via traverse_commit_list(), which explains why this case was missed. And our tests covered only broken links from commits. Let's be more comprehensive and cover broken tree entries (which do work) and tags (which shows off this bug). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 20, 2017 at 04:30 UTC a3ba6bf10abcaed1819d27fa45675c3a0e141f95
2 files changed +27 -2
revision.c
+1 -1
@@ -230,7 +230,7 @@ static struct commit *handle_commit(struct rev_info *revs,
230 die("bad tag");
231 object = parse_object(tag->tagged->oid.hash);
232 if (!object) {
233 - if (flags & UNINTERESTING)
233 + if (revs->ignore_missing_links || (flags & UNINTERESTING))
234 return NULL;
235 die("bad object %s", oid_to_hex(&tag->tagged->oid));
236 }
t/t6501-freshen-objects.sh
+26 -1
@@ -129,7 +129,7 @@ for repack in '' true; do
129 '
130 done
131
132 -test_expect_success 'do not complain about existing broken links' '
132 +test_expect_success 'do not complain about existing broken links (commit)' '
133 cat >broken-commit <<-\EOF &&
134 tree 0000000000000000000000000000000000000001
135 parent 0000000000000000000000000000000000000002
@@ -144,4 +144,29 @@ test_expect_success 'do not complain about existing broken links' '
144 test_must_be_empty stderr
145 '
146
147 +test_expect_success 'do not complain about existing broken links (tree)' '
148 + cat >broken-tree <<-\EOF &&
149 + 100644 blob 0000000000000000000000000000000000000003 foo
150 + EOF
151 + tree=$(git mktree --missing <broken-tree) &&
152 + git gc 2>stderr &&
153 + git cat-file -e $tree &&
154 + test_must_be_empty stderr
155 +'
156 +
157 +test_expect_success 'do not complain about existing broken links (tag)' '
158 + cat >broken-tag <<-\EOF &&
159 + object 0000000000000000000000000000000000000004
160 + type commit
161 + tag broken
162 + tagger whatever <whatever@example.com> 1234 -0000
163 +
164 + this is a broken tag
165 + EOF
166 + tag=$(git hash-object -t tag -w broken-tag) &&
167 + git gc 2>stderr &&
168 + git cat-file -e $tag &&
169 + test_must_be_empty stderr
170 +'
171 +
172 test_done