# HG changeset patch # User Franz Glasner # Date 1538834017 -7200 # Node ID caf53dafd2d841b1e2aac5e7bfd6b7cc52b754e1 # Parent 514e564db240b62a931cd37fb3e29b2100790c13 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. diff -r 514e564db240 -r caf53dafd2d8 extensions/timestamps.py --- 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