Mercurial > hgrepos > DevTools > mercurial-extensions
changeset 213:da2552a8b0ce
Most commit work done: collect timestamps.
BUGS: A commit throws an exception if this extension is enabled.
The exception in in "commitctx()".
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Wed, 17 Oct 2018 09:43:52 +0200 |
| parents | bfb41de4584d |
| children | dddcc8ff7b6e |
| files | extensions/timestamps.py |
| diffstat | 1 files changed, 44 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/extensions/timestamps.py Tue Oct 16 17:56:52 2018 +0200 +++ b/extensions/timestamps.py Wed Oct 17 09:43:52 2018 +0200 @@ -64,6 +64,7 @@ import collections import datetime import io +import itertools import os import re @@ -658,6 +659,9 @@ def __getitem__(self, key): return self._d[key] + def __delitem__(self, key): + del self._d[key] + def __contains__(self, key): return key in self._d @@ -691,19 +695,52 @@ if ts is None: ts = Timestamps.create(self.ui) + # + # collect the timestamps + # + + # + # get the status of all files w/o timestamps database and + # config + # + fstatus = self.status( + match=_matchmod.differencematcher( + match, + _matchmod.exact( + self.root, + '', + [TIMESTAMPS_DATABASE, + TIMESTAMPS_CONFIGFILE]))) + # remove delete items + for f in fstatus.removed: + try: + del ts[f] + except KeyError: + pass + # put each file's mtime into the database + with FloatTimesInStat(): + for f in itertools.chain(fstatus.added, + fstatus.modified): + if tsmatch(f): + st = os.lstat(self.wjoin(f)) + ts[f] = to_isoformat(st.st_mtime) + with io.open(self.wjoin(TIMESTAMPS_DATABASE), "wb") as fp: ts.write(fp) + # ensure the database file is really tracked - dbstatus = wctx.status( + dbstatus = self.status( match=_matchmod.exact(self.root, '', [TIMESTAMPS_DATABASE]), - listclean=True) + clean=True) if dbstatus.modified or dbstatus.added or dbstatus.clean: # already tracked pass else: wctx.add([TIMESTAMPS_DATABASE]) # - # add the timestamps database to the commit match + # Add the timestamps database and the configuration to + # the commit match always, If the files are not changed + # it does not harm. # # match: "hg ci" -> alwaysmatcher # "hg ci file1 ... -> patternmatcher with the files @@ -715,7 +752,10 @@ # also handles the very rare cases if match.isexact() holds match = _matchmod.unionmatcher( [match, - _matchmod.exact(self.root, '', [TIMESTAMPS_DATABASE])]) + _matchmod.exact(self.root, + '', + [TIMESTAMPS_DATABASE, + TIMESTAMPS_CONFIGFILE])]) else: self.ui.debug("TimestampedRepo.commit():" " timestamps not activated/configured\n")
