[PATCH 1 of 6 STABLE] log/graphlog: introduce --print-revset for debugging purposes

Patrick Mezard patrick at mezard.eu
Sat Feb 18 19:57:38 UTC 2012


# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1329594703 -3600
# Branch stable
# Node ID 5f0e7395d1135cb2fe60e16bc1a18fd4d8936ae2
# Parent  0e0060bf2f440d5cc33e5f36d99868a5380debd4
log/graphlog: introduce --print-revset for debugging purposes

Using "hg log -G --print-revset" prints the revset generated by graphlog and
exits. This helps debugging and writing shorter tests.

I think this change is acceptable for stable as the implementation is
straightforward and will help exhibiting existing bugs in graphlog revset
generation code.

diff --git a/hgext/graphlog.py b/hgext/graphlog.py
--- a/hgext/graphlog.py
+++ b/hgext/graphlog.py
@@ -17,7 +17,7 @@
 from mercurial.i18n import _
 from mercurial.node import nullrev
 from mercurial import cmdutil, commands, extensions, scmutil
-from mercurial import hg, util, graphmod
+from mercurial import hg, util, graphmod, revset
 
 cmdtable = {}
 command = cmdutil.command(cmdtable)
@@ -245,7 +245,7 @@
         raise util.Abort(_("-G/--graph option is incompatible with --follow "
                            "with file argument"))
 
-def revset(pats, opts):
+def makerevset(pats, opts):
     """Return revset str built of revisions, log options and file patterns.
     """
     opt2revset = {
@@ -326,7 +326,12 @@
 
     check_unsupported_flags(pats, opts)
 
-    revs = sorted(scmutil.revrange(repo, [revset(pats, opts)]), reverse=1)
+    expr = makerevset(pats, opts)
+    if opts.get('print_revset'):
+        tree = revset.parse(expr)[0]
+        ui.write(tree, "\n")
+        return 0
+    revs = sorted(scmutil.revrange(repo, [expr]), reverse=1)
     limit = cmdutil.loglimit(opts)
     if limit is not None:
         revs = revs[:limit]
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3763,6 +3763,8 @@
     ('P', 'prune', [],
      _('do not display revision or any of its ancestors'), _('REV')),
     ('', 'hidden', False, _('show hidden changesets (DEPRECATED)')),
+    ('', 'print-revset', False,
+     _('print generated revset and exit (DEPRECATED)')),
     ] + logopts + walkopts,
     _('[OPTION]... [FILE]'))
 def log(ui, repo, *pats, **opts):
diff --git a/tests/test-debugcomplete.t b/tests/test-debugcomplete.t
--- a/tests/test-debugcomplete.t
+++ b/tests/test-debugcomplete.t
@@ -197,7 +197,7 @@
   export: output, switch-parent, rev, text, git, nodates
   forget: include, exclude
   init: ssh, remotecmd, insecure
-  log: follow, follow-first, date, copies, keyword, rev, removed, only-merges, user, only-branch, branch, prune, hidden, patch, git, limit, no-merges, stat, style, template, include, exclude
+  log: follow, follow-first, date, copies, keyword, rev, removed, only-merges, user, only-branch, branch, prune, hidden, print-revset, patch, git, limit, no-merges, stat, style, template, include, exclude
   merge: force, rev, preview, tool
   phase: public, draft, secret, force, rev
   pull: update, force, rev, bookmark, branch, ssh, remotecmd, insecure
diff --git a/tests/test-glog.t b/tests/test-glog.t
--- a/tests/test-glog.t
+++ b/tests/test-glog.t
@@ -1400,7 +1400,8 @@
   $ hg log -G -b 'something nice'
   abort: unknown revision 'something nice'!
   [255]
-  $ hg log -G -k 'something nice'
+  $ hg log -G --print-revset -k 'something' -k 'nice'
+  ('group', ('and', ('func', ('symbol', 'keyword'), ('string', 'something')), ('func', ('symbol', 'keyword'), ('string', 'nice'))))
   $ hg log -G --only-branch 'something nice'
   abort: unknown revision 'something nice'!
   [255]



More information about the Mercurial-devel mailing list