Rev 3170: Add a version: marker to journal entries. in http://people.ubuntu.com/~robertc/baz2.0/inventory.journalled

Robert Collins robertc at robertcollins.net
Thu Jan 3 23:21:05 GMT 2008


At http://people.ubuntu.com/~robertc/baz2.0/inventory.journalled

------------------------------------------------------------
revno: 3170
revision-id:robertc at robertcollins.net-20080103232100-jgfdz48a9pruhyg4
parent: robertc at robertcollins.net-20080103230626-71rwt9wb1er9hhan
committer: Robert Collins <robertc at robertcollins.net>
branch nick: inventory.journalled
timestamp: Fri 2008-01-04 10:21:00 +1100
message:
  Add a version: marker to journal entries.
modified:
  bzrlib/journalled_inventory.py journalled_inventory-20080103020931-0ht5n40kwc0p7fy1-1
  bzrlib/tests/test_journalled_inv.py test_journalled_inv.-20080103012121-ny2w9slze5jgty8i-1
=== modified file 'bzrlib/journalled_inventory.py'
--- a/bzrlib/journalled_inventory.py	2008-01-03 23:06:26 +0000
+++ b/bzrlib/journalled_inventory.py	2008-01-03 23:21:00 +0000
@@ -73,16 +73,18 @@
 class _JournalEntry(object):
     """An individual entry in a journalled inventory."""
 
-    def __init__(self, parent_revision, by_id, versioned_root,
+    def __init__(self, version, parent_revision, by_id, versioned_root,
         tree_references):
         """Create a _JournalEntry.
 
+        :param version: The version of this InventoryJournal.
         :param parent_revision: The parent revision this entry is written
             against. null: indicates the start of a new delta chain.
         :param by_id: The text-split items in this entry indexed by id.
         :param version_root: True if / paths will be versioned.
         :param tree_references: True if tree references are supported.
         """
+        self.version = version
         self.parent_revision = parent_revision
         self.by_id = by_id
         self.versioned_root = versioned_root
@@ -115,22 +117,25 @@
         if tree_references:
             self._entry_to_content['tree-reference'] = _reference_content
 
-    def delta_to_lines(self, old_inventory_name, delta_to_new):
+    def delta_to_lines(self, old_inventory_name, new_name, delta_to_new):
         """Return a line sequence for delta_to_new.
 
         :param old_inventory_name: A UTF8 revision id for the old inventory.
             May be NULL_REVISION if there is no older inventory and
             delta_to_new includes the entire inventory contents.
+        :param new_name: The version name of the inventory we create with this
+            delta.
         :param delta_to_new: An inventory delta such as Inventory.apply_delta
             takes.
         """
-        lines = ['', '']
+        lines = ['', '', '']
         to_line = self._delta_item_to_line
         for delta_item in delta_to_new:
             lines.append(to_line(delta_item))
         lines.sort()
         lines[0] = "format: %s\n" % InventoryJournal.FORMAT_1
         lines[1] = "parent: %s\n" % old_inventory_name
+        lines[2] = "version: %s\n" % new_name
         return lines
 
     def _delta_item_to_line(self, delta_item):
@@ -177,8 +182,11 @@
         if len(lines) < 2 or not lines[1].startswith('parent: '):
             raise errors.BzrError('missing parent: marker')
         parent_id = lines[1][8:]
+        if len(lines) < 3 or not lines[2].startswith('version: '):
+            raise errors.BzrError('missing version: marker')
+        version_id = lines[2][9:]
         by_id = {}
-        for line in lines[2:]:
+        for line in lines[3:]:
             newpath_utf8, file_id, parent_id, last_modified, content \
                 = line.split('\x00', 4)
             parent_id = parent_id or None
@@ -192,8 +200,8 @@
                     raise errors.BzrError("Versioned root found: %r" % line)
             if not self._tree_references and content.startswith('tree\x00'):
                 raise errors.BzrError("Tree reference found: %r" % line)
-        if len(by_id) + 2 != len(lines):
+        if len(by_id) + 3 != len(lines):
             raise errors.BzrError(
                 "duplicate file id in journal entry %r" % lines)
-        return _JournalEntry(parent_id, by_id, self._versioned_root,
+        return _JournalEntry(version_id, parent_id, by_id, self._versioned_root,
             self._tree_references)

=== modified file 'bzrlib/tests/test_journalled_inv.py'
--- a/bzrlib/tests/test_journalled_inv.py	2008-01-03 23:06:26 +0000
+++ b/bzrlib/tests/test_journalled_inv.py	2008-01-03 23:21:00 +0000
@@ -33,20 +33,24 @@
 ### DO NOT REFLOW THESE TEXTS. NEW LINES ARE SIGNIFICANT. ###
 empty_lines = """format: bzr journalled inventory v1 (bzr 1.1)
 parent: null:
+version: null:
 """
 
 root_only_lines = """format: bzr journalled inventory v1 (bzr 1.1)
 parent: null:
+version: entry-version
 /\x00an-id\x00\x00a at e\xe5ample.com--2004\x00dir\x00\x00
 """
 
 root_only_unversioned = """format: bzr journalled inventory v1 (bzr 1.1)
 parent: null:
+version: entry-version
 /\x00TREE_ROOT\x00\x00null:\x00dir\x00\x00
 """
 
 reference_lines = """format: bzr journalled inventory v1 (bzr 1.1)
 parent: null:
+version: entry-version
 /\x00TREE_ROOT\x00\x00a at e\xe5ample.com--2004\x00dir\x00\x00
 /foo\x00id\x00TREE_ROOT\x00changed\x00tree\x00subtree-version\x00
 """
@@ -80,7 +84,7 @@
         journal = journalled_inventory.InventoryJournal(versioned_root=True,
             tree_references=True)
         self.assertEqual(StringIO(empty_lines).readlines(),
-            journal.delta_to_lines(NULL_REVISION, delta))
+            journal.delta_to_lines(NULL_REVISION, NULL_REVISION, delta))
 
     def test_root_only_to_lines(self):
         old_inv = Inventory(None)
@@ -92,7 +96,7 @@
         journal = journalled_inventory.InventoryJournal(versioned_root=True,
             tree_references=True)
         self.assertEqual(StringIO(root_only_lines).readlines(),
-            journal.delta_to_lines(NULL_REVISION, delta))
+            journal.delta_to_lines(NULL_REVISION, 'entry-version', delta))
 
     def test_unversioned_root(self):
         old_inv = Inventory(None)
@@ -103,7 +107,7 @@
         journal = journalled_inventory.InventoryJournal(versioned_root=False,
             tree_references=False)
         self.assertEqual(StringIO(root_only_unversioned).readlines(),
-            journal.delta_to_lines(NULL_REVISION, delta))
+            journal.delta_to_lines(NULL_REVISION, 'entry-version', delta))
 
     def test_unversioned_non_root_errors(self):
         old_inv = Inventory(None)
@@ -117,7 +121,7 @@
         journal = journalled_inventory.InventoryJournal(versioned_root=True,
             tree_references=True)
         self.assertRaises(errors.BzrError,
-            journal.delta_to_lines, NULL_REVISION, delta)
+            journal.delta_to_lines, NULL_REVISION, 'entry-version', delta)
 
     def test_richroot_unversioned_root_errors(self):
         old_inv = Inventory(None)
@@ -128,7 +132,7 @@
         journal = journalled_inventory.InventoryJournal(versioned_root=True,
             tree_references=True)
         self.assertRaises(errors.BzrError,
-            journal.delta_to_lines, NULL_REVISION, delta)
+            journal.delta_to_lines, NULL_REVISION, 'entry-version', delta)
 
     def test_nonrichroot_versioned_root_errors(self):
         old_inv = Inventory(None)
@@ -140,7 +144,7 @@
         journal = journalled_inventory.InventoryJournal(versioned_root=False,
             tree_references=True)
         self.assertRaises(errors.BzrError,
-            journal.delta_to_lines, NULL_REVISION, delta)
+            journal.delta_to_lines, NULL_REVISION, 'entry-version', delta)
 
     def test_nonrichroot_non_TREE_ROOT_id_errors(self):
         old_inv = Inventory(None)
@@ -151,7 +155,7 @@
         journal = journalled_inventory.InventoryJournal(versioned_root=False,
             tree_references=True)
         self.assertRaises(errors.BzrError,
-            journal.delta_to_lines, NULL_REVISION, delta)
+            journal.delta_to_lines, NULL_REVISION, 'entry-version', delta)
 
     def test_unknown_kind_errors(self):
         old_inv = Inventory(None)
@@ -169,7 +173,7 @@
         # we expect keyerror because there is little value wrapping this.
         # This test aims to prove that it errors more than how it errors.
         self.assertRaises(KeyError,
-            journal.delta_to_lines, NULL_REVISION, delta)
+            journal.delta_to_lines, NULL_REVISION, 'entry-version', delta)
 
     def test_tree_reference_disabled(self):
         old_inv = Inventory(None)
@@ -188,7 +192,7 @@
         # we expect keyerror because there is little value wrapping this.
         # This test aims to prove that it errors more than how it errors.
         self.assertRaises(KeyError,
-            journal.delta_to_lines, NULL_REVISION, delta)
+            journal.delta_to_lines, NULL_REVISION, 'entry-version', delta)
 
     def test_tree_reference_enabled(self):
         old_inv = Inventory(None)
@@ -205,7 +209,7 @@
         journal = journalled_inventory.InventoryJournal(versioned_root=True,
             tree_references=True)
         self.assertEqual(StringIO(reference_lines).readlines(),
-            journal.delta_to_lines(NULL_REVISION, delta))
+            journal.delta_to_lines(NULL_REVISION, 'entry-version', delta))
 
     def test_parse_no_bytes(self):
         journal = journalled_inventory.InventoryJournal(versioned_root=True,
@@ -225,6 +229,14 @@
             journal.parse_text_bytes,
             'format: bzr journalled inventory v1 (bzr 1.1)\n')
 
+    def test_parse_no_version(self):
+        journal = journalled_inventory.InventoryJournal(versioned_root=True,
+            tree_references=True)
+        self.assertRaises(errors.BzrError,
+            journal.parse_text_bytes,
+            'format: bzr journalled inventory v1 (bzr 1.1)\n'
+            'parent: null:\n')
+
     def test_parse_empty(self):
         # quick loop to check that the parameters propogate to the generated
         # entry.
@@ -238,6 +250,7 @@
                 self.assertEqual({}, journal_entry.by_id)
                 self.assertEqual(versioned_root, journal_entry.versioned_root)
                 self.assertEqual(tree_references, journal_entry.tree_references)
+                self.assertEqual(NULL_REVISION, journal_entry.version)
 
     def test_parse_duplicate_key_errors(self):
         journal = journalled_inventory.InventoryJournal(versioned_root=True,
@@ -245,6 +258,7 @@
         double_root_lines = \
 """format: bzr journalled inventory v1 (bzr 1.1)
 parent: null:
+version: null:
 /\x00an-id\x00\x00a at e\xe5ample.com--2004\x00dir\x00\x00
 /\x00an-id\x00\x00a at e\xe5ample.com--2004\x00dir\x00\x00
 """
@@ -266,6 +280,7 @@
             tree_references=True)
         root_only_lines = """format: bzr journalled inventory v1 (bzr 1.1)
 parent: null:
+version: null:
 /\x00TREE_ROOT\x00\x00a at e\xe5ample.com--2004\x00dir\x00\x00
 """
         self.assertRaises(errors.BzrError,
@@ -276,6 +291,7 @@
             tree_references=True)
         root_only_lines = """format: bzr journalled inventory v1 (bzr 1.1)
 parent: null:
+version: null:
 /\x00an-id\x00\x00null:\x00dir\x00\x00
 """
         self.assertRaises(errors.BzrError,



More information about the bazaar-commits mailing list