Commits

Friedrich Kastner-Masilko committed c565115

fixed timestamp for 1.4

Comments (0)

Files changed (1)

 # of the GNU General Public License, incorporated herein by reference.
 
 from mercurial.i18n import _
-from mercurial import localrepo
+from mercurial import localrepo, util
 import os, time
 
 def hook(ui, repo, hooktype, parent1=None, parent2=None, **kwargs):
-    '''hook for restoring timestamps after update'''
-    
-    if hooktype != 'update':
-        return
+    '''hook for restoring timestamps after update'''    
     
     tsfile=''
     try:
         tsfile = file(repo.root+'/.hgtimestamp', 'r')        
     except:
+        ui.debug('.hgtimestamp not found!\n')
         return
 
     tsdict= dict()
     tslist= list()
+
+    ui.debug(_('Restoring timestamps\n'))
     for line in tsfile.readlines():
         try:
             fname, mtime = line.strip().split(',')
             tsdict[fname] = float(mtime)
             tslist.append(fname)
-        except:
+        except:            
             if len(line)>0:
                 fname = line.strip().split(',')[0]
                 tsdict[fname] = float(-1)
             try:
                 st = os.stat(fname)
                 os.utime(fname, (st.st_atime, type(st.st_mtime)(mtime)))
+                ui.debug(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(mtime)), " \t", f, "\n")
             except:
-                pass
+                ui.debug(_('File stat failed for "'), fname, '"!\n')                
+        else:
+            ui.debug(f, _(' skipped\n'))
 
 def timestamp(ui, repo, **opts):
     '''save or restore modification times of files'''
                     os.utime(fname, (st.st_atime, type(st.st_mtime)(mtime)))
                     ui.status(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(mtime)), " \t", f, "\n")
                 except:
-                    pass
+                    ui.status(_('File stat failed for "'), fname, '"!\n')
+            else:
+                ui.status(f, _(' skipped\n'))
     else:        
         for fname in tslist:
             mtime=tsdict[fname]
             if mtime>=0:
                 ui.status(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(mtime)), " \t", fname, "\n")
+            else:
+                ui.debug(fname, _(' skipped\n'))
     return True
 
 cmdtable = {
               _('hg timestamp [-s | -r]')),
 }
 
-def _commit(repo, *args, **kwargs):
+def _commit(repo, text="", user=None, date=None, matchin=None,
+                force=False, editor=False, extra={}):
     '''Hack to get a real precommit hook. One that allows to modify files e.g.
     The precommit hook is only called in localrepo.commit. I hope it is
     safe to only decorate localrepo.commit.
     else:
         tsdict= dict()
         tslist= list()
+        repo.ui.debug(_('Checking timestamps\n'))
         for line in tsfile.readlines():
             try:
                 fname, mtime = line.strip().split(',')
                     tsdict[fname] = float(-1)
                     tslist.append(fname)
 
-        if args[0]:
-            match = args[0]
+        matchfiles=matchin.files()
+        if len(matchfiles)>0:            
+            match = matchfiles
         else:
             modified, added, removed, deleted, unknown, ignored, clean = [
                 n for n in repo.status()]
 
         changed = False
         for f in match:
-            if f in tsdict:
+            if f in tsdict and matchin(f):
                 fname = repo.wjoin(f)
                 stamp = tsdict[f] = float(os.stat(fname).st_mtime)
+                repo.ui.debug(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(stamp)), " \t", f, "\n")
                 changed = True
         if changed:
             pm = file(repo.root+'/.hgtimestamp', 'w')
                     pm.write("%s\n" % fname)
                 else:                    
                     pm.write("%s,%s\n" % (fname, tsdict[fname]))
-            if args[0]:
-                if '.hgtimestamp' in args[0]:
-                    pass
-                else:
-                    args[0].append('.hgtimestamp')
+            if matchin('.hgtimestamp'):
+                pass
+            else:
+                def matchfn(fn):
+                    if fn=='.hgtimestamp':
+                        return True
+                    else:
+                        return matchin.timestamp_origmatchfn(fn)
+                matchin.timestamp_origmatchfn=matchin.matchfn
+                matchin.matchfn=matchfn
+                if (len(matchfiles)>0):
+                    matchfiles.append('.hgtimestamp')
             pm.close()
+        else:
+            repo.ui.debug(_('No tracked timestamp\n'))
                                             
-    return repo.timestamp_origcommit(*args, **kwargs)
+    return repo.timestamp_origcommit(text, user, date, matchin, force, editor, extra)
 
 localrepo.localrepository.timestamp_origcommit = localrepo.localrepository.commit
 localrepo.localrepository.commit = _commit