changeset 41579:028bb170e74d

largefiles: use wrappedfunction() for util.copyfile() override Differential Revision: https://phab.mercurial-scm.org/D5866
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 05 Feb 2019 14:29:37 -0800
parents 8d1dc380b026
children 9f11759fc5f5
files hgext/largefiles/overrides.py
diffstat 1 files changed, 11 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/largefiles/overrides.py	Tue Feb 05 14:15:34 2019 -0800
+++ b/hgext/largefiles/overrides.py	Tue Feb 05 14:29:37 2019 -0800
@@ -686,23 +686,18 @@
             else:
                 listpats.append(makestandin(pat))
 
-        try:
-            origcopyfile = util.copyfile
-            copiedfiles = []
-            def overridecopyfile(src, dest, *args, **kwargs):
-                if (lfutil.shortname in src and
-                    dest.startswith(repo.wjoin(lfutil.shortname))):
-                    destlfile = dest.replace(lfutil.shortname, '')
-                    if not opts['force'] and os.path.exists(destlfile):
-                        raise IOError('',
-                            _('destination largefile already exists'))
-                copiedfiles.append((src, dest))
-                origcopyfile(src, dest, *args, **kwargs)
-
-            util.copyfile = overridecopyfile
+        copiedfiles = []
+        def overridecopyfile(orig, src, dest, *args, **kwargs):
+            if (lfutil.shortname in src and
+                dest.startswith(repo.wjoin(lfutil.shortname))):
+                destlfile = dest.replace(lfutil.shortname, '')
+                if not opts['force'] and os.path.exists(destlfile):
+                    raise IOError('',
+                                  _('destination largefile already exists'))
+            copiedfiles.append((src, dest))
+            orig(src, dest, *args, **kwargs)
+        with extensions.wrappedfunction(util, 'copyfile', overridecopyfile):
             result += orig(ui, repo, listpats, opts, rename)
-        finally:
-            util.copyfile = origcopyfile
 
         lfdirstate = lfutil.openlfdirstate(ui, repo)
         for (src, dest) in copiedfiles: