threads / patch / 39539

v2, 2 partsspecify commit by negative pattern

Subject: [PATCH v2 0/2] specify commit by negative pattern

## tl;dr

26 messages between Jun 6, 2015 and Feb 1, 2016. Diffs are folded; open one to read it.

replies: 25people: 5as markdown or json

Will Palmer· Jun 6, 2015, 00:24 UTC · lore

add support for negative pattern matching in @^{/<pattern>} style revision specifiers. So now you can find the first commit whose message doesn't match a pattern, complementing the existing positive matching. e.g.:

    $ git rebase -i @^{/!-^WIP}

My use-case is in having a "work, work, work, rebase, push"-style workflow, which generates a lot of "WIP foo" commits. While rebasing is usually handled via "git rebase -i origin/master", occasionally I will already have several "good, but not yet ready to push" commits hanging around while I finish work on related commits. In these situations, the ability to quickly "git diff @^{/!-^WIP}" to get an overview of all changes "since the last one I was happy with", can be useful.

This is the second version of the patch series. The previous attempt used the notation @^{/!WIP}, rather than @^{/!-WIP}, so the "modifier" was the '!' character. Now, '!' is taken as an indicator that the pattern is to be interpreted differently, and '-' is taken as an indicator of how it is to be interpreted differently. This follows recent discussion with "Junio C Hamano" <gitster@pobox.com> and much-less recent discussion archived at:

http://thread.gmane.org/gmane.comp.version-control.git/40460/focus=40477

In summary, '!' is to be used as an "escape hatch", for further extension of the "name commit by pattern" functionality. Theorised future extensions indicated things like "what was to be searched", e.g.: @^{/!(a=author)}. With only two interpretations of the '!' leader, for now (including the '!!' literal notation), adding such a verbose form, such as '@^{/!(negative)foo}', seemed inappropriate at this time. In the event that such verbose forms are ever implemented, this new form may act as a shorthand, for a basic case.

Will Palmer (2):
  test for '!' handling in rev-parse's named commits
  object name: introduce '^{/!-<negative pattern>}' notation
 Documentation/revisions.txt | 11 +++++-----
 sha1_name.c                 | 20 ++++++++++++-----
 t/t1511-rev-parse-caret.sh  | 53 ++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 73 insertions(+), 11 deletions(-)
-- 
2.3.0.rc1
Will Palmer· Jun 6, 2015, 00:24 UTC · re: Will Palmer · lore

[PATCH v2 1/2] test for '!' handling in rev-parse's named commits

In anticipation of extending this behaviour, add tests verifying the handling of exclamation marks when looking up a commit "by name".

Specifically, as documented: '<rev>^{/!Message}' should fail, as the '!' prefix is reserved; while '<rev>^{!!Message}' should search for a commit whose message contains the string "!Message".

Signed-off-by: Will Palmer <wmpalmer@gmail.com>
---
 t/t1511-rev-parse-caret.sh | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
Show changes to t/t1511-rev-parse-caret.sh +22 −1
diff --git a/t/t1511-rev-parse-caret.sh b/t/t1511-rev-parse-caret.sh
index 15973f2..e0fe102 100755
--- a/t/t1511-rev-parse-caret.sh
+++ b/t/t1511-rev-parse-caret.sh
@@ -18,7 +18,14 @@ test_expect_success 'setup' '
 	git checkout master &&
 	echo modified >>a-blob &&
 	git add -u &&
-	git commit -m Modified
+	git commit -m Modified &&
+	echo changed! >>a-blob &&
+	git add -u &&
+	git commit -m !Exp &&
+	git branch expref &&
+	echo changed >>a-blob &&
+	git add -u &&
+	git commit -m Changed
 '
 
 test_expect_success 'ref^{non-existent}' '
@@ -77,4 +84,18 @@ test_expect_success 'ref^{/Initial}' '
 	test_cmp expected actual
 '
 
+test_expect_success 'ref^{/!Exp}' '
+	test_must_fail git rev-parse master^{/!Exp}
+'
+
+test_expect_success 'ref^{/!}' '
+	test_must_fail git rev-parse master^{/!}
+'
+
+test_expect_success 'ref^{/!!Exp}' '
+	git rev-parse expref >expected &&
+	git rev-parse master^{/!!Exp} >actual &&
+	test_cmp expected actual
+'
+
 test_done
-- 
2.3.0.rc1
Will Palmer· Jun 6, 2015, 00:24 UTC · re: Will Palmer · lore

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

To name a commit, you can now say
    $ git rev-parse HEAD^{/!-foo}

and it will return the hash of the first commit reachable from HEAD, whose commit message does not contain "foo". This is the opposite of the existing <rev>^{/<pattern>} syntax.

The specific use-case this is intended for is to perform an operation, excluding the most-recent commits containing a particular marker. For example, if you tend to make "work in progress" commits, with messages beginning with "WIP", you work, then it could be useful to diff against "the most recent commit which was not a WIP commit". That sort of thing now possible, via commands such as:

    $ git diff @^{/!-^WIP}

The leader '/!-', rather than simply '/!', to denote a negative match, is chosen to leave room for additional modifiers in the future.

Signed-off-by: Will Palmer <wmpalmer@gmail.com>
---
 Documentation/revisions.txt | 11 ++++++-----
 sha1_name.c                 | 20 +++++++++++++++-----
 t/t1511-rev-parse-caret.sh  | 32 +++++++++++++++++++++++++++++++-
 3 files changed, 52 insertions(+), 11 deletions(-)
Show changes to 3 files +52 −11

Documentation/revisions.txt, sha1_name.c, t/t1511-rev-parse-caret.sh

diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt
index d85e303..0c84d4f 100644
--- a/Documentation/revisions.txt
+++ b/Documentation/revisions.txt
@@ -176,11 +176,12 @@ existing tag object.
   A colon, followed by a slash, followed by a text, names
   a commit whose commit message matches the specified regular expression.
   This name returns the youngest matching commit which is
-  reachable from any ref.  If the commit message starts with a
-  '!' you have to repeat that;  the special sequence ':/!',
-  followed by something else than '!', is reserved for now.
-  The regular expression can match any part of the commit message. To
-  match messages starting with a string, one can use e.g. ':/^foo'.
+  reachable from any ref. The regular expression can match any part of the
+  commit message. To match messages starting with a string, one can use
+  e.g. ':/^foo'. The special sequence ':/!' is reserved for modifiers to what
+  is matched. ':/!-foo' performs a negative match, while ':/!!foo' matches a
+  literal '!' character, followed by 'foo'. Any other sequence beginning with
+  ':/!' is reserved for now.
 
 '<rev>:<path>', e.g. 'HEAD:README', ':README', 'master:./README'::
   A suffix ':' followed by a path names the blob or tree
diff --git a/sha1_name.c b/sha1_name.c
index e57513e..82de2db 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -838,8 +838,12 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned l
  * through history and returning the first commit whose message starts
  * the given regular expression.
  *
- * For future extension, ':/!' is reserved. If you want to match a message
- * beginning with a '!', you have to repeat the exclamation mark.
+ * For negative-matching, prefix the pattern-part with '!-', like: ':/!-WIP'.
+ *
+ * For a literal '!' character at the beginning of a pattern, you have to repeat
+ * that, like: ':/!!foo'
+ *
+ * For future extension, all other sequences beginning with ':/!' are reserved.
  */
 
 /* Remember to update object flag allocation in object.h */
@@ -868,12 +872,18 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
 {
 	struct commit_list *backup = NULL, *l;
 	int found = 0;
+	int negative = 0;
 	regex_t regex;
 
 	if (prefix[0] == '!') {
-		if (prefix[1] != '!')
-			die ("Invalid search pattern: %s", prefix);
 		prefix++;
+
+		if (prefix[0] == '-') {
+			prefix++;
+			negative = 1;
+		} else if (prefix[0] != '!') {
+			die ("Invalid search pattern: %s", prefix);
+		}
 	}
 
 	if (regcomp(&regex, prefix, REG_EXTENDED))
@@ -893,7 +903,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
 			continue;
 		buf = get_commit_buffer(commit, NULL);
 		p = strstr(buf, "\n\n");
-		matches = p && !regexec(&regex, p + 2, 0, NULL, 0);
+		matches = p && (negative ^ !regexec(&regex, p + 2, 0, NULL, 0));
 		unuse_commit_buffer(commit, buf);
 
 		if (matches) {
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 &&
 	echo changed! >>a-blob &&
 	git add -u &&
 	git commit -m !Exp &&
 	git branch expref &&
 	echo changed >>a-blob &&
 	git add -u &&
-	git commit -m Changed
+	git commit -m Changed &&
+	echo changed-again >>a-blob &&
+	git add -u &&
+	git commit -m Changed-again
 '
 
 test_expect_success 'ref^{non-existent}' '
@@ -98,4 +102,30 @@ test_expect_success 'ref^{/!!Exp}' '
 	test_cmp expected actual
 '
 
+test_expect_success 'ref^{/!-}' '
+	test_must_fail git rev-parse master^{/!-}
+'
+
+test_expect_success 'ref^{/!-.}' '
+	test_must_fail git rev-parse master^{/!-.}
+'
+
+test_expect_success 'ref^{/!-non-existent}' '
+	git rev-parse master >expected &&
+	git rev-parse master^{/!-non-existent} >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'ref^{/!-Changed}' '
+	git rev-parse expref >expected &&
+	git rev-parse master^{/!-Changed} >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'ref^{/!-!Exp}' '
+	git rev-parse modref >expected &&
+	git rev-parse expref^{/!-!Exp} >actual &&
+	test_cmp expected actual
+'
+
 test_done
-- 
2.3.0.rc1
Junio C Hamano· Jun 8, 2015, 16:39 UTC · re: Will Palmer · lore

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

Will Palmer <wmpalmer@gmail.com> writes:
Show 9 quoted lines
> - * For future extension, ':/!' is reserved. If you want to match a message
> - * beginning with a '!', you have to repeat the exclamation mark.
> + * For negative-matching, prefix the pattern-part with '!-', like: ':/!-WIP'.
> + *
> + * For a literal '!' character at the beginning of a pattern, you have to repeat
> + * that, like: ':/!!foo'
> + *
> + * For future extension, all other sequences beginning with ':/!' are reserved.
>   */
Good.
Show 9 quoted lines
> 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?
> +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 ;-).
> +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.

Show 5 quoted lines
> +test_expect_success 'ref^{/!-non-existent}' '
> +	git rev-parse master >expected &&
> +	git rev-parse master^{/!-non-existent} >actual &&
> +	test_cmp expected actual
> +'
OK.
Show 5 quoted lines
> +test_expect_success 'ref^{/!-Changed}' '
> +	git rev-parse expref >expected &&
> +	git rev-parse master^{/!-Changed} >actual &&
> +	test_cmp expected actual
> +'
OK.
Show 5 quoted lines
> +test_expect_success 'ref^{/!-!Exp}' '
> +	git rev-parse modref >expected &&
> +	git rev-parse expref^{/!-!Exp} >actual &&
> +	test_cmp expected actual
> +'
OK.
>  test_done
Will Palmer· Jun 9, 2015, 18:14 UTC · re: Junio C Hamano · lore

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

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<----------------------------------------------------------------------

Show changes to sha1_name.c +5 −1
--- 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.
Junio C Hamano· Oct 28, 2015, 17:52 UTC · re: Will Palmer · lore

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

Will Palmer <wmpalmer@gmail.com> writes:
> In summary: it looks like I'll be sending another one.

Has anything happened to this topic since then? I am asking primarily because I want to decide if I should discard wp/sha1-name-negative-match topic from my tree [*1*].

I think what it attempts to do is a worthy thing, and it is shame to see the initial implementation and review cycles we have spent so far go to waste.

[Footnote]
*1* Not that my dropping a topic from 'pu' means very much; a
    dropped topic can still be submitted and requeued after all.
Stephen Smith· Jan 8, 2016, 06:04 UTC · re: Junio C Hamano · lore

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

Junio C Hamano <gitster <at> pobox.com> writes:
Show 7 quoted lines
> >  	echo modified >>a-blob &&
> >  	git add -u &&
> >  	git commit -m Modified &&
> > +	git branch modref &&
> 
> This probably belongs to the previous step, no?
> 

What did you mean by this comment? I looked at the original patch and at Will's response to your comment and am not quite sure what was meant.

> > +test_expect_success 'ref^{/!-}' '
> > +	test_must_fail git rev-parse master^{/!-}
> > +'
> 
I plan on leaving this in.
> > +test_expect_success 'ref^{/!-.}' '
> > +	test_must_fail git rev-parse master^{/!-.}
> > +'
> 
I plan on leaving this in.
Junio C Hamano· Jan 8, 2016, 18:21 UTC · re: Stephen Smith · lore

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

Stephen Smith <ischis2@cox.net> writes:
Show 10 quoted lines
> Junio C Hamano <gitster <at> pobox.com> writes:
>> >  	echo modified >>a-blob &&
>> >  	git add -u &&
>> >  	git commit -m Modified &&
>> > +	git branch modref &&
>> 
>> This probably belongs to the previous step, no?
>> 
> What did you mean by this comment?  I looked at the original patch and at 
> Will's response to your comment and am not quite sure what was meant.

Notice that the title is [2/2], so there is [1/2], which turns out to be http://article.gmane.org/gmane.comp.version-control.git/270898

That patch updates the preparatory steps of the test script so that [2/2] have more commits and refs to work with to perform more tests.

Marking the result of that "Modified" commit so that it can be referenced later with a short name 'modref' is something that should have done in [1/2], which added that new invocation of "git commit" to record that "Modified" commit, not in [2/2] as an afterthought "Oh I created Modified commit in 1/2 so that I can use it in the test in 2/2, but I forgot to give it a name, so I am adding a new invocation of 'git branch' in this step".

Show 12 quoted lines
>
>> > +test_expect_success 'ref^{/!-}' '
>> > +	test_must_fail git rev-parse master^{/!-}
>> > +'
>> 
> I plan on leaving this in.
>
>> > +test_expect_success 'ref^{/!-.}' '
>> > +	test_must_fail git rev-parse master^{/!-.}
>> > +'
>> 
> I plan on leaving this in.
Stephen P. Smith· Jan 10, 2016, 02:20 UTC · re: Junio C Hamano · lore

[PATCH V3 0/2] specify commit by negative pattern

Add support for negative pattern matching in <at> ^{/<pattern>} style revision specifiers. So now you can find the first commit whose message doesn't match a pattern, complementing the existing positive matching. e.g.:

    $ git rebase -i  <at> ^{/!-^WIP}

My use-case is in having a "work, work, work, rebase, push"-style workflow, which generates a lot of "WIP foo" commits. While rebasing is usually handled via "git rebase -i origin/master", occasionally I will already have several "good, but not yet ready to push" commits hanging around while I finish work on related commits. In these situations, the ability to quickly "git diff <at> ^{/!-^WIP}" to get an overview of all changes "since the last one I was happy with", can be useful.

This is the second version of the patch series. The previous attempt used the notation <at> ^{/!WIP}, rather than <at> ^{/!-WIP}, so the "modifier" was the '!' character. Now, '!' is taken as an indicator that the pattern is to be interpreted differently, and '-' is taken as an indicator of how it is to be interpreted differently. This follows recent discussion with "Junio C Hamano" <gitster <at> pobox.com> and much-less recent discussion archived at:

http://thread.gmane.org/gmane.comp.version-control.git/40460/focus=40477

In summary, '!' is to be used as an "escape hatch", for further extension of the "name commit by pattern" functionality. Theorised future extensions indicated things like "what was to be searched", e.g.: <at> ^{/!(a=author)}. With only two interpretations of the '!' leader, for now (including the '!!' literal notation), adding such a verbose form, such as ' <at> ^{/!(negative)foo}', seemed inappropriate at this time. In the event that such verbose forms are ever implemented, this new form may act as a shorthand, for a basic case.

Will Palmer (2):
  test for '!' handling in rev-parse's named commits
  object name: introduce '^{/!-<negative pattern>}' notation
 Documentation/revisions.txt | 11 +++++-----
 sha1_name.c                 | 20 ++++++++++++-----
 t/t1511-rev-parse-caret.sh  | 53 ++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 73 insertions(+), 11 deletions(-)
-- 
2.7.0-rc2
Stephen P. Smith· Jan 10, 2016, 02:22 UTC · re: Stephen P. Smith · lore

[PATCH V3 1/2] test for '!' handling in rev-parse's named commits

From: Will Palmer <wmpalmer@gmail.com>

In anticipation of extending this behaviour, add tests verifying the handling of exclamation marks when looking up a commit "by name".

Specifically, as documented: '<rev>^{/!Message}' should fail, as the '!' prefix is reserved; while '<rev>^{!!Message}' should search for a commit whose message contains the string "!Message".

Signed-off-by: Will Palmer <wmpalmer@gmail.com>
Signed-off-by: Stephen P. Smith <ischis2@cox.net>
---
Notes:
    Moved modref branch from 2/2 to the 1/2 patch as discussed in [1] and
    [2].
    
    In [3] the suggestion was made to change ^{!/... to ^{/!.  The comment
    notes that anything after { is reserved and can be used.
    
    The v2 commit mesage (which has been retained) noted that !Message
    should fail as '!' is reserved where !!Message should search for a
    string that contains !Message.
    
    Because of the commit note, I chose not to make the change from
    ^{!/... to ^{/!..
    
    [1] http://article.gmane.org/gmane.comp.version-control.git/271071
    [2] http://article.gmane.org/gmane.comp.version-control.git/283573
    [3] http://article.gmane.org/gmane.comp.version-control.git/283597
 t/t1511-rev-parse-caret.sh | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
Show changes to t/t1511-rev-parse-caret.sh +23 −1
diff --git a/t/t1511-rev-parse-caret.sh b/t/t1511-rev-parse-caret.sh
index 15973f2..b2f90be 100755
--- a/t/t1511-rev-parse-caret.sh
+++ b/t/t1511-rev-parse-caret.sh
@@ -18,7 +18,15 @@ test_expect_success 'setup' '
 	git checkout master &&
 	echo modified >>a-blob &&
 	git add -u &&
-	git commit -m Modified
+	git commit -m Modified &&
+	git branch modref &&
+	echo changed! >>a-blob &&
+	git add -u &&
+	git commit -m !Exp &&
+	git branch expref &&
+	echo changed >>a-blob &&
+	git add -u &&
+	git commit -m Changed
 '
 
 test_expect_success 'ref^{non-existent}' '
@@ -77,4 +85,18 @@ test_expect_success 'ref^{/Initial}' '
 	test_cmp expected actual
 '
 
+test_expect_success 'ref^{/!Exp}' '
+	test_must_fail git rev-parse master^{/!Exp}
+'
+
+test_expect_success 'ref^{/!}' '
+	test_must_fail git rev-parse master^{/!}
+'
+
+test_expect_success 'ref^{/!!Exp}' '
+	git rev-parse expref >expected &&
+	git rev-parse master^{/!!Exp} >actual &&
+	test_cmp expected actual
+'
+
 test_done
-- 
2.7.0-rc2
Stephen P. Smith· Jan 10, 2016, 02:23 UTC · re: Stephen P. Smith · lore

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

From: Will Palmer <wmpalmer@gmail.com>
To name a commit, you can now say
    $ git rev-parse HEAD^{/!-foo}

and it will return the hash of the first commit reachable from HEAD, whose commit message does not contain "foo". This is the opposite of the existing <rev>^{/<pattern>} syntax.

The specific use-case this is intended for is to perform an operation, excluding the most-recent commits containing a particular marker. For example, if you tend to make "work in progress" commits, with messages beginning with "WIP", you work, then it could be useful to diff against "the most recent commit which was not a WIP commit". That sort of thing now possible, via commands such as:

    $ git diff @^{/!-^WIP}

The leader '/!-', rather than simply '/!', to denote a negative match, is chosen to leave room for additional modifiers in the future.

Signed-off-by: Will Palmer <wmpalmer@gmail.com>
Signed-off-by: Stephen P. Smith <ischis2@cox.net>
---
Notes:
    Moved modref branch from 2/2 to the 1/2 patch as discussed in [1] and
    [2].
    
    [1] http://article.gmane.org/gmane.comp.version-control.git/271071
    [2] http://article.gmane.org/gmane.comp.version-control.git/283573
 Documentation/revisions.txt | 11 ++++++-----
 sha1_name.c                 | 20 +++++++++++++++-----
 t/t1511-rev-parse-caret.sh  | 31 ++++++++++++++++++++++++++++++-
 3 files changed, 51 insertions(+), 11 deletions(-)
Show changes to 3 files +51 −11

Documentation/revisions.txt, sha1_name.c, t/t1511-rev-parse-caret.sh

diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt
index d85e303..0c84d4f 100644
--- a/Documentation/revisions.txt
+++ b/Documentation/revisions.txt
@@ -176,11 +176,12 @@ existing tag object.
   A colon, followed by a slash, followed by a text, names
   a commit whose commit message matches the specified regular expression.
   This name returns the youngest matching commit which is
-  reachable from any ref.  If the commit message starts with a
-  '!' you have to repeat that;  the special sequence ':/!',
-  followed by something else than '!', is reserved for now.
-  The regular expression can match any part of the commit message. To
-  match messages starting with a string, one can use e.g. ':/^foo'.
+  reachable from any ref. The regular expression can match any part of the
+  commit message. To match messages starting with a string, one can use
+  e.g. ':/^foo'. The special sequence ':/!' is reserved for modifiers to what
+  is matched. ':/!-foo' performs a negative match, while ':/!!foo' matches a
+  literal '!' character, followed by 'foo'. Any other sequence beginning with
+  ':/!' is reserved for now.
 
 '<rev>:<path>', e.g. 'HEAD:README', ':README', 'master:./README'::
   A suffix ':' followed by a path names the blob or tree
diff --git a/sha1_name.c b/sha1_name.c
index 892db21..a2c5303 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -848,8 +848,12 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned l
  * through history and returning the first commit whose message starts
  * the given regular expression.
  *
- * For future extension, ':/!' is reserved. If you want to match a message
- * beginning with a '!', you have to repeat the exclamation mark.
+ * For negative-matching, prefix the pattern-part with '!-', like: ':/!-WIP'.
+ *
+ * For a literal '!' character at the beginning of a pattern, you have to repeat
+ * that, like: ':/!!foo'
+ *
+ * For future extension, all other sequences beginning with ':/!' are reserved.
  */
 
 /* Remember to update object flag allocation in object.h */
@@ -878,12 +882,18 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
 {
 	struct commit_list *backup = NULL, *l;
 	int found = 0;
+	int negative = 0;
 	regex_t regex;
 
 	if (prefix[0] == '!') {
-		if (prefix[1] != '!')
-			die ("Invalid search pattern: %s", prefix);
 		prefix++;
+
+		if (prefix[0] == '-') {
+			prefix++;
+			negative = 1;
+		} else if (prefix[0] != '!') {
+			die ("Invalid search pattern: %s", prefix);
+		}
 	}
 
 	if (regcomp(&regex, prefix, REG_EXTENDED))
@@ -903,7 +913,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
 			continue;
 		buf = get_commit_buffer(commit, NULL);
 		p = strstr(buf, "\n\n");
-		matches = p && !regexec(&regex, p + 2, 0, NULL, 0);
+		matches = p && (negative ^ !regexec(&regex, p + 2, 0, NULL, 0));
 		unuse_commit_buffer(commit, buf);
 
 		if (matches) {
diff --git a/t/t1511-rev-parse-caret.sh b/t/t1511-rev-parse-caret.sh
index b2f90be..8a5983f 100755
--- a/t/t1511-rev-parse-caret.sh
+++ b/t/t1511-rev-parse-caret.sh
@@ -26,7 +26,10 @@ test_expect_success 'setup' '
 	git branch expref &&
 	echo changed >>a-blob &&
 	git add -u &&
-	git commit -m Changed
+	git commit -m Changed &&
+	echo changed-again >>a-blob &&
+	git add -u &&
+	git commit -m Changed-again
 '
 
 test_expect_success 'ref^{non-existent}' '
@@ -99,4 +102,30 @@ test_expect_success 'ref^{/!!Exp}' '
 	test_cmp expected actual
 '
 
+test_expect_success 'ref^{/!-}' '
+	test_must_fail git rev-parse master^{/!-}
+'
+
+test_expect_success 'ref^{/!-.}' '
+	test_must_fail git rev-parse master^{/!-.}
+'
+
+test_expect_success 'ref^{/!-non-existent}' '
+	git rev-parse master >expected &&
+	git rev-parse master^{/!-non-existent} >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'ref^{/!-Changed}' '
+	git rev-parse expref >expected &&
+	git rev-parse master^{/!-Changed} >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'ref^{/!-!Exp}' '
+	git rev-parse modref >expected &&
+	git rev-parse expref^{/!-!Exp} >actual &&
+	test_cmp expected actual
+'
+
 test_done
-- 
2.7.0-rc2
Philip Oakley· Jan 11, 2016, 17:59 UTC · re: Stephen P. Smith · lore

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

From: "Stephen P. Smith" <ischis2@cox.net>
> From: Will Palmer <wmpalmer@gmail.com>
>
> To name a commit, you can now say

perhaps s|say|use the :/!-<negative pattern> regex style, and consequentially, say|

Should the patch subject line also be updated to reflect the change?
Show 172 quoted lines
>
>    $ git rev-parse HEAD^{/!-foo}
>
> and it will return the hash of the first commit reachable from HEAD,
> whose commit message does not contain "foo". This is the opposite of the
> existing <rev>^{/<pattern>} syntax.
>
> The specific use-case this is intended for is to perform an operation,
> excluding the most-recent commits containing a particular marker. For
> example, if you tend to make "work in progress" commits, with messages
> beginning with "WIP", you work, then it could be useful to diff against
> "the most recent commit which was not a WIP commit". That sort of thing
> now possible, via commands such as:
>
>    $ git diff @^{/!-^WIP}
>
> The leader '/!-', rather than simply '/!', to denote a negative match,
> is chosen to leave room for additional modifiers in the future.
>
> Signed-off-by: Will Palmer <wmpalmer@gmail.com>
> Signed-off-by: Stephen P. Smith <ischis2@cox.net>
> ---
>
> Notes:
>    Moved modref branch from 2/2 to the 1/2 patch as discussed in [1] and
>    [2].
>
>    [1] http://article.gmane.org/gmane.comp.version-control.git/271071
>    [2] http://article.gmane.org/gmane.comp.version-control.git/283573
>
> Documentation/revisions.txt | 11 ++++++-----
> sha1_name.c                 | 20 +++++++++++++++-----
> t/t1511-rev-parse-caret.sh  | 31 ++++++++++++++++++++++++++++++-
> 3 files changed, 51 insertions(+), 11 deletions(-)
>
> diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt
> index d85e303..0c84d4f 100644
> --- a/Documentation/revisions.txt
> +++ b/Documentation/revisions.txt
> @@ -176,11 +176,12 @@ existing tag object.
>   A colon, followed by a slash, followed by a text, names
>   a commit whose commit message matches the specified regular expression.
>   This name returns the youngest matching commit which is
> -  reachable from any ref.  If the commit message starts with a
> -  '!' you have to repeat that;  the special sequence ':/!',
> -  followed by something else than '!', is reserved for now.
> -  The regular expression can match any part of the commit message. To
> -  match messages starting with a string, one can use e.g. ':/^foo'.
> +  reachable from any ref. The regular expression can match any part of 
> the
> +  commit message. To match messages starting with a string, one can use
> +  e.g. ':/^foo'. The special sequence ':/!' is reserved for modifiers to 
> what
> +  is matched. ':/!-foo' performs a negative match, while ':/!!foo' 
> matches a
> +  literal '!' character, followed by 'foo'. Any other sequence beginning 
> with
> +  ':/!' is reserved for now.
>
> '<rev>:<path>', e.g. 'HEAD:README', ':README', 'master:./README'::
>   A suffix ':' followed by a path names the blob or tree
> diff --git a/sha1_name.c b/sha1_name.c
> index 892db21..a2c5303 100644
> --- a/sha1_name.c
> +++ b/sha1_name.c
> @@ -848,8 +848,12 @@ static int get_sha1_1(const char *name, int len, 
> unsigned char *sha1, unsigned l
>  * through history and returning the first commit whose message starts
>  * the given regular expression.
>  *
> - * For future extension, ':/!' is reserved. If you want to match a 
> message
> - * beginning with a '!', you have to repeat the exclamation mark.
> + * For negative-matching, prefix the pattern-part with '!-', like: 
> ':/!-WIP'.
> + *
> + * For a literal '!' character at the beginning of a pattern, you have to 
> repeat
> + * that, like: ':/!!foo'
> + *
> + * For future extension, all other sequences beginning with ':/!' are 
> reserved.
>  */
>
> /* Remember to update object flag allocation in object.h */
> @@ -878,12 +882,18 @@ static int get_sha1_oneline(const char *prefix, 
> unsigned char *sha1,
> {
>  struct commit_list *backup = NULL, *l;
>  int found = 0;
> + int negative = 0;
>  regex_t regex;
>
>  if (prefix[0] == '!') {
> - if (prefix[1] != '!')
> - die ("Invalid search pattern: %s", prefix);
>  prefix++;
> +
> + if (prefix[0] == '-') {
> + prefix++;
> + negative = 1;
> + } else if (prefix[0] != '!') {
> + die ("Invalid search pattern: %s", prefix);
> + }
>  }
>
>  if (regcomp(&regex, prefix, REG_EXTENDED))
> @@ -903,7 +913,7 @@ static int get_sha1_oneline(const char *prefix, 
> unsigned char *sha1,
>  continue;
>  buf = get_commit_buffer(commit, NULL);
>  p = strstr(buf, "\n\n");
> - matches = p && !regexec(&regex, p + 2, 0, NULL, 0);
> + matches = p && (negative ^ !regexec(&regex, p + 2, 0, NULL, 0));
>  unuse_commit_buffer(commit, buf);
>
>  if (matches) {
> diff --git a/t/t1511-rev-parse-caret.sh b/t/t1511-rev-parse-caret.sh
> index b2f90be..8a5983f 100755
> --- a/t/t1511-rev-parse-caret.sh
> +++ b/t/t1511-rev-parse-caret.sh
> @@ -26,7 +26,10 @@ test_expect_success 'setup' '
>  git branch expref &&
>  echo changed >>a-blob &&
>  git add -u &&
> - git commit -m Changed
> + git commit -m Changed &&
> + echo changed-again >>a-blob &&
> + git add -u &&
> + git commit -m Changed-again
> '
>
> test_expect_success 'ref^{non-existent}' '
> @@ -99,4 +102,30 @@ test_expect_success 'ref^{/!!Exp}' '
>  test_cmp expected actual
> '
>
> +test_expect_success 'ref^{/!-}' '
> + test_must_fail git rev-parse master^{/!-}
> +'
> +
> +test_expect_success 'ref^{/!-.}' '
> + test_must_fail git rev-parse master^{/!-.}
> +'
> +
> +test_expect_success 'ref^{/!-non-existent}' '
> + git rev-parse master >expected &&
> + git rev-parse master^{/!-non-existent} >actual &&
> + test_cmp expected actual
> +'
> +
> +test_expect_success 'ref^{/!-Changed}' '
> + git rev-parse expref >expected &&
> + git rev-parse master^{/!-Changed} >actual &&
> + test_cmp expected actual
> +'
> +
> +test_expect_success 'ref^{/!-!Exp}' '
> + git rev-parse modref >expected &&
> + git rev-parse expref^{/!-!Exp} >actual &&
> + test_cmp expected actual
> +'
> +
> test_done
> -- 
> 2.7.0-rc2
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
Stephen P. Smith· Jan 13, 2016, 04:51 UTC · re: Philip Oakley · lore

[PATCH V4 0/2] specify commit by negative pattern

Add support for negative pattern matching in the @^{/<pattern>} regex pattern style, and consequentially the style revision specifiers. So now you can find the first commit whose message doesn't match a pattern, complementing the existing positive matching. e.g.:

    $ git rebase -i @^{/!-^WIP}

My use-case is in having a "work, work, work, rebase, push"-style workflow, which generates a lot of "WIP foo" commits. While rebasing is usually handled via "git rebase -i origin/master", occasionally I will already have several "good, but not yet ready to push" commits hanging around while I finish work on related commits. In these situations, the ability to quickly "git diff @^{/!-^WIP}" to get an overview of all changes "since the last one I was happy with", can be useful.

This is the forth version of the patch series. The previous attempt used the notation @^{/!WIP}, rather than @^{/!-WIP}, so the "modifier" was the '!' character. Now, '!' is taken as an indicator that the pattern is to be interpreted differently, and '-' is taken as an indicator of how it is to be interpreted differently. This follows recent discussion with "Junio C Hamano" <gitster@pobox.com> and much-less recent discussion archived at:

http://thread.gmane.org/gmane.comp.version-control.git/40460/focus=40477

In summary, '!' is to be used as an "escape hatch", for further extension of the "name commit by pattern" functionality. Theorised future extensions indicated things like "what was to be searched", e.g.: @^{/!(a=author)}. With only two interpretations of the '!' leader, for now (including the '!!' literal notation), adding such a verbose form, such as '@^{/!(negative)foo}', seemed inappropriate at this time. In the event that such verbose forms are ever implemented, this new form may act as a shorthand, for a basic case.

Will Palmer (2):
  test for '!' handling in rev-parse's named commits
  object name: introduce '^{/!-<negative pattern>}' notation
 Documentation/revisions.txt | 11 +++++-----
 sha1_name.c                 | 20 ++++++++++++-----
 t/t1511-rev-parse-caret.sh  | 53 ++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 73 insertions(+), 11 deletions(-)
-- 
2.7.0-rc2
Stephen P. Smith· Jan 13, 2016, 04:51 UTC · re: Philip Oakley · lore

[PATCH V4 1/2] test for '!' handling in rev-parse's named commits

From: Will Palmer <wmpalmer@gmail.com>

In anticipation of extending this behaviour, add tests verifying the handling of exclamation marks when looking up a commit "by name".

Specifically, as documented: '<rev>^{/!Message}' should fail, as the '!' prefix is reserved; while '<rev>^{!!Message}' should search for a commit whose message contains the string "!Message".

Signed-off-by: Will Palmer <wmpalmer@gmail.com>
Signed-off-by: Stephen P. Smith <ischis2@cox.net>
---
Notes:
    No actual changes made to this patch.  Just re-sending to keep 
    consistent with updates to the rest of the series.
 t/t1511-rev-parse-caret.sh | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
Show changes to t/t1511-rev-parse-caret.sh +23 −1
diff --git a/t/t1511-rev-parse-caret.sh b/t/t1511-rev-parse-caret.sh
index 15973f2..b2f90be 100755
--- a/t/t1511-rev-parse-caret.sh
+++ b/t/t1511-rev-parse-caret.sh
@@ -18,7 +18,15 @@ test_expect_success 'setup' '
 	git checkout master &&
 	echo modified >>a-blob &&
 	git add -u &&
-	git commit -m Modified
+	git commit -m Modified &&
+	git branch modref &&
+	echo changed! >>a-blob &&
+	git add -u &&
+	git commit -m !Exp &&
+	git branch expref &&
+	echo changed >>a-blob &&
+	git add -u &&
+	git commit -m Changed
 '
 
 test_expect_success 'ref^{non-existent}' '
@@ -77,4 +85,18 @@ test_expect_success 'ref^{/Initial}' '
 	test_cmp expected actual
 '
 
+test_expect_success 'ref^{/!Exp}' '
+	test_must_fail git rev-parse master^{/!Exp}
+'
+
+test_expect_success 'ref^{/!}' '
+	test_must_fail git rev-parse master^{/!}
+'
+
+test_expect_success 'ref^{/!!Exp}' '
+	git rev-parse expref >expected &&
+	git rev-parse master^{/!!Exp} >actual &&
+	test_cmp expected actual
+'
+
 test_done
-- 
2.7.0-rc2
Stephen P. Smith· Jan 13, 2016, 04:52 UTC · re: Philip Oakley · lore

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

From: Will Palmer <wmpalmer@gmail.com>

To name a commit, you can now use the :/!-<negative pattern> regex style, and consequentially, say

    $ git rev-parse HEAD^{/!-foo}

and it will return the hash of the first commit reachable from HEAD, whose commit message does not contain "foo". This is the opposite of the existing <rev>^{/<pattern>} syntax.

The specific use-case this is intended for is to perform an operation, excluding the most-recent commits containing a particular marker. For example, if you tend to make "work in progress" commits, with messages beginning with "WIP", you work, then it could be useful to diff against "the most recent commit which was not a WIP commit". That sort of thing now possible, via commands such as:

    $ git diff @^{/!-^WIP}

The leader '/!-', rather than simply '/!', to denote a negative match, is chosen to leave room for additional modifiers in the future.

Signed-off-by: Will Palmer <wmpalmer@gmail.com>
Signed-off-by: Stephen P. Smith <ischis2@cox.net>
---
Notes:
    Changed |say|use the :/!-<negative pattern> regex style, and consequentially, say|.
    
    Chose not to chagne subject since it matches the end of
    git rev-parse HEAD^{/!-foo}
    Mailing list web interface is again not working; therefore, I don't 
    have URLs for the earlier review comments.
 Documentation/revisions.txt | 11 ++++++-----
 sha1_name.c                 | 20 +++++++++++++++-----
 t/t1511-rev-parse-caret.sh  | 31 ++++++++++++++++++++++++++++++-
 3 files changed, 51 insertions(+), 11 deletions(-)
Show changes to 3 files +51 −11

Documentation/revisions.txt, sha1_name.c, t/t1511-rev-parse-caret.sh

diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt
index d85e303..0c84d4f 100644
--- a/Documentation/revisions.txt
+++ b/Documentation/revisions.txt
@@ -176,11 +176,12 @@ existing tag object.
   A colon, followed by a slash, followed by a text, names
   a commit whose commit message matches the specified regular expression.
   This name returns the youngest matching commit which is
-  reachable from any ref.  If the commit message starts with a
-  '!' you have to repeat that;  the special sequence ':/!',
-  followed by something else than '!', is reserved for now.
-  The regular expression can match any part of the commit message. To
-  match messages starting with a string, one can use e.g. ':/^foo'.
+  reachable from any ref. The regular expression can match any part of the
+  commit message. To match messages starting with a string, one can use
+  e.g. ':/^foo'. The special sequence ':/!' is reserved for modifiers to what
+  is matched. ':/!-foo' performs a negative match, while ':/!!foo' matches a
+  literal '!' character, followed by 'foo'. Any other sequence beginning with
+  ':/!' is reserved for now.
 
 '<rev>:<path>', e.g. 'HEAD:README', ':README', 'master:./README'::
   A suffix ':' followed by a path names the blob or tree
diff --git a/sha1_name.c b/sha1_name.c
index 892db21..a2c5303 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -848,8 +848,12 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned l
  * through history and returning the first commit whose message starts
  * the given regular expression.
  *
- * For future extension, ':/!' is reserved. If you want to match a message
- * beginning with a '!', you have to repeat the exclamation mark.
+ * For negative-matching, prefix the pattern-part with '!-', like: ':/!-WIP'.
+ *
+ * For a literal '!' character at the beginning of a pattern, you have to repeat
+ * that, like: ':/!!foo'
+ *
+ * For future extension, all other sequences beginning with ':/!' are reserved.
  */
 
 /* Remember to update object flag allocation in object.h */
@@ -878,12 +882,18 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
 {
 	struct commit_list *backup = NULL, *l;
 	int found = 0;
+	int negative = 0;
 	regex_t regex;
 
 	if (prefix[0] == '!') {
-		if (prefix[1] != '!')
-			die ("Invalid search pattern: %s", prefix);
 		prefix++;
+
+		if (prefix[0] == '-') {
+			prefix++;
+			negative = 1;
+		} else if (prefix[0] != '!') {
+			die ("Invalid search pattern: %s", prefix);
+		}
 	}
 
 	if (regcomp(&regex, prefix, REG_EXTENDED))
@@ -903,7 +913,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
 			continue;
 		buf = get_commit_buffer(commit, NULL);
 		p = strstr(buf, "\n\n");
-		matches = p && !regexec(&regex, p + 2, 0, NULL, 0);
+		matches = p && (negative ^ !regexec(&regex, p + 2, 0, NULL, 0));
 		unuse_commit_buffer(commit, buf);
 
 		if (matches) {
diff --git a/t/t1511-rev-parse-caret.sh b/t/t1511-rev-parse-caret.sh
index b2f90be..8a5983f 100755
--- a/t/t1511-rev-parse-caret.sh
+++ b/t/t1511-rev-parse-caret.sh
@@ -26,7 +26,10 @@ test_expect_success 'setup' '
 	git branch expref &&
 	echo changed >>a-blob &&
 	git add -u &&
-	git commit -m Changed
+	git commit -m Changed &&
+	echo changed-again >>a-blob &&
+	git add -u &&
+	git commit -m Changed-again
 '
 
 test_expect_success 'ref^{non-existent}' '
@@ -99,4 +102,30 @@ test_expect_success 'ref^{/!!Exp}' '
 	test_cmp expected actual
 '
 
+test_expect_success 'ref^{/!-}' '
+	test_must_fail git rev-parse master^{/!-}
+'
+
+test_expect_success 'ref^{/!-.}' '
+	test_must_fail git rev-parse master^{/!-.}
+'
+
+test_expect_success 'ref^{/!-non-existent}' '
+	git rev-parse master >expected &&
+	git rev-parse master^{/!-non-existent} >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'ref^{/!-Changed}' '
+	git rev-parse expref >expected &&
+	git rev-parse master^{/!-Changed} >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'ref^{/!-!Exp}' '
+	git rev-parse modref >expected &&
+	git rev-parse expref^{/!-!Exp} >actual &&
+	test_cmp expected actual
+'
+
 test_done
-- 
2.7.0-rc2
Junio C Hamano· Jan 13, 2016, 19:15 UTC · re: Stephen P. Smith · lore

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

"Stephen P. Smith" <ischis2@cox.net> writes:
Show 35 quoted lines
> From: Will Palmer <wmpalmer@gmail.com>
>
> To name a commit, you can now use the :/!-<negative pattern> regex
> style, and consequentially, say
>
>     $ git rev-parse HEAD^{/!-foo}
>
> and it will return the hash of the first commit reachable from HEAD,
> whose commit message does not contain "foo". This is the opposite of the
> existing <rev>^{/<pattern>} syntax.
>
> The specific use-case this is intended for is to perform an operation,
> excluding the most-recent commits containing a particular marker. For
> example, if you tend to make "work in progress" commits, with messages
> beginning with "WIP", you work, then it could be useful to diff against
> "the most recent commit which was not a WIP commit". That sort of thing
> now possible, via commands such as:
>
>     $ git diff @^{/!-^WIP}
>
> The leader '/!-', rather than simply '/!', to denote a negative match,
> is chosen to leave room for additional modifiers in the future.
>
> Signed-off-by: Will Palmer <wmpalmer@gmail.com>
> Signed-off-by: Stephen P. Smith <ischis2@cox.net>
> ---
>
> Notes:
>     Changed |say|use the :/!-<negative pattern> regex style, and consequentially, say|.
>     
>     Chose not to chagne subject since it matches the end of
>     git rev-parse HEAD^{/!-foo}
>
>     Mailing list web interface is again not working; therefore, I don't 
>     have URLs for the earlier review comments.

Thanks, this looks good (and it looked good already at the previous round).

Show 19 quoted lines
> diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt
> index d85e303..0c84d4f 100644
> --- a/Documentation/revisions.txt
> +++ b/Documentation/revisions.txt
> @@ -176,11 +176,12 @@ existing tag object.
>    A colon, followed by a slash, followed by a text, names
>    a commit whose commit message matches the specified regular expression.
>    This name returns the youngest matching commit which is
> -  reachable from any ref.  If the commit message starts with a
> -  '!' you have to repeat that;  the special sequence ':/!',
> -  followed by something else than '!', is reserved for now.
> -  The regular expression can match any part of the commit message. To
> -  match messages starting with a string, one can use e.g. ':/^foo'.
> +  reachable from any ref. The regular expression can match any part of the
> +  commit message. To match messages starting with a string, one can use
> +  e.g. ':/^foo'. The special sequence ':/!' is reserved for modifiers to what
> +  is matched. ':/!-foo' performs a negative match, while ':/!!foo' matches a
> +  literal '!' character, followed by 'foo'. Any other sequence beginning with
> +  ':/!' is reserved for now.

The original text reads as if ":/foo" looks for 'foo' anywhere in the log message while ":/!!foo" looks for '!foo' at the beginning, which was incorrect as far as I can tell, but the updated text corrects it. Good.

Show 7 quoted lines
> @@ -903,7 +913,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
>  			continue;
>  		buf = get_commit_buffer(commit, NULL);
>  		p = strstr(buf, "\n\n");
> -		matches = p && !regexec(&regex, p + 2, 0, NULL, 0);
> +		matches = p && (negative ^ !regexec(&regex, p + 2, 0, NULL, 0));
>  		unuse_commit_buffer(commit, buf);

Hmph, without "negative pattern match", if you asked for ":/foo" and the commit did not have any body (which I do not think the current version of Git allows to create by default, but there may be such commits created by older versions of Git or reimplementation of Git made by others), p could be NULL. In such a case, any regex would not match, so I would expect that commit to be shown.

In other words, I wonder if the above should be
		matches = negative ^ (p && !regexec(&regex, p + 2, 0, NULL, 0));

This would not make practical difference, but I would expect any change to introduce "negative patch" to an original logic that is

	matches = ORIGINAL_LOGIC_TO_COMPUTE_MATCH
to become
	matches = negative ^ ORIGINAL_LOGIC_TO_COMPUTE_MATCH
Stephen P. Smith· Jan 31, 2016, 00:06 UTC · re: Junio C Hamano · lore

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

From: Will Palmer <wmpalmer@gmail.com>

To name a commit, you can now use the :/!-<negative pattern> regex style, and consequentially, say

    $ git rev-parse HEAD^{/!-foo}

and it will return the hash of the first commit reachable from HEAD, whose commit message does not contain "foo". This is the opposite of the existing <rev>^{/<pattern>} syntax.

The specific use-case this is intended for is to perform an operation, excluding the most-recent commits containing a particular marker. For example, if you tend to make "work in progress" commits, with messages beginning with "WIP", you work, then it could be useful to diff against "the most recent commit which was not a WIP commit". That sort of thing now possible, via commands such as:

    $ git diff @^{/!-^WIP}

The leader '/!-', rather than simply '/!', to denote a negative match, is chosen to leave room for additional modifiers in the future.

Signed-off-by: Will Palmer <wmpalmer@gmail.com>
Signed-off-by: Stephen P. Smith <ischis2@cox.net>
---
Notes:
    I agree that there may be commits that have an empty body which were made
    with older git releases.
    
    Even if the current git does check for empty bodied commits (by
    default), the git plumbing should be able to still create such
    commits.
    
    The tests show that the change from:
        matches = p && (negative ^ !regexec(&regex, p + 2, 0, NULL, 0));
    to
        matches = negative ^ (p && !regexec(&regex, p + 2, 0, NULL, 0));
    did not break the proposed patch.
 Documentation/revisions.txt | 11 ++++++-----
 sha1_name.c                 | 20 +++++++++++++++-----
 t/t1511-rev-parse-caret.sh  | 31 ++++++++++++++++++++++++++++++-
 3 files changed, 51 insertions(+), 11 deletions(-)
Show changes to 3 files +51 −11

Documentation/revisions.txt, sha1_name.c, t/t1511-rev-parse-caret.sh

diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt
index d85e303..0c84d4f 100644
--- a/Documentation/revisions.txt
+++ b/Documentation/revisions.txt
@@ -176,11 +176,12 @@ existing tag object.
   A colon, followed by a slash, followed by a text, names
   a commit whose commit message matches the specified regular expression.
   This name returns the youngest matching commit which is
-  reachable from any ref.  If the commit message starts with a
-  '!' you have to repeat that;  the special sequence ':/!',
-  followed by something else than '!', is reserved for now.
-  The regular expression can match any part of the commit message. To
-  match messages starting with a string, one can use e.g. ':/^foo'.
+  reachable from any ref. The regular expression can match any part of the
+  commit message. To match messages starting with a string, one can use
+  e.g. ':/^foo'. The special sequence ':/!' is reserved for modifiers to what
+  is matched. ':/!-foo' performs a negative match, while ':/!!foo' matches a
+  literal '!' character, followed by 'foo'. Any other sequence beginning with
+  ':/!' is reserved for now.
 
 '<rev>:<path>', e.g. 'HEAD:README', ':README', 'master:./README'::
   A suffix ':' followed by a path names the blob or tree
diff --git a/sha1_name.c b/sha1_name.c
index 892db21..89918ca 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -848,8 +848,12 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned l
  * through history and returning the first commit whose message starts
  * the given regular expression.
  *
- * For future extension, ':/!' is reserved. If you want to match a message
- * beginning with a '!', you have to repeat the exclamation mark.
+ * For negative-matching, prefix the pattern-part with '!-', like: ':/!-WIP'.
+ *
+ * For a literal '!' character at the beginning of a pattern, you have to repeat
+ * that, like: ':/!!foo'
+ *
+ * For future extension, all other sequences beginning with ':/!' are reserved.
  */
 
 /* Remember to update object flag allocation in object.h */
@@ -878,12 +882,18 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
 {
 	struct commit_list *backup = NULL, *l;
 	int found = 0;
+	int negative = 0;
 	regex_t regex;
 
 	if (prefix[0] == '!') {
-		if (prefix[1] != '!')
-			die ("Invalid search pattern: %s", prefix);
 		prefix++;
+
+		if (prefix[0] == '-') {
+			prefix++;
+			negative = 1;
+		} else if (prefix[0] != '!') {
+			die ("Invalid search pattern: %s", prefix);
+		}
 	}
 
 	if (regcomp(&regex, prefix, REG_EXTENDED))
@@ -903,7 +913,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
 			continue;
 		buf = get_commit_buffer(commit, NULL);
 		p = strstr(buf, "\n\n");
-		matches = p && !regexec(&regex, p + 2, 0, NULL, 0);
+		matches = negative ^ (p && !regexec(&regex, p + 2, 0, NULL, 0));
 		unuse_commit_buffer(commit, buf);
 
 		if (matches) {
diff --git a/t/t1511-rev-parse-caret.sh b/t/t1511-rev-parse-caret.sh
index b2f90be..8a5983f 100755
--- a/t/t1511-rev-parse-caret.sh
+++ b/t/t1511-rev-parse-caret.sh
@@ -26,7 +26,10 @@ test_expect_success 'setup' '
 	git branch expref &&
 	echo changed >>a-blob &&
 	git add -u &&
-	git commit -m Changed
+	git commit -m Changed &&
+	echo changed-again >>a-blob &&
+	git add -u &&
+	git commit -m Changed-again
 '
 
 test_expect_success 'ref^{non-existent}' '
@@ -99,4 +102,30 @@ test_expect_success 'ref^{/!!Exp}' '
 	test_cmp expected actual
 '
 
+test_expect_success 'ref^{/!-}' '
+	test_must_fail git rev-parse master^{/!-}
+'
+
+test_expect_success 'ref^{/!-.}' '
+	test_must_fail git rev-parse master^{/!-.}
+'
+
+test_expect_success 'ref^{/!-non-existent}' '
+	git rev-parse master >expected &&
+	git rev-parse master^{/!-non-existent} >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'ref^{/!-Changed}' '
+	git rev-parse expref >expected &&
+	git rev-parse master^{/!-Changed} >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'ref^{/!-!Exp}' '
+	git rev-parse modref >expected &&
+	git rev-parse expref^{/!-!Exp} >actual &&
+	test_cmp expected actual
+'
+
 test_done
-- 
2.7.0-rc2
Philip Oakley· Jan 10, 2016, 11:00 UTC · re: Stephen P. Smith · lore

Re: [PATCH V3 0/2] specify commit by negative pattern

From: "Stephen P. Smith" <ischis2@cox.net>
> Add support for negative pattern matching in  <at> ^{/<pattern>} style
Has this become mangled by replacing the '@' with ' <at> ' ?

When I look at the update to revisions.txt it doesn't look like its touching the '@' description. Is this '@^' a new (for the documenation) combination. Or has the example confused me?

Show 46 quoted lines
> revision specifiers. So now you can find the first commit whose message
> doesn't match a pattern, complementing the existing positive matching.
> e.g.:
>
>    $ git rebase -i  <at> ^{/!-^WIP}
>
> My use-case is in having a "work, work, work, rebase, push"-style
> workflow, which generates a lot of "WIP foo" commits. While rebasing is
> usually handled via "git rebase -i origin/master", occasionally I will
> already have several "good, but not yet ready to push" commits hanging
> around while I finish work on related commits. In these situations, the
> ability to quickly "git diff  <at> ^{/!-^WIP}" to get an overview of all
> changes "since the last one I was happy with", can be useful.
>
> This is the second version of the patch series. The previous attempt
> used the notation  <at> ^{/!WIP}, rather than  <at> ^{/!-WIP}, so the 
> "modifier"
> was the '!' character. Now, '!' is taken as an indicator that the
> pattern is to be interpreted differently, and '-' is taken as an
> indicator of how it is to be interpreted differently. This follows
> recent discussion with "Junio C Hamano" <gitster <at> pobox.com> and 
> much-less
> recent discussion archived at:
>
> http://thread.gmane.org/gmane.comp.version-control.git/40460/focus=40477
>
> In summary, '!' is to be used as an "escape hatch", for further
> extension of the "name commit by pattern" functionality. Theorised future
> extensions indicated things like "what was to be searched",
> e.g.:  <at> ^{/!(a=author)}.  With only two interpretations of the '!'
> leader, for now (including the '!!' literal notation), adding such a
> verbose form, such as ' <at> ^{/!(negative)foo}', seemed inappropriate at 
> this
> time. In the event that such verbose forms are ever implemented, this new
> form may act as a shorthand, for a basic case.
>
> Will Palmer (2):
>  test for '!' handling in rev-parse's named commits
>  object name: introduce '^{/!-<negative pattern>}' notation
>
> Documentation/revisions.txt | 11 +++++-----
> sha1_name.c                 | 20 ++++++++++++-----
> t/t1511-rev-parse-caret.sh  | 53 
> ++++++++++++++++++++++++++++++++++++++++++++-
> 3 files changed, 73 insertions(+), 11 deletions(-)
>

-- Philip

Stephen P. Smith· Jan 11, 2016, 00:08 UTC · re: Philip Oakley · lore

[PATCH V3 0/2] specify commit by negative pattern

Add support for negative pattern matching in @^{/<pattern>} style revision specifiers. So now you can find the first commit whose message doesn't match a pattern, complementing the existing positive matching. e.g.:

    $ git rebase -i @^{/!-^WIP}

My use-case is in having a "work, work, work, rebase, push"-style workflow, which generates a lot of "WIP foo" commits. While rebasing is usually handled via "git rebase -i origin/master", occasionally I will already have several "good, but not yet ready to push" commits hanging around while I finish work on related commits. In these situations, the ability to quickly "git diff @^{/!-^WIP}" to get an overview of all changes "since the last one I was happy with", can be useful.

This is the second version of the patch series. The previous attempt used the notation @^{/!WIP}, rather than @^{/!-WIP}, so the "modifier" was the '!' character. Now, '!' is taken as an indicator that the pattern is to be interpreted differently, and '-' is taken as an indicator of how it is to be interpreted differently. This follows recent discussion with "Junio C Hamano" <gitster@pobox.com> and much-less recent discussion archived at:

http://thread.gmane.org/gmane.comp.version-control.git/40460/focus=40477

In summary, '!' is to be used as an "escape hatch", for further extension of the "name commit by pattern" functionality. Theorised future extensions indicated things like "what was to be searched", e.g.: @^{/!(a=author)}. With only two interpretations of the '!' leader, for now (including the '!!' literal notation), adding such a verbose form, such as '@^{/!(negative)foo}', seemed inappropriate at this time. In the event that such verbose forms are ever implemented, this new form may act as a shorthand, for a basic case.

Will Palmer (2):
  test for '!' handling in rev-parse's named commits
  object name: introduce '^{/!-<negative pattern>}' notation
 Documentation/revisions.txt | 11 +++++-----
 sha1_name.c                 | 20 ++++++++++++-----
 t/t1511-rev-parse-caret.sh  | 53 ++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 73 insertions(+), 11 deletions(-)
-- 
2.7.0-rc2
Philip Oakley· Jan 11, 2016, 17:59 UTC · re: Stephen P. Smith · lore

Re: [PATCH V3 0/2] specify commit by negative pattern

From: "Stephen P. Smith" <ischis2@cox.net>
> Add support for negative pattern matching in

perhaps s!in!in the :/<text> regex pattern style, and consequentially the!

Given that the documenation changes are there.
Show 52 quoted lines
>         @^{/<pattern>} style
> revision specifiers. So now you can find the first commit whose message
> doesn't match a pattern, complementing the existing positive matching.
> e.g.:
>
>    $ git rebase -i @^{/!-^WIP}
>
> My use-case is in having a "work, work, work, rebase, push"-style
> workflow, which generates a lot of "WIP foo" commits. While rebasing is
> usually handled via "git rebase -i origin/master", occasionally I will
> already have several "good, but not yet ready to push" commits hanging
> around while I finish work on related commits. In these situations, the
> ability to quickly "git diff @^{/!-^WIP}" to get an overview of all
> changes "since the last one I was happy with", can be useful.
>
> This is the second version of the patch series. The previous attempt
> used the notation @^{/!WIP}, rather than @^{/!-WIP}, so the "modifier"
> was the '!' character. Now, '!' is taken as an indicator that the
> pattern is to be interpreted differently, and '-' is taken as an
> indicator of how it is to be interpreted differently. This follows
> recent discussion with "Junio C Hamano" <gitster@pobox.com> and much-less
> recent discussion archived at:
>
> http://thread.gmane.org/gmane.comp.version-control.git/40460/focus=40477
>
> In summary, '!' is to be used as an "escape hatch", for further
> extension of the "name commit by pattern" functionality. Theorised future
> extensions indicated things like "what was to be searched",
> e.g.: @^{/!(a=author)}.  With only two interpretations of the '!'
> leader, for now (including the '!!' literal notation), adding such a
> verbose form, such as '@^{/!(negative)foo}', seemed inappropriate at this
> time. In the event that such verbose forms are ever implemented, this new
> form may act as a shorthand, for a basic case.
>
> Will Palmer (2):
>  test for '!' handling in rev-parse's named commits
>  object name: introduce '^{/!-<negative pattern>}' notation
>
> Documentation/revisions.txt | 11 +++++-----
> sha1_name.c                 | 20 ++++++++++++-----
> t/t1511-rev-parse-caret.sh  | 53 
> ++++++++++++++++++++++++++++++++++++++++++++-
> 3 files changed, 73 insertions(+), 11 deletions(-)
>
> -- 
> 2.7.0-rc2
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
Stephen & Linda Smith· Jan 10, 2016, 14:14 UTC · re: Stephen P. Smith · lore

Re: [PATCH V3 0/2] specify commit by negative pattern

On Sunday, January 10, 2016 01:25:42 PM Philip Oakley wrote:
> From: "Stephen P. Smith" <ischis2@cox.net>
> > Add support for negative pattern matching in  <at> ^{/<pattern>} style
> 
> Has this become mangled by replacing the '@' with ' <at> ' ?

It looks like the cover letter got mangled. I will fix after I get any comments on the patches themselves.

Show 55 quoted lines
> 
> When I look at the update to revisions.txt it doesn't look like its touching 
> the '@' description.
> Is this '@^' a new (for the documenation) combination. Or has the example 
> confused me?
> 
> > revision specifiers. So now you can find the first commit whose message
> > doesn't match a pattern, complementing the existing positive matching.
> > e.g.:
> >
> >    $ git rebase -i  <at> ^{/!-^WIP}
> >
> > My use-case is in having a "work, work, work, rebase, push"-style
> > workflow, which generates a lot of "WIP foo" commits. While rebasing is
> > usually handled via "git rebase -i origin/master", occasionally I will
> > already have several "good, but not yet ready to push" commits hanging
> > around while I finish work on related commits. In these situations, the
> > ability to quickly "git diff  <at> ^{/!-^WIP}" to get an overview of all
> > changes "since the last one I was happy with", can be useful.
> >
> > This is the second version of the patch series. The previous attempt
> > used the notation  <at> ^{/!WIP}, rather than  <at> ^{/!-WIP}, so the 
> > "modifier"
> > was the '!' character. Now, '!' is taken as an indicator that the
> > pattern is to be interpreted differently, and '-' is taken as an
> > indicator of how it is to be interpreted differently. This follows
> > recent discussion with "Junio C Hamano" <gitster <at> pobox.com> and 
> > much-less
> > recent discussion archived at:
> >
> > http://thread.gmane.org/gmane.comp.version-control.git/40460/focus=40477
> >
> > In summary, '!' is to be used as an "escape hatch", for further
> > extension of the "name commit by pattern" functionality. Theorised future
> > extensions indicated things like "what was to be searched",
> > e.g.:  <at> ^{/!(a=author)}.  With only two interpretations of the '!'
> > leader, for now (including the '!!' literal notation), adding such a
> > verbose form, such as ' <at> ^{/!(negative)foo}', seemed inappropriate at 
> > this
> > time. In the event that such verbose forms are ever implemented, this new
> > form may act as a shorthand, for a basic case.
> >
> > Will Palmer (2):
> >  test for '!' handling in rev-parse's named commits
> >  object name: introduce '^{/!-<negative pattern>}' notation
> >
> > Documentation/revisions.txt | 11 +++++-----
> > sha1_name.c                 | 20 ++++++++++++-----
> > t/t1511-rev-parse-caret.sh  | 53 
> > ++++++++++++++++++++++++++++++++++++++++++++-
> > 3 files changed, 73 insertions(+), 11 deletions(-)
> >
> --
> Philip 
> 
Philip Oakley· Jan 10, 2016, 23:08 UTC · re: Stephen & Linda Smith · lore

Re: [PATCH V3 0/2] specify commit by negative pattern

From: "Stephen & Linda Smith" <ischis2@cox.net>
Show 9 quoted lines
> On Sunday, January 10, 2016 01:25:42 PM Philip Oakley wrote:
>> From: "Stephen P. Smith" <ischis2@cox.net>
>> > Add support for negative pattern matching in  <at> ^{/<pattern>} style
>>
>> Has this become mangled by replacing the '@' with ' <at> ' ?
> It looks like the cover letter got mangled.  I will fix after I get any 
> comments
> on the patches themselves.
>

I think I was also confused between the extra ways of spelling @ (listed first in revisions.txt), and the extra was of spelling <rev>, i.e. the <rev>^{/<text>}, and then in patch 2/2 it actually being the :/<text> syntax.

Show 66 quoted lines
>>
>> When I look at the update to revisions.txt it doesn't look like its 
>> touching
>> the '@' description.
>> Is this '@^' a new (for the documenation) combination. Or has the example
>> confused me?
>>
>> > revision specifiers. So now you can find the first commit whose message
>> > doesn't match a pattern, complementing the existing positive matching.
>> > e.g.:
>> >
>> >    $ git rebase -i  <at> ^{/!-^WIP}
>> >
>> > My use-case is in having a "work, work, work, rebase, push"-style
>> > workflow, which generates a lot of "WIP foo" commits. While rebasing is
>> > usually handled via "git rebase -i origin/master", occasionally I will
>> > already have several "good, but not yet ready to push" commits hanging
>> > around while I finish work on related commits. In these situations, the
>> > ability to quickly "git diff  <at> ^{/!-^WIP}" to get an overview of 
>> > all
>> > changes "since the last one I was happy with", can be useful.
>> >
>> > This is the second version of the patch series. The previous attempt
>> > used the notation  <at> ^{/!WIP}, rather than  <at> ^{/!-WIP}, so the
>> > "modifier"
>> > was the '!' character. Now, '!' is taken as an indicator that the
>> > pattern is to be interpreted differently, and '-' is taken as an
>> > indicator of how it is to be interpreted differently. This follows
>> > recent discussion with "Junio C Hamano" <gitster <at> pobox.com> and
>> > much-less
>> > recent discussion archived at:
>> >
>> > http://thread.gmane.org/gmane.comp.version-control.git/40460/focus=40477
>> >
>> > In summary, '!' is to be used as an "escape hatch", for further
>> > extension of the "name commit by pattern" functionality. Theorised 
>> > future
>> > extensions indicated things like "what was to be searched",
>> > e.g.:  <at> ^{/!(a=author)}.  With only two interpretations of the '!'
>> > leader, for now (including the '!!' literal notation), adding such a
>> > verbose form, such as ' <at> ^{/!(negative)foo}', seemed inappropriate 
>> > at
>> > this
>> > time. In the event that such verbose forms are ever implemented, this 
>> > new
>> > form may act as a shorthand, for a basic case.
>> >
>> > Will Palmer (2):
>> >  test for '!' handling in rev-parse's named commits
>> >  object name: introduce '^{/!-<negative pattern>}' notation
>> >
>> > Documentation/revisions.txt | 11 +++++-----
>> > sha1_name.c                 | 20 ++++++++++++-----
>> > t/t1511-rev-parse-caret.sh  | 53
>> > ++++++++++++++++++++++++++++++++++++++++++++-
>> > 3 files changed, 73 insertions(+), 11 deletions(-)
>> >
>> --
>> Philip
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
Stephen & Linda Smith· Jan 9, 2016, 01:55 UTC · re: Stephen Smith · lore

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

On Friday, January 08, 2016 10:21:48 AM Junio C Hamano wrote:
Show 16 quoted lines
> Stephen Smith <ischis2@cox.net> writes:
> 
> > Junio C Hamano <gitster <at> pobox.com> writes:
> >> >  	echo modified >>a-blob &&
> >> >  	git add -u &&
> >> >  	git commit -m Modified &&
> >> > +	git branch modref &&
> >> 
> >> This probably belongs to the previous step, no?
> >> 
> > What did you mean by this comment?  I looked at the original patch and at 
> > Will's response to your comment and am not quite sure what was meant.
> 
> Notice that the title is [2/2], so there is [1/2], which turns out
> to be http://article.gmane.org/gmane.comp.version-control.git/270898
> 
I had that patch but didn't connect it to your comment.   
Show 10 quoted lines
> That patch updates the preparatory steps of the test script so that
> [2/2] have more commits and refs to work with to perform more tests.
> 
> Marking the result of that "Modified" commit so that it can be
> referenced later with a short name 'modref' is something that should
> have done in [1/2], which added that new invocation of "git commit"
> to record that "Modified" commit, not in [2/2] as an afterthought
> "Oh I created Modified commit in 1/2 so that I can use it in the
> test in 2/2, but I forgot to give it a name, so I am adding a new
> invocation of 'git branch' in this step".
Yep makes sense.
Show 13 quoted lines
> 
> >
> >> > +test_expect_success 'ref^{/!-}' '
> >> > +	test_must_fail git rev-parse master^{/!-}
> >> > +'
> >> 
> > I plan on leaving this in.
> >
> >> > +test_expect_success 'ref^{/!-.}' '
> >> > +	test_must_fail git rev-parse master^{/!-.}
> >> > +'
> >> 
> > I plan on leaving this in.
Duy Nguyen· Jan 9, 2016, 02:18 UTC · re: Stephen Smith · lore

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

On Fri, Jan 8, 2016 at 1:04 PM, Stephen Smith <ischis2@cox.net> wrote:
>> > +test_expect_success 'ref^{/!-}' '
>> > +   test_must_fail git rev-parse master^{/!-}
>> > +'

Shouldn't it be ^{!/... instead of ^{/!... ? People could have a pattern starting with "!" and /! will change its meaning. On the other hand, anything else after { is still reserved and can safely be used.

-- 
Duy
Junio C Hamano· Jan 11, 2016, 17:13 UTC · re: Duy Nguyen · lore

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

Duy Nguyen <pclouds@gmail.com> writes:
Show 8 quoted lines
> On Fri, Jan 8, 2016 at 1:04 PM, Stephen Smith <ischis2@cox.net> wrote:
>>> > +test_expect_success 'ref^{/!-}' '
>>> > +   test_must_fail git rev-parse master^{/!-}
>>> > +'
>
> Shouldn't it be ^{!/... instead of ^{/!... ? People could have a
> pattern starting with "!" and /! will change its meaning. On the other
> hand, anything else after { is still reserved and can safely be used.

http://thread.gmane.org/gmane.comp.version-control.git/40460/focus=40477 clarifies the above, I think.

Back then we seem to have been thinking only about ":" as the overall "search the history to name an object traversing from all tips" prefix, but the current one is described in terms of the more generally useful "<committish>^{/<pattern>}" syntax and the escape hatch applies--they are both handled by get_sha1_oneline() the same way.

← back to recent threads