Patchwork [9,of,9] bundle-ng: move progress out of the linkrev callback

login
register
mail settings
Submitter Sune Foldager
Date Feb. 14, 2013, 7:40 p.m.
Message ID <f91e6ea657eb37840f2f.1360870819@firefly.edlund.dk>
Download mbox | patch
Permalink /patch/996/
State Superseded
Headers show

Comments

Sune Foldager - Feb. 14, 2013, 7:40 p.m.
# HG changeset patch
# User Benoit Boissinot <benoit.boissinot@ens-lyon.org>
# Date 1360592532 -3600
# Node ID f91e6ea657eb37840f2fdd1414c89d963c7b20d4
# Parent  b667e61d5bfba9ca82e92be3af855da55b856c7a
bundle-ng: move progress out of the linkrev callback

Patch

diff -r b667e61d5bfb -r f91e6ea657eb mercurial/changegroup.py
--- a/mercurial/changegroup.py	Sun Feb 10 16:55:30 2013 +0100
+++ b/mercurial/changegroup.py	Mon Feb 11 15:22:12 2013 +0100
@@ -242,13 +242,14 @@ 
             reorder = False
         self._repo = repo
         self._reorder = reorder
+        self._progress = repo.ui.progress
     def close(self):
         return closechunk()
 
     def fileheader(self, fname):
         return chunkheader(len(fname)) + fname
 
-    def group(self, nodelist, revlog, lookup, reorder=None):
+    def group(self, nodelist, revlog, lookup, units=None, reorder=None):
         """Calculate a delta group, yielding a sequence of changegroup chunks
         (strings).
 
@@ -260,6 +261,7 @@ 
         changegroup starts with a full revision.
         """
 
+        _bundling = _('bundling')
         # if we don't have any revisions touched by these changesets, bail
         if len(nodelist) == 0:
             yield self.close()
@@ -279,7 +281,10 @@ 
         revs.insert(0, p)
 
         # build deltas
+        total = len(revs) - 1
         for r in xrange(len(revs) - 1):
+            if units is not None:
+                self._progress(_bundling, r + 1, unit=units, total=total)
             prev, curr = revs[r], revs[r + 1]
             linknode = lookup(revlog.node(curr))
             for c in self.revchunk(revlog, curr, prev, linknode):
@@ -293,8 +298,7 @@ 
         cl = self._changelog
         mf = self._manifest
         reorder = self._reorder
-        progress = repo.ui.progress
-        count = [0, 0]
+        progress = self._progress
         _bundling = _('bundling')
         _changesets = _('changesets')
         _manifests = _('manifests')
@@ -314,9 +318,6 @@ 
             c = cl.read(x)
             changedfiles.update(c[3])
             mfs.setdefault(c[0], x)
-            count[0] += 1
-            progress(_bundling, count[0],
-                     unit=_changesets, total=count[1])
             return x
 
         def lookupmf(x):
@@ -326,27 +327,24 @@ 
                 for f, n in mdata.iteritems():
                     if f in changedfiles:
                         fnodes[f].setdefault(n, clnode)
-            count[0] += 1
-            progress(_bundling, count[0],
-                     unit=_manifests, total=count[1])
             return clnode
 
-        count[:] = [0, len(clnodes)]
-        for chunk in self.group(clnodes, cl, lookupcl, reorder=reorder):
+        for chunk in self.group(clnodes, cl, lookupcl, units=_changesets,
+                                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, lookupmf, reorder=reorder):
+        for chunk in self.group(mfnodes, mf, lookupmf, units=_manifests,
+                                reorder=reorder):
             yield chunk
         progress(_bundling, None)
 
         mfs.clear()
-        count[:] = [0, len(changedfiles)]
-        for fname in sorted(changedfiles):
+        total = len(changedfiles)
+        for i, fname in enumerate(sorted(changedfiles)):
             filerevlog = repo.file(fname)
             if not len(filerevlog):
                 raise util.Abort(_("empty or missing revlog for %s")
@@ -364,16 +362,15 @@ 
             linkrevnodes = fnodes.pop(fname, {})
             # Lookup for filenodes.
             def lookupfilelog(x):
-                progress(_bundling, count[0], item=fname,
-                         unit=_files, total=count[1])
                 return linkrevnodes[x]
 
             filenodes = prune(filerevlog, linkrevnodes)
             if filenodes:
-                count[0] += 1
+                progress(_bundling, i + 1, item=fname, unit=_files,
+                         total=total)
                 yield self.fileheader(fname)
                 for chunk in self.group(filenodes, filerevlog, lookupfilelog,
-                                        reorder):
+                                        reorder=reorder):
                     yield chunk
         yield self.close()
         progress(_bundling, None)