{"thread":{"id":"34842","subject":"[PATCH v3] peel_onion(): add support for <rev>^{tag}","startedAt":"2013-09-03T17:37:33Z","lastAt":"2013-09-03T19:39:41Z","messageCount":4,"participants":["Richard Hansen","Jeff King","Eric Sunshine"],"isPatch":true,"patchVersion":3,"patchTotal":null},"messages":[{"id":"226647","messageId":"1378229853-21236-1-git-send-email-rhansen@bbn.com","threadId":"34842","inReplyTo":null,"subject":"[PATCH v3] peel_onion(): add support for <rev>^{tag}","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2013-09-03T17:37:33Z","receivedAt":"2013-09-03T17:37:33Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"Complete the <rev>^{<type>} family of object descriptors by having\n<rev>^{tag} dereference <rev> until a tag object is found (or fail if\nunable).\n\nAt first glance this may not seem very useful, as commits, trees, and\nblobs cannot be peeled to a tag, and a tag would just peel to itself.\nHowever, this can be used to ensure that <rev> names a tag object:\n\n    $ git rev-parse --verify v1.8.4^{tag}\n    04f013dc38d7512eadb915eba22efc414f18b869\n    $ git rev-parse --verify master^{tag}\n    error: master^{tag}: expected tag type, but the object dereferences to tree type\n    fatal: Needed a single revision\n\nUsers can already ensure that <rev> is a tag object by checking the\noutput of 'git cat-file -t <rev>', but:\n  * users may expect <rev>^{tag} to exist given that <rev>^{commit},\n    <rev>^{tree}, and <rev>^{blob} all exist\n  * this syntax is more convenient/natural in some circumstances\n\nSigned-off-by: Richard Hansen <rhansen@bbn.com>\n---\nChanges since v2 (2013-09-02, see\n<http://thread.gmane.org/gmane.comp.version-control.git/233598>):\n  * add a test case (hopefully I didn't go overboard)\n  * explain in the commit message why we might want <rev>^{tag} when\n    it's already possible to parse the output of 'git cat-file -t\n    <rev>'\n\n Documentation/revisions.txt |  3 +++\n sha1_name.c                 |  2 ++\n t/t1511-rev-parse-caret.sh  | 29 ++++++++++++++++++++++++++++-\n 3 files changed, 33 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/revisions.txt b/Documentation/revisions.txt\nindex d477b3f..b3322ad 100644\n--- a/Documentation/revisions.txt\n+++ b/Documentation/revisions.txt\n@@ -121,6 +121,9 @@ some output processing may assume ref names in UTF-8.\n object that exists, without requiring 'rev' to be a tag, and\n without dereferencing 'rev'; because a tag is already an object,\n it does not have to be dereferenced even once to get to an object.\n++\n+'rev{caret}\\{tag\\}' can be used to ensure that 'rev' identifies an\n+existing tag object.\n \n '<rev>{caret}\\{\\}', e.g. 'v0.99.8{caret}\\{\\}'::\n   A suffix '{caret}' followed by an empty brace pair\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 65ad066..6dc496d 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -679,6 +679,8 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)\n \tsp++; /* beginning of type name, or closing brace for empty */\n \tif (!strncmp(commit_type, sp, 6) && sp[6] == '}')\n \t\texpected_type = OBJ_COMMIT;\n+\telse if (!strncmp(tag_type, sp, 3) && sp[3] == '}')\n+\t\texpected_type = OBJ_TAG;\n \telse if (!strncmp(tree_type, sp, 4) && sp[4] == '}')\n \t\texpected_type = OBJ_TREE;\n \telse if (!strncmp(blob_type, sp, 4) && sp[4] == '}')\ndiff --git a/t/t1511-rev-parse-caret.sh b/t/t1511-rev-parse-caret.sh\nindex eaefc77..5771cbd 100755\n--- a/t/t1511-rev-parse-caret.sh\n+++ b/t/t1511-rev-parse-caret.sh\n@@ -6,14 +6,21 @@ test_description='tests for ref^{stuff}'\n \n test_expect_success 'setup' '\n \techo blob >a-blob &&\n-\tgit tag -a -m blob blob-tag `git hash-object -w a-blob` &&\n+\tBLOB_SHA1=`git hash-object -w a-blob` &&\n+\tgit tag -a -m blob blob-tag $BLOB_SHA1 &&\n+\tBLOB_TAG_SHA1=`git rev-parse --verify blob-tag` &&\n \tmkdir a-tree &&\n \techo moreblobs >a-tree/another-blob &&\n \tgit add . &&\n \tTREE_SHA1=`git write-tree` &&\n \tgit tag -a -m tree tree-tag \"$TREE_SHA1\" &&\n+\tTREE_TAG_SHA1=`git rev-parse --verify tree-tag` &&\n \tgit commit -m Initial &&\n+\tCOMMIT_SHA1=`git rev-parse --verify HEAD` &&\n \tgit tag -a -m commit commit-tag &&\n+\tCOMMIT_TAG_SHA1=`git rev-parse --verify commit-tag` &&\n+\tgit tag -a -m tag tag-tag $COMMIT_TAG_SHA1 &&\n+\tTAG_TAG_SHA1=`git rev-parse --verify tag-tag` &&\n \tgit branch ref &&\n \tgit checkout master &&\n \techo modified >>a-blob &&\n@@ -54,6 +61,26 @@ test_expect_success 'ref^{tree}' '\n \ttest_must_fail git rev-parse blob-tag^{tree}\n '\n \n+test_expect_success 'ref^{tag}' '\n+\techo $BLOB_TAG_SHA1 >expected &&\n+\tgit rev-parse --verify blob-tag^{tag} >actual &&\n+\ttest_cmp expected actual &&\n+\techo $TREE_TAG_SHA1 >expected &&\n+\tgit rev-parse --verify tree-tag^{tag} >actual &&\n+\ttest_cmp expected actual &&\n+\techo $COMMIT_TAG_SHA1 >expected &&\n+\tgit rev-parse --verify commit-tag^{tag} >actual &&\n+\ttest_cmp expected actual &&\n+\techo $TAG_TAG_SHA1 >expected &&\n+\tgit rev-parse --verify tag-tag^{tag} >actual &&\n+\ttest_cmp expected actual &&\n+\ttest_must_fail git rev-parse --verify $BLOB_SHA1^{tag} &&\n+\ttest_must_fail git rev-parse --verify $TREE_SHA1^{tag} &&\n+\ttest_must_fail git rev-parse --verify $COMMIT_SHA1^{tag} &&\n+\ttest_must_fail git rev-parse --verify rev^{tag} &&\n+\ttrue\n+'\n+\n test_expect_success 'ref^{/.}' '\n \tgit rev-parse master >expected &&\n \tgit rev-parse master^{/.} >actual &&\n-- \n1.8.4\n"},{"id":"226648","messageId":"20130903174604.GD1050@sigill.intra.peff.net","threadId":"34842","inReplyTo":"1378229853-21236-1-git-send-email-rhansen@bbn.com","subject":"Re: [PATCH v3] peel_onion(): add support for <rev>^{tag}","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-09-03T17:46:04Z","receivedAt":"2013-09-03T17:46:04Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Sep 03, 2013 at 01:37:33PM -0400, Richard Hansen wrote:\n\n> ---\n> Changes since v2 (2013-09-02, see\n> <http://thread.gmane.org/gmane.comp.version-control.git/233598>):\n>   * add a test case (hopefully I didn't go overboard)\n\nPersonally I was thinking just\n\n  test_must_fail git rev-parse HEAD^{tag} &&\n  git rev-parse commit-tag >expect &&\n  git rev-parse commit-tag^{tag} >actual &&\n  test_cmp expect actual\n\nbut I do not think it hurts to be more thorough.\n\nThanks, this version of the patch looks ready to me.\n\n-Peff\n"},{"id":"226654","messageId":"CAPig+cRQP5CGz_1ckf5Qr6HcB+OvWHNPtGQ8RxWdqTZK0fRo2w@mail.gmail.com","threadId":"34842","inReplyTo":"1378229853-21236-1-git-send-email-rhansen@bbn.com","subject":"Re: [PATCH v3] peel_onion(): add support for <rev>^{tag}","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2013-09-03T19:03:14Z","receivedAt":"2013-09-03T19:03:14Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Sep 3, 2013 at 1:37 PM, Richard Hansen <rhansen@bbn.com> wrote:\n> diff --git a/t/t1511-rev-parse-caret.sh b/t/t1511-rev-parse-caret.sh\n> index eaefc77..5771cbd 100755\n> --- a/t/t1511-rev-parse-caret.sh\n> +++ b/t/t1511-rev-parse-caret.sh\n> @@ -54,6 +61,26 @@ test_expect_success 'ref^{tree}' '\n>         test_must_fail git rev-parse blob-tag^{tree}\n>  '\n>\n> +test_expect_success 'ref^{tag}' '\n> +       echo $BLOB_TAG_SHA1 >expected &&\n> +       git rev-parse --verify blob-tag^{tag} >actual &&\n> +       test_cmp expected actual &&\n> +       echo $TREE_TAG_SHA1 >expected &&\n> +       git rev-parse --verify tree-tag^{tag} >actual &&\n> +       test_cmp expected actual &&\n> +       echo $COMMIT_TAG_SHA1 >expected &&\n> +       git rev-parse --verify commit-tag^{tag} >actual &&\n> +       test_cmp expected actual &&\n> +       echo $TAG_TAG_SHA1 >expected &&\n> +       git rev-parse --verify tag-tag^{tag} >actual &&\n> +       test_cmp expected actual &&\n> +       test_must_fail git rev-parse --verify $BLOB_SHA1^{tag} &&\n> +       test_must_fail git rev-parse --verify $TREE_SHA1^{tag} &&\n> +       test_must_fail git rev-parse --verify $COMMIT_SHA1^{tag} &&\n> +       test_must_fail git rev-parse --verify rev^{tag} &&\n> +       true\n> +'\n\nThe unnecessary trailing \"&& true\" is unusual. Such form is not used\nelsewhere in this file, or in any script in the test suite.\n\n> +\n>  test_expect_success 'ref^{/.}' '\n>         git rev-parse master >expected &&\n>         git rev-parse master^{/.} >actual &&\n> --\n> 1.8.4\n"},{"id":"226660","messageId":"52263AFD.3060308@bbn.com","threadId":"34842","inReplyTo":"CAPig+cRQP5CGz_1ckf5Qr6HcB+OvWHNPtGQ8RxWdqTZK0fRo2w@mail.gmail.com","subject":"Re: [PATCH v3] peel_onion(): add support for <rev>^{tag}","fromName":"Richard Hansen","fromEmail":"rhansen@bbn.com","sentAt":"2013-09-03T19:39:41Z","receivedAt":"2013-09-03T19:39:41Z","isPatch":true,"sender":{"key":"rhansen@rhansen.org","avatar":null},"body":"On 2013-09-03 15:03, Eric Sunshine wrote:\n> On Tue, Sep 3, 2013 at 1:37 PM, Richard Hansen <rhansen@bbn.com> wrote:\n>> diff --git a/t/t1511-rev-parse-caret.sh b/t/t1511-rev-parse-caret.sh\n>> index eaefc77..5771cbd 100755\n>> --- a/t/t1511-rev-parse-caret.sh\n>> +++ b/t/t1511-rev-parse-caret.sh\n>> @@ -54,6 +61,26 @@ test_expect_success 'ref^{tree}' '\n>>         test_must_fail git rev-parse blob-tag^{tree}\n>>  '\n>>\n>> +test_expect_success 'ref^{tag}' '\n>> +       echo $BLOB_TAG_SHA1 >expected &&\n>> +       git rev-parse --verify blob-tag^{tag} >actual &&\n>> +       test_cmp expected actual &&\n>> +       echo $TREE_TAG_SHA1 >expected &&\n>> +       git rev-parse --verify tree-tag^{tag} >actual &&\n>> +       test_cmp expected actual &&\n>> +       echo $COMMIT_TAG_SHA1 >expected &&\n>> +       git rev-parse --verify commit-tag^{tag} >actual &&\n>> +       test_cmp expected actual &&\n>> +       echo $TAG_TAG_SHA1 >expected &&\n>> +       git rev-parse --verify tag-tag^{tag} >actual &&\n>> +       test_cmp expected actual &&\n>> +       test_must_fail git rev-parse --verify $BLOB_SHA1^{tag} &&\n>> +       test_must_fail git rev-parse --verify $TREE_SHA1^{tag} &&\n>> +       test_must_fail git rev-parse --verify $COMMIT_SHA1^{tag} &&\n>> +       test_must_fail git rev-parse --verify rev^{tag} &&\n>> +       true\n>> +'\n> \n> The unnecessary trailing \"&& true\" is unusual. Such form is not used\n> elsewhere in this file, or in any script in the test suite.\n\nTrue.  I can take it out, and while I'm at it simplify the test case to\nwhat Peff suggested.\n\nI'm in the habit of using that idiom because (1) I won't break things if\nI forget to add/remove '&&' when I add/remove lines in a future commit,\nand (2) it simplifies conflict resolution if two commits touch the same\nlist of stuff.\n\n-Richard\n"}]}