incoming/outgoing: handle --graph in core

This commit is contained in:
Patrick Mezard 2012-07-11 18:22:07 +02:00
parent ea80881882
commit 1bc1374fa9
4 changed files with 42 additions and 77 deletions

View File

@ -12,21 +12,13 @@ commands. When this options is given, an ASCII representation of the
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 @@ def graphlog(ui, repo, *pats, **opts):
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")))

View File

@ -1450,6 +1450,19 @@ def graphlog(ui, repo, *pats, **opts):
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 = []

View File

@ -15,7 +15,7 @@ import archival, changegroup, cmdutil, hbisect
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 @@ logopts = [
_('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 @@ def incoming(ui, repo, source="default", **opts):
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 @@ def locate(ui, repo, *pats, **opts):
('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 @@ def outgoing(ui, repo, dest=None, **opts):
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')

View File

@ -199,7 +199,7 @@ Show all commands + options
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 @@ Show all commands + options
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: