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

Re: Why does "git log -G<regex>" works with "regexp-ignore-case" but not with other regexp-related options?

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Apr 20, 2015, 18:33 UTC
Message-ID
<CA+55aFzdSgvYo11PHamkOVASz61RUq26+s0na0Zh2RRwsEkrMg@mail.gmail.com>
In-Reply-To
<xmqqbniin1cw.fsf@gitster.dls.corp.google.com>
On Mon, Apr 20, 2015 at 10:41 AM, Junio C Hamano <gitster@pobox.com> wrote:
>
> Ahh, OK.  And not just -S and -G, the "fields in headers" may be
> something user may want to switch independently?

So personally, I hate extra command line flags for this. I'd much rather see is use something in the regular expression itself, and make *that* be the way you do it, and make it be the preferred format.

Otherwise, you'll always have the issue that you want *part* to be case-ignoring, and another entry not, and then it's just messy with the "ignore case" being some other thing.

And we support that with perl regexps, but those are only enabled with libpcre. I wonder if we could just make some simple pattern extension that we make work even *without* libpcre.

IOW, instead of making people use "-regexp-ignore-case", could we just say that we *always* support the syntax of appending "(?i)" in front of the regexp. So that your

    git log --regexp-ignore-case --author=tiM --grep=wip
example would be
    git log --author="(?i)tiM" --grep=wip

and it would match the _author_ with ignoring case, but the "--grep=wip" part would be an exact grep.

Right now the above already works (I think) if you:
 - build with USE_LIBPCRE
 - add that "--perl-regexp" switch.

but what I'm suggesting is that we'd make a special case for the magical perl modifier pattern at the beginning for "(?i)", and make it work even without USE_LIBPCRE, and without specifying "--perl-regexp".

We'd just special-case that pattern (and perhaps _only_ that special four-byte sequence of "(?i)" at the beginning of the search string), but perhaps we could support '(?s)' too?

Hmm? I realize that this would be theoretically an incompatible change, but it would be very convenient and if we document it well it might be ok. I doubt people really search for "(?i)" at the beginning of strings _except_ if they already know about the perl syntax and want it.

And to clarify: I don't suggest always building with libpcre. I literally suggest having something like

     /* hacky mac-hack hack */
    if (strncmp("(?i)", p->pattern, 4)) {
        p->pattern += 4;
        p->ignore_case = true;
    }
just in front of the "regcomp() call, and nothing more fancy than that.
                           Linus
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 12 in “Why does "git log -G<regex>" works with "regexp-ignore-case" but not with other regexp-related options?”
  1. Tim FriskeApr 17, 2015
  2. Michael J GruberApr 17, 2015
  3. Junio C HamanoApr 17, 2015
  4. Junio C HamanoApr 17, 2015
  5. Junio C HamanoApr 17, 2015
  6. Michael J GruberApr 20, 2015
  7. Junio C HamanoApr 20, 2015
  8. Linus TorvaldsApr 20, 2015
  9. Junio C HamanoApr 20, 2015
  10. Michael J GruberApr 21, 2015
  11. Junio C HamanoApr 21, 2015
  12. Michael J GruberApr 22, 2015

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.