summaryrefslogtreecommitdiff
path: root/sha1_name.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-04-03 09:34:53 -0700
committerJunio C Hamano <gitster@pobox.com>2013-04-03 09:34:54 -0700
commit1b7b22bfd0fb1fe62cf9d40e2b1de031cc48771d (patch)
treefe0c000ccf0b96163780404babd29ccbaf69d09e /sha1_name.c
parent41ae34d136e623cb4a6c6096d905dc648daabfb9 (diff)
parenta6a3f2cc0761a347e8796280a1544e2a0d08cb51 (diff)
downloadgit-1b7b22bfd0fb1fe62cf9d40e2b1de031cc48771d.tar.gz
Merge branch 'jc/sha1-name-object-peeler'
There was no good way to ask "I have a random string that came from outside world. I want to turn it into a 40-hex object name while making sure such an object exists". A new peeling suffix ^{object} can be used for that purpose, together with "rev-parse --verify". * jc/sha1-name-object-peeler: peel_onion(): teach $foo^{object} peeler peel_onion: disambiguate to favor tree-ish when we know we want a tree-ish
Diffstat (limited to 'sha1_name.c')
-rw-r--r--sha1_name.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/sha1_name.c b/sha1_name.c
index 2fbda48e02..3820f28ae7 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -594,7 +594,7 @@ struct object *peel_to_type(const char *name, int namelen,
while (1) {
if (!o || (!o->parsed && !parse_object(o->sha1)))
return NULL;
- if (o->type == expected_type)
+ if (expected_type == OBJ_ANY || o->type == expected_type)
return o;
if (o->type == OBJ_TAG)
o = ((struct tag*) o)->tagged;
@@ -645,6 +645,8 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
expected_type = OBJ_TREE;
else if (!strncmp(blob_type, sp, 4) && sp[4] == '}')
expected_type = OBJ_BLOB;
+ else if (!prefixcmp(sp, "object}"))
+ expected_type = OBJ_ANY;
else if (sp[0] == '}')
expected_type = OBJ_NONE;
else if (sp[0] == '/')
@@ -654,6 +656,8 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
if (expected_type == OBJ_COMMIT)
lookup_flags = GET_SHA1_COMMITTISH;
+ else if (expected_type == OBJ_TREE)
+ lookup_flags = GET_SHA1_TREEISH;
if (get_sha1_1(name, sp - name - 2, outer, lookup_flags))
return -1;