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

26 messages from 2015-06-06 to 2016-02-01. Participants: Will Palmer, Junio C Hamano, Stephen Smith, Stephen & Linda Smith, Duy Nguyen, Stephen P. Smith, Philip Oakley.
Thread: https://gitlist.dev/t/39539

## Will Palmer, 2015-06-06 00:24

Subject: [PATCH v2 0/2] specify commit by negative pattern
Message-ID: <1433550295-15098-1-git-send-email-wmpalmer@gmail.com>
URL: https://gitlist.dev/e/1433550295-15098-1-git-send-email-wmpalmer%40gmail.com

```
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, 2015-06-06 00:24

Subject: [PATCH v2 1/2] test for '!' handling in rev-parse's named commits
Message-ID: <1433550295-15098-2-git-send-email-wmpalmer@gmail.com>
URL: https://gitlist.dev/e/1433550295-15098-2-git-send-email-wmpalmer%40gmail.com
In-Reply-To: <1433550295-15098-1-git-send-email-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>
---
 t/t1511-rev-parse-caret.sh | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

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, 2015-06-06 00:24

Subject: [PATCH v2 2/2] object name: introduce '^{/!-<negative pattern>}' notation
Message-ID: <1433550295-15098-3-git-send-email-wmpalmer@gmail.com>
URL: https://gitlist.dev/e/1433550295-15098-3-git-send-email-wmpalmer%40gmail.com
In-Reply-To: <1433550295-15098-1-git-send-email-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>
---
 Documentation/revisions.txt | 11 ++++++-----
 sha1_name.c                 | 20 +++++++++++++++-----
 t/t1511-rev-parse-caret.sh  | 32 +++++++++++++++++++++++++++++++-
 3 files changed, 52 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 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, 2015-06-08 16:39

Subject: Re: [PATCH v2 2/2] object name: introduce '^{/!-<negative pattern>}' notation
Message-ID: <xmqqbngqcfxd.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqqbngqcfxd.fsf%40gitster.dls.corp.google.com
In-Reply-To: <1433550295-15098-3-git-send-email-wmpalmer@gmail.com>

```
Will Palmer <wmpalmer@gmail.com> writes:

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

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

> +test_expect_success 'ref^{/!-non-existent}' '
> +	git rev-parse master >expected &&
> +	git rev-parse master^{/!-non-existent} >actual &&
> +	test_cmp expected actual
> +'

OK.

> +test_expect_success 'ref^{/!-Changed}' '
> +	git rev-parse expref >expected &&
> +	git rev-parse master^{/!-Changed} >actual &&
> +	test_cmp expected actual
> +'

OK.

> +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, 2015-06-09 18:14

Subject: Re: [PATCH v2 2/2] object name: introduce '^{/!-<negative pattern>}' notation
Message-ID: <CAAKF_ub5c+2vVmG161O6gnUUeEcNfDUMU=mtn+k0T8bC-9ZHPw@mail.gmail.com>
URL: https://gitlist.dev/e/CAAKF_ub5c%2B2vVmG161O6gnUUeEcNfDUMU%3Dmtn%2Bk0T8bC-9ZHPw%40mail.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:
> 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.

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

```

## Junio C Hamano, 2015-10-28 17:52

Subject: Re: [PATCH v2 2/2] object name: introduce '^{/!-<negative pattern>}' notation
Message-ID: <xmqq7fm6lw35.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq7fm6lw35.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <CAAKF_ub5c+2vVmG161O6gnUUeEcNfDUMU=mtn+k0T8bC-9ZHPw@mail.gmail.com>

```
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, 2016-01-08 06:04

Subject: Re: [PATCH v2 2/2] object name: introduce '^{/!-<negativepattern>}' notation
Message-ID: <loom.20160108T065547-969@post.gmane.org>
URL: https://gitlist.dev/e/loom.20160108T065547-969%40post.gmane.org
In-Reply-To: <xmqqbngqcfxd.fsf@gitster.dls.corp.google.com>

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

> > +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, 2016-01-08 18:21

Subject: Re: [PATCH v2 2/2] object name: introduce '^{/!-<negativepattern>}' notation
Message-ID: <xmqq37u82apv.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq37u82apv.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <loom.20160108T065547-969@post.gmane.org>

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

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

>
>> > +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 & Linda Smith, 2016-01-09 01:55

Subject: Re: [PATCH v2 2/2] object name: introduce '^{/!-<negativepattern>}' notation
Message-ID: <17299684.zSfrSa31Pt@thunderbird>
URL: https://gitlist.dev/e/17299684.zSfrSa31Pt%40thunderbird
In-Reply-To: <loom.20160108T065547-969@post.gmane.org>

```

On Friday, January 08, 2016 10:21:48 AM Junio C Hamano wrote:
> 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.   

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

> 
> >
> >> > +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, 2016-01-09 02:18

Subject: Re: [PATCH v2 2/2] object name: introduce '^{/!-<negativepattern>}' notation
Message-ID: <CACsJy8Dar9sCkTg_SQsDUOWYNQ1PHjmA0KcgrvpvmeY=yVXPMg@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8Dar9sCkTg_SQsDUOWYNQ1PHjmA0KcgrvpvmeY%3DyVXPMg%40mail.gmail.com
In-Reply-To: <loom.20160108T065547-969@post.gmane.org>

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

```

## Stephen P. Smith, 2016-01-10 02:20

Subject: [PATCH V3 0/2] specify commit by negative pattern
Message-ID: <1452392429-2578-1-git-send-email-ischis2@cox.net>
URL: https://gitlist.dev/e/1452392429-2578-1-git-send-email-ischis2%40cox.net
In-Reply-To: <xmqq37u82apv.fsf@gitster.mtv.corp.google.com>

```
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, 2016-01-10 02:22

Subject: [PATCH V3 1/2] test for '!' handling in rev-parse's named commits
Message-ID: <1452392549-2656-1-git-send-email-ischis2@cox.net>
URL: https://gitlist.dev/e/1452392549-2656-1-git-send-email-ischis2%40cox.net
In-Reply-To: <1452392429-2578-1-git-send-email-ischis2@cox.net>

```
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(-)

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, 2016-01-10 02:23

Subject: [PATCH V3 2/2] object name: introduce '^{/!-<negative pattern>}' notation
Message-ID: <1452392583-2708-1-git-send-email-ischis2@cox.net>
URL: https://gitlist.dev/e/1452392583-2708-1-git-send-email-ischis2%40cox.net
In-Reply-To: <1452392429-2578-1-git-send-email-ischis2@cox.net>

```
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(-)

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, 2016-01-10 11:00

Subject: Re: [PATCH V3 0/2] specify commit by negative pattern
Message-ID: <87DF51336FE74635921A8C6857125F8B@PhilipOakley>
URL: https://gitlist.dev/e/87DF51336FE74635921A8C6857125F8B%40PhilipOakley
In-Reply-To: <1452392429-2578-1-git-send-email-ischis2@cox.net>

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

> 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 & Linda Smith, 2016-01-10 14:14

Subject: Re: [PATCH V3 0/2] specify commit by negative pattern
Message-ID: <1686181.AoEpo53h6D@thunderbird>
URL: https://gitlist.dev/e/1686181.AoEpo53h6D%40thunderbird
In-Reply-To: <1452392429-2578-1-git-send-email-ischis2@cox.net>

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

> 
> 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, 2016-01-10 23:08

Subject: Re: [PATCH V3 0/2] specify commit by negative pattern
Message-ID: <72AF834F7D7B46D298EFE697EBF19E0E@PhilipOakley>
URL: https://gitlist.dev/e/72AF834F7D7B46D298EFE697EBF19E0E%40PhilipOakley
In-Reply-To: <1686181.AoEpo53h6D@thunderbird>

```
From: "Stephen & Linda Smith" <ischis2@cox.net>
> 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.

>>
>> 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 P. Smith, 2016-01-11 00:08

Subject: [PATCH V3 0/2] specify commit by negative pattern
Message-ID: <1452470880-8753-1-git-send-email-ischis2@cox.net>
URL: https://gitlist.dev/e/1452470880-8753-1-git-send-email-ischis2%40cox.net
In-Reply-To: <87DF51336FE74635921A8C6857125F8B@PhilipOakley>

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

```

## Junio C Hamano, 2016-01-11 17:13

Subject: Re: [PATCH v2 2/2] object name: introduce '^{/!-<negativepattern>}' notation
Message-ID: <xmqqpox8xcn6.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqpox8xcn6.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <CACsJy8Dar9sCkTg_SQsDUOWYNQ1PHjmA0KcgrvpvmeY=yVXPMg@mail.gmail.com>

```
Duy Nguyen <pclouds@gmail.com> writes:

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

```

## Philip Oakley, 2016-01-11 17:59

Subject: Re: [PATCH V3 0/2] specify commit by negative pattern
Message-ID: <9A32BC480D1F4BD38436CE498D062D0B@PhilipOakley>
URL: https://gitlist.dev/e/9A32BC480D1F4BD38436CE498D062D0B%40PhilipOakley
In-Reply-To: <1452470880-8753-1-git-send-email-ischis2@cox.net>

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

>         @^{/<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
> 

```

## Philip Oakley, 2016-01-11 17:59

Subject: Re: [PATCH V3 2/2] object name: introduce '^{/!-<negative pattern>}' notation
Message-ID: <ED12DDDA0C004D23BDDB14973C675800@PhilipOakley>
URL: https://gitlist.dev/e/ED12DDDA0C004D23BDDB14973C675800%40PhilipOakley
In-Reply-To: <1452392583-2708-1-git-send-email-ischis2@cox.net>

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

>
>    $ 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, 2016-01-13 04:51

Subject: [PATCH V4 0/2] specify commit by negative pattern
Message-ID: <1452660671-5512-1-git-send-email-ischis2@cox.net>
URL: https://gitlist.dev/e/1452660671-5512-1-git-send-email-ischis2%40cox.net
In-Reply-To: <ED12DDDA0C004D23BDDB14973C675800@PhilipOakley>

```
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, 2016-01-13 04:51

Subject: [PATCH V4 1/2] test for '!' handling in rev-parse's named commits
Message-ID: <1452660708-5568-1-git-send-email-ischis2@cox.net>
URL: https://gitlist.dev/e/1452660708-5568-1-git-send-email-ischis2%40cox.net
In-Reply-To: <ED12DDDA0C004D23BDDB14973C675800@PhilipOakley>

```
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(-)

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, 2016-01-13 04:52

Subject: [PATCH V4 2/2] object name: introduce '^{/!-<negative pattern>}' notation
Message-ID: <1452660741-5616-1-git-send-email-ischis2@cox.net>
URL: https://gitlist.dev/e/1452660741-5616-1-git-send-email-ischis2%40cox.net
In-Reply-To: <ED12DDDA0C004D23BDDB14973C675800@PhilipOakley>

```
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(-)

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, 2016-01-13 19:15

Subject: Re: [PATCH V4 2/2] object name: introduce '^{/!-<negative pattern>}' notation
Message-ID: <xmqqh9ihnveu.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqh9ihnveu.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <1452660741-5616-1-git-send-email-ischis2@cox.net>

```
"Stephen P. Smith" <ischis2@cox.net> writes:

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

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

> @@ -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, 2016-01-31 00:06

Subject: [PATCH V5 2/2] object name: introduce '^{/!-<negative pattern>}' notation
Message-ID: <1454198761-27357-1-git-send-email-ischis2@cox.net>
URL: https://gitlist.dev/e/1454198761-27357-1-git-send-email-ischis2%40cox.net
In-Reply-To: <xmqqh9ihnveu.fsf@gitster.mtv.corp.google.com>

```
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(-)

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

```

## Junio C Hamano, 2016-02-01 21:42

Subject: Re: [PATCH V5 2/2] object name: introduce '^{/!-<negative pattern>}' notation
Message-ID: <xmqq4mdsumz9.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq4mdsumz9.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <1454198761-27357-1-git-send-email-ischis2@cox.net>

```
Thanks.

```
