1. Friedrich Kastner-Masilko
  2. timestamp
Issue #2 open

Remove a file, then commit causes an error message on Windows/TortoiseHg

Ruslan Yushchenko
created an issue

When I remove a file under using shell extension "Remove file..." the file is scheduled for deletion from the next commit and also is deleted on disk. When I press "commit..." in shell extension menu and following error appeares:

[Error 2] The system cannot find the file specified: <File name>

It seems the _commit script uses os.stat() every file in .hgtimestamp. Here is a patch that fixes this behavior:

{{{ diff -r 6d6cbc4ca3c3 -r 926fb17321a9 timestamp.py --- a/timestamp.py Mon Mar 22 09:24:16 2010 +0100 +++ b/timestamp.py Tue Apr 06 14:31:29 2010 +0300 @@ -163,9 +163,18 @@ for f in match: if f in tsdict and ((not matchin) or 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 + try: + tmpfile = file(fname, 'r') + tmpfile.close() + stamp = float(os.stat(fname).st_mtime) + except: + stamp = -1 + if tsdict[f]==stamp or stamp<0: + pass + else: + repo.ui.debug(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(stamp)), " \t", f, "\n") + tsdict[f]=stamp
+ changed = True if changed: pm = file(repo.root+'/.hgtimestamp', 'w') for fname in tslist:

}}}

Comments (3)

  1. Friedrich Kastner-Masilko repo owner

    This one is quite interesting... I originally refrained from doing the try-open-close-except dance, because 'match' should only contain modified and added files. I can't do a open-close just to do stat'ing here, because my files are under some IDE's exclusive read-lock. It would fail for all files for me, so your patch is not working here.

    Obviously, the match object contains the deleted file(s), too, when called from TortoiseHg. The current hook is not filtering out those files, so I think a possible solution would be located here: http://bitbucket.org/face/timestamp/src/tip/timestamp.py#cl-156

    Thanks for the heads-up, I'll check it against TortoiseHg's call signature some more...

  2. Ruslan Yushchenko reporter

    Good point! Maybe just try/catch os.stat() then. Tried this and it worked also.

    diff --git a/timestamp.py b/timestamp.py
    --- a/timestamp.py
    +++ b/timestamp.py
    @@ -165,9 +165,15 @@
             for f in match:
                 if f in tsdict and ((not matchin) or 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
    +                try:
    +                    stamp = float(os.stat(fname).st_mtime)
    +                except:
    +                    stamp = -1
    +                if tsdict[f]==stamp or stamp<0:
    +                    pass
    +                else:
    +                    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')
                 for fname in tslist:
    
  3. Log in to comment