Rev 3171: Journal entry combining. in http://people.ubuntu.com/~robertc/baz2.0/inventory.journalled
Robert Collins
robertc at robertcollins.net
Fri Jan 4 00:01:36 GMT 2008
At http://people.ubuntu.com/~robertc/baz2.0/inventory.journalled
------------------------------------------------------------
revno: 3171
revision-id:robertc at robertcollins.net-20080104000131-baifhdmzp69re52u
parent: robertc at robertcollins.net-20080103232100-jgfdz48a9pruhyg4
committer: Robert Collins <robertc at robertcollins.net>
branch nick: inventory.journalled
timestamp: Fri 2008-01-04 11:01:31 +1100
message:
Journal entry combining.
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:21:00 +0000
+++ b/bzrlib/journalled_inventory.py 2008-01-04 00:01:31 +0000
@@ -90,6 +90,26 @@
self.versioned_root = versioned_root
self.tree_references = tree_references
+ def combine_with(self, parent_entry):
+ """Combine this journal entry with its parent. (build-backwards)
+
+ After combining:
+ - the parent of this entry will be the parent of it's parent.
+ - all ids listed in parent_entry not already in by_id will have been
+ copied to by_id.
+ - parent_entry will be unchanged.
+
+ :param parent_entry: The parent _JournalEntry of this _JournalEntry.
+ :return: None
+ """
+ if parent_entry.version != self.parent_revision:
+ raise errors.BzrError("Can only combine with %s not %s" %
+ (self.parent_revision, parent_entry.version))
+ for line in parent_entry.by_id.iteritems():
+ if line[0] not in self.by_id:
+ self.by_id[line[0]] = line[1]
+ self.parent_revision = parent_entry.parent_revision
+
class EntryAccess(object):
"""Provide access to named bytesequences of the journal entries."""
@@ -181,10 +201,10 @@
raise errors.BzrError('unknown format %r' % lines[0:1])
if len(lines) < 2 or not lines[1].startswith('parent: '):
raise errors.BzrError('missing parent: marker')
- parent_id = lines[1][8:]
+ journal_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:]
+ journal_version_id = lines[2][9:]
by_id = {}
for line in lines[3:]:
newpath_utf8, file_id, parent_id, last_modified, content \
@@ -203,5 +223,5 @@
if len(by_id) + 3 != len(lines):
raise errors.BzrError(
"duplicate file id in journal entry %r" % lines)
- return _JournalEntry(version_id, parent_id, by_id, self._versioned_root,
- self._tree_references)
+ return _JournalEntry(journal_version_id, journal_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:21:00 +0000
+++ b/bzrlib/tests/test_journalled_inv.py 2008-01-04 00:01:31 +0000
@@ -42,6 +42,12 @@
/\x00an-id\x00\x00a at e\xe5ample.com--2004\x00dir\x00\x00
"""
+root_change_lines = """format: bzr journalled inventory v1 (bzr 1.1)
+parent: entry-version
+version: changed-root
+/\x00an-id\x00\x00different-version\x00dir\x00\x00
+"""
+
root_only_unversioned = """format: bzr journalled inventory v1 (bzr 1.1)
parent: null:
version: entry-version
@@ -55,6 +61,12 @@
/foo\x00id\x00TREE_ROOT\x00changed\x00tree\x00subtree-version\x00
"""
+change_tree_lines = """format: bzr journalled inventory v1 (bzr 1.1)
+parent: entry-version
+version: change-tree
+/foo\x00id\x00TREE_ROOT\x00changed-twice\x00tree\x00subtree-version2\x00
+"""
+
class TestSerializer(TestCase):
"""Test journalled inventory serialisation."""
@@ -247,10 +259,10 @@
tree_references=tree_references)
journal_entry = journal.parse_text_bytes(empty_lines)
self.assertEqual(NULL_REVISION, journal_entry.parent_revision)
+ self.assertEqual(NULL_REVISION, journal_entry.version)
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,
@@ -274,6 +286,8 @@
('dir', '', '')),
},
journal_entry.by_id)
+ self.assertEqual(NULL_REVISION, journal_entry.parent_revision)
+ self.assertEqual('entry-version', journal_entry.version)
def test_parse_versioned_root_versioned_disabled(self):
journal = journalled_inventory.InventoryJournal(versioned_root=False,
@@ -310,6 +324,53 @@
journal.parse_text_bytes, reference_lines)
+class TestJournalEntry(TestCase):
+
+ def assertJournalEntriesEqual(self, left, right):
+ self.assertEqual(left.__dict__, right.__dict__)
+
+ def test_combine_null_and_root_gives_unchanged_root(self):
+ journal = journalled_inventory.InventoryJournal(versioned_root=True,
+ tree_references=True)
+ a_root = journal.parse_text_bytes(root_only_lines)
+ null = journal.parse_text_bytes(empty_lines)
+ root = journal.parse_text_bytes(root_only_lines)
+ print root.parent_revision
+ root.combine_with(null)
+ self.assertJournalEntriesEqual(a_root, root)
+
+ def test_combine_with_other_than_parent_errors(self):
+ journal = journalled_inventory.InventoryJournal(versioned_root=True,
+ tree_references=True)
+ root = journal.parse_text_bytes(root_only_lines)
+ self.assertRaises(errors.BzrError, root.combine_with, root)
+
+ def test_combine_changes_parent_id(self):
+ journal = journalled_inventory.InventoryJournal(versioned_root=True,
+ tree_references=True)
+ root = journal.parse_text_bytes(root_only_lines)
+ root_change = journal.parse_text_bytes(root_change_lines)
+ root_change.combine_with(root)
+ self.assertEqual(root.parent_revision, root_change.parent_revision)
+ self.assertEqual({
+ 'an-id': ('/', 'an-id', None, 'different-version',
+ ('dir', '', '')),
+ }, root_change.by_id)
+
+ def test_combine_adds_new_ids(self):
+ journal = journalled_inventory.InventoryJournal(versioned_root=True,
+ tree_references=True)
+ root = journal.parse_text_bytes(reference_lines)
+ change_tree = journal.parse_text_bytes(change_tree_lines)
+ change_tree.combine_with(root)
+ self.assertEqual({
+ 'TREE_ROOT': ('/', 'TREE_ROOT', None, 'a at e\xe5ample.com--2004',
+ ('dir', '', '')),
+ 'id': ('/foo', 'id', 'TREE_ROOT', 'changed-twice',
+ ('tree', 'subtree-version2', '')),
+ }, change_tree.by_id)
+
+
class TestContent(TestCase):
def test_dir(self):
More information about the bazaar-commits
mailing list