Merge branch 'rh/peeling-tag-to-tag'
authorJunio C Hamano <gitster@pobox.com>
Fri, 20 Sep 2013 19:27:18 +0000 (12:27 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Sep 2013 19:27:18 +0000 (12:27 -0700)
Make "foo^{tag}" to peel a tag to itself, i.e. no-op., and fail if
"foo" is not a tag. "git rev-parse --verify v1.0^{tag}" would be a
more convenient way to say "test $(git cat-file -t v1.0) = tag".

* rh/peeling-tag-to-tag:
peel_onion: do not assume length of x_type globals
peel_onion(): add support for <rev>^{tag}

1  2 
Documentation/revisions.txt
sha1_name.c
index b0f4284cfbec9745d25fb242d32f808c83d0953f,b3322adf24880d95c502869097aca29eb4637776..71dcd12ebd25811ed2c4c41717371f3a97321288
@@@ -111,20 -111,19 +111,23 @@@ some output processing may assume ref n
  
  '<rev>{caret}\{<type>\}', e.g. 'v0.99.8{caret}\{commit\}'::
    A suffix '{caret}' followed by an object type name enclosed in
 -  brace pair means the object
 -  could be a tag, and dereference the tag recursively until an
 -  object of that type is found or the object cannot be
 -  dereferenced anymore (in which case, barf).  '<rev>{caret}0'
 +  brace pair means dereference the object at '<rev>' recursively until
 +  an object of type '<type>' is found or the object cannot be
 +  dereferenced anymore (in which case, barf).
 +  For example, if '<rev>' is a commit-ish, '<rev>{caret}\{commit\}'
 +  describes the corresponding commit object.
 +  Similarly, if '<rev>' is a tree-ish, '<rev>{caret}\{tree\}'
 +  describes the corresponding tree object.
 +  '<rev>{caret}0'
    is a short-hand for '<rev>{caret}\{commit\}'.
  +
  'rev{caret}\{object\}' can be used to make sure 'rev' names an
  object that exists, without requiring 'rev' to be a tag, and
  without dereferencing 'rev'; because a tag is already an object,
  it does not have to be dereferenced even once to get to an object.
+ +
+ 'rev{caret}\{tag\}' can be used to ensure that 'rev' identifies an
+ existing tag object.
  
  '<rev>{caret}\{\}', e.g. 'v0.99.8{caret}\{\}'::
    A suffix '{caret}' followed by an empty brace pair
diff --combined sha1_name.c
index ad79d7b81249b6908bb9728b88addbb2fe6955cd,2f6e5abaafc5403fd7655ea59e86589ee0016485..78c093f79e40db5eada30f3bbf6cfe314fb22834
@@@ -677,11 -677,13 +677,13 @@@ static int peel_onion(const char *name
                return -1;
  
        sp++; /* beginning of type name, or closing brace for empty */
-       if (!strncmp(commit_type, sp, 6) && sp[6] == '}')
+       if (!prefixcmp(sp, "commit}"))
                expected_type = OBJ_COMMIT;
-       else if (!strncmp(tree_type, sp, 4) && sp[4] == '}')
+       else if (!prefixcmp(sp, "tag}"))
+               expected_type = OBJ_TAG;
+       else if (!prefixcmp(sp, "tree}"))
                expected_type = OBJ_TREE;
-       else if (!strncmp(blob_type, sp, 4) && sp[4] == '}')
+       else if (!prefixcmp(sp, "blob}"))
                expected_type = OBJ_BLOB;
        else if (!prefixcmp(sp, "object}"))
                expected_type = OBJ_ANY;
@@@ -1130,13 -1132,13 +1132,13 @@@ int get_sha1(const char *name, unsigne
  }
  
  /*
 - * Many callers know that the user meant to name a committish by
 + * Many callers know that the user meant to name a commit-ish by
   * syntactical positions where the object name appears.  Calling this
   * function allows the machinery to disambiguate shorter-than-unique
 - * abbreviated object names between committish and others.
 + * abbreviated object names between commit-ish and others.
   *
   * Note that this does NOT error out when the named object is not a
 - * committish. It is merely to give a hint to the disambiguation
 + * commit-ish. It is merely to give a hint to the disambiguation
   * machinery.
   */
  int get_sha1_committish(const char *name, unsigned char *sha1)