diff mbox series

[v8,3/7] object-name: explicitly handle bad tags in show_ambiguous_object()

Message ID patch-v8-3.7-eaede34fa4f-20220127T052116Z-avarab@gmail.com (mailing list archive)
State Accepted
Commit 667a560be7ae977e61d81ca4bcb95ded1cdacc9c
Headers show
Series object-name: make ambiguous object output translatable + show tag date | expand

Commit Message

Ævar Arnfjörð Bjarmason Jan. 27, 2022, 5:26 a.m. UTC
Follow-up the handling of OBJ_BAD in the preceding commit and
explicitly handle those cases where parse_tag() fails, or we don't end
up with a non-NULL pointer in in tag->tag.

If we run into such a tag we'd previously be silent about it. We
really should also be handling these batter in parse_tag_buffer() by
being more eager to emit an error(), instead of silently aborting with
"return -1;".

One example of such a tag is the one that's tested for in
"t3800-mktag.sh", where the code takes the "size <
the_hash_algo->hexsz + 24" branch.

But in lieu of earlier missing "error" output let's show the user
something to indicate why we're not showing a tag message in these
cases, now instead of showing:

    hint:   deadbeef tag

We'll instead display:

    hint:   deadbeef tag [tag could not be parsed]

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 object-name.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/object-name.c b/object-name.c
index 9750634ee76..298b742bac9 100644
--- a/object-name.c
+++ b/object-name.c
@@ -382,6 +382,8 @@  static int show_ambiguous_object(const struct object_id *oid, void *data)
 		struct tag *tag = lookup_tag(ds->repo, oid);
 		if (!parse_tag(tag) && tag->tag)
 			strbuf_addf(&desc, " %s", tag->tag);
+		else
+			strbuf_addstr(&desc, " [tag could not be parsed]");
 	}
 
 out: