summaryrefslogtreecommitdiff
path: root/builtin/describe.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-02-12 17:23:06 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-02-12 20:32:35 (GMT)
commita8e7a2bf0fe843836f4ec286c6cdba24bf40fac8 (patch)
tree882bd47dd9f070c584e254612e5695b67866ce32 /builtin/describe.c
parent644eb60bd01a15f665b63774fd80e3b6316073a1 (diff)
downloadgit-a8e7a2bf0fe843836f4ec286c6cdba24bf40fac8.zip
git-a8e7a2bf0fe843836f4ec286c6cdba24bf40fac8.tar.gz
git-a8e7a2bf0fe843836f4ec286c6cdba24bf40fac8.tar.bz2
describe: confirm that blobs actually exist
Prior to 644eb60bd0 (builtin/describe.c: describe a blob, 2017-11-15), we noticed and complained about missing objects, since they were not valid commits: $ git describe 0000000000000000000000000000000000000000 fatal: 0000000000000000000000000000000000000000 is not a valid 'commit' object After that commit, we feed any non-commit to lookup_blob(), and complain only if it returns NULL. But the lookup_* functions do not actually look at the on-disk object database at all. They return an entry from the in-memory object hash if present (and if it matches the requested type), and otherwise auto-create a "struct object" of the requested type. A missing object would hit that latter case: we create a bogus blob struct, walk all of history looking for it, and then exit successfully having produced no output. One reason nobody may have noticed this is that some related cases do still work OK: 1. If we ask for a tree by sha1, then the call to lookup_commit_referecne_gently() would have parsed it, and we would have its true type in the in-memory object hash. 2. If we ask for a name that doesn't exist but isn't a 40-hex sha1, then get_oid() would complain before we even look at the objects at all. We can fix this by replacing the lookup_blob() call with a check of the true type via sha1_object_info(). This is not quite as efficient as we could possibly make this check. We know in most cases that the object was already parsed in the earlier commit lookup, so we could call lookup_object(), which does auto-create, and check the resulting struct's type (or NULL). However it's not worth the fragility nor code complexity to save a single object lookup. The new tests cover this case, as well as that of a tree-by-sha1 (which does work as described above, but was not explicitly tested). Noticed-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Jeff King <peff@peff.net> Acked-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/describe.c')
-rw-r--r--builtin/describe.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/builtin/describe.c b/builtin/describe.c
index 5b4bfab..1e7ba09 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -498,7 +498,7 @@ static void describe(const char *arg, int last_one)
if (cmit)
describe_commit(&oid, &sb);
- else if (lookup_blob(&oid))
+ else if (sha1_object_info(oid.hash, NULL) == OBJ_BLOB)
describe_blob(oid, &sb);
else
die(_("%s is neither a commit nor blob"), arg);