Patchwork [08,of,10,v2] bundle-ng: simplify bundle10.generate

login
register
mail settings
Submitter Benoit Boissinot
Date May 10, 2013, 9:59 p.m.
Message ID <183988c0a67f984a5a97.1368223196@pouchy.lan>
Download mbox | patch
Permalink /patch/1614/
State Accepted
Commit 6308896b1d4a763f3c347aee8787067abeaf608d
Headers show

Comments

Benoit Boissinot - May 10, 2013, 9:59 p.m.
# HG changeset patch
# User Sune Foldager <cryo@cyanite.org>
# Date 1368219474 -7200
#      Fri May 10 22:57:54 2013 +0200
# Node ID 183988c0a67f984a5a9791cff986db64f86452f0
# Parent  47992d9a8134d9e26a95240a2fd6d991dd77a78a
bundle-ng: simplify bundle10.generate

Remove complex local sub-functions mutating function-global variables. Simplify
counting used for progress output.

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -245,8 +245,6 @@ 
         self._repo = repo
         self._reorder = reorder
         self.count = [0, 0]
-    def start(self, lookup):
-        self._lookup = lookup
     def close(self):
         return closechunk()
 
@@ -340,17 +338,29 @@ 
                          unit=_files, total=count[1])
                 return fstate[1][x]
 
-        self.start(lookup)
+        self._lookup = lookup
 
-        def getmfnodes():
-            for f in changedfiles:
-                fnodes[f] = {}
-            count[:] = [0, len(mfs)]
-            return prune(mf, mfs)
-        def getfiles():
-            mfs.clear()
-            return changedfiles
-        def getfilenodes(fname, filerevlog):
+        count[:] = [0, len(clnodes)]
+        for chunk in self.group(clnodes, cl, reorder=reorder):
+            yield chunk
+        progress(_bundling, None)
+
+        for f in changedfiles:
+            fnodes[f] = {}
+        count[:] = [0, len(mfs)]
+        mfnodes = prune(mf, mfs)
+        for chunk in self.group(mfnodes, mf, reorder=reorder):
+            yield chunk
+        progress(_bundling, None)
+
+        mfs.clear()
+        count[:] = [0, len(changedfiles)]
+        for fname in sorted(changedfiles):
+            filerevlog = repo.file(fname)
+            if not len(filerevlog):
+                raise util.Abort(_("empty or missing revlog for %s")
+                                 % fname)
+
             if fastpathlinkrev:
                 ln, llr = filerevlog.node, filerevlog.linkrev
                 def genfilenodes():
@@ -361,30 +371,11 @@ 
                 fnodes[fname] = dict(genfilenodes())
             fstate[0] = fname
             fstate[1] = fnodes.pop(fname, {})
-            return prune(filerevlog, fstate[1])
-
-
-        count[:] = [0, len(clnodes)]
-        for chunk in self.group(clnodes, cl, reorder=reorder):
-            yield chunk
-        progress(_bundling, None)
-
-        for chunk in self.group(getmfnodes(), mf, reorder=reorder):
-            yield chunk
-        progress(_bundling, None)
-
-        changedfiles = getfiles()
-        count[:] = [0, len(changedfiles)]
-        for fname in sorted(changedfiles):
-            filerevlog = repo.file(fname)
-            if not len(filerevlog):
-                raise util.Abort(_("empty or missing revlog for %s")
-                                 % fname)
-            nodelist = getfilenodes(fname, filerevlog)
-            if nodelist:
+            filenodes = prune(filerevlog, fstate[1])
+            if filenodes:
                 count[0] += 1
                 yield self.fileheader(fname)
-                for chunk in self.group(nodelist, filerevlog, reorder):
+                for chunk in self.group(filenodes, filerevlog, reorder):
                     yield chunk
         yield self.close()
         progress(_bundling, None)