Mercurial > public > mercurial-scm > hg
comparison hgext/graphlog.py @ 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 | 434e5bd615fc |
comparison
equal
deleted
inserted
replaced
17181:6f71167292f2 | 17182:cdf1532d89c6 |
---|---|
10 This extension adds a --graph option to the incoming, outgoing and log | 10 This extension adds a --graph option to the incoming, outgoing and log |
11 commands. When this options is given, an ASCII representation of the | 11 commands. When this options is given, an ASCII representation of the |
12 revision graph is also shown. | 12 revision graph is also shown. |
13 ''' | 13 ''' |
14 | 14 |
15 from mercurial.cmdutil import show_changeset | |
16 from mercurial.i18n import _ | 15 from mercurial.i18n import _ |
17 from mercurial import cmdutil, commands, extensions | 16 from mercurial import cmdutil, commands |
18 from mercurial import hg, util, graphmod | |
19 | 17 |
20 cmdtable = {} | 18 cmdtable = {} |
21 command = cmdutil.command(cmdtable) | 19 command = cmdutil.command(cmdtable) |
22 testedwith = 'internal' | 20 testedwith = 'internal' |
23 | |
24 def _checkunsupportedflags(pats, opts): | |
25 for op in ["newest_first"]: | |
26 if op in opts and opts[op]: | |
27 raise util.Abort(_("-G/--graph option is incompatible with --%s") | |
28 % op.replace("_", "-")) | |
29 | 21 |
30 @command('glog', | 22 @command('glog', |
31 [('f', 'follow', None, | 23 [('f', 'follow', None, |
32 _('follow changeset history, or file history across copies and renames')), | 24 _('follow changeset history, or file history across copies and renames')), |
33 ('', 'follow-first', None, | 25 ('', 'follow-first', None, |
58 | 50 |
59 Nodes printed as an @ character are parents of the working | 51 Nodes printed as an @ character are parents of the working |
60 directory. | 52 directory. |
61 """ | 53 """ |
62 return cmdutil.graphlog(ui, repo, *pats, **opts) | 54 return cmdutil.graphlog(ui, repo, *pats, **opts) |
63 | |
64 def graphrevs(repo, nodes, opts): | |
65 limit = cmdutil.loglimit(opts) | |
66 nodes.reverse() | |
67 if limit is not None: | |
68 nodes = nodes[:limit] | |
69 return graphmod.nodes(repo, nodes) | |
70 | |
71 def goutgoing(ui, repo, dest=None, **opts): | |
72 """show the outgoing changesets alongside an ASCII revision graph | |
73 | |
74 Print the outgoing changesets alongside a revision graph drawn with | |
75 ASCII characters. | |
76 | |
77 Nodes printed as an @ character are parents of the working | |
78 directory. | |
79 """ | |
80 | |
81 _checkunsupportedflags([], opts) | |
82 o = hg._outgoing(ui, repo, dest, opts) | |
83 if o is None: | |
84 return | |
85 | |
86 revdag = graphrevs(repo, o, opts) | |
87 displayer = show_changeset(ui, repo, opts, buffered=True) | |
88 showparents = [ctx.node() for ctx in repo[None].parents()] | |
89 cmdutil.displaygraph(ui, revdag, displayer, showparents, | |
90 graphmod.asciiedges) | |
91 | |
92 def gincoming(ui, repo, source="default", **opts): | |
93 """show the incoming changesets alongside an ASCII revision graph | |
94 | |
95 Print the incoming changesets alongside a revision graph drawn with | |
96 ASCII characters. | |
97 | |
98 Nodes printed as an @ character are parents of the working | |
99 directory. | |
100 """ | |
101 def subreporecurse(): | |
102 return 1 | |
103 | |
104 _checkunsupportedflags([], opts) | |
105 def display(other, chlist, displayer): | |
106 revdag = graphrevs(other, chlist, opts) | |
107 showparents = [ctx.node() for ctx in repo[None].parents()] | |
108 cmdutil.displaygraph(ui, revdag, displayer, showparents, | |
109 graphmod.asciiedges) | |
110 | |
111 hg._incoming(display, subreporecurse, ui, repo, source, opts, buffered=True) | |
112 | |
113 def uisetup(ui): | |
114 '''Initialize the extension.''' | |
115 _wrapcmd('incoming', commands.table, gincoming) | |
116 _wrapcmd('outgoing', commands.table, goutgoing) | |
117 | |
118 def _wrapcmd(cmd, table, wrapfn): | |
119 '''wrap the command''' | |
120 def graph(orig, *args, **kwargs): | |
121 if kwargs['graph']: | |
122 return wrapfn(*args, **kwargs) | |
123 return orig(*args, **kwargs) | |
124 entry = extensions.wrapcommand(table, cmd, graph) | |
125 entry[1].append(('G', 'graph', None, _("show the revision DAG"))) |