Rev 3288: Add VersionedFile.get_parent_map. in http://people.ubuntu.com/~robertc/baz2.0/versioned_files
Robert Collins
robertc at robertcollins.net
Tue Mar 18 01:10:25 GMT 2008
At http://people.ubuntu.com/~robertc/baz2.0/versioned_files
------------------------------------------------------------
revno: 3288
revision-id:robertc at robertcollins.net-20080318011005-9h7ypif44ixhlqry
parent: pqm at pqm.ubuntu.com-20080316165803-tisoc9mpob9z544o
committer: Robert Collins <robertc at robertcollins.net>
branch nick: versionedfile.apicleanup
timestamp: Tue 2008-03-18 12:10:05 +1100
message:
Add VersionedFile.get_parent_map.
modified:
BRANCH.TODO BRANCH.TODO-20060103052123-79ac4969351c03a9
bzrlib/knit.py knit.py-20051212171256-f056ac8f0fbe1bd9
bzrlib/tests/test_versionedfile.py test_versionedfile.py-20060222045249-db45c9ed14a1c2e5
bzrlib/versionedfile.py versionedfile.py-20060222045106-5039c71ee3b65490
bzrlib/weave.py knit.py-20050627021749-759c29984154256b
=== modified file 'BRANCH.TODO'
--- a/BRANCH.TODO 2007-04-28 15:04:17 +0000
+++ b/BRANCH.TODO 2008-03-18 01:10:05 +0000
@@ -3,3 +3,50 @@
#
#
+vf apis to keep:
+check_not_reserved_id
+versions
+add_lines
+ (with ghosts version/perhaps flag)
+add_mpdiff
+ (nb, add_lines adds one version, add_mpdiffs adds many, we should make these
+ consistent)
+check (but rename validate?)
+get_format_signature
+make_mpdiffs (but rename to get_something, or iter_mpdiffs) ?
+get_sha1s
+get_parent_map (because this is what bzrlib.graph wants; iter_parents is
+ better on incremental work)
+annotate_iter (perhaps rename to iter_annotations)
+iter_lines_added_or_present_in_versions
+weave_merge
+get_bytes
+get_lines
+
+apis to decide on:
+plan_merge (perhaps keep this)
+
+apis to remove:
+has_version
+copy_to
+access_mode in constructor
+finished
+iter_parents
+join
+annotate
+get_sha1
+has_ghost
+add_lines_non_ghost
+enable_cache
+clear_cache
+clone_text
+create_empty
+get_suffixes
+get_text
+get_texts
+get_lines
+get_ancestry
+get_ancestry_with_ghosts
+get_graph
+get_graph_with_ghosts
+transaction_finished
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py 2008-03-15 10:01:28 +0000
+++ b/bzrlib/knit.py 2008-03-18 01:10:05 +0000
@@ -1258,22 +1258,16 @@
"""See VersionedFile.annotate_iter."""
return self.factory.annotate_iter(self, version_id)
- def get_parents(self, version_id):
- """See VersionedFile.get_parents."""
- # perf notes:
- # optimism counts!
- # 52554 calls in 1264 872 internal down from 3674
- try:
- return self._index.get_parents(version_id)
- except KeyError:
- raise RevisionNotPresent(version_id, self.filename)
-
- def get_parents_with_ghosts(self, version_id):
- """See VersionedFile.get_parents."""
- try:
- return self._index.get_parents_with_ghosts(version_id)
- except KeyError:
- raise RevisionNotPresent(version_id, self.filename)
+ def get_parent_map(self, version_ids):
+ """See VersionedFile.get_parent_map."""
+ result = {}
+ lookup = self._index.get_parents_with_ghosts
+ for version_id in version_ids:
+ try:
+ result[version_id] = tuple(lookup(version_id))
+ except KeyError:
+ pass
+ return result
def get_ancestry(self, versions, topo_sorted=True):
"""See VersionedFile.get_ancestry."""
=== modified file 'bzrlib/tests/test_versionedfile.py'
--- a/bzrlib/tests/test_versionedfile.py 2008-01-11 05:08:20 +0000
+++ b/bzrlib/tests/test_versionedfile.py 2008-03-18 01:10:05 +0000
@@ -458,6 +458,29 @@
self.assertRaises(RevisionNotPresent,
f.get_parents, 'y')
+ def test_get_parent_map(self):
+ f = self.get_file()
+ f.add_lines('r0', [], ['a\n', 'b\n'])
+ self.assertEqual(
+ {'r0':()}, f.get_parent_map(['r0']))
+ f.add_lines('r1', ['r0'], ['a\n', 'b\n'])
+ self.assertEqual(
+ {'r1':('r0',)}, f.get_parent_map(['r1']))
+ self.assertEqual(
+ {'r0':(),
+ 'r1':('r0',)},
+ f.get_parent_map(['r0', 'r1']))
+ f.add_lines('r2', [], ['a\n', 'b\n'])
+ f.add_lines('r3', [], ['a\n', 'b\n'])
+ f.add_lines('m', ['r0', 'r1', 'r2', 'r3'], ['a\n', 'b\n'])
+ self.assertEqual(
+ {'m':('r0', 'r1', 'r2', 'r3')}, f.get_parent_map(['m']))
+ self.assertEqual({}, f.get_parent_map('y'))
+ self.assertEqual(
+ {'r0':(),
+ 'r1':('r0',)},
+ f.get_parent_map(['r0', 'y', 'r1']))
+
def test_annotate(self):
f = self.get_file()
f.add_lines('r0', [], ['a\n', 'b\n'])
=== modified file 'bzrlib/versionedfile.py'
--- a/bzrlib/versionedfile.py 2008-01-11 05:08:20 +0000
+++ b/bzrlib/versionedfile.py 2008-03-18 01:10:05 +0000
@@ -371,13 +371,30 @@
"""
raise NotImplementedError(self.get_graph_with_ghosts)
+ def get_parent_map(self, version_ids):
+ """Get a map of the parents of version_ids.
+
+ :param version_ids: The version ids to look up parents for.
+ :return: A mapping from version id to parents.
+ """
+ raise NotImplementedError(self.get_parent_map)
+
def get_parents(self, version_id):
"""Return version names for parents of a version.
Must raise RevisionNotPresent if version is not present in
file history.
"""
- raise NotImplementedError(self.get_parents)
+ try:
+ all = self.get_parent_map([version_id])[version_id]
+ except KeyError:
+ raise errors.RevisionNotPresent(version_id, self)
+ result = []
+ parent_parents = self.get_parent_map(all)
+ for version_id in all:
+ if version_id in parent_parents:
+ result.append(version_id)
+ return result
def get_parents_with_ghosts(self, version_id):
"""Return version names for parents of version_id.
@@ -388,7 +405,10 @@
Ghosts that are known about will be included in the parent list,
but are not explicitly marked.
"""
- raise NotImplementedError(self.get_parents_with_ghosts)
+ try:
+ return list(self.get_parent_map([version_id])[version_id])
+ except KeyError:
+ raise errors.RevisionNotPresent(version_id, self)
def annotate_iter(self, version_id):
"""Yield list of (version-id, line) pairs for the specified
=== modified file 'bzrlib/weave.py'
--- a/bzrlib/weave.py 2008-01-02 03:08:59 +0000
+++ b/bzrlib/weave.py 2008-03-18 01:10:05 +0000
@@ -245,9 +245,19 @@
__contains__ = has_version
- def get_parents(self, version_id):
- """See VersionedFile.get_parent."""
- return map(self._idx_to_name, self._parents[self._lookup(version_id)])
+ def get_parent_map(self, version_ids):
+ """See VersionedFile.get_parent_map."""
+ result = {}
+ for version_id in version_ids:
+ try:
+ result[version_id] = tuple(
+ map(self._idx_to_name, self._parents[self._lookup(version_id)]))
+ except RevisionNotPresent:
+ pass
+ return result
+
+ def get_parents_with_ghosts(self, version_id):
+ raise NotImplementedError(self.get_parents_with_ghosts)
def _check_repeated_add(self, name, parents, text, sha1):
"""Check that a duplicated add is OK.
More information about the bazaar-commits
mailing list