Patchwork [11,of,12,V2] largefiles: use "outgoinghooks" to avoid redundant outgoing check

login
register
mail settings
Submitter Katsunori FUJIWARA
Date April 15, 2014, 3:52 p.m.
Message ID <cca25a4c3c8eb6f712cf.1397577152@juju>
Download mbox | patch
Permalink /patch/4367/
State Accepted
Commit cde32cb5a565c93f674ab744e29a4ea3e48c2a4f
Headers show

Comments

Katsunori FUJIWARA - April 15, 2014, 3:52 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1397576244 -32400
#      Wed Apr 16 00:37:24 2014 +0900
# Node ID cca25a4c3c8eb6f712cf7a035cf6177000bd09cb
# Parent  d6e861694142d91195adf094f9604543c7ee5f56
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 omits "if toupload is None" ("No remote repo") case,
because failure of looking remote repository up should raise exception
in "commands.outgoing()" before invocation of "outgoinghooks".

Newly added "hg outgoing --large --graph" tests examine
"outgoinghooks" invocations in "hg outgoing --graph" code path.

Patch

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -1005,23 +1005,19 @@ 
     lfutil.getlfilestoupload(repo, o, lambda fn, lfhash: toupload.add(fn))
     return sorted(toupload)
 
-def overrideoutgoing(orig, ui, repo, dest=None, **opts):
-    result = orig(ui, repo, dest, **opts)
-
+def outgoinghook(ui, repo, other, 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 = set()
+        lfutil.getlfilestoupload(repo, missing,
+                                 lambda fn, lfhash: toupload.add(fn))
+        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,10 +2153,15 @@ 
   comparing with $TESTTMP/issue3651/src (glob)
   searching for changes
   no changes found
-  searching for changes
   largefiles: no files to upload
   [1]
 
+  $ hg -R clone2 outgoing --large --graph --template "{rev}"
+  comparing with $TESTTMP/issue3651/src (glob)
+  searching for changes
+  no changes found
+  largefiles: no files to upload
+
 check messages when there are files to upload:
 
   $ echo b > clone2/b
@@ -2181,7 +2185,14 @@ 
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     #1
   
+  largefiles to upload:
+  b
+  
+  $ hg -R clone2 outgoing --large --graph --template "{rev}"
+  comparing with $TESTTMP/issue3651/src
   searching for changes
+  @  1
+  
   largefiles to upload:
   b