transactions: change backupfiles format to use newlines stable
authorDurham Goode <durham@fb.com>
Tue, 21 Oct 2014 12:38:28 -0700
branchstable
changeset 23065 963f311e3a81
parent 23064 5dc888b79e70
child 23066 ad144882318d
transactions: change backupfiles format to use newlines Previously the journal.backupfiles file was delimited by \0. Now we delimit it using \n (same as the journal file). This allows us to change the number of values in each line more easily, rather than relying on the count of \0's.
mercurial/transaction.py
--- a/mercurial/transaction.py	Tue Oct 21 11:37:29 2014 -0700
+++ b/mercurial/transaction.py	Tue Oct 21 12:38:28 2014 -0700
@@ -128,7 +128,7 @@
         self.file.write(d)
         self.file.flush()
 
-        d = ''.join(['%s\0%s\0' % (f, b) for f, b in backups])
+        d = ''.join(['%s\0%s\n' % (f, b) for f, b in backups])
         self.backupsfile.write(d)
         self.backupsfile.flush()
 
@@ -177,7 +177,7 @@
 
         self.backupentries.append((file, backupfile, None))
         self.backupmap[file] = len(self.backupentries) - 1
-        self.backupsfile.write("%s\0%s\0" % (file, backupfile))
+        self.backupsfile.write("%s\0%s\n" % (file, backupfile))
         self.backupsfile.flush()
 
     @active
@@ -349,20 +349,16 @@
     backupjournal = "%s.backupfiles" % file
     if opener.exists(backupjournal):
         fp = opener.open(backupjournal)
-        data = fp.read()
-        if len(data) > 0:
-            ver = version
-            versionend = data.find('\n')
-            if versionend != -1:
-                ver = data[:versionend]
-                data = data[versionend + 1:]
-
+        lines = fp.readlines()
+        if lines:
+            ver = lines[0][:-1]
             if ver == str(version):
-                parts = data.split('\0')
-                # Skip the final part, since it's just a trailing empty space
-                for i in xrange(0, len(parts) - 1, 2):
-                    f, b = parts[i:i + 2]
-                    backupentries.append((f, b, None))
+                for line in lines[1:]:
+                    if line:
+                        # Shave off the trailing newline
+                        line = line[:-1]
+                        f, b = line.split('\0')
+                        backupentries.append((f, b, None))
             else:
                 report(_("journal was created by a newer version of "
                          "Mercurial"))