[PATCH 1 of 8] changegroup: extract generatemanifests()

Martin von Zweigbergk martinvonz at google.com
Tue Feb 23 14:52:26 EST 2016


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1455250788 28800
#      Thu Feb 11 20:19:48 2016 -0800
# Node ID 69b9904d0834a17e54cbbb7d101a7b887f3a13a6
# Parent  19775bc34da34f28451c2b27a4e06433da058f74
changegroup: extract generatemanifests()

The changegroup.generate() function is pretty long, so let's extract
the manifest generation part of it.

diff -r 19775bc34da3 -r 69b9904d0834 mercurial/changegroup.py
--- a/mercurial/changegroup.py	Mon Feb 22 23:18:19 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


More information about the Mercurial-devel mailing list