[PATCH 2 of 3] debugdag and debugindexdag: emit changelog/revlog DAGs as concise text
Peter Arrenbrecht
peter.arrenbrecht at gmail.com
Tue Feb 9 02:11:40 CST 2010
# HG changeset patch
# User Peter Arrenbrecht <peter.arrenbrecht at gmail.com>
# Date 1265702978 -3600
debugdag and debugindexdag: emit changelog/revlog DAGs as concise text
Mainly useful for reusing DAGs somewhere else, for example for attaching
them to a bug report, or for importing them into other environments
(like my test environment for incoming/outgoing discovery).
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -15,6 +15,7 @@
from hgweb import server
import merge as merge_
import minirst
+import dagparser
# Commands start here, listed alphabetically
@@ -898,6 +899,38 @@
ui.write(' source %s\n' % v[0])
ui.write(' revision %s\n' % v[1])
+def debugdag(ui, repo, tags=False, branches=False, dots=False):
+ """format the changelog DAG as a concise textual description"""
+ cl = repo.changelog
+
+ if tags:
+ labels = {}
+ for l, n in repo.tags().items():
+ labels.setdefault(cl.rev(n), []).append(l)
+
+ def events():
+ b = "default"
+ for r in cl:
+ if branches:
+ newb = cl.read(cl.node(r))[5]['branch']
+ if newb != b:
+ yield 'a', newb
+ b = newb
+ yield 'n', (r, list(set(p for p in cl.parentrevs(r) if p != -1)))
+ if tags:
+ ls = labels.get(r)
+ if ls:
+ for l in ls:
+ yield 'l', (r, l)
+
+ for line in dagparser.dagtextlines(events(),
+ wraplabels=True,
+ wrapannotations=True,
+ wrapnonlinear=dots,
+ usedots=dots):
+ ui.write(line)
+ ui.write("\n")
+
def debugdata(ui, file_, rev):
"""dump the contents of a data file revision"""
r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_[:-2] + ".i")
@@ -945,6 +978,26 @@
ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i))
ui.write("}\n")
+def debugindexdag(ui, file_, *revs, **opts):
+ """format an index DAG as a concise textual description
+
+ If you list revision numbers, they get labelled in the output as rN.
+ """
+ rlog = revlog.revlog(util.opener(os.getcwd(), audit=False), file_)
+ revs = set((int(r) for r in revs))
+
+ def events():
+ for r in rlog:
+ yield 'n', (r, list(set(p for p in rlog.parentrevs(r) if p != -1)))
+ if r in revs:
+ yield 'l', (r, "r%i" % r)
+
+ for line in dagparser.dagtextlines(events(),
+ wraplabels=True,
+ usedots=opts.get("dots")):
+ ui.write(line)
+ ui.write("\n")
+
def debuginstall(ui):
'''test Mercurial installation'''
@@ -3498,6 +3551,13 @@
(debugcomplete,
[('o', 'options', None, _('show the command options'))],
_('[-o] CMD')),
+ "debugdag":
+ (debugdag,
+ [('t', 'tags', None, _('use tags as labels')),
+ ('b', 'branches', None, _('annotate with branch names')),
+ ('', 'dots', None, _('use dots for runs')),
+ ],
+ _('[OPTION]...')),
"debugdate":
(debugdate,
[('e', 'extended', None, _('try extended date formats'))],
@@ -3505,6 +3565,10 @@
"debugdata": (debugdata, [], _('FILE REV')),
"debugfsinfo": (debugfsinfo, [], _('[PATH]')),
"debugindex": (debugindex, [], _('FILE')),
+ "debugindexdag":
+ (debugindexdag,
+ [('', 'dots', None, _('use dots for runs'))],
+ _('[OPTION]... FILE [REV]...')),
"debugindexdot": (debugindexdot, [], _('FILE')),
"debuginstall": (debuginstall, [], ''),
"debugrebuildstate":
@@ -3804,5 +3868,6 @@
}
norepo = ("clone init version help debugcommands debugcomplete debugdata"
- " debugindex debugindexdot debugdate debuginstall debugfsinfo")
+ " debugindex debugindexdag debugindexdot debugdate debuginstall"
+ " debugfsinfo")
optionalrepo = ("identify paths serve showconfig debugancestor")
More information about the Mercurial-devel
mailing list