changeset 198:caf53dafd2d8

Use the working context as default revision if not one is given. Also provide a Timestamps.from_ctx method to get a timestamps database from the history.
author Franz Glasner <hg@dom66.de>
date Sat, 06 Oct 2018 15:53:37 +0200
parents 514e564db240
children 29cc67db9aa5
files extensions/timestamps.py
diffstat 1 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/extensions/timestamps.py	Sat Oct 06 15:30:02 2018 +0200
+++ b/extensions/timestamps.py	Sat Oct 06 15:53:37 2018 +0200
@@ -113,7 +113,7 @@
         ("", "save", None, _("save modification times")),
         ("", "restore", None, _("restore modification times")),
         ("", "show", None, _("show the contents of the timestamps database")),
-        ("r", "rev", "", _("the revision to use"), _("REV")),
+        ("r", "rev", "", _("the revision to use (default is the working space)"), _("REV")),
         ("", "tsconfig", "", _("use an alternate configuration file"), _("TSCONFIG")),
         ("", "amend", None, _("amend the current database file instead of generating a fresh one")),
     ],
@@ -128,7 +128,7 @@
 
     """
     opts = pycompat.byteskwargs(opts)
-    ctx = scmutil.revsingle(repo, opts.get("rev"))
+    ctx = scmutil.revsingle(repo, opts.get("rev"), default=None)
     if not ctx:
         raise error.Abort(_("no Mercurial working directory"))
     if opts.get("save"):
@@ -158,7 +158,7 @@
     if matcher is None:
         raise error.Abort(_("timestamps are not activated"))
     if amend:
-        ts = Timestamps.from_filename(repo.wjoin(TIMESTAMPS_DATABASE))
+        ts = Timestamps.from_filename(name=repo.wjoin(TIMESTAMPS_DATABASE))
     else:
         ts = Timestamps()
         ts.version = 1
@@ -181,7 +181,7 @@
     matcher = gen_matcher(repo, ctx, tsconfig=tsconfig)
     if matcher is None:
         raise error.Abort(_("timestamps are not activated"))
-    ts = Timestamps.from_filename(repo.wjoin(TIMESTAMPS_DATABASE))
+    ts = Timestamps.from_filename(name=repo.wjoin(TIMESTAMPS_DATABASE))
 
 
 def show_timestamps(ui, repo, ctx, fm,
@@ -190,7 +190,7 @@
     # NOTE: no need for a local repo here
     #
     matcher = gen_matcher(repo, ctx, tsconfig=tsconfig)
-    ts = Timestamps.from_filename(repo.wjoin(TIMESTAMPS_DATABASE))
+    ts = Timestamps.from_ctx(ctx, name=TIMESTAMPS_DATABASE)
     if ui.debugflag or ui.verbose:
         files = iter(ts)
     else:
@@ -498,8 +498,15 @@
         self._version = self._encoding = None
 
     @classmethod
-    def from_filename(cls_, filename):
-        with io.open(filename, "rb") as f:
+    def from_filename(cls_, name=TIMESTAMPS_DATABASE):
+        with io.open(name, "rb") as f:
+            ts = cls_()
+            ts.read(f)
+            return ts
+
+    @classmethod
+    def from_ctx(cls_, ctx, name=TIMESTAMPS_DATABASE):
+        with io.BytesIO(ctx[name].data()) as f:
             ts = cls_()
             ts.read(f)
             return ts