[PATCH 3 of 8] localrepo: fix variable binding in handling of old filters

Mads Kiilerich mads at kiilerich.com
Sun Oct 13 20:13:37 EDT 2019


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1570925119 -7200
#      Sun Oct 13 02:05:19 2019 +0200
# Node ID 1e663f4a658dbf6669c9bfd53918bf1daa734dc6
# Parent  2b91375a812ce3c694efa35a98a1777709387962
localrepo: fix variable binding in handling of old filters

The lambda was referencing oldfn in outer scope without binding the current
value. If oldfn function were reassigned before use, wrong filters could be
used.

Fixed by having oldfn as named parameter default value of the lambda.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1900,7 +1900,7 @@ class localrepository(object):
                 # Wrap old filters not supporting keyword arguments
                 if not pycompat.getargspec(fn)[2]:
                     oldfn = fn
-                    fn = lambda s, c, **kwargs: oldfn(s, c)
+                    fn = lambda s, c, oldfn=oldfn, **kwargs: oldfn(s, c)
                     fn.__name__ = 'compat-' + oldfn.__name__
                 l.append((mf, fn, params))
             self._filterpats[filter] = l


More information about the Mercurial-devel mailing list