changegroup: simplify by not reusing 'prog(ress)' instance
authorMartin von Zweigbergk <martinvonz@google.com>
Fri, 12 Jun 2015 11:00:50 -0700
changeset 25574 88a17ccf0196
parent 25573 3e89e67f17e8
child 25575 475eae3497af
changegroup: simplify by not reusing 'prog(ress)' instance Just create a new instance of the 'prog' class for each step instead of replacing its fields and resetting the counter.
mercurial/changegroup.py
--- a/mercurial/changegroup.py	Fri Jun 12 10:54:10 2015 -0700
+++ b/mercurial/changegroup.py	Fri Jun 12 11:00:50 2015 -0700
@@ -741,15 +741,15 @@
         repo.ui.status(_("adding changesets\n"))
         clstart = len(cl)
         class prog(object):
-            step = _('changesets')
-            count = 1
-            total = expectedtotal
+            def __init__(self, step, total):
+                self._step = step
+                self._total = total
+                self._count = 1
             def __call__(self):
-                repo.ui.progress(self.step, self.count, unit=_('chunks'),
-                                 total=self.total)
-                self.count += 1
-        pr = prog()
-        source.callback = pr
+                repo.ui.progress(self._step, self._count, unit=_('chunks'),
+                                 total=self._total)
+                self._count += 1
+        source.callback = prog(_('changesets'), expectedtotal)
 
         source.changelogheader()
         srccontent = cl.addgroup(source, csmap, trp)
@@ -764,9 +764,8 @@
 
         # pull off the manifest group
         repo.ui.status(_("adding manifests\n"))
-        pr.step = _('manifests')
-        pr.count = 1
-        pr.total = changesets # manifests <= changesets
+        # manifests <= changesets
+        source.callback = prog(_('manifests'), changesets)
         # no need to check for empty manifest group here:
         # if the result of the merge of 1 and 2 is the same in 3 and 4,
         # no new manifest will be created and the manifest group will
@@ -787,11 +786,8 @@
 
         # process the files
         repo.ui.status(_("adding file changes\n"))
-        pr.step = _('files')
-        pr.count = 1
-        pr.total = efiles
         source.callback = None
-
+        pr = prog(_('files'), efiles)
         newrevs, newfiles = addchangegroupfiles(repo, source, revmap, trp, pr,
                                                 needfiles)
         revisions += newrevs