From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ramkumar Ramachandra Subject: [PATCH 3/5] name-rev: fix assumption about --name-only usage Date: Tue, 18 Jun 2013 22:43:26 +0530 Message-ID: <1371575608-9980-4-git-send-email-artagnon@gmail.com> References: <1371575608-9980-1-git-send-email-artagnon@gmail.com> Cc: Junio C Hamano To: Git List X-From: git-owner@vger.kernel.org Tue Jun 18 19:16:58 2013 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UozWa-0003FH-4K for gcvg-git-2@plane.gmane.org; Tue, 18 Jun 2013 19:16:56 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932885Ab3FRRQq (ORCPT ); Tue, 18 Jun 2013 13:16:46 -0400 Received: from mail-pd0-f170.google.com ([209.85.192.170]:62739 "EHLO mail-pd0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752400Ab3FRRQo (ORCPT ); Tue, 18 Jun 2013 13:16:44 -0400 Received: by mail-pd0-f170.google.com with SMTP id x11so4124448pdj.29 for ; Tue, 18 Jun 2013 10:16:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=pBMvAindiHQhFMEYrzhq6/ftTCJPMfDMO2yVsffHJaI=; b=GC0oOgPIWbz+cH5bAJg6MHFSCIjKKTXhCWucH5p3d8SgpoqYebIj75isPKjxtV8F9y n8tleCIRCW/NvfmJWdJUrWmWBodNPMBszIxtoMPDHO5TSxZ8P88yK8xZOJEWpkdTaFN+ 2nLzbo0baJVczZPOgGB3oXBhX1YX+7Y/mtah3sbYgtPM1M6LzKZMJhD9E1Y/lFvt3RWL 7whWWh3nBA6rNPCmo8YQconQE8cl1xvB+kH89tUnkwzDeTgg5xqhRE0qMOeZac0PsVch n9RtGG4bNSZy3zh1Y/DCF2aWH6MTzXIW08LpwA3YJHx61TZLtE4bfYyyUcBuK4arIFl+ ki4w== X-Received: by 10.68.171.226 with SMTP id ax2mr18217445pbc.201.1371575803955; Tue, 18 Jun 2013 10:16:43 -0700 (PDT) Received: from localhost.localdomain ([122.164.211.22]) by mx.google.com with ESMTPSA id vz8sm20498303pac.20.2013.06.18.10.16.41 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Jun 2013 10:16:43 -0700 (PDT) X-Mailer: git-send-email 1.8.3.1.456.gb7f4cb6.dirty In-Reply-To: <1371575608-9980-1-git-send-email-artagnon@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: 236157 (Teach git-describe how to run name-rev, 2007-05-21) introduced `git name-rev --name-only`, with the intent of using it to implement `git describe --contains`. According to the message, users wanted to use describe to figure out which tags contains a specific commit. name-rev already did this, but didn't print out in the same format as describe: $ git describe v1.8.3~1 v1.8.3-rc3-8-g5e49f30 $ git name-rev v1.8.3~1 v1.8.3~1 tags/v1.8.3~1 There are two problems with using the output of name-rev in describe: first, it prints out the given argument before describing it. Second, it prefixes "tags/" to the tag description. To eliminate these two problems, 236157 proposed that the --name-rev option would strip these things when used with --tags, to match the describe output more closely: $ git name-rev --name-only --tags v1.8.3~1 v1.8.3~1 236157 did not anticipate a problem with always combining --name-rev with --tags, because it was primarily intended to be used from describe, where it hard-coded these two arguments in the execv() of name-rev. Later, 3f7701 (make 'git describe --all --contains' work, 2007-12-19) noticed that describe didn't work with --contains and --all. This is because --contains implied a call to --name-rev (in with --tags was hard-coded), but --all implied that any ref should be used to describe the given argument (not just tags). 3f7701 took the band-aid approach, and made --all disable --tags when calling name-rev. As a result, while $ git describe --contains v1.8.3~1 v1.8.3~1 would get name-rev to print output in the same format as describe, $ git describe --contains --all v1.8.3~1 tags/v1.8.3~1 would not strip the leading "tags/". The bug exists in git to this day. Fix it by removing the assumption that name-rev --name-only is only intended to be used with --tags. Also update some tests. Users and scripts have learnt to live with 3f7701, and it will continue to be a small quirk. Even after this patch, notice $ git checkout -b foom v1.8.3 $ git describe --contains @~1 v1.8.3~1 $ git describe --contains --all @~1 foom~1 In other words, --contains implies --tags in name-rev, which gives precedence to tags; --all cancels that effect thereby giving precedence to branches in the case of a tie. Signed-off-by: Ramkumar Ramachandra --- Documentation/git-name-rev.txt | 6 +++--- builtin/name-rev.c | 3 +-- t/t4202-log.sh | 8 ++++---- t/t6007-rev-list-cherry-pick-file.sh | 32 ++++++++++++++++---------------- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Documentation/git-name-rev.txt b/Documentation/git-name-rev.txt index ad1d146..5cd0d0d 100644 --- a/Documentation/git-name-rev.txt +++ b/Documentation/git-name-rev.txt @@ -36,9 +36,9 @@ OPTIONS --name-only:: Instead of printing both the SHA-1 and the name, print only - the name. If given with --tags the usual tag prefix of - "tags/" is also omitted from the name, matching the output - of `git-describe` more closely. + the name. The usual tag prefix of "tags/" is also omitted + from the name, matching the output of `git-describe` more + closely. --no-undefined:: Die with error code != 0 when a reference is undefined, diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 6238247..524d790 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -112,8 +112,7 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void if (!prefixcmp(path, "refs/heads/")) path = path + 11; - else if (data->tags_only - && data->name_only + else if (data->name_only && !prefixcmp(path, "refs/tags/")) path = path + 10; else if (!prefixcmp(path, "refs/")) diff --git a/t/t4202-log.sh b/t/t4202-log.sh index cb03d28..9bec360 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -302,7 +302,7 @@ cat > expect <<\EOF | | | | side-2 | | -| * commit tags/side-1 +| * commit side-1 | | Author: A U Thor | | | | side-1 @@ -327,17 +327,17 @@ cat > expect <<\EOF | | fourth | -* commit tags/side-1~1 +* commit side-1~1 | Author: A U Thor | | third | -* commit tags/side-1~2 +* commit side-1~2 | Author: A U Thor | | second | -* commit tags/side-1~3 +* commit side-1~3 Author: A U Thor initial diff --git a/t/t6007-rev-list-cherry-pick-file.sh b/t/t6007-rev-list-cherry-pick-file.sh index 28d4f6b..5a8175e 100755 --- a/t/t6007-rev-list-cherry-pick-file.sh +++ b/t/t6007-rev-list-cherry-pick-file.sh @@ -49,8 +49,8 @@ test_expect_success setup ' ' cat >expect <tags/C +C EOF test_expect_success '--left-right' ' @@ -70,7 +70,7 @@ test_expect_success '--cherry-pick foo comes up empty' ' ' cat >expect <tags/C +>C EOF test_expect_success '--cherry-pick bar does not come up empty' ' @@ -88,8 +88,8 @@ test_expect_success 'bar does not come up empty' ' ' cat >expect <tags/E +E EOF test_expect_success '--cherry-pick bar does not come up empty (II)' ' @@ -100,10 +100,10 @@ test_expect_success '--cherry-pick bar does not come up empty (II)' ' ' cat >expect <expect <tags/E -=tags/C +E +=C EOF test_expect_success '--cherry-mark --left-right' ' @@ -128,7 +128,7 @@ test_expect_success '--cherry-mark --left-right' ' ' cat >expect <expect <