Mercurial > hgrepos > DevTools > mercurial-extensions
diff extensions/kwarchive.py @ 44:71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Mon, 13 Nov 2017 09:39:06 +0100 |
| parents | b46ab29aefd8 |
| children | c077d30da0ee |
line wrap: on
line diff
--- a/extensions/kwarchive.py Sun Nov 12 09:27:15 2017 +0100 +++ b/extensions/kwarchive.py Mon Nov 13 09:39:06 2017 +0100 @@ -164,25 +164,8 @@ def make_keyword_filter(ui, repo, ctx, archive_class, prefix, hgpath="default"): + keywords = make_node_keywords(ui, repo, ctx, prefix, hgpath=hgpath) - if hgpath: - if hgpath == '.': - path_url = repo.root - else: - try: - path_url = util.hidepassword(ui.paths[hgpath].loc) - except LookupError: - raise error.Abort(_('repository %s not found') % hgpath) - else: - path_url = repo.root - # node specific keywords - keywords = { - "HGpath": path_url, - "HGrevision": ctx.hex(), - "Revision": templatefilters.short(ctx.hex()), - "Author": templatefilters.person(ctx.user()), - "Date": templatefilters.isodatesec(ctx.date()), - } # .hgkwarchive try: kwconfig = ctx[".hgkwarchive"] @@ -190,6 +173,10 @@ def _filter(name, data): return data else: + # + # Parse the data in ".hgkwarchive" and generate a + # Mercurial matcher + # cfg = config.config() cfg.parse(".kwarchive", kwconfig.data()) include = [] @@ -236,3 +223,27 @@ return data return _filter + + +def make_node_keywords(ui, repo, ctx, prefix, hgpath="default"): + """Make all the node-specific (i.e. file-path independent) keywords + + """ + if hgpath: + if hgpath == '.': + path_url = repo.root + else: + try: + path_url = util.hidepassword(ui.paths[hgpath].loc) + except LookupError: + raise error.Abort(_('repository %s not found') % hgpath) + else: + path_url = repo.root + keywords = { + "HGpath": path_url, + "HGrevision": ctx.hex(), + "Revision": templatefilters.short(ctx.hex()), + "Author": templatefilters.person(ctx.user()), + "Date": templatefilters.isodatesec(ctx.date()), + } + return keywords
