Rev 2494: Change from adler to crc checksums, as adler32 in python is not stable from 32 to 64 bit systems. in http://bazaar.launchpad.net/~bzr/bzr/dirstate

Robert Collins robertc at robertcollins.net
Wed Mar 7 08:01:51 GMT 2007


At http://bazaar.launchpad.net/~bzr/bzr/dirstate

------------------------------------------------------------
revno: 2494
revision-id: robertc at robertcollins.net-20070307080048-zxljn4k8ydbi12py
parent: robertc at robertcollins.net-20070307060453-57bjf3z967sc6cda
committer: Robert Collins <robertc at robertcollins.net>
branch nick: dirstate
timestamp: Wed 2007-03-07 19:00:48 +1100
message:
  Change from adler to crc checksums, as adler32 in python is not stable from 32 to 64 bit systems.
modified:
  bzrlib/dirstate.py             dirstate.py-20060728012006-d6mvoihjb3je9peu-1
  bzrlib/tests/test_dirstate.py  test_dirstate.py-20060728012006-d6mvoihjb3je9peu-2
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py	2007-03-07 03:09:14 +0000
+++ b/bzrlib/dirstate.py	2007-03-07 08:00:48 +0000
@@ -30,7 +30,7 @@
 dirstate format = header line, full checksum, row count, parent details,
  ghost_details, entries;
 header line = "#bazaar dirstate flat format 2", NL;
-full checksum = "adler32: ", ["-"], WHOLE_NUMBER, NL;
+full checksum = "crc32: ", ["-"], WHOLE_NUMBER, NL;
 row count = "num_entries: ", digit, NL;
 parent_details = WHOLE NUMBER, {REVISION_ID}* NL;
 ghost_details = WHOLE NUMBER, {REVISION_ID}*, NL;
@@ -1494,7 +1494,7 @@
         output_lines = [DirState.HEADER_FORMAT_3]
         lines.append('') # a final newline
         inventory_text = '\0\n\0'.join(lines)
-        output_lines.append('adler32: %s\n' % (zlib.adler32(inventory_text),))
+        output_lines.append('crc32: %s\n' % (zlib.crc32(inventory_text),))
         # -3, 1 for num parents, 1 for ghosts, 1 for final newline
         num_entries = len(lines)-3
         output_lines.append('num_entries: %s\n' % (num_entries,))
@@ -1532,7 +1532,7 @@
             # has been called in the mean time)
             self._state_file.seek(self._end_of_header)
             text = self._state_file.read()
-            # TODO: check the adler checksums. adler_measured = zlib.adler32(text)
+            # TODO: check the crc checksums. crc_measured = zlib.crc32(text)
 
             fields = text.split('\0')
             # Remove the last blank entry
@@ -1628,7 +1628,7 @@
         After reading in, the file should be positioned at the null
         just before the start of the first record in the file.
 
-        :return: (expected adler checksum, number of entries, parent list)
+        :return: (expected crc checksum, number of entries, parent list)
         """
         self._read_prelude()
         parent_line = self._state_file.readline()
@@ -1656,7 +1656,7 @@
     def _read_prelude(self):
         """Read in the prelude header of the dirstate file
 
-        This only reads in the stuff that is not connected to the adler
+        This only reads in the stuff that is not connected to the crc
         checksum. The position will be correct to read in the rest of
         the file and check the checksum after this point.
         The next entry in the file should be the number of parents,
@@ -1665,9 +1665,9 @@
         header = self._state_file.readline()
         assert header == DirState.HEADER_FORMAT_3, \
             'invalid header line: %r' % (header,)
-        adler_line = self._state_file.readline()
-        assert adler_line.startswith('adler32: '), 'missing adler32 checksum'
-        self.adler_expected = int(adler_line[len('adler32: '):-1])
+        crc_line = self._state_file.readline()
+        assert crc_line.startswith('crc32: '), 'missing crc32 checksum'
+        self.crc_expected = int(crc_line[len('crc32: '):-1])
         num_entries_line = self._state_file.readline()
         assert num_entries_line.startswith('num_entries: '), 'missing num_entries line'
         self._num_entries = int(num_entries_line[len('num_entries: '):-1])

=== modified file 'bzrlib/tests/test_dirstate.py'
--- a/bzrlib/tests/test_dirstate.py	2007-03-07 03:09:14 +0000
+++ b/bzrlib/tests/test_dirstate.py	2007-03-07 08:00:48 +0000
@@ -790,7 +790,7 @@
         state = self.create_dirstate_with_root_and_subdir()
         try:
             self.assertEqual(['#bazaar dirstate flat format 3\n',
-                'adler32: -1327947603\n',
+                'crc32: 41262208\n',
                 'num_entries: 2\n',
                 '0\x00\n\x00'
                 '0\x00\n\x00'



More information about the bazaar-commits mailing list