Patchwork [2,of,6,"] debugdiscovery: small internal refactoring

login
register
mail settings
Submitter Pierre-Yves David
Date March 26, 2019, 5:04 p.m.
Message ID <5c807938c6bda9aebe63.1553619895@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/39391/
State Superseded
Headers show

Comments

Pierre-Yves David - March 26, 2019, 5:04 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1553605473 -3600
#      Tue Mar 26 14:04:33 2019 +0100
# Node ID 5c807938c6bda9aebe6366a2aa89ecec7099a394
# Parent  86368c692741cc1c8484a1e43f25f0dc9186496e
# EXP-Topic debug-discovery
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 5c807938c6bd
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.

Patch

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