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

Re: How to use path limiting (using a glob)?

From
Sitaram Chamarty <sitaramc@gmail.com>
Date
Feb 12, 2009, 11:09 UTC
Message-ID
<slrngp80rg.rmg.sitaramc@sitaramc.homelinux.net>
In-Reply-To
<20090212102719.GD27232@m62s10.vlinux.de>
On 2009-02-12, Peter Baumann <waste.manager@gmx.de> wrote:
> On Wed, Feb 11, 2009 at 11:40:44AM -0800, Linus Torvalds wrote:
Show 27 quoted lines
>> On Wed, 11 Feb 2009, Peter Baumann wrote:
>> 
>> > after reading Junio's nice blog today where he
>> > explained how to use git grep efficiently, I saw him
>> > using a glob to match for the interesting files:
>> > 
>> > 	 $ git grep -e ';;' -- '*.c'
>> > 
>> > Is it possible to have the same feature in git diff and the revision
>> > machinery?
>> 
>> Not really. Git has two different kinds of path limiters, and they are 
>> really really different.
>> 
>>  - the "walk current index/directory recursively" kind that "git ls-files" 
>>    uses, which takes a 'fnmatch()' type path regexp (not a real regexp, 
>>    but the kind you're used to with shell)
>> 
>>    NOTE! On purpose, we don't set the FNM_PATHNAME, so "*.c" here is 
>>    different from *.c in shell (it's more like "**.c" in tcsh). IOW, * 
>>    matches '/' too, and will walk subdirectories.
>> 
>
> Hm. But if git does only anchor the * at the current directory, wouldn't
> this solve (or at least reduce) the performance problems you described in the
> later paragraph? Having the "**.c" do a recurisve search for every .c
> file would then be used to do a recusrive search. 

I think Linus meant that it's expensive to look for all *.c files at any depth in the tree, for every commit in repository.

You can have either a prefix matcher to limit the search *within* a tree so you can afford to walk all revs in the repo, or you stick to just one tree (or a few explicitly named ones).

You seem to be saying 'fine, I know, and I'm willing to indicate that I'm accepting this cost by using a different syntax'.

But the syntax is not the point. You can certainly do that right now, if you really wish to. Just don't try it on a large repo :-)

    git grep -e pattern $(git rev-list --all) -- *.c

Make suitable modifications to the '--all' in the git rev-list to limit the revs you want to search.

Regardless of whether there is a simple syntax to support it or not, this is probably not what you want, most of the time :-)

Sitaram
Previous: Peter BaumannNext: Junio C Hamano
Message 4 of 6 in “How to use path limiting (using a glob)?”
  1. Peter BaumannFeb 11, 2009
  2. Linus TorvaldsFeb 11, 2009
  3. Peter BaumannFeb 12, 2009
  4. Sitaram ChamartyFeb 12, 2009
  5. Junio C HamanoFeb 11, 2009
  6. Nanako ShiraishiFeb 11, 2009

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.