changeset 207:1d1f2d7de448

A new factory method to create an empty Timestamps() database
author Franz Glasner <hg@dom66.de>
date Sun, 14 Oct 2018 22:14:12 +0200
parents 057b33f9c8a5
children 99a1f7a1aec8
files extensions/timestamps.py
diffstat 1 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/extensions/timestamps.py	Sun Oct 14 22:07:28 2018 +0200
+++ b/extensions/timestamps.py	Sun Oct 14 22:14:12 2018 +0200
@@ -80,6 +80,8 @@
 
 TIMESTAMPS_CONFIGFILE = ".hgtimestamps"
 TIMESTAMPS_DATABASE = TIMESTAMPS_CONFIGFILE + ".db"
+TIMESTAMPS_DEFAULT_VERSION = 1
+TIMESTAMPS_DEFAULT_ENCODING = "binary"
 
 TIMESTAMP_FORMAT = re.compile(r"^(?P<year>[0-9]{4})-(?P<month>[0-9]{2})-(?P<day>[0-9]{2})T(?P<hour>[0-9]{2}):(?P<minute>[0-9]{2}):(?P<second>[0-9]{2})(\.(?P<ms>[0-9]+))?Z$")
 
@@ -166,9 +168,7 @@
             raise error.Abort(_("timestamps database file does not exist"
                                 " -- cannot amend"))
     else:
-        ts = Timestamps()
-        ts.version = 1
-        ts.encoding = "binary"
+        ts = Timestamps.create(ui)
     with FloatTimesInStat():
         for fn in ctx:
             if matcher(fn):
@@ -517,6 +517,15 @@
         self._version = self._encoding = None
 
     @classmethod
+    def create(cls_, ui,
+               version=TIMESTAMPS_DEFAULT_VERSION,
+               encoding=TIMESTAMPS_DEFAULT_ENCODING):
+        ts = cls_()
+        ts.version = version
+        ts.encoding = encoding
+        return ts
+
+    @classmethod
     def from_filename(cls_, ui, name=TIMESTAMPS_DATABASE):
         try:
             with io.open(name, "rb") as fp: