debugdiscovery: small internal refactoring
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 26 Mar 2019 14:04:33 +0100
changeset 42031 d31d8c5279c6
parent 42030 6ae1a776dd1a
child 42032 63165e4a76da
debugdiscovery: small internal refactoring The part of the code displaying statistic is made independant from the one running the discovery. In the same do, the declaration of the discovery function is a bit simplified.
mercurial/debugcommands.py
--- a/mercurial/debugcommands.py	Tue Mar 26 14:02:40 2019 +0100
+++ b/mercurial/debugcommands.py	Tue Mar 26 14:04:33 2019 +0100
@@ -785,8 +785,10 @@
     # make sure tests are repeatable
     random.seed(int(opts['seed']))
 
-    def doit(pushedrevs, remoteheads, remote=remote):
-        if opts.get('old'):
+
+
+    if opts.get('old'):
+        def doit(pushedrevs, remoteheads, remote=remote):
             if not util.safehasattr(remote, 'branches'):
                 # enable in-client legacy support
                 remote = localrepo.locallegacypeer(remote.local())
@@ -800,26 +802,30 @@
                 clnode = repo.changelog.node
                 common = repo.revs('heads(::%ln)', common)
                 common = {clnode(r) for r in common}
-        else:
+            return common, hds
+    else:
+        def doit(pushedrevs, remoteheads, remote=remote):
             nodes = None
             if pushedrevs:
                 revs = scmutil.revrange(repo, pushedrevs)
                 nodes = [repo[r].node() for r in revs]
             common, any, hds = setdiscovery.findcommonheads(ui, repo, remote,
                                                             ancestorsof=nodes)
-        common = set(common)
-        rheads = set(hds)
-        lheads = set(repo.heads())
-        ui.write(("common heads: %s\n") %
-                 " ".join(sorted(short(n) for n in common)))
-        if lheads <= common:
-            ui.write(("local is subset\n"))
-        elif rheads <= common:
-            ui.write(("remote is subset\n"))
+            return common, hds
 
     remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches, revs=None)
     localrevs = opts['rev']
-    doit(localrevs, remoterevs)
+    common, hds = doit(localrevs, remoterevs)
+
+    common = set(common)
+    rheads = set(hds)
+    lheads = set(repo.heads())
+    ui.write(("common heads: %s\n") %
+             " ".join(sorted(short(n) for n in common)))
+    if lheads <= common:
+        ui.write(("local is subset\n"))
+    elif rheads <= common:
+        ui.write(("remote is subset\n"))
 
 _chunksize = 4 << 10