Mercurial > hgrepos > DevTools > mercurial-extensions
changeset 118:e9c78a0bfe6a
Allow multiple style keyword expansion in one file.
Possible styles: RCS, reST.
Default is RCS.
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Thu, 16 Aug 2018 23:43:16 +0200 |
| parents | 21ab96f061c5 |
| children | 65a2e6fc8442 |
| files | extensions/kwarchive.py |
| diffstat | 1 files changed, 30 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/extensions/kwarchive.py Thu Aug 16 23:37:20 2018 +0200 +++ b/extensions/kwarchive.py Thu Aug 16 23:43:16 2018 +0200 @@ -18,11 +18,15 @@ Example:: [patterns] + # # expand keywords in every python file except those matching "x*" + # using RCS style expansion format (which is the default style) **.py = x* = NO - # this file has reStructuredText style keyword expansion "|VCS<kw>|" + # this file has reStructuredText style keyword expansion "|VCS<kw>|" only path:VERSION = reST + # this file has reStructuredText style and RCS style keyword expansion + path:README = reST, RCS A non-existing ``.hgkwarchive`` file deactivates keyword expansion as does an empty ``[patterns]`` section. @@ -323,6 +327,7 @@ include = [] exclude = [] patterns = [] + patterns_rcs = [] patterns_rst = [] if cfg.items("patterns"): for pattern, styles in cfg.items("patterns"): @@ -333,12 +338,29 @@ exclude.append(pattern) else: patterns.append(pattern) - if "REST" in styles or "RST" in styles: - patterns_rst.append(pattern) + if "REST" in styles or "RST" in styles \ + or "RCS" in styles: + if "RCS" in styles: + patterns_rcs.append(pattern) + if "REST" in styles or "RST" in styles: + patterns_rst.append(pattern) + else: + # default to RCS if no keyword style is given + patterns_rcs.append(pattern) matcher = match.match(repo.root, '', patterns=patterns, include=include, exclude=exclude) else: matcher = match.never(repo.root, '') + + # + # An empty patterns_rcs does not mean that match_rcs is always + # true. + # + if not patterns_rcs: + matcher_rcs = match.never(repo.root, '') + else: + matcher_rcs = match.match(repo.root, '', patterns=patterns_rcs, + include=[], exclude=[]) # # An empty patterns_rst does not mean that match_rst is always # true. @@ -372,13 +394,14 @@ _MARKER = '$' _MARKER_RST = '|' for kw, value in itertools.chain(keywords.items(), file_keywords.items()): + if matcher_rcs(real_name): + filekw = "%s%s%s" % (_MARKER, kw, _MARKER) + filevalue = "%s%s: %s %s" % (_MARKER, kw, value, _MARKER) + data = data.replace(filekw, filevalue) if matcher_rst(real_name): filekw = "%sVCS%s%s" % (_MARKER_RST, kw, _MARKER_RST) filevalue = value - else: - filekw = "%s%s%s" % (_MARKER, kw, _MARKER) - filevalue = "%s%s: %s %s" % (_MARKER, kw, value, _MARKER) - data = data.replace(filekw, filevalue) + data = data.replace(filekw, filevalue) return data return _filter
