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

Yuya Nishihara yuya at tcha.org
Wed Jan 30 07:09:48 EST 2019


> +  [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.


More information about the Mercurial-devel mailing list