changeset 165:ffe20b7d21c4

Some tests with matching and ISO formatting
author Franz Glasner <hg@dom66.de>
date Thu, 30 Aug 2018 09:47:08 +0200
parents a6a739ed3d05
children 3a6df7bfdae0
files extensions/timestamps.py
diffstat 1 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/extensions/timestamps.py	Thu Aug 30 00:58:29 2018 +0200
+++ b/extensions/timestamps.py	Thu Aug 30 09:47:08 2018 +0200
@@ -38,6 +38,8 @@
 
   * optional second non-comment line: :encoding: ENCODING
 
+  * timestamp in ISOFORMAT (``YYYY-MM-DDTHH:MM:SS.mmmmmm+HH:MM``)
+
   (This is roughly simalar to a Perforce checkpoint.)
 
 - Otherwise mostly modelled after TimestampMod
@@ -54,7 +56,9 @@
 __author__ = "Franz Glasner"
 
 
+import os
 import io
+import datetime
 
 from mercurial.i18n import _
 from mercurial import (cmdutil, scmutil, config, util, error, match,
@@ -129,7 +133,9 @@
         raise error.Abort(_("repository is not local"))
     matcher = gen_matcher(repo, ctx, tsconfig=tsconfig)
     for fn in ctx:
-        print fn, matcher(fn)
+        if matcher(fn):
+            st = os.lstat(fn)
+            print (fn, st, st.st_mtime, to_isoformat(st.st_mtime))
 
 
 def restore_timestamps(ui, repo, ctx,
@@ -182,3 +188,11 @@
                               patterns=["**"],
                               exclude=[".hg*"])
     return matcher
+
+
+def to_isoformat(t):
+    dt = datetime.datetime.utcfromtimestamp(t)
+    if dt.utcoffset() is None:
+        return dt.isoformat() + "Z"
+    else:
+        return dt.isoformat()