Patchwork D5869: largefiles: use wrappedfunction() in overriderevert()

login
register
mail settings
Submitter phabricator
Date Feb. 6, 2019, 11:57 a.m.
Message ID <01736ee9ffa24d2970a11203a125da6b@localhost.localdomain>
Download mbox | patch
Permalink /patch/38479/
State Not Applicable
Headers show

Comments

phabricator - Feb. 6, 2019, 11:57 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG7b2580e0dbbd: largefiles: use wrappedfunction() in overriderevert() (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5869?vs=13844&id=13849

REVISION DETAIL
  https://phab.mercurial-scm.org/D5869

AFFECTED FILES
  hgext/largefiles/overrides.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers, pulkit
Cc: mercurial-devel

Patch

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -78,22 +78,6 @@ 
     m.matchfn = lambda f: notlfile(f) and origmatchfn(f)
     return m
 
-def installmatchfn(f):
-    '''monkey patch the scmutil module with a custom match function.
-    Warning: it is monkey patching the _module_ on runtime! Not thread safe!'''
-    oldmatch = scmutil.match
-    setattr(f, 'oldmatch', oldmatch)
-    scmutil.match = f
-    return oldmatch
-
-def restorematchfn():
-    '''restores scmutil.match to what it was before installmatchfn
-    was called.  no-op if scmutil.match is its original function.
-
-    Note that n calls to installmatchfn will require n calls to
-    restore the original matchfn.'''
-    scmutil.match = getattr(scmutil.match, 'oldmatch')
-
 def addlargefiles(ui, repo, isaddremove, matcher, **opts):
     large = opts.get(r'large')
     lfsize = lfutil.getminsize(
@@ -756,11 +740,11 @@ 
 
         oldstandins = lfutil.getstandinsstate(repo)
 
-        def overridematch(mctx, pats=(), opts=None, globbed=False,
+        def overridematch(orig, mctx, pats=(), opts=None, globbed=False,
                 default='relpath', badfn=None):
             if opts is None:
                 opts = {}
-            match = oldmatch(mctx, pats, opts, globbed, default, badfn=badfn)
+            match = orig(mctx, pats, opts, globbed, default, badfn=badfn)
             m = copy.copy(match)
 
             # revert supports recursing into subrepos, and though largefiles
@@ -791,11 +775,8 @@ 
                 return origmatchfn(f)
             m.matchfn = matchfn
             return m
-        oldmatch = installmatchfn(overridematch)
-        try:
+        with extensions.wrappedfunction(scmutil, 'match', overridematch):
             orig(ui, repo, ctx, parents, *pats, **opts)
-        finally:
-            restorematchfn()
 
         newstandins = lfutil.getstandinsstate(repo)
         filelist = lfutil.getlfilestoupdate(oldstandins, newstandins)