git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
* Feature request: 'git grep' over multiple working trees
@ 2020-03-24  7:49 Ed Avis
  2020-03-24 18:40 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Ed Avis @ 2020-03-24  7:49 UTC (permalink / raw)
  To: git

If the current directory contains several git working trees (each in its own subdirectory) then 'git grep' should search all of them.  It would be roughly equivalent to

% for i in * ; do (cd $i ; git grep whatever); done

except that the filenames listed would have the full path.

As you see it's fairly simple to script up, and there are tools to do it (one called 'multi'), but having it built in to 'git grep' would be handy.
If the current directory doesn't contain any git working trees, then 'git grep' can die as it does now.  If there are some working trees and some random other stuff, it can warn and skip the other stuff.

Please ignore confidentiality stuff after this point.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Feature request: 'git grep' over multiple working trees
  2020-03-24  7:49 Feature request: 'git grep' over multiple working trees Ed Avis
@ 2020-03-24 18:40 ` Junio C Hamano
  2020-03-25  8:04   ` Ed Avis
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2020-03-24 18:40 UTC (permalink / raw)
  To: Ed Avis; +Cc: git

Ed Avis <ed.avis@qmaw.com> writes:

> If the current directory contains several git working trees (each
> in its own subdirectory) then 'git grep' should search all of
> them.  It would be roughly equivalent to
>
> % for i in * ; do (cd $i ; git grep whatever); done
>
> except that the filenames listed would have the full path.

I am not sure where that "should search" comes from.

In my $HOME/w directory, I have working trees of various
repositories, belonging to different and unrelated projects.
Should "git grep foo" in there search in everywhre?

Are you looking for "grep -r --exclude=.git" (not a git command at
all)?

In other words, surely anybody can wish anything nonsensical, but I
do not quite see the point for adding such a mode to "Git".

It sounds like saying 'git grep' "should" search all of them if the
current directly is a git repository with several git commits, which
would be roughly equivalent to

    git rev-list --all |
    while read rev
    do
	git grep -e pattern... $rev
    done

Similarly, you could say that 'git grep' "should" search all of them
if the current directory is a git repository with several branches,
which would be roughly equivalent to

    git for-each-ref --format='%(objectname)' refs/heads/ |
    while read rev
    do
	git grep -e pattern... $rev
    done

Neither of the above smell like a reasonable use of "should", at
least to me, and yours does not, either.

What is the real use case, if any, of what you are proposing?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: Feature request: 'git grep' over multiple working trees
  2020-03-24 18:40 ` Junio C Hamano
@ 2020-03-25  8:04   ` Ed Avis
  0 siblings, 0 replies; 3+ messages in thread
From: Ed Avis @ 2020-03-25  8:04 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Thanks for your reply. Please interpret 'should' in the context of this being a feature request. If you reject the request then no, it should not :-)

The use case is just as you describe: having several different repositories checked out under a common root, and wanting to search all of them, while keeping the speed and other advantages of git grep. 

I do this multi-repos search all the time. In a pure software development context it may not make much sense. If projects are so tightly coupled that you commonly search all of them, they would be in one repository. But for in-house code in a more 'dev ops' setup it's invaluable. What code references this database table? User fred has left the company, which config files still grant him permissions? Does any other group call the Pogg() function in our in-house library? Even with a single development team you are likely to have more than one repository to search; in a larger organization you'll have other teams with their own repos which nonetheless you have to grep before you can consider changing that Pogg().

I think I'm not the only one with this use case, judging by questions on q&a sites. To me it seems like a natural (though limited) extension of the existing recursive search. It doesn't change any existing behaviour or break any scripts, since it concerns a case where the current behaviour is to give an error. 

I appreciate one can get bogged down in questions of what happens if the working trees are two levels deep, or there is a mixture of working trees and other stuff. I have tried to keep the scope fairly narrow by stipulating a single directory which contains git trees under its top level. I believe this is a fairly common case.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-24  7:49 Feature request: 'git grep' over multiple working trees Ed Avis
2020-03-24 18:40 ` Junio C Hamano
2020-03-25  8:04   ` Ed Avis

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git