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

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

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

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

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

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

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

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

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

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

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

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

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