changeset 2084:d66278012853

Fix transaction handling during interleaved file split.
author Chris Mason <mason@suse.com>
date Mon, 17 Apr 2006 13:19:58 -0400
parents 345107e167a0
children f71e9656524f
files mercurial/revlog.py mercurial/transaction.py
diffstat 2 files changed, 34 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Sat Apr 08 20:10:46 2006 -0400
+++ b/mercurial/revlog.py	Mon Apr 17 13:19:58 2006 -0400
@@ -826,7 +826,15 @@
         size = fp.tell()
         if size < 131072:
             return
-        tr.add(self.datafile, 0)
+        trinfo = tr.find(self.indexfile)
+        if trinfo == None:
+            raise RevlogError(_("%s not found in the transaction"  %
+                              self.indexfile))
+
+        trindex = trinfo[2]
+        dataoff = self.start(trindex)
+
+        tr.add(self.datafile, dataoff)
         df = self.opener(self.datafile, 'w')
         calc = struct.calcsize(self.indexformat)
         for r in xrange(self.count()):
@@ -854,6 +862,8 @@
         # if we don't call rename, the temp file will never replace the
         # real index
         fp.rename()
+
+        tr.replace(self.indexfile, trindex * calc)
         self.chunkcache = None
 
     def addrevision(self, text, transaction, link, p1=None, p2=None, d=None):
@@ -922,7 +932,7 @@
         else:
             f = self.opener(self.indexfile, "a+")
             f.seek(0, 2)
-            transaction.add(self.indexfile, f.tell())
+            transaction.add(self.indexfile, f.tell(), self.count() - 1)
 
         if len(self.index) == 1 and self.version != 0:
             l = struct.pack(versionformat, self.version)
@@ -1071,7 +1081,7 @@
 
         ifh = self.opener(self.indexfile, "a+")
         ifh.seek(0, 2)
-        transaction.add(self.indexfile, ifh.tell())
+        transaction.add(self.indexfile, ifh.tell(), self.count())
         if self.inlinedata():
             dfh = None
         else:
--- a/mercurial/transaction.py	Sat Apr 08 20:10:46 2006 -0400
+++ b/mercurial/transaction.py	Mon Apr 17 13:19:58 2006 -0400
@@ -39,14 +39,27 @@
             try: os.unlink(self.journal)
             except: pass
 
-    def add(self, file, offset):
+    def add(self, file, offset, data=None):
         if file in self.map: return
-        self.entries.append((file, offset))
-        self.map[file] = 1
+        self.entries.append((file, offset, data))
+        self.map[file] = len(self.entries) - 1
         # add enough data to the journal to do the truncate
         self.file.write("%s\0%d\n" % (file, offset))
         self.file.flush()
 
+    def find(self, file):
+        if file in self.map:
+            return self.entries[self.map[file]]
+        return None
+
+    def replace(self, file, offset, data=None):
+        if file not in self.map:
+            raise KeyError(file)
+        index = self.map[file]
+        self.entries[index] = (file, offset, data)
+        self.file.write("%s\0%d\n" % (file, offset))
+        self.file.flush()
+
     def nest(self):
         self.count += 1
         return self
@@ -71,7 +84,7 @@
 
         self.report(_("transaction abort!\n"))
 
-        for f, o in self.entries:
+        for f, o, ignore in self.entries:
             try:
                 self.opener(f, "a").truncate(o)
             except:
@@ -82,8 +95,12 @@
         self.report(_("rollback completed\n"))
 
 def rollback(opener, file):
+    files = {}
     for l in open(file).readlines():
         f, o = l.split('\0')
+        files[f] = o
+    for f in files:
+        o = files[f]
         opener(f, "a").truncate(int(o))
     os.unlink(file)