D10224: debugdiscovery: also integrate the discovery output in the json one
marmoute (Pierre-Yves David)
phabricator at mercurial-scm.org
Mon Mar 15 23:01:59 UTC 2021
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
We add a way for formatter to informs code that free output is unwanted, and we
incorporate it in the json output.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D10224
AFFECTED FILES
mercurial/debugcommands.py
mercurial/formatter.py
tests/test-setdiscovery.t
CHANGE DETAILS
diff --git a/tests/test-setdiscovery.t b/tests/test-setdiscovery.t
--- a/tests/test-setdiscovery.t
+++ b/tests/test-setdiscovery.t
@@ -1734,13 +1734,6 @@
> --local-as-revs 'first(heads(all()), 25)' \
> --remote-as-revs 'last(heads(all()), 25)' \
> --config devel.discovery.randomize=false
- query 1; heads
- searching for changes
- taking quick initial sample
- query 2; still undecided: 375, sample size is: 81
- sampling from both directions
- query 3; still undecided: 3, sample size is: 3
- 3 total queries in *s (glob)
[
{
"elapsed": *, (glob)
@@ -1763,6 +1756,7 @@
"nb-revs": 400,
"nb-revs-common": 300,
"nb-revs-missing": 100,
+ "output": "query 1; heads\nsearching for changes\ntaking quick initial sample\nquery 2; still undecided: 375, sample size is: 81\nsampling from both directions\nquery 3; still undecided: 3, sample size is: 3\n3 total queries in *s\n", (glob)
"total-roundtrips": 3
}
]
diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -178,6 +178,11 @@
class baseformatter(object):
+
+ # set to True if the formater output a strict format that does not support
+ # arbitrary output in the stream.
+ strict_format = False
+
def __init__(self, ui, topic, opts, converter):
self._ui = ui
self._topic = topic
@@ -418,6 +423,9 @@
class jsonformatter(baseformatter):
+
+ strict_format = True
+
def __init__(self, ui, out, topic, opts):
baseformatter.__init__(self, ui, topic, opts, _nullconverter)
self._out = out
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -9,6 +9,7 @@
import codecs
import collections
+import contextlib
import difflib
import errno
import glob
@@ -1089,8 +1090,21 @@
remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches, revs=None)
localrevs = opts[b'rev']
- with util.timedcm('debug-discovery') as t:
- common, hds = doit(localrevs, remoterevs)
+
+ fm = ui.formatter(b'debugdiscovery', opts)
+ if fm.strict_format:
+
+ @contextlib.contextmanager
+ def may_capture_output():
+ ui.pushbuffer()
+ yield
+ data[b'output'] = ui.popbuffer()
+
+ else:
+ may_capture_output = util.nullcontextmanager
+ with may_capture_output():
+ with util.timedcm('debug-discovery') as t:
+ common, hds = doit(localrevs, remoterevs)
# compute all statistics
heads_common = set(common)
@@ -1141,7 +1155,6 @@
data[b'nb-ini_und-common'] = len(common_initial_undecided)
data[b'nb-ini_und-missing'] = len(missing_initial_undecided)
- fm = ui.formatter(b'debugdiscovery', opts)
fm.startitem()
fm.data(**pycompat.strkwargs(data))
# display discovery summary
To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list