diff hgext/evolve.py @ 1315:445d7f46f25d

evolve: refactor code computing stats of obsolescence markers Duplicated code removal by extracting a function.
author Laurent Charignon <lcharignon@fb.com>
date Thu, 30 Apr 2015 15:11:00 -0700
parents d13d97363521
children f11363699766
line wrap: on
line diff
--- a/hgext/evolve.py	Thu Apr 30 14:55:04 2015 -0700
+++ b/hgext/evolve.py	Thu Apr 30 15:11:00 2015 -0700
@@ -1047,6 +1047,23 @@
 
 @command('debugobsstorestat', [], '')
 def cmddebugobsstorestat(ui, repo):
+    def _updateclustermap(nodes, mark, clustersmap):
+        c = (set(nodes), set([mark]))
+        toproceed = set(nodes)
+        while toproceed:
+            n = toproceed.pop()
+            other = clustersmap.get(n)
+            if (other is not None
+                and other is not c):
+                other[0].update(c[0])
+                other[1].update(c[1])
+                for on in c[0]:
+                    if on in toproceed:
+                        continue
+                    clustersmap[on] = other
+                c = other
+            clustersmap[n] = c
+
     """print statistic about obsolescence markers in the repo"""
     store = repo.obsstore
     unfi = repo.unfiltered()
@@ -1076,42 +1093,12 @@
         if parents:
             parentsdata += 1
         # cluster handling
-        nodes = set()
+        nodes = set(mark[1])
         nodes.add(mark[0])
-        nodes.update(mark[1])
-        c = (set(nodes), set([mark]))
-
-        toproceed = set(nodes)
-        while toproceed:
-            n = toproceed.pop()
-            other = clustersmap.get(n)
-            if (other is not None
-                and other is not c):
-                other[0].update(c[0])
-                other[1].update(c[1])
-                for on in c[0]:
-                    if on in toproceed:
-                        continue
-                    clustersmap[on] = other
-                c = other
-            clustersmap[n] = c
+        _updateclustermap(nodes, mark, clustersmap) 
         # same with parent data
         nodes.update(parents)
-        c = (set(nodes), set([mark]))
-        toproceed = set(nodes)
-        while toproceed:
-            n = toproceed.pop()
-            other = pclustersmap.get(n)
-            if (other is not None
-                and other is not c):
-                other[0].update(c[0])
-                other[1].update(c[1])
-                for on in c[0]:
-                    if on in toproceed:
-                        continue
-                    pclustersmap[on] = other
-                c = other
-            pclustersmap[n] = c
+        _updateclustermap(nodes, mark, pclustersmap) 
 
     # freezing the result
     for c in clustersmap.values():