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

login
register
mail settings
Submitter Mads Kiilerich
Date Oct. 14, 2019, 12:13 a.m.
Message ID <1e663f4a658dbf6669c9.1571012017@xps>
Download mbox | patch
Permalink /patch/42305/
State Accepted
Headers show

Comments

Mads Kiilerich - Oct. 14, 2019, 12:13 a.m.
# HG changeset patch
# User Mads Kiilerich <mads@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.

Patch

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