shrink-revlog: make it work on windows (issue1976)
authorPatrick Mezard <pmezard@gmail.com>
Mon, 11 Jan 2010 21:15:53 +0100
changeset 10234 c8d6f339bbd7
parent 10233 69e07d234cc6
child 10235 318d58fe4ceb
shrink-revlog: make it work on windows (issue1976)
contrib/shrink-revlog.py
--- a/contrib/shrink-revlog.py	Mon Jan 11 22:41:49 2010 +0100
+++ b/contrib/shrink-revlog.py	Mon Jan 11 21:15:53 2010 +0100
@@ -169,7 +169,7 @@
     # absolute. Doing it this way keeps things simple: everything is an
     # absolute path.
     lock = repo.lock(wait=False)
-    tr = transaction.transaction(sys.stderr.write,
+    tr = transaction.transaction(ui.warn,
                                  open,
                                  repo.sjoin('journal'))
 
@@ -188,13 +188,14 @@
             if os.path.exists(tmpdatafn):
                 os.unlink(tmpdatafn)
             raise
+        # Racy since both files cannot be renamed atomically
+        util.os_link(indexfn, oldindexfn)
+        util.os_link(datafn, olddatafn)
+        util.rename(tmpindexfn, indexfn)
+        util.rename(tmpdatafn, datafn)
     finally:
         lock.release()
 
-    os.link(indexfn, oldindexfn)
-    os.link(datafn, olddatafn)
-    os.rename(tmpindexfn, indexfn)
-    os.rename(tmpdatafn, datafn)
     ui.write('note: old revlog saved in:\n'
           '  %s\n'
           '  %s\n'