Mercurial > hgrepos > DevTools > mercurial-extensions
diff extensions/kwarchive.py @ 122:e6037655967b
Implemented a keyword white-list including aliases.
BUGS: Aliases are allowed only together with explicit white-listing.
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Fri, 17 Aug 2018 02:59:27 +0200 |
| parents | 9ed197b60e99 |
| children | 46b7d34ef0b2 |
line wrap: on
line diff
--- a/extensions/kwarchive.py Fri Aug 17 02:20:34 2018 +0200 +++ b/extensions/kwarchive.py Fri Aug 17 02:59:27 2018 +0200 @@ -38,10 +38,10 @@ # are expanded. # [keywords] - # $Revision$ and possibly the |VCSRevision| keyword is expanded + # `Revision' and possibly the `VCSRevision' keyword is expanded Revision = - # $MyKeyword$ is expanded with the contents of - MyKeyword = + # `MyKeyword' is expanded with the contents of the pre-defined `JustDate' + MyKeyword = JustDate A non-existing ``.hgkwarchive`` file deactivates keyword expansion as does an empty ``[patterns]`` section. @@ -387,6 +387,14 @@ include=[], exclude=[]) # + # This is the mapping from all the (white-listed) pre-defined + # keywords to the keywords to be expanded in files (with aliases). + # + keyword_aliases = {} + for alias, keyword in cfg.items("keywords"): + keyword_aliases.setdefault(keyword or alias, []).append(alias) + + # # Get the manifest to be able to determine a file's NodeId # manifest = ctx.manifest() @@ -409,15 +417,21 @@ _MARKER_RCS = '$' _MARKER_RST = '|' for kw, value in itertools.chain(keywords.items(), file_keywords.items()): - if matcher_rcs(real_name): - filekw = "%s%s%s" % (_MARKER_RCS, kw, _MARKER_RCS) - filevalue = "%s%s: %s %s" \ - % (_MARKER_RCS, kw, value, _MARKER_RCS) - data = data.replace(filekw, filevalue) - if matcher_rst(real_name): - filekw = "%sVCS%s%s" % (_MARKER_RST, kw, _MARKER_RST) - filevalue = value - data = data.replace(filekw, filevalue) + # an empty database means: all keywords allowed, no aliases + if keyword_aliases: + kwds = keyword_aliases.get(kw, []) + else: + kwds = [kw] + for kw in kwds: + if matcher_rcs(real_name): + filekw = "%s%s%s" % (_MARKER_RCS, kw, _MARKER_RCS) + filevalue = "%s%s: %s %s" \ + % (_MARKER_RCS, kw, value, _MARKER_RCS) + data = data.replace(filekw, filevalue) + if matcher_rst(real_name): + filekw = "%sVCS%s%s" % (_MARKER_RST, kw, _MARKER_RST) + filevalue = value + data = data.replace(filekw, filevalue) return data return _filter
