Mercurial > public > mercurial-scm > hg-stable
diff hgext/show.py @ 33058:11f768258dcc
show: construct changeset templater during dispatch
Previously, we constructed a formatter from a specific template
topic. Then from show() we reached into the internals of the
formatter to resolve a template string to be used to construct
a changeset templater.
A downside to this approach was it limited us to having the
entire template defined in a single entry in the map file. You
couldn't reference other entries in the map file and this would
lead to long templates and redundancy in the map file.
This commit teaches @showview how to instantiate a changeset
templater so we can construct a templater with full access to
the map file. To prove it works, we've split "showwork" into
components.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 24 Jun 2017 12:47:25 -0700 |
parents | 50586a0a946f |
children | 99ce2f586cd4 |
line wrap: on
line diff
--- a/hgext/show.py Sat Jun 24 11:47:26 2017 -0700 +++ b/hgext/show.py Sat Jun 24 12:47:25 2017 -0700 @@ -43,7 +43,7 @@ # Used by _formatdoc(). _docformat = '%s -- %s' - def _extrasetup(self, name, func, fmtopic=None): + def _extrasetup(self, name, func, fmtopic=None, csettopic=None): """Called with decorator arguments to register a show view. ``name`` is the sub-command name. @@ -52,8 +52,16 @@ ``fmtopic`` is the topic in the style that will be rendered for this view. + + ``csettopic`` is the topic in the style to be used for a changeset + printer. + + If ``fmtopic`` is specified, the view function will receive a + formatter instance. If ``csettopic`` is specified, the view + function will receive a changeset printer. """ func._fmtopic = fmtopic + func._csettopic = csettopic showview = showcmdfunc() @@ -109,11 +117,21 @@ hint=_('run "hg show" to see available views')) template = template or 'show' - fmtopic = 'show%s' % views[view]._fmtopic + fn = views[view] ui.pager('show') - with ui.formatter(fmtopic, {'template': template}) as fm: - return views[view](ui, repo, fm) + + if fn._fmtopic: + fmtopic = 'show%s' % fn._fmtopic + with ui.formatter(fmtopic, {'template': template}) as fm: + return fn(ui, repo, fm) + elif fn._csettopic: + ref = 'show%s' % fn._csettopic + spec = formatter.lookuptemplate(ui, ref, template) + displayer = cmdutil.changeset_templater(ui, repo, spec, buffered=True) + return fn(ui, repo, displayer) + else: + return fn(ui, repo) @showview('bookmarks', fmtopic='bookmarks') def showbookmarks(ui, repo, fm): @@ -189,15 +207,13 @@ return subset & relevant -@showview('work', fmtopic='work') -def showwork(ui, repo, fm): +@showview('work', csettopic='work') +def showwork(ui, repo, displayer): """changesets that aren't finished""" # TODO support date-based limiting when calling revset. revs = repo.revs('sort(_underway(), topo)') revdag = graphmod.dagwalker(repo, revs) - tmpl = fm._t.load(fm._topic) - displayer = cmdutil.makelogtemplater(ui, repo, tmpl, buffered=True) ui.setconfig('experimental', 'graphshorten', True) cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges)