[PATCH 2 of 6 "V2] debugdiscovery: small internal refactoring

Pierre-Yves David pierre-yves.david at ens-lyon.org
Wed Mar 27 07:23:10 EDT 2019


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1553605473 -3600
#      Tue Mar 26 14:04:33 2019 +0100
# Node ID faecfbf1a16ef274e365de1ea0cd16fb53020ad3
# Parent  9ed78aeb439439b95c218d097f17f0416cb21129
# EXP-Topic debug-discovery
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r faecfbf1a16e
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.

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -785,8 +785,10 @@ def debugdiscovery(ui, repo, remoteurl="
     # 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 @@ def debugdiscovery(ui, repo, remoteurl="
                 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
 


More information about the Mercurial-devel mailing list