Mercurial > hgrepos > DevTools > mercurial-extensions
changeset 65:bdb549d71148
Allow customization of the $Author$ output when expanding keywords.
The filters are the same as in Mercurial templates: user, person and email.
BUGS: The complete user information is not yet handled. There are some encoding issues.
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Sun, 26 Nov 2017 17:26:20 +0100 |
| parents | 9250db8a629a |
| children | fe4feca5b136 |
| files | extensions/kwarchive.py |
| diffstat | 1 files changed, 36 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/extensions/kwarchive.py Sun Nov 26 15:08:05 2017 +0100 +++ b/extensions/kwarchive.py Sun Nov 26 17:26:20 2017 +0100 @@ -67,6 +67,7 @@ ('', 'path', 'default', _('the canonical repository to use'), _('PATH')), ('', "kwconfig", '', _('an alternate pattern configuration configuration file'), _('PATTERNCONFIG')), ('', "no-shorten-path", None, _("don't shorten the path urls")), + ('', "user-filter", "person", _("the part of the user to be printed"), _("USERFILTER")), ] + cmdutil.subrepoopts + cmdutil.walkopts, _('[OPTION]... DEST')) def kwarchive(ui, repo, dest, **opts): @@ -115,6 +116,12 @@ Full path URLs are printed somewhat shortened by default. To use them as-is use the --no-shorten-path option. + Allowed --user-filter values are: + + :``user``: the short representation of a user name or email address + :``person``: the name before an email address as per RFC 5322 + :``email``: the email address + Returns 0 on success. ''' @@ -156,6 +163,7 @@ archival.tidyprefix(dest, kind, prefix), hgpath=opts.get("path"), shorten_path_url=not opts.get("no_shorten_path"), + user_filter=get_checked_user_filter(opts), kwconfig=opts.get("kwconfig"))) archival.archive(repo, dest, node, kind, not opts.get('no_decode'), @@ -173,6 +181,7 @@ [('r', 'rev', '', _('revision to distribute'), _('REV')), ('', 'path', 'default', _('the canonical repository to use'), _('PATH')), ('', "no-shorten-path", None, _("don't shorten the path urls")), + ('', "user-filter", "person", _("the part of the user to be printed"), _("USERFILTER")), ] + cmdutil.subrepoopts + cmdutil.walkopts, _('[OPTION]...')) def kwprint(ui, repo, **opts): @@ -189,6 +198,12 @@ Full path URLs are printed somewhat shortened by default. To use them as-is use the --no-shorten-path option. + Allowed --user-filter values are: + + :``user``: the short representation of a user name or email address + :``person``: the name before an email address as per RFC 5322 + :``email``: the email address + Returns 0 on success. ''' @@ -204,7 +219,8 @@ keywords = make_node_keywords( ui, repo, ctx, prefix, hgpath=opts.get("path"), - shorten_path_url=not opts.get("no_shorten_path")) + shorten_path_url=not opts.get("no_shorten_path"), + user_filter=get_checked_user_filter(opts)) for key in sorted(keywords.keys()): ui.write("$%s: %s $\n" % (key, keywords[key])) @@ -225,10 +241,12 @@ def make_keyword_filter(ui, repo, ctx, archive_class, prefix, hgpath="default", shorten_path_url=True, + user_filter="person", kwconfig=""): keywords = make_node_keywords(ui, repo, ctx, prefix, hgpath=hgpath, - shorten_path_url=shorten_path_url) + shorten_path_url=shorten_path_url, + user_filter=user_filter) kwconfigdata = kwconfigname = None if kwconfig: kwconfigdata = open(kwconfig, "rb").read() @@ -296,7 +314,8 @@ def make_node_keywords(ui, repo, ctx, prefix, hgpath="default", - shorten_path_url=True): + shorten_path_url=True, + user_filter="person"): """Make all the node-specific (i.e. file-path independent) keywords """ @@ -323,9 +342,15 @@ "HGpath": path_uri, "HGrevision": ctx.hex(), "Revision": templatefilters.short(ctx.hex()), - "Author": templatefilters.utf8(templatefilters.person(ctx.user()).replace(' ', '+')), "Date": templatefilters.isodatesec(ctx.date()), } + if user_filter == "person": + keywords["Author"] = templatefilters.utf8(templatefilters.person(ctx.user()).replace(' ', '+')) + elif user_filter == "user": + keywords["Author"] = templatefilters.userfilter(ctx.user()) + elif user_filter == "email": + keywords["Author"] = templatefilters.email(ctx.user()) + return keywords @@ -337,3 +362,10 @@ if idx < 0: return hostname return hostname[:idx] + + +def get_checked_user_filter(opts): + uf = opts.get("user_filter") + if not uf in ("person", "user", "email"): + raise error.Abort(_("user filter must be any of `person', `user' or `email'")) + return uf
