Patchwork [09,of,10] largefiles: use "outgoinghooks" to avoid redundant outgoing check

login
register
mail settings
Submitter Katsunori FUJIWARA
Date March 5, 2014, 12:12 p.m.
Message ID <1b3d6993b6a37cf23507.1394021534@juju>
Download mbox | patch
Permalink /patch/3850/
State Superseded
Headers show

Comments

Katsunori FUJIWARA - March 5, 2014, 12:12 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1394019743 -32400
#      Wed Mar 05 20:42:23 2014 +0900
# Node ID 1b3d6993b6a37cf23507d0e1fa0ab5c8bde1a101
# Parent  98753a1c33c34326dcc5a23e8b83b29818e5f54c
largefiles: use "outgoinghooks" to avoid redundant outgoing check

Before this patch, "hg outgoing" invokes "findcommonoutgoing()" not
only in "commands.outgoing()" but also in
"overrides.overrideoutgoing()" (via "getoutgoinglfiles()"), when
largefiles is enabled. The latter is redundant.

This patch uses "outgoinghooks" to avoid redundant outgoing check.

Newly introduced function "overrides.outgoinghook()" is registered
into "outgoinghooks" to get the result of outgoing check in
"commands.outgoing()".

It invokes "lfutil.getlfilestoupload()" directly with the result of
outgoing check to avoid redundant outgoing check in
"getoutgoinglfiles()": "sort()" is needed, because
"lfutil.getlfilestoupload()" doesn't sort the result of it.

This patch also makes the "if toupload is None" ("No remote repo")
case meaningless, because failure of looking remote repository up
should raise exception in "commands.outgoing()" before invocation of
"outgoinghooks".

Patch

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -1001,23 +1001,17 @@ 
 
     return sorted(lfutil.getlfilestoupload(repo, o))
 
-def overrideoutgoing(orig, ui, repo, dest=None, **opts):
-    result = orig(ui, repo, dest, **opts)
-
+def outgoinghook(ui, repo, opts, missing):
     if opts.pop('large', None):
-        toupload = getoutgoinglfiles(ui, repo, dest, **opts)
-        if toupload is None:
-            ui.status(_('largefiles: No remote repo\n'))
-        elif not toupload:
+        toupload = lfutil.getlfilestoupload(repo, missing)
+        if not toupload:
             ui.status(_('largefiles: no files to upload\n'))
         else:
             ui.status(_('largefiles to upload:\n'))
-            for file in toupload:
+            for file in sorted(toupload):
                 ui.status(lfutil.splitstandin(file) + '\n')
             ui.status('\n')
 
-    return result
-
 def summaryremotehook(ui, repo, opts, changes):
     largeopt = opts.get('large', False)
     if changes is None:
diff --git a/hgext/largefiles/uisetup.py b/hgext/largefiles/uisetup.py
--- a/hgext/largefiles/uisetup.py
+++ b/hgext/largefiles/uisetup.py
@@ -65,10 +65,11 @@ 
     debugstateopt = [('', 'large', None, _('display largefiles dirstate'))]
     entry[1].extend(debugstateopt)
 
-    entry = extensions.wrapcommand(commands.table, 'outgoing',
-        overrides.overrideoutgoing)
+    outgoing = lambda orgfunc, *arg, **kwargs: orgfunc(*arg, **kwargs)
+    entry = extensions.wrapcommand(commands.table, 'outgoing', outgoing)
     outgoingopt = [('', 'large', None, _('display outgoing largefiles'))]
     entry[1].extend(outgoingopt)
+    cmdutil.outgoinghooks.add('largefiles', overrides.outgoinghook)
     entry = extensions.wrapcommand(commands.table, 'summary',
                                    overrides.overridesummary)
     summaryopt = [('', 'large', None, _('display outgoing largefiles'))]
diff --git a/tests/test-largefiles.t b/tests/test-largefiles.t
--- a/tests/test-largefiles.t
+++ b/tests/test-largefiles.t
@@ -703,7 +703,6 @@ 
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     this used to not notice the rm
   
-  searching for changes
   largefiles to upload:
   foo
   large
@@ -2154,7 +2153,6 @@ 
   comparing with $TESTTMP/issue3651/src (glob)
   searching for changes
   no changes found
-  searching for changes
   largefiles: no files to upload
   [1]
 
@@ -2181,7 +2179,6 @@ 
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     #1
   
-  searching for changes
   largefiles to upload:
   b