mercurial/transaction.py
changeset 162 5dcbe4d9a30c
parent 108 8d55c2d72c7c
child 421 43b8da7420a9
child 429 688d03d6997a
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -15,16 +15,18 @@ import os
 
 class transaction:
     def __init__(self, opener, journal, after = None):
+        self.journal = None
+
+        # abort here if the journal already exists
+        if os.path.exists(journal):
+            raise "journal already exists - run hg recover"
+
         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):
-            raise "journal already exists!"
-
         self.file = open(self.journal, "w")
 
     def __del__(self):
@@ -63,9 +65,9 @@ class transaction:
 
         print "rollback completed"
         
-    def recover(self):
-        for l in open(self.journal).readlines():
-            f, o = l.split('\0')
-            self.opener(f, "a").truncate(int(o))
-        os.unlink(self.journal)
+def rollback(opener, file):
+    for l in open(file).readlines():
+        f, o = l.split('\0')
+        opener(f, "a").truncate(int(o))
+    os.unlink(file)