Skip to contentSkip to conversation

bug: git grep -P and multiline mode

DISCUSSION Noel Grandin 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hi

It looks like the perl regular expression multiline mode does not work with 'git grep'

for example, something like

git grep -P '(?s)foo.*?bar"

will not match a file in the repo where it has something like

foo
bar

ie. split across two lines

Regards, Noel Grandin

#1 lore raw
Quoted 1 line · Noel Grandin

It looks like the perl regular expression multiline mode does not work with 'git grep'

Yes, and deliberately so, to avoid having to think about things like "how would a multi-line match interact with 'grep -n'?"

We behave as if we feed each line of the contents one line at a time to the matching engine that is chosen by the -P/-E/-G/-F optoins, so this limitation is unlikely to change.

#2 lore raw
Quoted 7 lines · Junio C Hamano
Quoted 1 line · Noel Grandin

It looks like the perl regular expression multiline mode does not work with 'git grep'

Yes, and deliberately so, to avoid having to think about things like "how would a multi-line match interact with 'grep -n'?"

Ah, that is a pity.

I find the multi-line mode very useful for finding code problems that span multiple lines.

I'm sure there are other options that conflict, and the solution is to normally write out some kind of informative error message?

Anyhow, since I'm too busy working on LibreOffice right now to work up a patch for git, I'll stick to using
find | xargs grep
:-)