Commits

Friedrich Kastner-Masilko  committed a11c183

Proof-of-Concept

  • Participants

Comments (0)

Files changed (1)

File timestamp.py

+# timestamps.py - save or restore modification times of files
+#
+# Copyright 2009 Friedrich Kastner-Masilko <face@snoopie.at>
+#
+# This software may be used and distributed according to the terms
+# of the GNU General Public License, incorporated herein by reference.
+
+from mercurial.i18n import _
+from mercurial.node import *
+from mercurial.repo import RepoError
+from mercurial import commands, cmdutil, hg, node, util
+import os, tempfile, time
+
+def timestamp(ui, repo, *files, **opts):
+    """save or restore modification times of files"""
+    modified, added, removed, deleted, unknown, ignored, clean = [
+        n for n in repo.status()]
+
+    tsdict= dict();
+
+    try:
+        tsfile = file(repo.root+'/.hgtimestamp', 'r')
+        for line in tsfile.readlines():
+            fname, mtime = line.strip().split(',')
+            tsdict[fname] = float(mtime)
+    except:
+        raise util.Abort(_('fail'));
+    
+    if opts['save']:
+        pm = file(repo.root+'/.hgtimestamp', 'w')
+        patched = modified + added
+        for fname in patched:
+            mtime = os.stat(fname).st_mtime
+            pm.write("%s,%s\n" % (fname, mtime))
+    elif opts['restore']:
+        pm = file(repo.root+'/.hgtimestamp', 'r')
+        for line in pm.readlines():
+            f, mtime = line.strip().split(',')
+            fname = repo.wjoin(f)
+            st = os.stat(fname)
+            os.utime(fname, (st.st_atime, type(st.st_mtime)(mtime)))
+    else:
+        for fname, mtime in tsdict.items():
+            ui.status(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(mtime)), " \t", fname, "\n")
+    return True
+
+cmdtable = {
+    "timestamp": 
+        (timestamp, 
+         [('s', 'save', None, _('save modification times')),
+          ('r', 'restore', None, _('restore modification times'))], 
+              _('hg timestamp [-s | -r]')),
+}