Skip to content

Commit a4324ba

Browse files
chriscoolgitster
authored andcommitted
revision: fix --missing=[print|allow*] for annotated tags
In 9830926 (rev-list: add commit object support in `--missing` option, 2023-10-27) we fixed the `--missing` option in `git rev-list` so that it works with missing commits, not just blobs/trees. Unfortunately, such a command was still failing with a "fatal: bad object <oid>" if it was passed a missing commit, blob or tree as an argument (before the rev walking even begins). This was fixed in a recent commit. That fix still doesn't work when an argument passed to the command is an annotated tag pointing to a missing commit though. In that case `git rev-list --missing=...` still errors out with a "fatal: bad object <oid>" error where <oid> is the object ID of the missing commit. Let's fix this issue, and also, while at it, let's add tests not just for annotated tags but also for regular tags and branches. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7b644c8 commit a4324ba

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

revision.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,21 @@ static struct commit *handle_commit(struct rev_info *revs,
419419
*/
420420
while (object->type == OBJ_TAG) {
421421
struct tag *tag = (struct tag *) object;
422+
struct object_id *oid;
422423
if (revs->tag_objects && !(flags & UNINTERESTING))
423424
add_pending_object(revs, object, tag->tag);
424-
object = parse_object(revs->repo, get_tagged_oid(tag));
425+
oid = get_tagged_oid(tag);
426+
object = parse_object(revs->repo, oid);
425427
if (!object) {
426428
if (revs->ignore_missing_links || (flags & UNINTERESTING))
427429
return NULL;
428430
if (revs->exclude_promisor_objects &&
429431
is_promisor_object(&tag->tagged->oid))
430432
return NULL;
433+
if (revs->do_not_die_on_missing_objects && oid) {
434+
oidset_insert(&revs->missing_commits, oid);
435+
return NULL;
436+
}
431437
die("bad object %s", oid_to_hex(&tag->tagged->oid));
432438
}
433439
object->flags |= flags;

t/t6022-rev-list-missing.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ TEST_PASSES_SANITIZE_LEAK=true
1010
test_expect_success 'create repository and alternate directory' '
1111
test_commit 1 &&
1212
test_commit 2 &&
13-
test_commit 3
13+
test_commit 3 &&
14+
git tag -m "tag message" annot_tag HEAD~1 &&
15+
git tag regul_tag HEAD~1 &&
16+
git branch a_branch HEAD~1
1417
'
1518

1619
# We manually corrupt the repository, which means that the commit-graph may
@@ -78,7 +81,7 @@ do
7881
done
7982
done
8083

81-
for missing_tip in "HEAD~1" "HEAD~1^{tree}" "HEAD:1.t"
84+
for missing_tip in "annot_tag" "regul_tag" "a_branch" "HEAD~1" "HEAD~1^{tree}" "HEAD:1.t"
8285
do
8386
# We want to check that things work when both
8487
# - all the tips passed are missing (case existing_tip = ""), and
@@ -88,9 +91,6 @@ do
8891
for action in "allow-any" "print"
8992
do
9093
test_expect_success "--missing=$action with tip '$missing_tip' missing and tip '$existing_tip'" '
91-
oid="$(git rev-parse $missing_tip)" &&
92-
path=".git/objects/$(test_oid_to_path $oid)" &&
93-
9494
# Before the object is made missing, we use rev-list to
9595
# get the expected oids.
9696
if test "$existing_tip" = "HEAD"
@@ -109,11 +109,23 @@ do
109109
echo $(git rev-parse HEAD:2.t) >>expect.raw
110110
fi &&
111111
112+
missing_oid="$(git rev-parse $missing_tip)" &&
113+
114+
if test "$missing_tip" = "annot_tag"
115+
then
116+
oid="$(git rev-parse $missing_tip^{commit})" &&
117+
echo "$missing_oid" >>expect.raw
118+
else
119+
oid="$missing_oid"
120+
fi &&
121+
122+
path=".git/objects/$(test_oid_to_path $oid)" &&
123+
112124
mv "$path" "$path.hidden" &&
113125
test_when_finished "mv $path.hidden $path" &&
114126
115127
git rev-list --missing=$action --objects --no-object-names \
116-
$oid $existing_tip >actual.raw &&
128+
$missing_oid $existing_tip >actual.raw &&
117129
118130
# When the action is to print, we should also add the missing
119131
# oid to the expect list.

0 commit comments

Comments
 (0)