git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 2/2] object name: introduce '^{/!-<negative pattern>}' notation

From
Will Palmer <wmpalmer@gmail.com>
Date
Jun 9, 2015, 18:14 UTC
Message-ID
<CAAKF_ub5c+2vVmG161O6gnUUeEcNfDUMU=mtn+k0T8bC-9ZHPw@mail.gmail.com>
In-Reply-To
<xmqqbngqcfxd.fsf@gitster.dls.corp.google.com>
On Mon, Jun 8, 2015 at 5:39 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 12 quoted lines
> Will Palmer <wmpalmer@gmail.com> writes:
>> diff --git a/t/t1511-rev-parse-caret.sh b/t/t1511-rev-parse-caret.sh
>> index e0fe102..8a5983f 100755
>> --- a/t/t1511-rev-parse-caret.sh
>> +++ b/t/t1511-rev-parse-caret.sh
>> @@ -19,13 +19,17 @@ test_expect_success 'setup' '
>>       echo modified >>a-blob &&
>>       git add -u &&
>>       git commit -m Modified &&
>> +     git branch modref &&
>
> This probably belongs to the previous step, no?

As it isn't referenced until the "negative" tests, I didn't bother adding it in the "verify the way things are" tests. Funny that it was mentioned, as I *did* originally have it in the first commit, but I moved it to the commit in which it was first used, so that it would be easier to notice.

Show 10 quoted lines
>
>> +test_expect_success 'ref^{/!-}' '
>> +     test_must_fail git rev-parse master^{/!-}
>> +'
>
> Hmmmm, we must fail because...?  We are looking for something that
> does not contain an empty string, which by definition does not
> exist.
>
> Funny, but is correct ;-).

This is left-over from the original patch's logic, which included a short-circuit to avoid an empty regex (as per 4322842 "get_sha1: handle special case $commit^{/}")... which I now realise perhaps should have been simply rephrased, rather than ommitted entirely.

I feel like adding something like: 8<----------------------------------------------------------------------

--- a/sha1_name.c
+++ b/sha1_name.c
@@ -737,11 +737,15 @@ static int peel_onion(const char *name, int len,
unsigned char *sha1)

                /*
                 * $commit^{/}. Some regex implementation may reject.
-                * We don't need regex anyway. '' pattern always matches.
+                * We don't need regex anyway. '' pattern always matches,
+                * and '!' pattern never matches.
                 */
                if (sp[1] == '}')
                        return 0;

+               if (sp[1] == '!' && sp[2] == '-' && sp[3] == '}')
+                       return -1;
+
                prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
                commit_list_insert((struct commit *)o, &list);
                ret = get_sha1_oneline(prefix, sha1, list);

---------------------------------------------------------------------->8
...would be the wrong place for this short-circuit check, in light of
discussion around extensibility; so, I'll see how it looks moving that
into get_sha1_oneline(...)

>
>
>> +test_expect_success 'ref^{/!-.}' '
>> +     test_must_fail git rev-parse master^{/!-.}
>> +'
>
> Likewise.  I however wonder if we catch a commit without any message
> (which you probably have to craft with either commit-tree or
> hash-object), but that falls into the "curiosity" not the
> "practicality" category.

A commit with "no message" should indeed by returned by 'master^{/!-.}',
or at least, that is the intent. This test is only meant to cover the
result of there being "no matching commit", however.




In summary: it looks like I'll be sending another one.
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 26 in “specify commit by negative pattern”
  1. 0/2 specify commit by negative patternWill Palmer, Jun 6, 2015
  2. 1/2 test for '!' handling in rev-parse's named commitsWill Palmer, Jun 6, 2015
  3. 2/2 object name: introduce '^{/!-<negative pattern>}' notationWill Palmer, Jun 6, 2015
  4. Junio C HamanoJun 8, 2015
  5. Will PalmerJun 9, 2015
  6. Junio C HamanoOct 28, 2015
  7. Stephen SmithJan 8, 2016
  8. Junio C HamanoJan 8, 2016
  9. 0/2 specify commit by negative patternStephen P. Smith, Jan 10, 2016
  10. 1/2 test for '!' handling in rev-parse's named commitsStephen P. Smith, Jan 10, 2016
  11. 2/2 object name: introduce '^{/!-<negative pattern>}' notationStephen P. Smith, Jan 10, 2016
  12. Philip OakleyJan 11, 2016
  13. 0/2 specify commit by negative patternStephen P. Smith, Jan 13, 2016
  14. 1/2 test for '!' handling in rev-parse's named commitsStephen P. Smith, Jan 13, 2016
  15. 2/2 object name: introduce '^{/!-<negative pattern>}' notationStephen P. Smith, Jan 13, 2016
  16. Junio C HamanoJan 13, 2016
  17. 2/2 object name: introduce '^{/!-<negative pattern>}' notationStephen P. Smith, Jan 31, 2016
  18. Junio C HamanoFeb 1, 2016
  19. Philip OakleyJan 10, 2016
  20. 0/2 specify commit by negative patternStephen P. Smith, Jan 11, 2016
  21. Philip OakleyJan 11, 2016
  22. Stephen & Linda SmithJan 10, 2016
  23. Philip OakleyJan 10, 2016
  24. Stephen & Linda SmithJan 9, 2016
  25. Duy NguyenJan 9, 2016
  26. Junio C HamanoJan 11, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.