Mercurial > hg-stable
changeset 32855:50586a0a946f
cmdutil: factor out helper to create changeset_templater with literal template
changeset_templater has lots of arguments, but most callers only need to
specify a literal template 'tmpl'.
"hg debugtemplate" has no diff option, which means 'opts' were effectively {},
so dropped opts.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 22 Apr 2017 18:42:03 +0900 |
parents | 29558247b00e |
children | 615ec3f14aa9 |
files | hgext/churn.py hgext/keyword.py hgext/show.py mercurial/cmdutil.py mercurial/debugcommands.py |
diffstat | 5 files changed, 11 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/churn.py Wed Jun 14 23:56:58 2017 -0400 +++ b/hgext/churn.py Sat Apr 22 18:42:03 2017 +0900 @@ -32,9 +32,6 @@ # leave the attribute unspecified. testedwith = 'ships-with-hg-core' -def maketemplater(ui, repo, tmpl): - return cmdutil.changeset_templater(ui, repo, False, None, tmpl, None, False) - def changedlines(ui, repo, ctx1, ctx2, fns): added, removed = 0, 0 fmatch = scmutil.matchfiles(repo, fns) @@ -55,7 +52,7 @@ return date.strftime(opts['dateformat']) else: tmpl = opts.get('oldtemplate') or opts.get('template') - tmpl = maketemplater(ui, repo, tmpl) + tmpl = cmdutil.makelogtemplater(ui, repo, tmpl) def getkey(ctx): ui.pushbuffer() tmpl.show(ctx)
--- a/hgext/keyword.py Wed Jun 14 23:56:58 2017 -0400 +++ b/hgext/keyword.py Sat Apr 22 18:42:03 2017 +0900 @@ -239,8 +239,8 @@ '''Replaces keywords in data with expanded template.''' def kwsub(mobj): kw = mobj.group(1) - ct = cmdutil.changeset_templater(self.ui, self.repo, False, None, - self.templates[kw], '', False) + ct = cmdutil.makelogtemplater(self.ui, self.repo, + self.templates[kw]) self.ui.pushbuffer() ct.show(ctx, root=self.repo.root, file=path) ekw = templatefilters.firstline(self.ui.popbuffer())
--- a/hgext/show.py Wed Jun 14 23:56:58 2017 -0400 +++ b/hgext/show.py Sat Apr 22 18:42:03 2017 +0900 @@ -196,9 +196,8 @@ revs = repo.revs('sort(_underway(), topo)') revdag = graphmod.dagwalker(repo, revs) - displayer = cmdutil.changeset_templater(ui, repo, None, None, - tmpl=fm._t.load(fm._topic), - mapfile=None, buffered=True) + 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)
--- a/mercurial/cmdutil.py Wed Jun 14 23:56:58 2017 -0400 +++ b/mercurial/cmdutil.py Sat Apr 22 18:42:03 2017 +0900 @@ -1674,6 +1674,11 @@ return formatter.lookuptemplate(ui, 'changeset', tmpl) +def makelogtemplater(ui, repo, tmpl, buffered=False): + """Create a changeset_templater from a literal template 'tmpl'""" + return changeset_templater(ui, repo, matchfn=None, diffopts={}, + tmpl=tmpl, mapfile=None, buffered=buffered) + def show_changeset(ui, repo, opts, buffered=False): """show one changeset using template or regular display.
--- a/mercurial/debugcommands.py Wed Jun 14 23:56:58 2017 -0400 +++ b/mercurial/debugcommands.py Sat Apr 22 18:42:03 2017 +0900 @@ -2120,14 +2120,12 @@ if newtree != tree: ui.note(("* expanded:\n"), templater.prettyformat(newtree), '\n') - mapfile = None if revs is None: k = 'debugtemplate' t = formatter.maketemplater(ui, k, tmpl) ui.write(templater.stringify(t(k, ui=ui, **props))) else: - displayer = cmdutil.changeset_templater(ui, repo, None, opts, tmpl, - mapfile, buffered=False) + displayer = cmdutil.makelogtemplater(ui, repo, tmpl) for r in revs: displayer.show(repo[r], **props) displayer.close()