diff extensions/revinfo.py @ 1:a80645763196

revinfo: a module to write .hg_archival.txt like repository metadata Should be useful for versioning applications without doing RCS keyword expansion. The metadata are collected into a separate file and can be read from there.
author Franz Glasner <hg@dom66.de>
date Fri, 14 Aug 2015 03:01:37 +0200
parents
children 133dab95fb84
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/revinfo.py	Fri Aug 14 03:01:37 2015 +0200
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+"""write a revision summary similar to .hg_archival.txt
+
+"""
+
+__version__ = "0"
+
+__author__ = "Franz Glasner"
+
+
+from mercurial.i18n import _
+from mercurial import commands, cmdutil, scmutil, util, archival
+
+
+cmdtable = {}
+
+command = cmdutil.command(cmdtable)
+
+
+@command("revinfo",
+         [("r", "rev", "",  _('revision to handle'), _('REV')),
+          ],
+         _("hg revinfo [OPTION]... [DEST]"))
+def revinfo(ui, repo, dest=None, **opts):
+    """write a revision summary
+
+    If DEST is given the info is written into the file DEST. Otherwise
+    it is written to stdout.
+
+    By default, the revision used is the parent of the working
+    directory; use -r/--rev to specify a different revision.
+
+    The printed information is the same as the :hg:`archive` command
+    writes into ".hg_archival.txt".
+
+    """
+    ctx = scmutil.revsingle(repo, opts.get("rev"))
+    if not ctx:
+        raise util.Abort(_('no working directory: please specify a revision'))
+
+    msg = archival.buildmetadata(ctx)
+    if dest:
+        with open(dest, "wb") as rfile:
+            rfile.write(msg)
+    else:
+        ui.write(msg)
+
+