Mercurial > public > mercurial-scm > hg
diff hgext/patchbomb.py @ 31187:6b8e1a08ef1d
patchbomb: add config knob to generate flags by template (issue5354)
This can be used to flag patches by branch or topic automatically. Flags
optionally given by --flag option are exported as {flags} template keyword,
so you can add --flag V2.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 25 Feb 2017 18:41:00 +0900 |
parents | 83fa357edbd5 |
children | 5b2e1689b24d |
line wrap: on
line diff
--- a/hgext/patchbomb.py Sat Feb 25 18:35:34 2017 +0900 +++ b/hgext/patchbomb.py Sat Feb 25 18:41:00 2017 +0900 @@ -60,6 +60,14 @@ intro=never # never include an introduction message intro=always # always include an introduction message +You can specify a template for flags to be added in subject prefixes. Flags +specified by --flag option are exported as ``{flags}`` keyword:: + + [patchbomb] + flagtemplate = "{separate(' ', + ifeq(branch, 'default', '', branch|upper), + flags)}" + You can set patchbomb to always ask for confirmation by setting ``patchbomb.confirm`` to true. ''' @@ -77,11 +85,13 @@ commands, encoding, error, + formatter, hg, mail, node as nodemod, patch, scmutil, + templater, util, ) stringio = util.stringio @@ -135,9 +145,22 @@ intro = 1 < number return intro +def _formatflags(ui, repo, rev, flags): + """build flag string optionally by template""" + tmpl = ui.config('patchbomb', 'flagtemplate') + if not tmpl: + return ' '.join(flags) + out = util.stringio() + opts = {'template': templater.unquotestring(tmpl)} + with formatter.templateformatter(ui, out, 'patchbombflag', opts) as fm: + fm.startitem() + fm.context(ctx=repo[rev]) + fm.write('flags', '%s', fm.formatlist(flags, name='flag')) + return out.getvalue() + def _formatprefix(ui, repo, rev, flags, idx, total, numbered): """build prefix to patch subject""" - flag = ' '.join(flags) + flag = _formatflags(ui, repo, rev, flags) if flag: flag = ' ' + flag