changeset 168:940b805a5afa

Begin the construction and parsing of timestamp database files
author Franz Glasner <hg@dom66.de>
date Fri, 31 Aug 2018 09:39:34 +0200
parents 3c9c7b41c41c
children 7b76125fe80c
files extensions/timestamps.py
diffstat 1 files changed, 44 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/extensions/timestamps.py	Fri Aug 31 08:49:29 2018 +0200
+++ b/extensions/timestamps.py	Fri Aug 31 09:39:34 2018 +0200
@@ -132,12 +132,17 @@
     if not repo.local():
         raise error.Abort(_("repository is not local"))
     matcher = gen_matcher(repo, ctx, tsconfig=tsconfig)
-    with FloatTimesInStat():
-        for fn in ctx:
-            if matcher(fn):
-                print fn
-                st = os.lstat(os.path.join(repo.root, fn))
-                print (fn, st, st.st_mtime, to_isoformat(st.st_mtime))
+    with util.posixfile(
+            os.path.join(repo.root, TIMESTAMPS_DATABASE), "wb") as db:
+        with FloatTimesInStat():
+            #db.write(":version: 1\n")
+            #db.write(":encoding: binary\n")
+            for fn in ctx:
+                if matcher(fn):
+                    st = os.lstat(os.path.join(repo.root, fn))
+                    print (fn, st, st.st_mtime, to_isoformat(st.st_mtime))
+                    db.write("%s %s\n" % (db_escape(fn),
+                                          to_isoformat(st.st_mtime)))
 
 
 def restore_timestamps(ui, repo, ctx,
@@ -192,6 +197,39 @@
     return matcher
 
 
+def db_escape(fn):
+    if " " in fn or "@" in fn:
+        return "@%s@" % fn.replace("@", "@@")
+    else:
+        return fn
+
+
+def read_posix_db(filename):
+    with util.posixfile(filename, "rb") as db:
+        for f in read_db(db):
+            yield f
+
+            
+def read_db(db):
+    """`db` is a binary file"""
+    db = il.BufferedReader(db)
+    c = db.read()
+    while c:
+        if c in '\r\n':
+            # record separator
+            pass
+        elif c == ' ':
+            # field
+            pass
+        elif c == '@':
+            sf = []
+            # field with special chars
+            c2 = db.read()
+            while c2:
+                if c2 == '@':
+                    pass # XXX TBD
+
+
 def to_isoformat(t):
     """Return the timestamp `t` formatted in full ISO format.