graphlog.py
125 lines
| 4.4 KiB
| text/x-python
|
PythonLexer
/ hgext / graphlog.py
|
r4344 | # ASCII graph log extension for Mercurial | ||
# | ||||
# Copyright 2007 Joel Rosdahl <joel@rosdahl.net> | ||||
|
r4516 | # | ||
|
r8225 | # This software may be used and distributed according to the terms of the | ||
|
r10263 | # GNU General Public License version 2 or any later version. | ||
|
r8228 | |||
|
r8934 | '''command to view revision graphs from a shell | ||
|
r7426 | |||
This extension adds a --graph option to the incoming, outgoing and log | ||||
|
r9259 | commands. When this options is given, an ASCII representation of the | ||
revision graph is also shown. | ||||
|
r7426 | ''' | ||
|
r4344 | |||
|
r14319 | from mercurial.cmdutil import show_changeset | ||
|
r4344 | from mercurial.i18n import _ | ||
|
r17181 | from mercurial import cmdutil, commands, extensions | ||
from mercurial import hg, util, graphmod | ||||
|
r5938 | |||
|
r14311 | cmdtable = {} | ||
command = cmdutil.command(cmdtable) | ||||
|
r16743 | testedwith = 'internal' | ||
|
r14311 | |||
|
r17163 | def _checkunsupportedflags(pats, opts): | ||
|
r16180 | for op in ["newest_first"]: | ||
|
r7426 | if op in opts and opts[op]: | ||
|
r14043 | raise util.Abort(_("-G/--graph option is incompatible with --%s") | ||
|
r10097 | % op.replace("_", "-")) | ||
|
r7426 | |||
|
r14311 | @command('glog', | ||
|
r16432 | [('f', 'follow', None, | ||
_('follow changeset history, or file history across copies and renames')), | ||||
('', 'follow-first', None, | ||||
_('only follow the first parent of merge changesets (DEPRECATED)')), | ||||
('d', 'date', '', _('show revisions matching date spec'), _('DATE')), | ||||
('C', 'copies', None, _('show copied files')), | ||||
('k', 'keyword', [], | ||||
_('do case-insensitive search for a given text'), _('TEXT')), | ||||
|
r14311 | ('r', 'rev', [], _('show the specified revision or range'), _('REV')), | ||
|
r16432 | ('', 'removed', None, _('include revisions where files were removed')), | ||
('m', 'only-merges', None, _('show only merges (DEPRECATED)')), | ||||
('u', 'user', [], _('revisions committed by user'), _('USER')), | ||||
('', 'only-branch', [], | ||||
_('show only changesets within the given named branch (DEPRECATED)'), | ||||
_('BRANCH')), | ||||
('b', 'branch', [], | ||||
_('show changesets within the given named branch'), _('BRANCH')), | ||||
('P', 'prune', [], | ||||
_('do not display revision or any of its ancestors'), _('REV')), | ||||
('', 'hidden', False, _('show hidden changesets (DEPRECATED)')), | ||||
] + commands.logopts + commands.walkopts, | ||||
_('[OPTION]... [FILE]')) | ||||
|
r14043 | def graphlog(ui, repo, *pats, **opts): | ||
|
r7325 | """show revision history alongside an ASCII revision graph | ||
|
r9259 | Print a revision history alongside a revision graph drawn with | ||
ASCII characters. | ||||
|
r7325 | |||
|
r9259 | Nodes printed as an @ character are parents of the working | ||
directory. | ||||
|
r7325 | """ | ||
|
r17181 | return cmdutil.graphlog(ui, repo, *pats, **opts) | ||
|
r7716 | |||
def graphrevs(repo, nodes, opts): | ||||
limit = cmdutil.loglimit(opts) | ||||
|
r8837 | nodes.reverse() | ||
|
r10111 | if limit is not None: | ||
|
r8837 | nodes = nodes[:limit] | ||
return graphmod.nodes(repo, nodes) | ||||
|
r7716 | |||
def goutgoing(ui, repo, dest=None, **opts): | ||||
"""show the outgoing changesets alongside an ASCII revision graph | ||||
|
r7325 | |||
|
r7716 | Print the outgoing changesets alongside a revision graph drawn with | ||
ASCII characters. | ||||
|
r7426 | |||
|
r7716 | Nodes printed as an @ character are parents of the working | ||
directory. | ||||
|
r7426 | """ | ||
|
r7716 | |||
|
r17163 | _checkunsupportedflags([], opts) | ||
|
r12735 | o = hg._outgoing(ui, repo, dest, opts) | ||
if o is None: | ||||
|
r7426 | return | ||
|
r7716 | |||
revdag = graphrevs(repo, o, opts) | ||||
|
r9368 | displayer = show_changeset(ui, repo, opts, buffered=True) | ||
showparents = [ctx.node() for ctx in repo[None].parents()] | ||||
|
r17180 | cmdutil.displaygraph(ui, revdag, displayer, showparents, | ||
graphmod.asciiedges) | ||||
|
r7426 | |||
def gincoming(ui, repo, source="default", **opts): | ||||
"""show the incoming changesets alongside an ASCII revision graph | ||||
|
r9259 | Print the incoming changesets alongside a revision graph drawn with | ||
ASCII characters. | ||||
|
r7426 | |||
|
r9259 | Nodes printed as an @ character are parents of the working | ||
directory. | ||||
|
r7426 | """ | ||
|
r12730 | def subreporecurse(): | ||
return 1 | ||||
|
r7426 | |||
|
r17163 | _checkunsupportedflags([], opts) | ||
|
r12730 | def display(other, chlist, displayer): | ||
|
r7716 | revdag = graphrevs(other, chlist, opts) | ||
|
r9368 | showparents = [ctx.node() for ctx in repo[None].parents()] | ||
|
r17180 | cmdutil.displaygraph(ui, revdag, displayer, showparents, | ||
graphmod.asciiedges) | ||||
|
r7426 | |||
|
r12730 | hg._incoming(display, subreporecurse, ui, repo, source, opts, buffered=True) | ||
|
r7426 | |||
def uisetup(ui): | ||||
'''Initialize the extension.''' | ||||
|
r14416 | _wrapcmd('incoming', commands.table, gincoming) | ||
_wrapcmd('outgoing', commands.table, goutgoing) | ||||
|
r7426 | |||
|
r14416 | def _wrapcmd(cmd, table, wrapfn): | ||
|
r7426 | '''wrap the command''' | ||
def graph(orig, *args, **kwargs): | ||||
if kwargs['graph']: | ||||
|
r14043 | return wrapfn(*args, **kwargs) | ||
|
r7426 | return orig(*args, **kwargs) | ||
entry = extensions.wrapcommand(table, cmd, graph) | ||||
|
r7763 | entry[1].append(('G', 'graph', None, _("show the revision DAG"))) | ||