Commits

Friedrich Kastner-Masilko  committed d45224c

Finished extension commands

  • Participants
  • Parent commits a11c183

Comments (0)

Files changed (1)

File timestamp.py

 
 def timestamp(ui, repo, *files, **opts):
     """save or restore modification times of files"""
+    tsdict= dict()
+    tslist= list()
+    tsfile=''
+
+    try:
+        tsfile = file(repo.root+'/.hgtimestamp', 'r')        
+    except:
+        return True
+    for line in tsfile.readlines():
+        try:
+            fname, mtime = line.strip().split(',')
+            tsdict[fname] = float(mtime)
+            tslist.append(fname)
+        except:
+            if len(line)>0:
+                fname = line.strip().split(',')[0]
+                tsdict[fname] = float(0)
+                tslist.append(fname)
+
     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'));
+    patched = modified + added
     
     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))
+        changed = False
+        ui.status(_('Checking timestamps\n'))
+        for f in patched:
+            if f in tsdict:
+                fname = repo.wjoin(f)
+                stamp = tsdict[f] = float(os.stat(fname).st_mtime)
+                changed = True
+                ui.status(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(stamp)), " \t", f, "\n")
+        if changed:
+            pm = file(repo.root+'/.hgtimestamp', 'w')
+            for fname in tslist:
+                pm.write("%s,%s\n" % (fname, tsdict[fname]))
+        else:
+            ui.status(_('No tracked timestamp modified\n'))
     elif opts['restore']:
-        pm = file(repo.root+'/.hgtimestamp', 'r')
-        for line in pm.readlines():
-            f, mtime = line.strip().split(',')
+        ui.status(_('Restoring timestamps\n'))
+        for f, mtime in tsdict.items():
             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")
+            ui.status(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(mtime)), " \t", f, "\n")
+    else:        
+        for fname in tslist:
+            ui.status(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(tsdict[fname])), " \t", fname, "\n")
     return True
 
 cmdtable = {