Skip to content

Commit

Permalink
name-rev: differentiate between tags and commits they point at
Browse files Browse the repository at this point in the history
"git name-rev --stdin" has been fixed to convert an object name that
points at a tag to a refname of the tag.  The codepath to handle its
command line arguments, however, fed the commit that the tag points
at to the underlying naming machinery.

With this fix, you will get this:

    $ git name-rev --refs=tags/\* --name-only $(git rev-parse v1.8.3 v1.8.3^0)
    v1.8.3
    v1.8.3^0

which is the same as what you would get from the fixed "--stdin" variant:

    $ git rev-parse v1.8.3 v1.8.3^0 | git name-rev --refs=tags/\* --name-only
    v1.8.3
    v1.8.3^0

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Jul 18, 2013
1 parent 45bc950 commit 118aa4a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
24 changes: 16 additions & 8 deletions builtin/name-rev.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)

for (; argc; argc--, argv++) {
unsigned char sha1[20];
struct object *o;
struct object *object;
struct commit *commit;

if (get_sha1(*argv, sha1)) {
Expand All @@ -343,17 +343,25 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
continue;
}

o = deref_tag(parse_object(sha1), *argv, 0);
if (!o || o->type != OBJ_COMMIT) {
fprintf(stderr, "Could not get commit for %s. Skipping.\n",
commit = NULL;
object = parse_object(sha1);
if (object) {
struct object *peeled = deref_tag(object, *argv, 0);
if (peeled && peeled->type == OBJ_COMMIT)
commit = (struct commit *)peeled;
}

if (!object) {
fprintf(stderr, "Could not get object for %s. Skipping.\n",
*argv);
continue;
}

commit = (struct commit *)o;
if (cutoff > commit->date)
cutoff = commit->date;
add_object_array((struct object *)commit, *argv, &revs);
if (commit) {
if (cutoff > commit->date)
cutoff = commit->date;
}
add_object_array(object, *argv, &revs);
}

if (cutoff)
Expand Down
12 changes: 12 additions & 0 deletions t/t6120-describe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,16 @@ check_describe "test2-lightweight-*" --tags --match="test2-*"

check_describe "test2-lightweight-*" --long --tags --match="test2-*" HEAD^

test_expect_success 'name-rev with exact tags' '
echo A >expect &&
tag_object=$(git rev-parse refs/tags/A) &&
git name-rev --tags --name-only $tag_object >actual &&
test_cmp expect actual &&
echo "A^0" >expect &&
tagged_commit=$(git rev-parse "refs/tags/A^0") &&
git name-rev --tags --name-only $tagged_commit >actual &&
test_cmp expect actual
'

test_done

0 comments on commit 118aa4a

Please sign in to comment.