changeset 220:710e9af4b283

Updating fully implemented now
author Franz Glasner <hg@dom66.de>
date Sun, 21 Oct 2018 20:03:13 +0200
parents 22244ee82c55
children af84624d0004
files extensions/timestamps.py
diffstat 1 files changed, 44 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/extensions/timestamps.py	Sat Oct 20 12:20:19 2018 +0200
+++ b/extensions/timestamps.py	Sun Oct 21 20:03:13 2018 +0200
@@ -61,6 +61,7 @@
 __author__ = "Franz Glasner"
 
 
+import calendar
 import collections
 import datetime
 import io
@@ -71,6 +72,7 @@
 from mercurial.i18n import _
 from mercurial import (cmdutil, scmutil, config, util, error, pycompat)
 from mercurial import match as _matchmod
+from mercurial import merge as _mergemod
 
 
 cmdtable = {}
@@ -193,6 +195,7 @@
     ts = Timestamps.from_filename(ui, name=repo.wjoin(TIMESTAMPS_DATABASE))
     if ts is None:
         raise error.Abort(_("timestamps database file does not exist"))
+    _restore_timestamps(repo, ctx, matcher, ts)
 
 
 def show_timestamps(ui, repo, ctx, fm,
@@ -661,6 +664,9 @@
     def __getitem__(self, key):
         return self._d[key]
 
+    def get(self, key, default=None):
+        return self._d.get(key, default)
+
     def __delitem__(self, key):
         del self._d[key]
 
@@ -815,8 +821,8 @@
             if not self.local():
                 self.ui.debug("update.timestamps: repo is not local\n")
                 return
-            if not self.__hooktype:
-                self.ui.warn("timestamps: no recorded hook data\n")
+            if not self.__hooktype or self.__hooktype != "pre-update":
+                self.ui.warn("timestamps: no recorded update hook data\n")
                 return
             wctx = self[None]
             tsmatch = gen_matcher(self, wctx)
@@ -826,8 +832,25 @@
                 if ts is None:
                     self.ui.warn(_("update.timestamps: timestamps database file could not be found or read\n"))
                 else:
-                    # XXX TBD
-                    pass
+                    to_update = set()
+                    for p in self.__from_parents:
+                        status = self.status(p)
+                        to_update.update(set(status.added))
+                        to_update.update(set(status.modified))
+                    if _DEV:
+                        self.ui.debug("UPDATE TO_UPDATE: " + repr(to_update)
+                                      + '\n')
+                    ms = _mergemod.mergestate.read(self)
+                    if _DEV:
+                        self.ui.debug("UPDATE MS ACTIVE: " + repr(ms.active())
+                                      + '\n')
+                        self.ui.debug("UPDATE MS: " + repr(ms.files()) + '\n')
+                    if ms.active():
+                        to_update.difference_update(set(ms.files()))
+                    if _DEV:
+                        self.ui.debug("UPDATE TO_UPDATE w/o resolved: "
+                                      + repr(to_update) + '\n')
+                    _restore_timestamps(self, to_update, tsmatch, ts)
             else:
                 self.ui.debug("update.timestamps: timestamps not activated/configured\n")
 
@@ -839,3 +862,20 @@
 
 def uisetup(ui):
     ui.setconfig('hooks', 'pre-update.timestamps', pre_hook)
+
+
+def _restore_timestamps(repo, candidates, tsmatch, tsdb):
+    """Restore file timestamps of files in iterable `candidates` that
+    match `tsmatch` to the times in database `tsdb`.
+
+    """
+    with FloatTimesInStat():
+        for f in candidates:
+            if tsmatch(f):
+                mtime = tsdb.get(f)
+                if mtime is not None:
+                    mt = calendar.timegm(dt_from_isoformat(mtime).timetuple())
+                    if _DEV:
+                        repo.ui.debug("RESTORING TIMESTAMP: " + f + ' -> '
+                                      + mtime + '\n')
+                    os.utime(repo.wjoin(f), (mt, mt))