41 """Register a function to be invoked for an `hg show <thing>`.""" |
41 """Register a function to be invoked for an `hg show <thing>`.""" |
42 |
42 |
43 # Used by _formatdoc(). |
43 # Used by _formatdoc(). |
44 _docformat = '%s -- %s' |
44 _docformat = '%s -- %s' |
45 |
45 |
46 def _extrasetup(self, name, func, fmtopic=None): |
46 def _extrasetup(self, name, func, fmtopic=None, csettopic=None): |
47 """Called with decorator arguments to register a show view. |
47 """Called with decorator arguments to register a show view. |
48 |
48 |
49 ``name`` is the sub-command name. |
49 ``name`` is the sub-command name. |
50 |
50 |
51 ``func`` is the function being decorated. |
51 ``func`` is the function being decorated. |
52 |
52 |
53 ``fmtopic`` is the topic in the style that will be rendered for |
53 ``fmtopic`` is the topic in the style that will be rendered for |
54 this view. |
54 this view. |
|
55 |
|
56 ``csettopic`` is the topic in the style to be used for a changeset |
|
57 printer. |
|
58 |
|
59 If ``fmtopic`` is specified, the view function will receive a |
|
60 formatter instance. If ``csettopic`` is specified, the view |
|
61 function will receive a changeset printer. |
55 """ |
62 """ |
56 func._fmtopic = fmtopic |
63 func._fmtopic = fmtopic |
|
64 func._csettopic = csettopic |
57 |
65 |
58 showview = showcmdfunc() |
66 showview = showcmdfunc() |
59 |
67 |
60 @command('show', [ |
68 @command('show', [ |
61 # TODO: Switch this template flag to use cmdutil.formatteropts if |
69 # TODO: Switch this template flag to use cmdutil.formatteropts if |
107 if view not in views: |
115 if view not in views: |
108 raise error.Abort(_('unknown view: %s') % view, |
116 raise error.Abort(_('unknown view: %s') % view, |
109 hint=_('run "hg show" to see available views')) |
117 hint=_('run "hg show" to see available views')) |
110 |
118 |
111 template = template or 'show' |
119 template = template or 'show' |
112 fmtopic = 'show%s' % views[view]._fmtopic |
120 |
113 |
121 fn = views[view] |
114 ui.pager('show') |
122 ui.pager('show') |
115 with ui.formatter(fmtopic, {'template': template}) as fm: |
123 |
116 return views[view](ui, repo, fm) |
124 if fn._fmtopic: |
|
125 fmtopic = 'show%s' % fn._fmtopic |
|
126 with ui.formatter(fmtopic, {'template': template}) as fm: |
|
127 return fn(ui, repo, fm) |
|
128 elif fn._csettopic: |
|
129 ref = 'show%s' % fn._csettopic |
|
130 spec = formatter.lookuptemplate(ui, ref, template) |
|
131 displayer = cmdutil.changeset_templater(ui, repo, spec, buffered=True) |
|
132 return fn(ui, repo, displayer) |
|
133 else: |
|
134 return fn(ui, repo) |
117 |
135 |
118 @showview('bookmarks', fmtopic='bookmarks') |
136 @showview('bookmarks', fmtopic='bookmarks') |
119 def showbookmarks(ui, repo, fm): |
137 def showbookmarks(ui, repo, fm): |
120 """bookmarks and their associated changeset""" |
138 """bookmarks and their associated changeset""" |
121 marks = repo._bookmarks |
139 marks = repo._bookmarks |
187 if wdirrev != nullrev: |
205 if wdirrev != nullrev: |
188 relevant += revset.baseset({wdirrev}) |
206 relevant += revset.baseset({wdirrev}) |
189 |
207 |
190 return subset & relevant |
208 return subset & relevant |
191 |
209 |
192 @showview('work', fmtopic='work') |
210 @showview('work', csettopic='work') |
193 def showwork(ui, repo, fm): |
211 def showwork(ui, repo, displayer): |
194 """changesets that aren't finished""" |
212 """changesets that aren't finished""" |
195 # TODO support date-based limiting when calling revset. |
213 # TODO support date-based limiting when calling revset. |
196 revs = repo.revs('sort(_underway(), topo)') |
214 revs = repo.revs('sort(_underway(), topo)') |
197 |
215 |
198 revdag = graphmod.dagwalker(repo, revs) |
216 revdag = graphmod.dagwalker(repo, revs) |
199 tmpl = fm._t.load(fm._topic) |
|
200 displayer = cmdutil.makelogtemplater(ui, repo, tmpl, buffered=True) |
|
201 |
217 |
202 ui.setconfig('experimental', 'graphshorten', True) |
218 ui.setconfig('experimental', 'graphshorten', True) |
203 cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges) |
219 cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges) |
204 |
220 |
205 # Adjust the docstring of the show command so it shows all registered views. |
221 # Adjust the docstring of the show command so it shows all registered views. |