changeset 45:c077d30da0ee

Implemented a "kwprint" command to print just some file-independent keywords
author Franz Glasner <hg@dom66.de>
date Tue, 14 Nov 2017 09:27:22 +0100
parents 71b321436cc1
children 4a0c26dfef3c
files extensions/kwarchive.py
diffstat 1 files changed, 34 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/extensions/kwarchive.py	Mon Nov 13 09:39:06 2017 +0100
+++ b/extensions/kwarchive.py	Tue Nov 14 09:27:22 2017 +0100
@@ -149,6 +149,40 @@
     # XXX FIXME: Should the original methods be restored here?
 
 
+@command('kwprint',
+    [('r', 'rev', '', _('revision to distribute'), _('REV')),
+     ('', 'path', 'default', _('the canonical repository to use'), _('PATH')),
+    ] + cmdutil.subrepoopts + cmdutil.walkopts,
+    _('[OPTION]...'))
+def kwprint(ui, repo, **opts):
+    '''print the file-independent keywords
+
+    By default, the revision used is the parent of the working
+    directory; use -r/--rev to specify a different revision.
+
+    Use --path to specify named path information from :hg:`paths` as
+    the canonical repository location.  Use ``.`` for the current
+    repository root root.  If no path is given then ``default`` is
+    assumed.
+
+    Returns 0 on success.
+
+    '''
+
+    opts = pycompat.byteskwargs(opts)
+    ctx = scmutil.revsingle(repo, opts.get('rev'))
+    if not ctx:
+        raise error.Abort(_('no working directory: please specify a revision'))
+    node = ctx.node()
+
+    prefix = cmdutil.makefilename(repo, "", node)
+
+    keywords = make_node_keywords(
+        ui, repo, ctx, prefix, hgpath=opts.get("path"))
+    for key in sorted(keywords.keys()):
+        ui.write("$%s: %s $\n" % (key, keywords[key]))
+
+
 def patch_archiver_class(archivername, filter):
     """Patch an archiver class and return the original unbound method"""