[PATCH 2 of 4] Apply longest patterns first and fix --debug output

Dirkjan Ochtman dirkjan at ochtman.nl
Sat Apr 18 03:09:25 CDT 2009


On 18/04/2009 03:44, Mark Hammond wrote:
> @@ -555,13 +555,17 @@
>                   if not inspect.getargspec(fn)[2]:
>                       oldfn = fn
>                       fn = lambda s, c, **kwargs: oldfn(s, c)
> -                l.append((mf, fn, params))
> -            self.filterpats[filter] = l
> +                # store a tuple - elt[0] is our sort key, elt[1] is the data.
> +                l.append((len(pat), (mf, fn, params, cmd)))
> +            # So we get deterministic behaviour, we sort the list such that
> +            # the longest patterns are always tested first.
> +            l.sort(key=lambda item: -item[0])
> +            self.filterpats[filter] = [item[1] for item in l]

Why not go for -len(pat) immediately, so that you don't need the extra 
lambda? Otherwise these patches look quite good. Might be useful to put 
a note in the comments there that this should be removed once we have a 
config parser that preserves ordering.

Cheers,

Dirkjan


More information about the Mercurial-devel mailing list