Patchwork [1,of,3] largefiles: override cmdutil.revert() instead of comands.revert()

login
register
mail settings
Submitter Martin von Zweigbergk
Date March 24, 2015, 6:16 p.m.
Message ID <05b3c16a656cce3130de.1427220999@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/8238/
State Accepted
Headers show

Comments

Martin von Zweigbergk - March 24, 2015, 6:16 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1426871131 25200
#      Fri Mar 20 10:05:31 2015 -0700
# Node ID 05b3c16a656cce3130de9851abcc425c412d7f9d
# Parent  811a1842cfe5f632145912d9bf2dc859e6ee3eeb
largefiles: override cmdutil.revert() instead of comands.revert()

By overriding the cmdutil method we don't need to override both the
function and the command. Also, we get access to the 'ctx' and
'parents' variables, which will soon prove useful.

Rename the 'ctx' argument to overridematch() to 'mctx' rather than
letting it shadow new 'ctx'.

Patch

diff -r 811a1842cfe5 -r 05b3c16a656c hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py	Mon Mar 23 14:47:35 2015 -0400
+++ b/hgext/largefiles/overrides.py	Fri Mar 20 10:05:31 2015 -0700
@@ -734,7 +734,7 @@ 
 # commits. Update the standins then run the original revert, changing
 # the matcher to hit standins instead of largefiles. Based on the
 # resulting standins update the largefiles.
-def overriderevert(orig, ui, repo, *pats, **opts):
+def overriderevert(orig, ui, repo, ctx, parents, *pats, **opts):
     # Because we put the standins in a bad state (by updating them)
     # and then return them to a correct state we need to lock to
     # prevent others from changing them in their incorrect state.
@@ -751,19 +751,20 @@ 
 
         oldstandins = lfutil.getstandinsstate(repo)
 
-        def overridematch(ctx, pats=[], opts={}, globbed=False,
+        def overridematch(mctx, pats=[], opts={}, globbed=False,
                 default='relpath'):
-            match = oldmatch(ctx, pats, opts, globbed, default)
+            match = oldmatch(mctx, pats, opts, globbed, default)
             m = copy.copy(match)
 
             # revert supports recursing into subrepos, and though largefiles
             # currently doesn't work correctly in that case, this match is
             # called, so the lfdirstate above may not be the correct one for
             # this invocation of match.
-            lfdirstate = lfutil.openlfdirstate(ctx.repo().ui, ctx.repo(), False)
+            lfdirstate = lfutil.openlfdirstate(mctx.repo().ui, mctx.repo(),
+                                               False)
 
             def tostandin(f):
-                if lfutil.standin(f) in ctx:
+                if lfutil.standin(f) in mctx:
                     return lfutil.standin(f)
                 elif lfutil.standin(f) in repo[None] or lfdirstate[f] == 'r':
                     return None
@@ -775,13 +776,13 @@ 
             def matchfn(f):
                 if lfutil.isstandin(f):
                     return (origmatchfn(lfutil.splitstandin(f)) and
-                            (f in repo[None] or f in ctx))
+                            (f in repo[None] or f in mctx))
                 return origmatchfn(f)
             m.matchfn = matchfn
             return m
         oldmatch = installmatchfn(overridematch)
         try:
-            orig(ui, repo, *pats, **opts)
+            orig(ui, repo, ctx, parents, *pats, **opts)
         finally:
             restorematchfn()
 
diff -r 811a1842cfe5 -r 05b3c16a656c hgext/largefiles/uisetup.py
--- a/hgext/largefiles/uisetup.py	Mon Mar 23 14:47:35 2015 -0400
+++ b/hgext/largefiles/uisetup.py	Fri Mar 20 10:05:31 2015 -0700
@@ -113,11 +113,7 @@ 
     entry = extensions.wrapfunction(subrepo.hgsubrepo, 'dirty',
                                     overrides.overridedirty)
 
-    # Backout calls revert so we need to override both the command and the
-    # function
-    entry = extensions.wrapcommand(commands.table, 'revert',
-                                   overrides.overriderevert)
-    entry = extensions.wrapfunction(commands, 'revert',
+    entry = extensions.wrapfunction(cmdutil, 'revert',
                                     overrides.overriderevert)
 
     extensions.wrapfunction(archival, 'archive', overrides.overridearchive)