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

Re: [BUG] git rev-parse :/ "regex" syntax not really regex?

From
AMAndreas Mohr <andi@lisas.de>
Date
Apr 17, 2016, 15:54 UTC
Message-ID
<20160417155440.GA4817@rhlx01.hs-esslingen.de>
In-Reply-To
<87inzgtjfv.fsf@linux-m68k.org>
On Sun, Apr 17, 2016 at 04:10:28PM +0200, Andreas Schwab wrote:
Show 11 quoted lines
> Andreas Mohr <andi@lisas.de> writes:
> 
> > Unless I happened to misunderstand git's regex flavour, or something else...
> > (hmm, perhaps it's a try-match-single-line vs. multi-line content issue,
> > which perhaps does not work by specifying the trailing $)
> 
> This is exactly the difference.  git log --grep matches individual lines
> (like grep), whereas :/<regexp> matches against the whole commit message
> including embedded (and trailing) newlines, and $ doesn't match an
> embedded newline.  Thus to address the second commit in your example you
> have to use $':/^My commit\n' (using bash's ANSI-C quoting feature).

At first I thought "no way, I already did try trailing \n", but then I realized that it's exactly use of that ANSI-C quoting feature which makes that \n newline be (non-)interpreted correctly here, and it truly works.

Thank you for a fast and well-inform{ed|ing} response!

Now there's only one question remaining: do we simply take this as a documentation-supplied-by-mailing-list item ;-), or should certain parts of the parse-rev :/ documentation be improved in a certain manner?

No, there's another one: this syntax seems to be (as indicated) indeed bash-specific, since a short dash test script (POSIX): #!/usr/bin/dash

git rev-parse $':/^My commit\n'

simply prints a $:/^My commit\n result, and no amount of syntax fiddling succeeded in getting the correct commit result on dash.

Well, since that \n simply *is* a newline (see also http://unix.stackexchange.com/questions/155367/when-to-use-bash-ansi-c-style-escape-e-g-n ), a successful way to encode it in dash (all non-bash shells?) is:

git rev-parse :/'^My commit '

i.e. with an *actual* newline.

BTW, as a (albeit weak) former m68k architecture user, thank you for your efforts!

Andreas Mohr
Previous: Andreas Schwab
Message 3 of 3 in “[BUG] git rev-parse :/ "regex" syntax not really regex?”
  1. Andreas MohrApr 17, 2016
  2. Andreas SchwabApr 17, 2016
  3. Andreas MohrApr 17, 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.