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

login
register
mail settings
Submitter Katsunori FUJIWARA
Date April 15, 2014, 3:52 p.m.
Message ID <4728096bc1fa68b93ed8.1397577148@juju>
Download mbox | patch
Permalink /patch/4366/
State Accepted
Commit ca7a57464fb373b85f182984b5f79d1249855094
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 4728096bc1fa68b93ed8a1779c1ecef737de9154
# Parent  3bab5cfe2a9d218851b80786d69634e88eb77972
largefiles: use "summaryremotehooks" to avoid redundant outgoing check

Before this patch, "hg summary --remote --large" invokes
"findcommonoutgoing()" not only in "commands.summary()" but also in
"overrides.overridesummary()" (via "getoutgoinglfiles()"). The latter
is redundant.

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

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

It invokes "lfutil.getlfilestoupload()" directly with the result of
outgoing check to avoid redundant outgoing check in
"getoutgoinglfiles()".

Patch

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -1022,25 +1022,37 @@ 
 
     return result
 
-def overridesummary(orig, ui, repo, *pats, **opts):
-    try:
-        repo.lfstatus = True
-        orig(ui, repo, *pats, **opts)
-    finally:
-        repo.lfstatus = False
-
-    if opts.pop('large', None):
-        toupload = getoutgoinglfiles(ui, repo, None, **opts)
-        if toupload is None:
+def summaryremotehook(ui, repo, opts, changes):
+    largeopt = opts.get('large', False)
+    if changes is None:
+        if largeopt:
+            return (False, True) # only outgoing check is needed
+        else:
+            return (False, False)
+    elif largeopt:
+        url, branch, peer, outgoing = changes[1]
+        if peer is None:
             # i18n: column positioning for "hg summary"
             ui.status(_('largefiles: (no remote repo)\n'))
-        elif not toupload:
+            return
+
+        toupload = set()
+        lfutil.getlfilestoupload(repo, outgoing.missing,
+                                 lambda fn, lfhash: toupload.add(fn))
+        if not toupload:
             # i18n: column positioning for "hg summary"
             ui.status(_('largefiles: (no files to upload)\n'))
         else:
             # i18n: column positioning for "hg summary"
             ui.status(_('largefiles: %d to upload\n') % len(toupload))
 
+def overridesummary(orig, ui, repo, *pats, **opts):
+    try:
+        repo.lfstatus = True
+        orig(ui, repo, *pats, **opts)
+    finally:
+        repo.lfstatus = False
+
 def scmutiladdremove(orig, repo, pats=[], opts={}, dry_run=None,
                      similarity=None):
     if not lfutil.islfilesrepo(repo):
diff --git a/hgext/largefiles/uisetup.py b/hgext/largefiles/uisetup.py
--- a/hgext/largefiles/uisetup.py
+++ b/hgext/largefiles/uisetup.py
@@ -73,6 +73,7 @@ 
                                    overrides.overridesummary)
     summaryopt = [('', 'large', None, _('display outgoing largefiles'))]
     entry[1].extend(summaryopt)
+    cmdutil.summaryremotehooks.add('largefiles', overrides.summaryremotehook)
 
     entry = extensions.wrapcommand(commands.table, 'update',
                                    overrides.overrideupdate)
diff --git a/tests/test-largefiles.t b/tests/test-largefiles.t
--- a/tests/test-largefiles.t
+++ b/tests/test-largefiles.t
@@ -2149,7 +2149,6 @@ 
   branch: default
   commit: (clean)
   update: (current)
-  searching for changes
   largefiles: (no files to upload)
   $ hg -R clone2 outgoing --large
   comparing with $TESTTMP/issue3651/src (glob)
@@ -2172,7 +2171,6 @@ 
   branch: default
   commit: (clean)
   update: (current)
-  searching for changes
   largefiles: 1 to upload
   $ hg -R clone2 outgoing --large
   comparing with $TESTTMP/issue3651/src (glob)