changeset 437:11bbdd7fd7b0

Provide "-T/--timestamp" and "-D/--date" options for revinfo. To print full commit timestamps or just the date.
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 30 May 2026 13:13:01 +0200
parents 111aa1d44ffd
children 973735883ab9
files README extensions/revinfo.py
diffstat 2 files changed, 25 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/README	Sat May 30 13:11:51 2026 +0200
+++ b/README	Sat May 30 13:13:01 2026 +0200
@@ -9,7 +9,7 @@
 :When:      $Date$
 :Date:      |VCSJustDate|
 :ID:        @(#) $HGheader$
-:Copyright: (C) 2015-2026 Franz Glasner <fzglas.hg@dom66.de>
+:Copyright: © 2015-2026 Franz Glasner <fzglas.hg@dom66.de>
 :License:   This software may be used and distributed according to the
             terms of the GNU General Public License version 2 or any
             later version.
--- a/extensions/revinfo.py	Sat May 30 13:11:51 2026 +0200
+++ b/extensions/revinfo.py	Sat May 30 13:13:01 2026 +0200
@@ -22,7 +22,7 @@
 
 from mercurial.i18n import _
 from mercurial import (cmdutil, scmutil, error, archival, pycompat, util,
-                       demandimport)
+                       templatefilters, demandimport)
 with demandimport.deactivated():
     try:
         from mercurial import registrar
@@ -74,6 +74,8 @@
     [
         (b'r', b"rev", b'',  _(b"revision to handle"), _(b"REV")),
         (b'', b"amend", None, _(b"amend a given file with path information")),
+        (b'T', b'timestamp', None, _(b"put also the commit timestamp into the file")),
+        (b'D', b'date', None, _(b"put also the the commit date into the file")),
         (b'p', b"path", [], _(b"the configured default path"), _(b"SOURCE")),
         (b'd', b"data", [], _(b"add an extra `KEY: VALUE' pair into the file"), _(b"KEY=VALUE")),
     ],
@@ -97,14 +99,27 @@
     Use --amend to extend a given file with a "path" item.
     Can also be used to put more than one path item into the file.
 
+    Use -T/--timestamp to put also the complete commit timestamp in ISO
+    format into the output. It will be printed as "timestamp" item.
+
+    Use -D/--date to put the commit date in ISO format (YYYY-MM-DD) into
+    the output. It will be printed as "date" item.
+
     The printed information is the same as the :hg:`archive` command
-    writes into ".hg_archival.txt". The "path" info is an extra item.
+    writes into ".hg_archival.txt". The "path", "timestamp" and "date" infos
+    are extra items.
 
     """
     opts = pycompat.byteskwargs(opts)
     if opts.get(b"amend") and opts.get(b"rev"):
         raise error.Abort(_(b"cannot use -r/--rev together with --amend"))
 
+    if opts.get(b"amend") and opts.get(b"timestamp"):
+        raise error.Abort(_(b"cannot use -T/--timestamp together with --amend"))
+
+    if opts.get(b"amend") and opts.get(b"date"):
+        raise error.Abort(_(b"cannot use -D/--date together with --amend"))
+
     if opts.get(b"amend"):
         if not dest:
             raise error.Abort(_(b"need a destination file with --amend"))
@@ -118,6 +133,13 @@
 
         msg = archival.buildmetadata(ctx)
 
+        if opts.get(b"timestamp"):
+            msg += b"timestamp: %s\n" % templatefilters.isodatesec(ctx.date())
+
+        if opts.get(b"date"):
+            msg += b"date: %s\n" % templatefilters.shortdate(ctx.date())
+
+
     for kv in opts.get(b"data"):
         kvparts = [i.strip() for i in kv.split(b'=', 1)]
         if len(kvparts) == 2: