[PATCH] add debugignore which yields the combined ignore patten of the .hgignore files

Jason Harris jason.f.harris at gmail.com
Sat Jan 15 18:59:10 CST 2011


On Jan 15, 2011, at 6:46 PM, Benoit Boissinot wrote:

> On Sat, Jan 15, 2011 at 04:39:53PM +0100, Jason Harris wrote:
>> # HG changeset patch
>> # User jfh <jason at jasonfharris.com>
>> # Date 1295103723 -3600
>> # Node ID a4f7a503527c84d73985b2eb2d1e45f5404a8da5
>> # Parent  129f5c8fcf76598918c68f39b4156b10d84fa08e
>> add debugignore which yields the combined ignore patten of the .hgignore files
> 
> Thanks for coming back with it.

Actually, thanks for your previous comments on it way back... :)

>> diff --git a/mercurial/commands.py b/mercurial/commands.py
>> --- a/mercurial/commands.py
>> +++ b/mercurial/commands.py
>> @@ -1261,6 +1261,10 @@
>>         m = util.matchdate(range)
>>         ui.write("match: %s\n" % m(d[0]))
>> 
>> +def debugignore(ui, repo, *values, **opts):
>> +    """display the combined ignore pattern"""
>> +    ui.write("%s\n" % repo.debugignorepat())
> 
> Maybe not worth the indirection through localrepo, we're accessing
> internals anyway.

Ok. I fixed this and just sent a version V2

>> +
>> def debugindex(ui, repo, file_, **opts):
>>     """dump the contents of an index file"""
>>     r = None
>> @@ -4172,6 +4176,7 @@
>>          _('[-e] DATE [RANGE]')),
>>     "debugdata": (debugdata, [], _('FILE REV')),
>>     "debugfsinfo": (debugfsinfo, [], _('[PATH]')),
>> +    "debugignore": (debugignore, [], ''),
>>     "debugindex": (debugindex,
>>                    [('f', 'format', 0, _('revlog format'), _('FORMAT'))],
>>                    _('FILE')),
>> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
>> --- a/mercurial/localrepo.py
>> +++ b/mercurial/localrepo.py
>> @@ -1259,6 +1259,10 @@
>>                 n = p[0]
>>         return b
>> 
>> +    def debugignorepat(self):
>> +        ignore = self.dirstate._ignore
>> +        return ignore.includepat
>> +
> 
> Do that directly in commands.py?
> 
>> diff --git a/mercurial/match.py b/mercurial/match.py
>> --- a/mercurial/match.py
>> +++ b/mercurial/match.py
>> @@ -39,11 +39,11 @@
>>         self._anypats = bool(include or exclude)
>> 
>>         if include:
>> -            im = _buildmatch(_normalize(include, 'glob', root, cwd, auditor),
>> -                             '(?:/|$)')
>> +            pats = _normalize(include, 'glob', root, cwd, auditor)
>> +            self.includepat, im = _buildmatch(pats, '(?:/|$)')
>>         if exclude:
>> -            em = _buildmatch(_normalize(exclude, 'glob', root, cwd, auditor),
>> -                             '(?:/|$)')
>> +            pats = _normalize(exclude, 'glob', root, cwd, auditor)
>> +            self.excludepat, em = _buildmatch(pats, '(?:/|$)')
>>         if exact:
>>             self._files = patterns
>>             pm = self.exact
>> @@ -51,7 +51,7 @@
>>             pats = _normalize(patterns, default, root, cwd, auditor)
>>             self._files = _roots(pats)
>>             self._anypats = self._anypats or _anypats(pats)
>> -            pm = _buildmatch(pats, '$')
>> +            self.patternspat, pm = _buildmatch(pats, '$')
> 
> That's not very nice, since the attributes won't get set properly if one
> of the list is empty.

I could set them to the empty string outside the if statements ? I am happy to do this if you want...

> Besides I'm not sure why you're interested only in the include pattern.
> The other patterns matter, right?

Well actually they didn't seem to for the ignore command see the source code in ignore.py with the call

        ignorefunc = match.match(root, '', [], allpats)

Thus all of the patterns are being funneled into allpats...

Thanks,
  Jas


More information about the Mercurial-devel mailing list