Beginnings of transaction undo support
authormpm@selenic.com
Wed, 18 May 2005 16:31:51 -0800
changeset 95 589f507bb259
parent 94 7daef883134f
child 96 fce47326677c
Beginnings of transaction undo support
mercurial/hg.py
mercurial/transaction.py
--- a/mercurial/hg.py	Wed May 18 16:29:39 2005 -0800
+++ b/mercurial/hg.py	Wed May 18 16:31:51 2005 -0800
@@ -294,7 +294,8 @@
         return filelog(self.opener, f)
 
     def transaction(self):
-        return transaction(self.opener, self.join("journal"))
+        return transaction(self.opener, self.join("journal"),
+                           self.join("undo"))
 
     def commit(self, parent, update = None, text = ""):
         tr = self.transaction()
--- a/mercurial/transaction.py	Wed May 18 16:29:39 2005 -0800
+++ b/mercurial/transaction.py	Wed May 18 16:31:51 2005 -0800
@@ -14,16 +14,16 @@
 import os
 
 class transaction:
-    def __init__(self, opener, journal):
+    def __init__(self, opener, journal, after = None):
         self.opener = opener
+        self.after = after
         self.entries = []
         self.map = {}
         self.journal = journal
 
         # abort here if the journal already exists
         if os.path.exists(self.journal):
-            print "journal already exists, recovering"
-            self.recover()
+            raise "journal already exists!"
 
         self.file = open(self.journal, "w")
 
@@ -43,7 +43,10 @@
     def close(self):
         self.file.close()
         self.entries = []
-        os.unlink(self.journal)
+        if self.after:
+            os.rename(self.journal, self.after)
+        else:
+            os.unlink(self.journal)
 
     def abort(self):
         if not self.entries: return