Example .hgignore regarding whole directories

Bill Barry after.fallout at gmail.com
Thu Apr 8 10:11:51 CDT 2010


Harry Putnam wrote:
> Mads Kiilerich <mads at kiilerich.com> writes:
>
>   
>> Harry Putnam wrote, On 04/07/2010 11:18 PM:
>>     
>>> I wasn't clear from a light (partial) reading of
>>>
>>>      `Mercurial: The Definitive Guide'
>>>
>>> What all works in `.hgignore'.
>>>
>>> There is a very light discussion in:
>>>    file-names-and-pattern-matching.html
>>>    
>>>       
>> The hgignore man page should be an even more definitive resource
>> (only second to the source) and has a very short but quite exact
>> description.
>>     
>
> Like and idiot, I didn't even think to look for a `man hgignore'
>
> That one little paragraph does give all that you need for directories:
>
>        [...]
>
>        For example, say we have an untracked file, file.c, at
>        a/b/file.c inside our repository. Mercurial will ignore file.c
>        if any pattern in .hgignore matches a/b/file.c, a/b or a.
>        
>        [...]  
>
> [...]
>
>   
>> To ignore everything in the directory foo you can match a "prefix
>> path" by specifying in .hgignore:
>>     ^foo$
>> or you can get (almost) the same with:
>>     syntax: glob
>>     foo
>>     
>
> Good info... thanks
>
>   
>>> When ignoring file/directory names... is the slash (/) part of what
>>> mercurial sees, and can therefore be part of the regex?
>>>    
>>>       
>> That depends on how you want to do it ... You can also make a regex
>> that matches the whole path:
>>     ^foo/
>>     
>
> So mercurial never sees an absolute path, only relative to the repo?
>   
Correct.

Optimizations can be done in your hgignore file too based on how you 
want to ignore things.

For instance "^foo" is better than "^foo/" as long as you don't have 
multiple files/directories that start with foo in the root of your repo. 
This is because ignores are done via a traversal of your tree and foo 
matches the directory name whereas foo/ matches part of the path for the 
all the files in the directory. Using this knowledge you can 
significantly speed up hg status and other commands whose performance 
has rotted over time due to an ever growing hgignore file and working copy.

Also note that regexes in python do short circuit. Given the following 
regexes:

^(.*\.bak|.*\.out|foo|bar|baz)$
^(foo|bar|baz|.*\.bak|.*\.out)$

the second should perform better (there is most certainly an art form 
here that is largely untapped).

In my company's main repository I converted a 120 line glob style 
hgignore file down to a single regex and over doubled the speed of hg 
st. Note that regexes are always going to be faster than globs here 
(internally globs are converted to regexes) and that it is pretty easy 
to manually write single regexes that perform better than the multiple 
ones combined by the engine itself.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial/attachments/20100408/63b75018/attachment.htm>


More information about the Mercurial mailing list