progress: extract function for closing topic
authorMartin von Zweigbergk <martinvonz@google.com>
Tue, 19 Jun 2018 22:11:34 -0700
changeset 46651 b34d0a6ef936bb927dc19d1dfb4cda2175a704d5
parent 46650 6bd9f18d31a81fd60c792537054b70cfe8f87708
child 46652 6dea017eb6ba434507180d107182b24c80ea54df
push id818
push usergszorc@mozilla.com
push dateSat, 23 Jun 2018 18:31:31 +0000
progress: extract function for closing topic progress(None) had a completely different implementation from the progress(<not None>) implementation. It very much feels like it should be a separate method, so this patch makes it so. That also makes it clear that only the topic parameter matters when closing a topic (e.g. "total" does not matter). Differential Revision: https://phab.mercurial-scm.org/D3821
mercurial/progress.py
--- a/mercurial/progress.py
+++ b/mercurial/progress.py
@@ -259,41 +259,45 @@ class progbar(object):
             # frequently. This is to avoid such dramatical change and make ETA
             # smoother.
             if newdelta < 0.1:
                 return
             self.startvals[topic] = pos - newdelta
             self.starttimes[topic] = now - interval
 
     def progress(self, topic, pos, item='', unit='', total=None):
+        if pos is None:
+            self.closetopic(topic)
+            return
         now = time.time()
         with self._refreshlock:
-            if pos is None:
-                self.starttimes.pop(topic, None)
-                self.startvals.pop(topic, None)
-                self.topicstates.pop(topic, None)
-                # reset the progress bar if this is the outermost topic
-                if self.topics and self.topics[0] == topic and self.printed:
-                    self.complete()
-                    self.resetstate()
-                # truncate the list of topics assuming all topics within
-                # this one are also closed
-                if topic in self.topics:
-                    self.topics = self.topics[:self.topics.index(topic)]
-                    # reset the last topic to the one we just unwound to,
-                    # so that higher-level topics will be stickier than
-                    # lower-level topics
-                    if self.topics:
-                        self.lasttopic = self.topics[-1]
-                    else:
-                        self.lasttopic = None
-            else:
-                if topic not in self.topics:
-                    self.starttimes[topic] = now
-                    self.startvals[topic] = pos
-                    self.topics.append(topic)
-                self.topicstates[topic] = pos, item, unit, total
-                self.curtopic = topic
-                self._calibrateestimate(topic, now, pos)
-                if now - self.lastprint >= self.refresh and self.topics:
-                    if self._oktoprint(now):
-                        self.lastprint = now
-                        self.show(now, topic, *self.topicstates[topic])
+            if topic not in self.topics:
+                self.starttimes[topic] = now
+                self.startvals[topic] = pos
+                self.topics.append(topic)
+            self.topicstates[topic] = pos, item, unit, total
+            self.curtopic = topic
+            self._calibrateestimate(topic, now, pos)
+            if now - self.lastprint >= self.refresh and self.topics:
+                if self._oktoprint(now):
+                    self.lastprint = now
+                    self.show(now, topic, *self.topicstates[topic])
+
+    def closetopic(self, topic):
+        with self._refreshlock:
+            self.starttimes.pop(topic, None)
+            self.startvals.pop(topic, None)
+            self.topicstates.pop(topic, None)
+            # reset the progress bar if this is the outermost topic
+            if self.topics and self.topics[0] == topic and self.printed:
+                self.complete()
+                self.resetstate()
+            # truncate the list of topics assuming all topics within
+            # this one are also closed
+            if topic in self.topics:
+                self.topics = self.topics[:self.topics.index(topic)]
+                # reset the last topic to the one we just unwound to,
+                # so that higher-level topics will be stickier than
+                # lower-level topics
+                if self.topics:
+                    self.lasttopic = self.topics[-1]
+                else:
+                    self.lasttopic = None