This is an archive of the discontinued Mercurial Phabricator instance.

histedit: add templating support to histedit's rule file generation
ClosedPublic

Authored by durin42 on Jan 29 2019, 7:26 PM.

Details

Summary

This will allow users to customize the display of the rule list for the
free-form segment that we don't interpret. We've had users want to add things
like bookmark names or similar to the rule list as a convenience, which seems
reasonable.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

durin42 created this revision.Jan 29 2019, 7:26 PM
durin42 updated this revision to Diff 13565.Jan 29 2019, 7:52 PM
yuja added a subscriber: yuja.Jan 30 2019, 7:11 AM

+ [histedit]
+ summary-format = '{rev} {bookmarks} {desc|firstline}'

Perhaps, "summary-template" is more consistent with the other config keys.

ctx = self.repo[self.node]
  • summary = _getsummary(ctx)
  • line = '%s %s %d %s' % (self.verb, ctx, ctx.rev(), summary)

+ ui = self.repo.ui
+ tres = formatter.templateresources(ui, self.repo)
+ t = formatter.maketemplater(ui, ui.config('histedit', 'summary-format'),
+ defaults=templatekw.keywords,
+ resources=tres)

cmdutil.rendertemplate() can be used.

And it's probably better to do templater.unquotestring(ui.config(...)) for
consistency, even though we won't need any syntax to preserve leading/trailing
spaces here.

+ summary = t.renderdefault({'ctx': ctx}).splitlines()[0]

Nit: splitlines()[0] would fail if template was empty.

durin42 updated this revision to Diff 13570.Jan 30 2019, 8:18 AM
This revision was automatically updated to reflect the committed changes.
yuja added a comment.Feb 1 2019, 8:50 PM

Queued, thanks.

+++ b/mercurial/help.py
@@ -394,7 +394,17 @@
def addtopichook(topic, rewriter):

helphooks.setdefault(topic, []).append(rewriter)

-def makeitemsdoc(ui, topic, doc, marker, items, dedent=False):
+def _templateextsyms(ui, topic, doc):
+ for name, ext in extensions.extensions(ui):
+ kw = getattr(ext, 'templatekeyword', None)
+ if kw is not None:
+ doc = addtopicsymbols(
+ 'templates', 'Filters\n=======', kw, keepmarker=True)
+ return doc
+
+addtopichook('templating', _templateextsyms)
+
+def makeitemsdoc(ui, topic, doc, marker, items, dedent=False, keepmarker=False):

"""Extract docstring from the items key to function mapping, build a
single documentation block and use it to overwrite the marker in doc.
"""

@@ -420,11 +430,14 @@

            doclines.append('  ' + l.strip())
    entries.append('\n'.join(doclines))
entries = '\n\n'.join(entries)

+ if keepmarker:
+ entries = entries + '\n\n' + marker

return doc.replace(marker, entries)

-def addtopicsymbols(topic, marker, symbols, dedent=False):
+def addtopicsymbols(topic, marker, symbols, dedent=False, keepmarker=False):

def add(ui, topic, doc):
  • return makeitemsdoc(ui, topic, doc, marker, symbols, dedent=dedent)

+ return makeitemsdoc(ui, topic, doc, marker, symbols, dedent=dedent,
+ keepmarker=keepmarker)

Looks like unrelated change. Dropped.

+ summary = cmdutil.rendertemplate(
+ ctx, ui.config('histedit', 'summary-template')) or ''
+ summary = summary.splitlines()[0]

Still crash. ''.splitlines() == []