Mercurial > hg-stable
changeset 26086:3670efdc7088
templater: move verbosity-to-template matcher to constructor
We're going to reuse this and it's silly for it to be done per-cset anyway.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Tue, 25 Aug 2015 13:38:20 -0500 |
parents | 1de0b66b65c5 |
children | 06cd67a5044f |
files | mercurial/cmdutil.py |
diffstat | 1 files changed, 23 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Tue Aug 25 12:59:08 2015 -0500 +++ b/mercurial/cmdutil.py Tue Aug 25 13:38:20 2015 -0500 @@ -1414,6 +1414,23 @@ self.cache = {} + # find correct templates for current mode + tmplmodes = [ + (True, None), + (self.ui.verbose, 'verbose'), + (self.ui.quiet, 'quiet'), + (self.ui.debugflag, 'debug'), + ] + + self._parts = {'header': '', 'footer': '', 'changeset': 'changeset'} + for mode, postfix in tmplmodes: + for t in self._parts: + cur = t + if postfix: + cur += "_" + postfix + if mode and cur in self.t: + self._parts[t] = cur + def _show(self, ctx, copies, matchfn, props): '''show a single changeset or file revision''' @@ -1440,27 +1457,10 @@ props['revcache'] = {'copies': copies} props['cache'] = self.cache - # find correct templates for current mode - tmplmodes = [ - (True, None), - (self.ui.verbose, 'verbose'), - (self.ui.quiet, 'quiet'), - (self.ui.debugflag, 'debug'), - ] - - types = {'header': '', 'footer': '', 'changeset': 'changeset'} - for mode, postfix in tmplmodes: - for t in types: - cur = t - if postfix: - cur += "_" + postfix - if mode and cur in self.t: - types[t] = cur - try: # write header - if types['header']: - h = templater.stringify(self.t(types['header'], **props)) + if self._parts['header']: + h = templater.stringify(self.t(self._parts['header'], **props)) if self.buffered: self.header[ctx.rev()] = h else: @@ -1469,14 +1469,14 @@ self.ui.write(h) # write changeset metadata, then patch if requested - key = types['changeset'] + key = self._parts['changeset'] self.ui.write(templater.stringify(self.t(key, **props))) self.showpatch(ctx.node(), matchfn) - if types['footer']: + if self._parts['footer']: if not self.footer: - self.footer = templater.stringify(self.t(types['footer'], - **props)) + self.footer = templater.stringify( + self.t(self._parts['footer'], **props)) except KeyError as inst: msg = _("%s: no key named '%s'") raise util.Abort(msg % (self.t.mapfile, inst.args[0]))