Mercurial > hgrepos > DevTools > mercurial-extensions
diff extensions/kwarchive.py @ 104:65789e3e8e3d
Provide a "HGnodeid" per file keyword that expands to the NodeID of the artifact.
This is the id that you see in "hg --debug manifest" all the files.
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Thu, 02 Aug 2018 18:22:43 +0200 |
| parents | d6e594644778 |
| children | f142bdb90c8d |
line wrap: on
line diff
--- a/extensions/kwarchive.py Thu Aug 02 16:57:44 2018 +0200 +++ b/extensions/kwarchive.py Thu Aug 02 18:22:43 2018 +0200 @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # $HGheader$ +# $HGnodeid$ # """like :hg:`archive` but with keyword expansion within selected files @@ -42,7 +43,7 @@ from mercurial.i18n import _ from mercurial import (archival, commands, config, cmdutil, error, match, - pycompat, scmutil, templatefilters, util) + pycompat, scmutil, templatefilters, util, node) testedwith = "4.3.1 4.3.2 4.4.1 4.4.2 4.5.2" @@ -327,6 +328,11 @@ matcher_rst = match.match(repo.root, '', patterns=patterns_rst, include=[], exclude=[]) + # + # Get the manifest to be able to determine a file's NodeId + # + manifest = ctx.manifest() + def _filter(name, data): real_name = name if archive_class != "fileit": @@ -335,6 +341,10 @@ real_name = name[len(prefix):] if not matcher(real_name): return data + try: + nodeid = node.hex(manifest[real_name]) + except LookupError: + nodeid = None # file specific keywords file_keywords = { "HGsource": keywords["HGpath"] + '/' + real_name, @@ -344,6 +354,7 @@ "HGid": "%s %s %s %s" % (keywords["HGpath"] + '/' + real_name, keywords["Revision"], keywords["Date"], keywords["Author"]), "HGheader": "%s %s %s %s" % (keywords["HGpath"] + '/' + real_name, keywords["HGrevision"], keywords["Date"], keywords["Author"]), "Id": "%s %s %s %s" % (templatefilters.basename(real_name), keywords["Revision"], keywords["Date"], keywords["Author"]), + "HGnodeid": nodeid or "", } # This prevents unwanted keyword expansion here _MARKER = '$'
