[PATCH 2 of 3] debugdag and debugindexdag: emit changelog/revlog DAGs as concise text

Peter Arrenbrecht peter.arrenbrecht at gmail.com
Fri Jun 11 03:31:05 CDT 2010


# HG changeset patch
# User Peter Arrenbrecht <peter.arrenbrecht at gmail.com>
# Date 1276163325 -7200
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
@@ -14,6 +14,7 @@
 import archival, changegroup, cmdutil, sshserver, hbisect, hgweb, hgweb.server
 import merge as mergemod
 import minirst, revset
+import dagparser
 
 # Commands start here, listed alphabetically
 
@@ -995,6 +996,59 @@
         ui.write(' source   %s\n' % v[0])
         ui.write(' revision %s\n' % v[1])
 
+def debugdag(ui, repo, file_=None, *revs, **opts):
+    """format the changelog or an index DAG as a concise textual description
+
+    If you pass a revlog index, the revlog's DAG is emitted. If you list
+    revision numbers, they get labelled in the output as rN.
+
+    Otherwise, the changelog DAG of the current repo is emitted.
+    """
+    spaces = opts.get('spaces')
+    dots = opts.get('dots')
+    if file_:
+        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)
+    elif repo:
+        cl = repo.changelog
+        tags = opts.get('tags')
+        branches = opts.get('branches')
+        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)
+    else:
+        raise util.Abort(_('need repo for changelog dag'))
+
+    for line in dagparser.dagtextlines(events(),
+                                       addspaces=spaces,
+                                       wraplabels=True,
+                                       wrapannotations=True,
+                                       wrapnonlinear=dots,
+                                       usedots=dots,
+                                       maxlinewidth=70):
+        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")
@@ -3781,6 +3835,14 @@
         (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')),
+          ('s', 'spaces', None, _('separate elements by spaces')),
+         ],
+         _('[OPTION]... [FILE [REV]...]')),
     "debugdate":
         (debugdate,
          [('e', 'extended', None, _('try extended date formats'))],
@@ -4097,4 +4159,4 @@
 
 norepo = ("clone init version help debugcommands debugcomplete debugdata"
           " debugindex debugindexdot debugdate debuginstall debugfsinfo")
-optionalrepo = ("identify paths serve showconfig debugancestor")
+optionalrepo = ("identify paths serve showconfig debugancestor debugdag")


More information about the Mercurial-devel mailing list