Rev 3156: Bring up second journal test. in http://people.ubuntu.com/~robertc/baz2.0/inventory.journalled

Robert Collins robertc at robertcollins.net
Thu Jan 3 20:30:21 GMT 2008


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

------------------------------------------------------------
revno: 3156
revision-id:robertc at robertcollins.net-20080103203016-ejclg0l76s5of81n
parent: robertc at robertcollins.net-20080103025910-vztidj6e9v3jrqsi
committer: Robert Collins <robertc at robertcollins.net>
branch nick: inventory.journalled
timestamp: Fri 2008-01-04 07:30:16 +1100
message:
  Bring up second journal test.
modified:
  bzrlib/journalled_inventory.py journalled_inventory-20080103020931-0ht5n40kwc0p7fy1-1
  bzrlib/tests/test_journalled_inv.py test_journalled_inv.-20080103012121-ny2w9slze5jgty8i-1
  doc/developers/inventory.txt   inventory.txt-20080103013957-opkrhxy6lmywmx4i-1
=== modified file 'bzrlib/journalled_inventory.py'
--- a/bzrlib/journalled_inventory.py	2008-01-03 02:59:10 +0000
+++ b/bzrlib/journalled_inventory.py	2008-01-03 20:30:16 +0000
@@ -25,6 +25,50 @@
 
 __all__ = ['EntryAccess', 'InventoryJournal']
 
+from bzrlib import errors
+from bzrlib.revision import NULL_REVISION
+
+
+def _directory_content(entry):
+    """Serialise the content component of entry which is a directory.
+    
+    :param entry: An InventoryDirectory.
+    """
+    return "dir"
+
+
+def _file_content(entry):
+    """Serialise the content component of entry which is a file.
+    
+    :param entry: An InventoryFile.
+    """
+    size_sha = (entry.text_size, entry.text_sha1)
+    if None in size_sha:
+        raise errors.BzrError('Missing size or sha for %s' % entry.file_id)
+    return "file %s %s" % size_sha
+
+
+def _link_content(entry):
+    """Serialise the content component of entry which is a symlink.
+    
+    :param entry: An InventoryLink.
+    """
+    target = entry.symlink_target
+    if target is None:
+        raise errors.BzrError('Missing target for %s' % entry.file_id)
+    return "link %s" % target
+
+
+def _reference_content(entry):
+    """Serialise the content component of entry which is a tree-reference.
+    
+    :param entry: A TreeReference.
+    """
+    tree_revision = entry.reference_revision
+    if tree_revision is None:
+        raise errors.BzrError('Missing reference revision for %s' % entry.file_id)
+    return "tree %s" % tree_revision
+
 
 class EntryAccess(object):
     """Provide access to named bytesequences of the journal entries."""
@@ -44,7 +88,43 @@
         :param delta_to_new: An inventory delta such as Inventory.apply_delta
             takes.
         """
-        lines = []
-        lines.append("format: %s\n" % InventoryJournal.FORMAT_1)
-        lines.append("parent: %s\n" % old_inventory_name)
+        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
         return lines
+
+    def _delta_item_to_line(self, delta_item):
+        """Convert delta_item to a line."""
+        _, newpath, file_id, entry = delta_item
+        if newpath is None:
+            # delete
+            newpath_utf8 = 'None'
+            parent_id = ''
+            last_modified = NULL_REVISION
+            content = 'deleted'
+        else:
+            # TODO: Test real-world utf8 cache hit rate. It may be a win.
+            newpath_utf8 = '/' + newpath.encode('utf8')
+            # Serialise None as ''
+            parent_id = entry.parent_id or ''
+            # Serialise unknown revisions as NULL_REVISION
+            last_modified = entry.revision
+            if last_modified is None:
+                # only the root is allowed to be unversioned.
+                if newpath_utf8 != '/':
+                    raise errors.BzrError("no version for fileid %s" % file_id)
+                else:
+                    last_modified = NULL_REVISION
+            self._entry_to_content = {
+                'directory': _directory_content,
+                'file': _file_content,
+                'symlink': _link_content,
+                'tree-reference': _reference_content,
+            }
+            content = self._entry_to_content[entry.kind](entry)
+        return ("%s %s %s %s %s\n" %
+            (newpath_utf8, file_id, parent_id, last_modified, content))

=== modified file 'bzrlib/tests/test_journalled_inv.py'
--- a/bzrlib/tests/test_journalled_inv.py	2008-01-03 02:59:10 +0000
+++ b/bzrlib/tests/test_journalled_inv.py	2008-01-03 20:30:16 +0000
@@ -42,6 +42,11 @@
 """
 root_only_lines_validator = ""
 
+root_only_unversioned = """format: bzr journalled inventory v1 (bzr 1.1)
+parent: null:
+/ TREE_ROOT  null: dir
+"""
+root_only_lines_validator = ""
 
 class TestSerializer(TestCase):
     """Test journalled inventory serialisation."""
@@ -65,9 +70,25 @@
         return delta
 
     def test_empty_delta_to_lines(self):
-        old_inv = Inventory()
-        new_inv = Inventory()
+        old_inv = Inventory(None)
+        new_inv = Inventory(None)
         delta = self.make_inv_delta(old_inv, new_inv)
         journal = journalled_inventory.InventoryJournal()
         self.assertEqual(StringIO(empty_lines).readlines(),
             journal.delta_to_lines(NULL_REVISION, delta))
+
+    def test_root_only_to_lines(self):
+        old_inv = Inventory(None)
+        new_inv = Inventory(None)
+        root = new_inv.make_entry('directory', '', None, 'TREE_ROOT')
+        root.revision = 'a at e\xe5ample.com--2004'
+        new_inv.add(root)
+        delta = self.make_inv_delta(old_inv, new_inv)
+        journal = journalled_inventory.InventoryJournal()
+        self.assertEqual(StringIO(root_only_lines).readlines(),
+            journal.delta_to_lines(NULL_REVISION, delta))
+
+# unversioned entry that is not root errors
+# unversioned root errors when not enabled
+# unknown kind raises
+# tree-reference when not enabled

=== modified file 'doc/developers/inventory.txt'
--- a/doc/developers/inventory.txt	2008-01-03 02:59:10 +0000
+++ b/doc/developers/inventory.txt	2008-01-03 20:30:16 +0000
@@ -94,25 +94,31 @@
 We will serialise the lines text for a new inventory as:
 'format: bzr journalled inventory v1' NL
 'parent:' SP BASIS_INVENTORY NL DELTA_LINES
-DELTA_LINES ::= DELTA_LINE (NL DELTA_LINE)*
+DELTA_LINES ::= (DELTA_LINE NL)*
 DELTA_LINE ::= NEWPATH SP file-id SP PARENT_ID SP LAST_MODIFIED SP CONTENT
 SP ::= ' '
 NEWPATH ::= NONE | PATH
 NONE ::= 'None'
 PATH ::= '/' path
 PARENT_ID ::= FILE_ID | ''
-CONTENT ::= FILE_CONTENT | DIR_CONTENT | TREE_CONTENT | LINK_CONTENT
+CONTENT ::= DELETED_CONTENT | FILE_CONTENT | DIR_CONTENT | TREE_CONTENT | LINK_CONTENT
+DELETED_CONTENT ::= 'deleted'
 FILE_CONTENT ::= 'file' text_size text_sha1
 DIR_CONTENT ::= 'dir'
 TREE_CONTENT ::= 'tree' tree-revision
 LINK_CONTENT ::= 'link' link-target
 BASIS_INVENTORY ::= NULL_OR_REVISION
-LAST_MODIFIED ::= REVISION
+LAST_MODIFIED ::= NULL_OR_REVISION
 NULL_OR_REVISION ::= 'null:' | REVISION
 REVISION ::= revision-id-in-utf8-no-whitespace
 
 DELTA_LINES is lexographically sorted.
 
+Some explanation is in order. When NEWPATH is 'None' a delete has been
+recorded, and because this journalled inventory is not attempting to be a
+reversible journal, the only other valid fields is 'file-id'. PARENT_ID is ''
+when a delete has been recorded or when recording a new root entry.
+
 At any commit the validator is the root of a tree. Changing the deltas -
 e.g. by rewriting an inventory in the history to be a full inventory
 itself will change validators for all inventories built upon that one.



More information about the bazaar-commits mailing list