git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] revision: fix --missing=[print|allow*] for annotated tags

From
Christian Couder <christian.couder@gmail.com>
Date
Feb 28, 2024, 09:10 UTC
Message-ID
<20240228091011.3652532-1-christian.couder@gmail.com>
In-Reply-To
<20240214142513.4002639-1-christian.couder@gmail.com>

In 9830926c7d (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 <chriscool@tuxfamily.org>
---

This is a follow up to cc/rev-list-allow-missing-tips which is in 'next' and scheduled to be merged to 'master'. So it depends on that branch.

 revision.c                  |  8 +++++++-
 t/t6022-rev-list-missing.sh | 24 ++++++++++++++++++------
 2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/revision.c b/revision.c
index 0c7266b1eb..8f0d638af1 100644
--- a/revision.c
+++ b/revision.c
@@ -419,15 +419,21 @@ static struct commit *handle_commit(struct rev_info *revs,
 	 */
 	while (object->type == OBJ_TAG) {
 		struct tag *tag = (struct tag *) object;
+		struct object_id *oid;
 		if (revs->tag_objects && !(flags & UNINTERESTING))
 			add_pending_object(revs, object, tag->tag);
-		object = parse_object(revs->repo, get_tagged_oid(tag));
+		oid = get_tagged_oid(tag);
+		object = parse_object(revs->repo, oid);
 		if (!object) {
 			if (revs->ignore_missing_links || (flags & UNINTERESTING))
 				return NULL;
 			if (revs->exclude_promisor_objects &&
 			    is_promisor_object(&tag->tagged->oid))
 				return NULL;
+			if (revs->do_not_die_on_missing_objects && oid) {
+				oidset_insert(&revs->missing_commits, oid);
+				return NULL;
+			}
 			die("bad object %s", oid_to_hex(&tag->tagged->oid));
 		}
 		object->flags |= flags;
diff --git a/t/t6022-rev-list-missing.sh b/t/t6022-rev-list-missing.sh
index 78387eebb3..127180e1c9 100755
--- a/t/t6022-rev-list-missing.sh
+++ b/t/t6022-rev-list-missing.sh
@@ -10,7 +10,10 @@ TEST_PASSES_SANITIZE_LEAK=true
 test_expect_success 'create repository and alternate directory' '
 	test_commit 1 &&
 	test_commit 2 &&
-	test_commit 3
+	test_commit 3 &&
+	git tag -m "tag message" annot_tag HEAD~1 &&
+	git tag regul_tag HEAD~1 &&
+	git branch a_branch HEAD~1
 '
 
 # We manually corrupt the repository, which means that the commit-graph may
@@ -78,7 +81,7 @@ do
 	done
 done
 
-for missing_tip in "HEAD~1" "HEAD~1^{tree}" "HEAD:1.t"
+for missing_tip in "annot_tag" "regul_tag" "a_branch" "HEAD~1" "HEAD~1^{tree}" "HEAD:1.t"
 do
 	# We want to check that things work when both
 	#   - all the tips passed are missing (case existing_tip = ""), and
@@ -88,9 +91,6 @@ do
 		for action in "allow-any" "print"
 		do
 			test_expect_success "--missing=$action with tip '$missing_tip' missing and tip '$existing_tip'" '
-				oid="$(git rev-parse $missing_tip)" &&
-				path=".git/objects/$(test_oid_to_path $oid)" &&
-
 				# Before the object is made missing, we use rev-list to
 				# get the expected oids.
 				if test "$existing_tip" = "HEAD"
@@ -109,11 +109,23 @@ do
 					echo $(git rev-parse HEAD:2.t) >>expect.raw
 				fi &&
 
+				missing_oid="$(git rev-parse $missing_tip)" &&
+
+				if test "$missing_tip" = "annot_tag"
+				then
+					oid="$(git rev-parse $missing_tip^{commit})" &&
+					echo "$missing_oid" >>expect.raw
+				else
+					oid="$missing_oid"
+				fi &&
+
+				path=".git/objects/$(test_oid_to_path $oid)" &&
+
 				mv "$path" "$path.hidden" &&
 				test_when_finished "mv $path.hidden $path" &&
 
 				git rev-list --missing=$action --objects --no-object-names \
-				     $oid $existing_tip >actual.raw &&
+				     $missing_oid $existing_tip >actual.raw &&
 
 				# When the action is to print, we should also add the missing
 				# oid to the expect list.
-- 
2.44.0.297.g8ee07f1da4
Previous: Linus ArverNext: Junio C Hamano
Message 29 of 30 in “rev-list: allow missing tips with --missing”
  1. 0/4 rev-list: allow missing tips with --missingChristian Couder, Feb 8, 2024
  2. 1/4 revision: clarify a 'return NULL' in get_reference()Christian Couder, Feb 8, 2024
  3. 2/4 oidset: refactor oidset_insert_from_set()Christian Couder, Feb 8, 2024
  4. Junio C HamanoFeb 8, 2024
  5. Linus ArverFeb 13, 2024
  6. Christian CouderFeb 14, 2024
  7. Linus ArverFeb 16, 2024
  8. Christian CouderFeb 16, 2024
  9. Linus ArverFeb 16, 2024
  10. 3/4 t6022: fix 'test' style and 'even though' typoChristian Couder, Feb 8, 2024
  11. 4/4 rev-list: allow missing tips with --missing=[print|allow*]Christian Couder, Feb 8, 2024
  12. Junio C HamanoFeb 8, 2024
  13. Linus ArverFeb 13, 2024
  14. Christian CouderFeb 14, 2024
  15. Junio C HamanoFeb 14, 2024
  16. Christian CouderFeb 14, 2024
  17. Linus ArverFeb 13, 2024
  18. Christian CouderFeb 14, 2024
  19. Linus ArverFeb 16, 2024
  20. Junio C HamanoFeb 8, 2024
  21. Christian CouderFeb 14, 2024
  22. 0/5 rev-list: allow missing tips with --missingChristian Couder, Feb 14, 2024
  23. 1/5 t9210: do not rely on lazy fetching to failChristian Couder, Feb 14, 2024
  24. 2/5 revision: clarify a 'return NULL' in get_reference()Christian Couder, Feb 14, 2024
  25. 3/5 oidset: refactor oidset_insert_from_set()Christian Couder, Feb 14, 2024
  26. 4/5 t6022: fix 'test' style and 'even though' typoChristian Couder, Feb 14, 2024
  27. 5/5 rev-list: allow missing tips with --missing=[print|allow*]Christian Couder, Feb 14, 2024
  28. Linus ArverFeb 16, 2024
  29. revision: fix --missing=[print|allow*] for annotated tagsChristian Couder, Feb 28, 2024
  30. Junio C HamanoFeb 28, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.