specify commit by negative pattern
v2 cover 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" <[email protected]> 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(-)
Signature · 1 line
2.3.0.rc1
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".
--- t/t1511-rev-parse-caret.sh | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
t/t1511-rev-parse-caret.sh +22 -1
@@ -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
Signature · 1 line
2.3.0.rc1
PATCH v2 2/2 object name: introduce '^{/!-<negative pattern>}' notation
In reply to Will PalmerTo 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.
--- Documentation/revisions.txt | 11 ++++++----- sha1_name.c | 20 +++++++++++++++----- t/t1511-rev-parse-caret.sh | 32 +++++++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 11 deletions(-)
Documentation/revisions.txt +6 -5
@@ -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
sha1_name.c +15 -5
@@ -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 (®ex, 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 (®ex, p +2 ,0 ,NULL ,0 ); + matches = p && (negative ^ !regexec (®ex, p +2 ,0 ,NULL ,0 ));unuse_commit_buffer (commit, buf);if (matches) {
t/t1511-rev-parse-caret.sh +31 -1
@@ -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
Signature · 1 line
2.3.0.rc1
Re: [PATCH v2 2/2] object name: introduce '^{/!-<negative pattern>}' notation
Quoted 9 lines · Will Palmer
- * 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.
t/t1511-rev-parse-caret.sh test_expect_success 'setup' ' · line 22
Quoted 9 lines
t/t1511-rev-parse-caret.sh +1
-0@@ -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?
t/t1511-rev-parse-caret.sh test_expect_success 'ref^{/!!Exp}' ' · line 107
Quoted 3 lines
t/t1511-rev-parse-caret.sh +3
-0+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 ;-).
t/t1511-rev-parse-caret.sh test_expect_success 'ref^{/!!Exp}' ' · line 111
Quoted 3 lines
t/t1511-rev-parse-caret.sh +3
-0+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.
t/t1511-rev-parse-caret.sh test_expect_success 'ref^{/!!Exp}' ' · line 117
Quoted 5 lines
t/t1511-rev-parse-caret.sh +5
-0+test_expect_success 'ref^{/!-non-existent}' ' + git rev-parse master >expected && + git rev-parse master^{/!-non-existent} >actual && + test_cmp expected actual +'
OK.
t/t1511-rev-parse-caret.sh test_expect_success 'ref^{/!!Exp}' ' · line 123
Quoted 5 lines
t/t1511-rev-parse-caret.sh +5
-0+test_expect_success 'ref^{/!-Changed}' ' + git rev-parse expref >expected && + git rev-parse master^{/!-Changed} >actual && + test_cmp expected actual +'
OK.
t/t1511-rev-parse-caret.sh test_expect_success 'ref^{/!!Exp}' ' · line 129
Quoted 5 lines
t/t1511-rev-parse-caret.sh +5
-0+test_expect_success 'ref^{/!-!Exp}' ' + git rev-parse modref >expected && + git rev-parse expref^{/!-!Exp} >actual && + test_cmp expected actual +'
OK.
Quoted 1 line
test_done
Re: [PATCH v2 2/2] object name: introduce '^{/!-<negative pattern>}' notation
Quoted 12 lines · Junio C Hamano
t/t1511-rev-parse-caret.sh test_expect_success 'setup' ' · line 22
Quoted 9 lines · Will Palmer
t/t1511-rev-parse-caret.sh +1
-0@@ -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.
Quoted 10 lines
t/t1511-rev-parse-caret.sh test_expect_success 'setup' ' · line 25
Quoted 4 lines
t/t1511-rev-parse-caret.sh +3
-0+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<----------------------------------------------------------------------
sha1_name.c +0 -0
@@ -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(...)
Quoted 10 lines
t/t1511-rev-parse-caret.sh test_expect_success 'setup' ' · line 28
Quoted 5 lines
t/t1511-rev-parse-caret.sh +3
-0+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.
Re: [PATCH v2 2/2] object name: introduce '^{/!-<negative pattern>}' notation
Quoted 1 line · Will Palmer
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.
Re: [PATCH v2 2/2] object name: introduce '^{/!-<negativepattern>}' notation
In reply to Junio C HamanoQuoted 7 lines · Junio C Hamano <gitster <at> pobox.com> writes:
t/t1511-rev-parse-caret.sh test_expect_success 'setup' ' · line 22
Quoted 4 lines
t/t1511-rev-parse-caret.sh +1
-0echo 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.
Quoted 4 lines
t/t1511-rev-parse-caret.sh test_expect_success 'ref^{/!!Exp}' ' · line 107
Quoted 3 lines
t/t1511-rev-parse-caret.sh +3
-0+test_expect_success 'ref^{/!-}' ' + test_must_fail git rev-parse master^{/!-} +'
I plan on leaving this in.
Quoted 4 lines
t/t1511-rev-parse-caret.sh test_expect_success 'ref^{/!!Exp}' ' · line 111
Quoted 3 lines
t/t1511-rev-parse-caret.sh +3
-0+test_expect_success 'ref^{/!-.}' ' + test_must_fail git rev-parse master^{/!-.} +'
I plan on leaving this in.
Re: [PATCH v2 2/2] object name: introduce '^{/!-<negativepattern>}' notation
Quoted 10 lines · Junio C Hamano
Quoted 8 lines · Stephen Smith
Quoted 7 lines · Junio C Hamano <gitster <at> pobox.com> writes:
t/t1511-rev-parse-caret.sh test_expect_success 'setup' ' · line 22
Quoted 4 lines
t/t1511-rev-parse-caret.sh +1
-0echo modified >>a-blob && git add -u && git commit -m Modified && + git branch modref &&This probably belongs to the previous step, no?
Quoted 6 lines
Quoted 2 lines
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.
Quoted 10 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.
Quoted 13 lines
Quoted 13 lines
Quoted 6 lines
t/t1511-rev-parse-caret.sh test_expect_success 'ref^{/!!Exp}' ' · line 107
Quoted 5 lines
t/t1511-rev-parse-caret.sh +3
-0+test_expect_success 'ref^{/!-}' ' + test_must_fail git rev-parse master^{/!-} +'I plan on leaving this in.
Quoted 4 lines
t/t1511-rev-parse-caret.sh test_expect_success 'ref^{/!!Exp}' ' · line 111
Quoted 3 lines
t/t1511-rev-parse-caret.sh +3
-0+test_expect_success 'ref^{/!-.}' ' + test_must_fail git rev-parse master^{/!-.} +'I plan on leaving this in.
Re: [PATCH v2 2/2] object name: introduce '^{/!-<negativepattern>}' notation
In reply to Stephen SmithQuoted 3 lines · Stephen Smith
Quoted 3 lines
t/t1511-rev-parse-caret.sh test_expect_success 'ref^{/!!Exp}' ' · line 107
Quoted 3 lines
t/t1511-rev-parse-caret.sh +3
-0+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.
Signature · 1 line
Duy
Re: [PATCH v2 2/2] object name: introduce '^{/!-<negativepattern>}' notation
Quoted 8 lines · Duy Nguyen
Quoted 3 lines · Stephen Smith
Quoted 3 lines
t/t1511-rev-parse-caret.sh test_expect_success 'ref^{/!!Exp}' ' · line 107
Quoted 3 lines
t/t1511-rev-parse-caret.sh +3
-0+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.
Re: [PATCH v2 2/2] object name: introduce '^{/!-<negativepattern>}' notation
In reply to Stephen SmithQuoted 10 lines · Stephen Smith
Quoted 7 lines · Junio C Hamano <gitster <at> pobox.com> writes:
t/t1511-rev-parse-caret.sh test_expect_success 'setup' ' · line 22
Quoted 4 lines
t/t1511-rev-parse-caret.sh +1
-0echo 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".
Quoted 12 lines
Quoted 5 lines
t/t1511-rev-parse-caret.sh test_expect_success 'ref^{/!!Exp}' ' · line 107
Quoted 4 lines
t/t1511-rev-parse-caret.sh +3
-0+test_expect_success 'ref^{/!-}' ' + test_must_fail git rev-parse master^{/!-} +'I plan on leaving this in.
Quoted 4 lines
t/t1511-rev-parse-caret.sh test_expect_success 'ref^{/!!Exp}' ' · line 111
Quoted 3 lines
t/t1511-rev-parse-caret.sh +3
-0+test_expect_success 'ref^{/!-.}' ' + test_must_fail git rev-parse master^{/!-.} +'I plan on leaving this in.
v3 cover 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(-)
Signature · 1 line
2.7.0-rc2
PATCH v3 1/2 test for '!' handling in rev-parse's named commits
From: Will Palmer <[email protected]>
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".
---
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(-)
t/t1511-rev-parse-caret.sh +23 -1
@@ -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
Signature · 1 line
2.7.0-rc2
PATCH v3 2/2 object name: introduce '^{/!-<negative pattern>}' notation
In reply to Stephen P. SmithFrom: Will Palmer <[email protected]>
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.
---
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/283573Documentation/revisions.txt | 11 ++++++----- sha1_name.c | 20 +++++++++++++++----- t/t1511-rev-parse-caret.sh | 31 ++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 11 deletions(-)
Documentation/revisions.txt +6 -5
@@ -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
sha1_name.c +15 -5
@@ -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 (®ex, 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 (®ex, p +2 ,0 ,NULL ,0 ); + matches = p && (negative ^ !regexec (®ex, p +2 ,0 ,NULL ,0 ));unuse_commit_buffer (commit, buf);if (matches) {
t/t1511-rev-parse-caret.sh +30 -1
@@ -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
Signature · 1 line
2.7.0-rc2
Re: [PATCH V3 2/2] object name: introduce '^{/!-<negative pattern>}' notation
From: "Stephen P. Smith" <[email protected]>
Quoted 3 lines
From: Will Palmer <[email protected]>
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?
Quoted 172 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 <[email protected]>Signed-off-by Stephen P. Smith <[email protected]>---
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/283573Documentation/revisions.txt | 11 ++++++----- sha1_name.c | 20 +++++++++++++++----- t/t1511-rev-parse-caret.sh | 31 ++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 11 deletions(-)Documentation/revisions.txt +1
-5@@ -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 ofthe
Documentation/revisions.txt +2
-0+ commit message. To match messages starting with a string, one can use + e.g. ':/^foo'. The special sequence ':/!' is reserved for modifiers towhat
+ 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 treesha1_name.c +0
-0@@ -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*/sha1_name.c +8
-2@@ -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(®ex, prefix, REG_EXTENDED))sha1_name.c +1
-1@@ -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 (®ex, p +2 ,0 ,NULL ,0 ); + matches = p && (negative ^ !regexec (®ex, p +2 ,0 ,NULL ,0 ));unuse_commit_buffer (commit, buf);if (matches) {
t/t1511-rev-parse-caret.sh +4
-1@@ -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}' 't/t1511-rev-parse-caret.sh +0
-0@@ -99,4 +102,30 @@ test_expect_success 'ref^{/!!Exp}' ' test_cmp expected actual'
t/t1511-rev-parse-caret.sh +26
-0+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_doneSignature · 6 lines
2.7.0-rc2 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
v4 cover 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" <[email protected]> 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(-)
Signature · 1 line
2.7.0-rc2
PATCH v4 1/2 test for '!' handling in rev-parse's named commits
In reply to Philip OakleyFrom: Will Palmer <[email protected]>
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".
---
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(-)
t/t1511-rev-parse-caret.sh +23 -1
@@ -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
Signature · 1 line
2.7.0-rc2
PATCH v4 2/2 object name: introduce '^{/!-<negative pattern>}' notation
In reply to Philip OakleyFrom: Will Palmer <[email protected]>
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.
---
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(-)
Documentation/revisions.txt +6 -5
@@ -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
sha1_name.c +15 -5
@@ -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 (®ex, 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 (®ex, p +2 ,0 ,NULL ,0 ); + matches = p && (negative ^ !regexec (®ex, p +2 ,0 ,NULL ,0 ));unuse_commit_buffer (commit, buf);if (matches) {
t/t1511-rev-parse-caret.sh +30 -1
@@ -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
Signature · 1 line
2.7.0-rc2
Re: [PATCH V4 2/2] object name: introduce '^{/!-<negative pattern>}' notation
Quoted 27 lines · Stephen P. Smith
From: Will Palmer <[email protected]>
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 <[email protected]>Signed-off-by Stephen P. Smith <[email protected]>---
Quoted 8 lines
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).
Quoted 9 lines
Documentation/revisions.txt +0
-1@@ -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
Documentation/revisions.txt existing tag object. · line 184
Quoted 10 lines
Documentation/revisions.txt +6
-4- '!' 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.
Documentation/revisions.txt static int get_sha1_oneline(const char *prefix, unsigned char *sha1, · line 917
Quoted 7 lines
Documentation/revisions.txt +1
-1@@ -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(®ex, p + 2, 0, NULL, 0); + matches = p && (negative ^ !regexec(®ex, 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(®ex, 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
PATCH v5 2/2 object name: introduce '^{/!-<negative pattern>}' notation
From: Will Palmer <[email protected]>
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.
---
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(®ex, p + 2, 0, NULL, 0));
to
matches = negative ^ (p && !regexec(®ex, 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(-)
Documentation/revisions.txt +6 -5
@@ -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
sha1_name.c +15 -5
@@ -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 (®ex, 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 (®ex, p +2 ,0 ,NULL ,0 ); + matches = negative ^ (p && !regexec (®ex, p +2 ,0 ,NULL ,0 ));unuse_commit_buffer (commit, buf);if (matches) {
t/t1511-rev-parse-caret.sh +30 -1
@@ -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
Signature · 1 line
2.7.0-rc2
Re: [PATCH V5 2/2] object name: introduce '^{/!-<negative pattern>}' notation
Thanks.
Quoted 4 lines · Philip Oakley
From: "Stephen P. Smith" <[email protected]>
Quoted 1 line
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.
Quoted 55 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?Quoted 40 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>}' notationQuoted 6 lines
Documentation/revisions.txt | 11 +++++----- sha1_name.c | 20 ++++++++++++----- t/t1511-rev-parse-caret.sh | 53 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 73 insertions(+), 11 deletions(-)--
Philip
From: "Stephen & Linda Smith" <[email protected]>
Quoted 8 lines · Philip Oakley
Quoted 4 lines
From: "Stephen P. Smith" <[email protected]>
Quoted 1 line
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.
Quoted 61 lines
Quoted 46 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?Quoted 40 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>}' notationQuoted 9 lines
Quoted 6 lines
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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: "Stephen P. Smith" <[email protected]>
Quoted 1 line
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?
Quoted 37 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
Quoted 6 lines
Documentation/revisions.txt | 11 +++++----- sha1_name.c | 20 ++++++++++++----- t/t1511-rev-parse-caret.sh | 53 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 73 insertions(+), 11 deletions(-)
--
Philip
v3 cover 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" <[email protected]> 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(-)
Signature · 1 line
2.7.0-rc2
From: "Stephen P. Smith" <[email protected]>
Quoted 1 line
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.
Quoted 52 lines
@^{/<pattern>} stylerevision 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" <[email protected]> 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>}' notationDocumentation/revisions.txt | 11 +++++----- sha1_name.c | 20 ++++++++++++----- t/t1511-rev-parse-caret.sh | 53 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 73 insertions(+), 11 deletions(-)Signature · 6 lines
2.7.0-rc2 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html