[PATCH 03 of 17] match: handle excludes using new differencematcher

Martin von Zweigbergk martinvonz at google.com
Fri May 26 11:22:10 EDT 2017


On Fri, May 26, 2017 at 8:10 AM, Yuya Nishihara <yuya at tcha.org> wrote:
> On Thu, 25 May 2017 11:24:44 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
>> # HG changeset patch
>> # User Martin von Zweigbergk <martinvonz at google.com>
>> # Date 1494977808 25200
>> #      Tue May 16 16:36:48 2017 -0700
>> # Node ID dc1a97dee1b5de53dda25285ffd7ebcc16105549
>> # Parent  8446a121f00de0575739e5285af58d564119a052
>> match: handle excludes using new differencematcher
>
>> +class differencematcher(basematcher):
>> +    '''Composes two matchers by matching if the first matches and the second
>> +    does not. Well, almost... If the user provides a pattern like "-X foo foo",
>> +    Mercurial actually does match "foo" against that. That's because exact
>> +    matches are treated specially. So, since this differencematcher is used for
>> +    excludes, it needs to special-case exact matching.
>
> Uh.
>
>> +    def isexact(self):
>> +        return self._m1.isexact()
>
> I don't know if new behavior is correct, but before, isexact() would be False
> if exclude patterns were specified. match.isexact is defined as follows:
>
>     def isexact(self):
>         return self.matchfn == self.exact
>
> and matchfn would be a composition of matchfns[].

Ah, good catch. That was actually an intentional change I made that
wasn't really necessary, but just an optimization. Sorry, I should
have mentioned that. isexact() is used in various places to allow fast
paths. So by saying that an exact matcher minus something is still
exact allows for those fast paths. However, I don't think exact
matchers ever have excludes in hg core (despite the comment somewhere
in match.py saying that excludes and includes still apply), so this is
probably only relevant for extensions.

>
> That said, the overall change looks great and no tests fail, so queued the
> first 4 patches. Thanks.


More information about the Mercurial-devel mailing list