Rev 2683: Merge more index support. in http://people.ubuntu.com/~robertc/baz2.0/repository

Robert Collins robertc at robertcollins.net
Mon Jul 30 05:01:58 BST 2007


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

------------------------------------------------------------
revno: 2683
revision-id: robertc at robertcollins.net-20070730040154-b1pf0rbhu86cvlio
parent: robertc at robertcollins.net-20070730015033-32n4pk5rtub4rls3
parent: robertc at robertcollins.net-20070730035831-mi0q02ry7zznzulr
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Mon 2007-07-30 14:01:54 +1000
message:
  Merge more index support.
modified:
  bzrlib/index.py                index.py-20070712131115-lolkarso50vjr64s-1
  bzrlib/tests/test_index.py     test_index.py-20070712131115-lolkarso50vjr64s-2
    ------------------------------------------------------------
    revno: 2592.1.25.2.20
    revision-id: robertc at robertcollins.net-20070730035831-mi0q02ry7zznzulr
    parent: robertc at robertcollins.net-20070729233741-tp1d2j06b7zde9j3
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: index
    timestamp: Mon 2007-07-30 13:58:31 +1000
    message:
      Implement add_node/add_nodes to the GraphIndexPrefixAdapter.
    modified:
      bzrlib/index.py                index.py-20070712131115-lolkarso50vjr64s-1
      bzrlib/tests/test_index.py     test_index.py-20070712131115-lolkarso50vjr64s-2
=== modified file 'bzrlib/index.py'
--- a/bzrlib/index.py	2007-07-30 00:50:48 +0000
+++ b/bzrlib/index.py	2007-07-30 04:01:54 +0000
@@ -692,6 +692,39 @@
         self.prefix_len = len(prefix)
         self.add_nodes_callback = add_nodes_callback
 
+    def add_nodes(self, nodes):
+        """Add nodes to the index.
+
+        :param nodes: An iterable of (key, node_refs, value) entries to add.
+        """
+        # save nodes in case its an iterator
+        nodes = tuple(nodes)
+        try:
+            for (key, value, node_refs) in nodes:
+                self.add_node(key, value, node_refs)
+        except ValueError:
+            # XXX: TODO add an explicit interface for getting the reference list
+            # status, to handle this bit of user-friendliness in the API more 
+            # explicitly.
+            for (key, value) in nodes:
+                self.add_node(key, value)
+
+    def add_node(self, key, value, references=()):
+        """Add a node to the index.
+
+        :param key: The key. keys are non-empty tuples containing
+            as many whitespace-free utf8 bytestrings as the key length
+            defined for this index.
+        :param references: An iterable of iterables of keys. Each is a
+            reference to another key.
+        :param value: The value to associate with the key. It may be any
+            bytes as long as it does not contain \0 or \n.
+        """
+        adjusted_references = (
+            tuple(tuple(self.prefix_key + ref_node for ref_node in ref_list)
+                for ref_list in references))
+        self.adapted.add_node(self.prefix_key + key, value, adjusted_references)
+
     def _strip_prefix(self, an_iter):
         """Strip prefix data from nodes and return it."""
         for node in an_iter:

=== modified file 'bzrlib/tests/test_index.py'
--- a/bzrlib/tests/test_index.py	2007-07-29 23:37:41 +0000
+++ b/bzrlib/tests/test_index.py	2007-07-30 03:58:31 +0000
@@ -762,6 +762,24 @@
         adapter = GraphIndexPrefixAdapter(result, ('prefix', ), key_elements - 1)
         return result, adapter
 
+    def test_add_node(self):
+        index, adapter = self.make_index()
+        adapter.add_node(('key',), 'value', ((('ref',),),))
+        self.assertEqual(set([(('prefix', 'key'), 'value', ((('prefix', 'ref'),),))]),
+            set(index.iter_all_entries()))
+
+    def test_add_nodes(self):
+        index, adapter = self.make_index()
+        adapter.add_nodes((
+            (('key',), 'value', ((('ref',),),)),
+            (('key2',), 'value2', ((),)),
+            ))
+        self.assertEqual(set([
+            (('prefix', 'key2'), 'value2', ((),)),
+            (('prefix', 'key'), 'value', ((('prefix', 'ref'),),))
+            ]),
+            set(index.iter_all_entries()))
+
     def test_construct(self):
         index = InMemoryGraphIndex()
         adapter = GraphIndexPrefixAdapter(index, ('prefix', ), 1)



More information about the bazaar-commits mailing list