Patchwork [3,of,3,STABLE] transactions: change backupfiles format to use newlines

login
register
mail settings
Submitter Durham Goode
Date Oct. 21, 2014, 7:58 p.m.
Message ID <4407a3d98344f7e7bacd.1413921516@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/6436/
State Accepted
Headers show

Comments

Durham Goode - Oct. 21, 2014, 7:58 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1413920308 25200
#      Tue Oct 21 12:38:28 2014 -0700
# Branch stable
# Node ID 4407a3d98344f7e7bacd19c5d0adf579e76b1813
# Parent  b4a651b82658895889a0f53f93fd75f59590c18d
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.
Augie Fackler - Oct. 22, 2014, 2:46 a.m.
On Tue, Oct 21, 2014 at 12:58:36PM -0700, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1413920308 25200
> #      Tue Oct 21 12:38:28 2014 -0700
> # Branch stable
> # Node ID 4407a3d98344f7e7bacd19c5d0adf579e76b1813
> # Parent  b4a651b82658895889a0f53f93fd75f59590c18d
> transactions: change backupfiles format to use newlines

queued these for stable, thanks

>
> 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.
>
> diff --git a/mercurial/transaction.py b/mercurial/transaction.py
> --- a/mercurial/transaction.py
> +++ b/mercurial/transaction.py
> @@ -128,7 +128,7 @@ class transaction(object):
>          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 @@ class transaction(object):
>
>          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 @@ def rollback(opener, file, report):
>      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"))
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -128,7 +128,7 @@  class transaction(object):
         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 @@  class transaction(object):
 
         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 @@  def rollback(opener, file, report):
     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"))