Rev 4677: (garyvdm) Add get_parent_keys, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Mon Sep 7 15:55:18 BST 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4677 [merge]
revision-id: pqm at pqm.ubuntu.com-20090907145517-70waesydou0uk4tk
parent: pqm at pqm.ubuntu.com-20090907041459-so0m9vkp5j6mgir0
parent: v.ladeuil+lp at free.fr-20090907141905-p0wsk0dz6adn1ji2
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2009-09-07 15:55:17 +0100
message:
(garyvdm) Add get_parent_keys,
and get_child_keys methods to KnownGraph
modified:
bzrlib/_known_graph_py.py _known_graph_py.py-20090610185421-vw8vfda2cgnckgb1-1
bzrlib/_known_graph_pyx.pyx _known_graph_pyx.pyx-20090610194911-yjk73td9hpjilas0-1
bzrlib/tests/test__known_graph.py test__known_graph.py-20090610185421-vw8vfda2cgnckgb1-2
=== modified file 'bzrlib/_known_graph_py.py'
--- a/bzrlib/_known_graph_py.py 2009-08-25 18:45:40 +0000
+++ b/bzrlib/_known_graph_py.py 2009-09-07 14:19:05 +0000
@@ -281,3 +281,26 @@
in tsort.merge_sort(as_parent_map, tip_key,
mainline_revisions=None,
generate_revno=True)]
+
+ def get_parent_keys(self, key):
+ """Get the parents for a key
+
+ Returns a list containg the parents keys. If the key is a ghost,
+ None is returned. A KeyError will be raised if the key is not in
+ the graph.
+
+ :param keys: Key to check (eg revision_id)
+ :return: A list of parents
+ """
+ return self._nodes[key].parent_keys
+
+ def get_child_keys(self, key):
+ """Get the children for a key
+
+ Returns a list containg the children keys. A KeyError will be raised
+ if the key is not in the graph.
+
+ :param keys: Key to check (eg revision_id)
+ :return: A list of children
+ """
+ return self._nodes[key].child_keys
=== modified file 'bzrlib/_known_graph_pyx.pyx'
--- a/bzrlib/_known_graph_pyx.pyx 2009-09-02 13:32:52 +0000
+++ b/bzrlib/_known_graph_pyx.pyx 2009-09-07 14:19:05 +0000
@@ -88,6 +88,18 @@
PyList_Append(keys, child.key)
return keys
+ property parent_keys:
+ def __get__(self):
+ if self.parents is None:
+ return None
+
+ cdef _KnownGraphNode parent
+
+ keys = []
+ for parent in self.parents:
+ PyList_Append(keys, parent.key)
+ return keys
+
cdef clear_references(self):
self.parents = None
self.children = None
@@ -549,6 +561,29 @@
# shown a specific impact, yet.
sorter = _MergeSorter(self, tip_key)
return sorter.topo_order()
+
+ def get_parent_keys(self, key):
+ """Get the parents for a key
+
+ Returns a list containg the parents keys. If the key is a ghost,
+ None is returned. A KeyError will be raised if the key is not in
+ the graph.
+
+ :param keys: Key to check (eg revision_id)
+ :return: A list of parents
+ """
+ return self._nodes[key].parent_keys
+
+ def get_child_keys(self, key):
+ """Get the children for a key
+
+ Returns a list containg the children keys. A KeyError will be raised
+ if the key is not in the graph.
+
+ :param keys: Key to check (eg revision_id)
+ :return: A list of children
+ """
+ return self._nodes[key].child_keys
cdef class _MergeSortNode:
=== modified file 'bzrlib/tests/test__known_graph.py'
--- a/bzrlib/tests/test__known_graph.py 2009-09-02 13:32:52 +0000
+++ b/bzrlib/tests/test__known_graph.py 2009-09-07 14:19:05 +0000
@@ -99,12 +99,27 @@
def test_children_ancestry1(self):
graph = self.make_known_graph(test_graph.ancestry_1)
- self.assertEqual(['rev1'], graph._nodes[NULL_REVISION].child_keys)
+ self.assertEqual(['rev1'], graph.get_child_keys(NULL_REVISION))
self.assertEqual(['rev2a', 'rev2b'],
- sorted(graph._nodes['rev1'].child_keys))
- self.assertEqual(['rev3'], sorted(graph._nodes['rev2a'].child_keys))
- self.assertEqual(['rev4'], sorted(graph._nodes['rev3'].child_keys))
- self.assertEqual(['rev4'], sorted(graph._nodes['rev2b'].child_keys))
+ sorted(graph.get_child_keys('rev1')))
+ self.assertEqual(['rev3'], graph.get_child_keys('rev2a'))
+ self.assertEqual(['rev4'], graph.get_child_keys('rev3'))
+ self.assertEqual(['rev4'], graph.get_child_keys('rev2b'))
+ self.assertRaises(KeyError, graph.get_child_keys, 'not_in_graph')
+
+ def test_parent_ancestry1(self):
+ graph = self.make_known_graph(test_graph.ancestry_1)
+ self.assertEqual([NULL_REVISION], graph.get_parent_keys('rev1'))
+ self.assertEqual(['rev1'], graph.get_parent_keys('rev2a'))
+ self.assertEqual(['rev1'], graph.get_parent_keys('rev2b'))
+ self.assertEqual(['rev2a'], graph.get_parent_keys('rev3'))
+ self.assertEqual(['rev2b', 'rev3'],
+ sorted(graph.get_parent_keys('rev4')))
+ self.assertRaises(KeyError, graph.get_child_keys, 'not_in_graph')
+
+ def test_parent_with_ghost(self):
+ graph = self.make_known_graph(test_graph.with_ghost)
+ self.assertEqual(None, graph.get_parent_keys('g'))
def test_gdfo_ancestry_1(self):
graph = self.make_known_graph(test_graph.ancestry_1)
More information about the bazaar-commits
mailing list