changegroup: extract generatemanifests()
authorMartin von Zweigbergk <martinvonz@google.com>
Thu, 11 Feb 2016 20:19:48 -0800
changeset 28227 1c36cc8e7870
parent 28226 377f0d8ff874
child 28228 abf120262683
changegroup: extract generatemanifests() The changegroup.generate() function is pretty long, so let's extract the manifest generation part of it.
mercurial/changegroup.py
--- a/mercurial/changegroup.py	Tue Feb 23 10:59:25 2016 -0800
+++ b/mercurial/changegroup.py	Thu Feb 11 20:19:48 2016 -0800
@@ -678,11 +678,9 @@
         '''yield a sequence of changegroup chunks (strings)'''
         repo = self._repo
         cl = repo.changelog
-        ml = repo.manifest
 
         clrevorder = {}
         mfs = {} # needed manifests
-        tmfnodes = {}
         fnodes = {} # needed file nodes
         # maps manifest node id -> set(changed files)
         mfchangedfiles = {}
@@ -729,6 +727,42 @@
         # send along with files. This could probably be fixed.
         fastpathlinkrev = fastpathlinkrev and (
             'treemanifest' not in repo.requirements)
+
+        for chunk in self.generatemanifests(commonrevs, clrevorder,
+                fastpathlinkrev, mfs, mfchangedfiles, fnodes):
+            yield chunk
+        mfs.clear()
+        clrevs = set(cl.rev(x) for x in clnodes)
+
+        if not fastpathlinkrev:
+            def linknodes(unused, fname):
+                return fnodes.get(fname, {})
+        else:
+            cln = cl.node
+            def linknodes(filerevlog, fname):
+                llr = filerevlog.linkrev
+                fln = filerevlog.node
+                revs = ((r, llr(r)) for r in filerevlog)
+                return dict((fln(r), cln(lr)) for r, lr in revs if lr in clrevs)
+
+        changedfiles = set()
+        for x in mfchangedfiles.itervalues():
+            changedfiles.update(x)
+        for chunk in self.generatefiles(changedfiles, linknodes, commonrevs,
+                                        source):
+            yield chunk
+
+        yield self.close()
+
+        if clnodes:
+            repo.hook('outgoing', node=hex(clnodes[0]), source=source)
+
+    def generatemanifests(self, commonrevs, clrevorder, fastpathlinkrev, mfs,
+                          mfchangedfiles, fnodes):
+        repo = self._repo
+        ml = repo.manifest
+        tmfnodes = {}
+
         # Callback for the manifest, used to collect linkrevs for filelog
         # revisions.
         # Returns the linkrev node (collected in lookupcl).
@@ -795,32 +829,6 @@
             mfnodes, tmfnodes, lookupmflinknode):
             yield x
 
-        mfs.clear()
-        clrevs = set(cl.rev(x) for x in clnodes)
-
-        if not fastpathlinkrev:
-            def linknodes(unused, fname):
-                return fnodes.get(fname, {})
-        else:
-            cln = cl.node
-            def linknodes(filerevlog, fname):
-                llr = filerevlog.linkrev
-                fln = filerevlog.node
-                revs = ((r, llr(r)) for r in filerevlog)
-                return dict((fln(r), cln(lr)) for r, lr in revs if lr in clrevs)
-
-        changedfiles = set()
-        for x in mfchangedfiles.itervalues():
-            changedfiles.update(x)
-        for chunk in self.generatefiles(changedfiles, linknodes, commonrevs,
-                                        source):
-            yield chunk
-
-        yield self.close()
-
-        if clnodes:
-            repo.hook('outgoing', node=hex(clnodes[0]), source=source)
-
     # The 'source' parameter is useful for extensions
     def generatefiles(self, changedfiles, linknodes, commonrevs, source):
         repo = self._repo