changeset 17182:cdf1532d89c6

incoming/outgoing: handle --graph in core
author Patrick Mezard <patrick@mezard.eu>
date Wed, 11 Jul 2012 18:22:07 +0200
parents 6f71167292f2
children 4253cfee08ef
files hgext/graphlog.py mercurial/cmdutil.py mercurial/commands.py tests/test-debugcomplete.t
diffstat 4 files changed, 42 insertions(+), 77 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/graphlog.py	Sat Jul 14 19:09:22 2012 +0200
+++ b/hgext/graphlog.py	Wed Jul 11 18:22:07 2012 +0200
@@ -12,21 +12,13 @@
 revision graph is also shown.
 '''
 
-from mercurial.cmdutil import show_changeset
 from mercurial.i18n import _
-from mercurial import cmdutil, commands, extensions
-from mercurial import hg, util, graphmod
+from mercurial import cmdutil, commands
 
 cmdtable = {}
 command = cmdutil.command(cmdtable)
 testedwith = 'internal'
 
-def _checkunsupportedflags(pats, opts):
-    for op in ["newest_first"]:
-        if op in opts and opts[op]:
-            raise util.Abort(_("-G/--graph option is incompatible with --%s")
-                             % op.replace("_", "-"))
-
 @command('glog',
     [('f', 'follow', None,
      _('follow changeset history, or file history across copies and renames')),
@@ -60,66 +52,3 @@
     directory.
     """
     return cmdutil.graphlog(ui, repo, *pats, **opts)
-
-def graphrevs(repo, nodes, opts):
-    limit = cmdutil.loglimit(opts)
-    nodes.reverse()
-    if limit is not None:
-        nodes = nodes[:limit]
-    return graphmod.nodes(repo, nodes)
-
-def goutgoing(ui, repo, dest=None, **opts):
-    """show the outgoing changesets alongside an ASCII revision graph
-
-    Print the outgoing changesets alongside a revision graph drawn with
-    ASCII characters.
-
-    Nodes printed as an @ character are parents of the working
-    directory.
-    """
-
-    _checkunsupportedflags([], opts)
-    o = hg._outgoing(ui, repo, dest, opts)
-    if o is None:
-        return
-
-    revdag = graphrevs(repo, o, opts)
-    displayer = show_changeset(ui, repo, opts, buffered=True)
-    showparents = [ctx.node() for ctx in repo[None].parents()]
-    cmdutil.displaygraph(ui, revdag, displayer, showparents,
-                         graphmod.asciiedges)
-
-def gincoming(ui, repo, source="default", **opts):
-    """show the incoming changesets alongside an ASCII revision graph
-
-    Print the incoming changesets alongside a revision graph drawn with
-    ASCII characters.
-
-    Nodes printed as an @ character are parents of the working
-    directory.
-    """
-    def subreporecurse():
-        return 1
-
-    _checkunsupportedflags([], opts)
-    def display(other, chlist, displayer):
-        revdag = graphrevs(other, chlist, opts)
-        showparents = [ctx.node() for ctx in repo[None].parents()]
-        cmdutil.displaygraph(ui, revdag, displayer, showparents,
-                             graphmod.asciiedges)
-
-    hg._incoming(display, subreporecurse, ui, repo, source, opts, buffered=True)
-
-def uisetup(ui):
-    '''Initialize the extension.'''
-    _wrapcmd('incoming', commands.table, gincoming)
-    _wrapcmd('outgoing', commands.table, goutgoing)
-
-def _wrapcmd(cmd, table, wrapfn):
-    '''wrap the command'''
-    def graph(orig, *args, **kwargs):
-        if kwargs['graph']:
-            return wrapfn(*args, **kwargs)
-        return orig(*args, **kwargs)
-    entry = extensions.wrapcommand(table, cmd, graph)
-    entry[1].append(('G', 'graph', None, _("show the revision DAG")))
--- a/mercurial/cmdutil.py	Sat Jul 14 19:09:22 2012 +0200
+++ b/mercurial/cmdutil.py	Wed Jul 11 18:22:07 2012 +0200
@@ -1450,6 +1450,19 @@
     displaygraph(ui, revdag, displayer, showparents,
                  graphmod.asciiedges, getrenamed, filematcher)
 
+def checkunsupportedgraphflags(pats, opts):
+    for op in ["newest_first"]:
+        if op in opts and opts[op]:
+            raise util.Abort(_("-G/--graph option is incompatible with --%s")
+                             % op.replace("_", "-"))
+
+def graphrevs(repo, nodes, opts):
+    limit = loglimit(opts)
+    nodes.reverse()
+    if limit is not None:
+        nodes = nodes[:limit]
+    return graphmod.nodes(repo, nodes)
+
 def add(ui, repo, match, dryrun, listsubrepos, prefix, explicitonly):
     join = lambda f: os.path.join(prefix, f)
     bad = []
--- a/mercurial/commands.py	Sat Jul 14 19:09:22 2012 +0200
+++ b/mercurial/commands.py	Wed Jul 11 18:22:07 2012 +0200
@@ -15,7 +15,7 @@
 import sshserver, hgweb, hgweb.server, commandserver
 import merge as mergemod
 import minirst, revset, fileset
-import dagparser, context, simplemerge
+import dagparser, context, simplemerge, graphmod
 import random, setdiscovery, treediscovery, dagutil, pvec
 import phases, obsolete
 
@@ -98,6 +98,7 @@
      _('limit number of changes displayed'), _('NUM')),
     ('M', 'no-merges', None, _('do not show merges')),
     ('', 'stat', None, _('output diffstat-style summary of changes')),
+    ('G', 'graph', None, _("show the revision DAG")),
 ] + templateopts
 
 diffopts = [
@@ -3828,6 +3829,17 @@
 
     Returns 0 if there are incoming changes, 1 otherwise.
     """
+    if opts.get('graph'):
+        cmdutil.checkunsupportedgraphflags([], opts)
+        def display(other, chlist, displayer):
+            revdag = cmdutil.graphrevs(other, chlist, opts)
+            showparents = [ctx.node() for ctx in repo[None].parents()]
+            cmdutil.displaygraph(ui, revdag, displayer, showparents,
+                                 graphmod.asciiedges)
+
+        hg._incoming(display, lambda: 1, ui, repo, source, opts, buffered=True)
+        return 0
+
     if opts.get('bundle') and opts.get('subrepos'):
         raise util.Abort(_('cannot combine --bundle and --subrepos'))
 
@@ -3928,7 +3940,6 @@
     ('P', 'prune', [],
      _('do not display revision or any of its ancestors'), _('REV')),
     ('', 'hidden', False, _('show hidden changesets (DEPRECATED)')),
-    ('G', 'graph', None, _("show the revision DAG")),
     ] + logopts + walkopts,
     _('[OPTION]... [FILE]'))
 def log(ui, repo, *pats, **opts):
@@ -4283,6 +4294,18 @@
 
     Returns 0 if there are outgoing changes, 1 otherwise.
     """
+    if opts.get('graph'):
+        cmdutil.checkunsupportedgraphflags([], opts)
+        o = hg._outgoing(ui, repo, dest, opts)
+        if o is None:
+            return
+
+        revdag = cmdutil.graphrevs(repo, o, opts)
+        displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True)
+        showparents = [ctx.node() for ctx in repo[None].parents()]
+        cmdutil.displaygraph(ui, revdag, displayer, showparents,
+                             graphmod.asciiedges)
+        return 0
 
     if opts.get('bookmarks'):
         dest = ui.expandpath(dest or 'default-push', dest or 'default')
--- a/tests/test-debugcomplete.t	Sat Jul 14 19:09:22 2012 +0200
+++ b/tests/test-debugcomplete.t	Wed Jul 11 18:22:07 2012 +0200
@@ -199,7 +199,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, graph, 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, patch, git, limit, no-merges, stat, graph, style, template, include, exclude
   merge: force, rev, preview, tool
   phase: public, draft, secret, force, rev
   pull: update, force, rev, bookmark, branch, ssh, remotecmd, insecure
@@ -255,10 +255,10 @@
   help: extension, command, keyword
   identify: rev, num, id, branch, tags, bookmarks, ssh, remotecmd, insecure
   import: strip, base, edit, force, no-commit, bypass, exact, import-branch, message, logfile, date, user, similarity
-  incoming: force, newest-first, bundle, rev, bookmarks, branch, patch, git, limit, no-merges, stat, style, template, ssh, remotecmd, insecure, subrepos
+  incoming: force, newest-first, bundle, rev, bookmarks, branch, patch, git, limit, no-merges, stat, graph, style, template, ssh, remotecmd, insecure, subrepos
   locate: rev, print0, fullpath, include, exclude
   manifest: rev, all
-  outgoing: force, rev, newest-first, bookmarks, branch, patch, git, limit, no-merges, stat, style, template, ssh, remotecmd, insecure, subrepos
+  outgoing: force, rev, newest-first, bookmarks, branch, patch, git, limit, no-merges, stat, graph, style, template, ssh, remotecmd, insecure, subrepos
   parents: rev, style, template
   paths: 
   recover: