largefiles: reuse "findcommonoutgoing()" result at "hg push"
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Wed, 16 Apr 2014 00:37:24 +0900
changeset 21044 52a5eabf1f2f
parent 21043 6c383c871fdb
child 21045 7f875ed19475
largefiles: reuse "findcommonoutgoing()" result at "hg push" Before this patch, "hg push" invokes "findcommonoutgoing()" not only in "exchange.push()" but also in "lfilesrepo.push()", when largefiles is enabled. The latter is redundant. This patch registers own "prepushoutgoinghook" function into "prepushoutgoinghooks" of "localrepository" to reuse "findcommonoutgoing()" result. "prepushoutgoinghook" omits "changelog.nodesbetween()" invocation, because "findcommonoutgoing()" invocation in "exchange.push()" takes "onlyheads" argument and it considers "nodesbetween()".
hgext/largefiles/reposetup.py
tests/test-largefiles.t
--- a/hgext/largefiles/reposetup.py	Wed Apr 16 00:37:24 2014 +0900
+++ b/hgext/largefiles/reposetup.py	Wed Apr 16 00:37:24 2014 +0900
@@ -10,7 +10,7 @@
 import copy
 import os
 
-from mercurial import error, manifest, match as match_, util, discovery
+from mercurial import error, manifest, match as match_, util
 from mercurial.i18n import _
 from mercurial import localrepo
 
@@ -412,15 +412,6 @@
                             " supported in the destination:"
                             " %s") % (', '.join(sorted(missing)))
                     raise util.Abort(msg)
-
-            outgoing = discovery.findcommonoutgoing(repo, remote.peer(),
-                                                    force=force)
-            if outgoing.missing:
-                toupload = set()
-                o = self.changelog.nodesbetween(outgoing.missing, revs)[0]
-                addfunc = lambda fn, lfhash: toupload.add(lfhash)
-                lfutil.getlfilestoupload(self, o, addfunc)
-                lfcommands.uploadlfiles(ui, self, remote, toupload)
             return super(lfilesrepo, self).push(remote, force=force, revs=revs,
                 newbranch=newbranch)
 
@@ -480,6 +471,14 @@
 
     repo.__class__ = lfilesrepo
 
+    def prepushoutgoinghook(local, remote, outgoing):
+        if outgoing.missing:
+            toupload = set()
+            addfunc = lambda fn, lfhash: toupload.add(lfhash)
+            lfutil.getlfilestoupload(local, outgoing.missing, addfunc)
+            lfcommands.uploadlfiles(ui, local, remote, toupload)
+    repo.prepushoutgoinghooks.add("largefiles", prepushoutgoinghook)
+
     def checkrequireslfiles(ui, repo, **kwargs):
         if 'largefiles' not in repo.requirements and util.any(
                 lfutil.shortname+'/' in f[0] for f in repo.store.datafiles()):
--- a/tests/test-largefiles.t	Wed Apr 16 00:37:24 2014 +0900
+++ b/tests/test-largefiles.t	Wed Apr 16 00:37:24 2014 +0900
@@ -1593,7 +1593,6 @@
   $ hg push ../dest
   pushing to ../dest
   searching for changes
-  searching for changes
   adding changesets
   adding manifests
   adding file changes
@@ -1687,7 +1686,6 @@
   $ hg push -R r7 http://localhost:$HGPORT1
   pushing to http://localhost:$HGPORT1/
   searching for changes
-  searching for changes
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
@@ -1711,7 +1709,6 @@
   $ hg push -R r8 http://localhost:$HGPORT2/#default
   pushing to http://localhost:$HGPORT2/
   searching for changes
-  searching for changes
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes