Rev 5987: (jelmer) Deprecate Repository.get_ancestry(). (Jelmer Vernooij) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Sun Jun 19 18:33:44 UTC 2011
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5987 [merge]
revision-id: pqm at pqm.ubuntu.com-20110619183340-ds1rpql77nxrmo4n
parent: pqm at pqm.ubuntu.com-20110619024801-czqq6tdnow5vy5ww
parent: jelmer at samba.org-20110619174943-v1adia1sb3tc8fvw
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sun 2011-06-19 18:33:40 +0000
message:
(jelmer) Deprecate Repository.get_ancestry(). (Jelmer Vernooij)
modified:
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/bundle/serializer/__init__.py __init__.py-20051118175413-86b97db0b618feef
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/repofmt/knitrepo.py knitrepo.py-20070206081537-pyy4a00xdas0j4pf-1
bzrlib/repository.py rev_storage.py-20051111201905-119e9401e46257e3
bzrlib/revisiontree.py revisiontree.py-20060724012533-bg8xyryhxd0o0i0h-1
bzrlib/sign_my_commits.py sign_my_commits.py-20060215152201-5a6363365180e671
bzrlib/tests/blackbox/test_sign_my_commits.py test_sign_my_commits.py-20060215152957-270238a1ffacc841
bzrlib/tests/matchers.py matchers.py-20100506074820-iiipsgdue8dhvidy-1
bzrlib/tests/per_interrepository/test_interrepository.py test_interrepository.py-20060220061411-1ec13fa99e5e3eee
bzrlib/tests/per_repository/test_fileid_involved.py test_file_involved.py-20051215205901-728a172d1014daaa
bzrlib/tests/per_repository_vf/test_reconcile.py test_reconcile.py-20110419123356-dlxq38sqo4w8agvl-1
bzrlib/tests/per_repository_vf/test_repository.py test_repository.py-20110224144010-ukgfmlxcgsibq4u4-3
bzrlib/tests/test_ancestry.py test_ancestry.py-20050913023709-69768e94848312c6
bzrlib/tests/test_commit.py test_commit.py-20050914060732-279f057f8c295434
bzrlib/tests/test_graph.py test_graph_walker.py-20070525030405-enq4r60hhi9xrujc-1
bzrlib/tests/test_matchers.py test_matchers.py-20100506074820-iiipsgdue8dhvidy-2
bzrlib/tests/test_remote.py test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
bzrlib/tests/test_revision.py testrevision.py-20050804210559-46f5e1eb67b01289
bzrlib/workingtree.py workingtree.py-20050511021032-29b6ec0a681e02e3
bzrlib/workingtree_4.py workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
doc/en/release-notes/bzr-2.4.txt bzr2.4.txt-20110114053217-k7ym9jfz243fddjm-1
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2011-06-01 16:50:59 +0000
+++ b/bzrlib/builtins.py 2011-06-16 16:45:18 +0000
@@ -1740,9 +1740,13 @@
b = wt.branch
last_revision = wt.last_revision()
- revision_ids = b.repository.get_ancestry(last_revision)
- revision_ids.pop(0)
- for revision_id in revision_ids:
+ self.add_cleanup(b.repository.lock_read().unlock)
+ graph = b.repository.get_graph()
+ revisions = [revid for revid, parents in
+ graph.iter_ancestry([last_revision])]
+ for revision_id in reversed(revisions):
+ if _mod_revision.is_null(revision_id):
+ continue
self.outf.write(revision_id + '\n')
=== modified file 'bzrlib/bundle/serializer/__init__.py'
--- a/bzrlib/bundle/serializer/__init__.py 2010-11-05 20:54:32 +0000
+++ b/bzrlib/bundle/serializer/__init__.py 2011-06-16 11:58:22 +0000
@@ -159,10 +159,9 @@
forced_bases = {revision_id:base_revision_id}
if base_revision_id is NULL_REVISION:
base_revision_id = None
- revision_ids = set(repository.get_ancestry(revision_id,
- topo_sorted=False))
- revision_ids.difference_update(repository.get_ancestry(
- base_revision_id, topo_sorted=False))
+ graph = repository.get_graph()
+ revision_ids = graph.find_unique_ancestors(revision_id,
+ [base_revision_id])
revision_ids = list(repository.get_graph().iter_topo_order(
revision_ids))
revision_ids.reverse()
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2011-06-16 17:39:40 +0000
+++ b/bzrlib/remote.py 2011-06-18 13:57:17 +0000
@@ -32,7 +32,6 @@
static_tuple,
symbol_versioning,
urlutils,
- versionedfile,
vf_repository,
)
from bzrlib.branch import BranchReferenceFormat, BranchWriteLockResult
@@ -1661,6 +1660,8 @@
self._real_repository.create_bundle(target, base, fileobj, format)
@needs_read_lock
+ @symbol_versioning.deprecated_method(
+ symbol_versioning.deprecated_in((2, 4, 0)))
def get_ancestry(self, revision_id, topo_sorted=True):
self._ensure_real()
return self._real_repository.get_ancestry(revision_id, topo_sorted)
=== modified file 'bzrlib/repofmt/knitrepo.py'
--- a/bzrlib/repofmt/knitrepo.py 2011-05-18 10:41:51 +0000
+++ b/bzrlib/repofmt/knitrepo.py 2011-06-16 14:54:47 +0000
@@ -181,31 +181,6 @@
result.get_parent_map([('A',)])
return result
- def fileid_involved_between_revs(self, from_revid, to_revid):
- """Find file_id(s) which are involved in the changes between revisions.
-
- This determines the set of revisions which are involved, and then
- finds all file ids affected by those revisions.
- """
- vf = self._get_revision_vf()
- from_set = set(vf.get_ancestry(from_revid))
- to_set = set(vf.get_ancestry(to_revid))
- changed = to_set.difference(from_set)
- return self._fileid_involved_by_set(changed)
-
- def fileid_involved(self, last_revid=None):
- """Find all file_ids modified in the ancestry of last_revid.
-
- :param last_revid: If None, last_revision() will be used.
- """
- if not last_revid:
- changed = set(self.all_revision_ids())
- else:
- changed = set(self.get_ancestry(last_revid))
- if None in changed:
- changed.remove(None)
- return self._fileid_involved_by_set(changed)
-
@needs_read_lock
def get_revision(self, revision_id):
"""Return the Revision object for a named revision"""
=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py 2011-06-16 12:50:32 +0000
+++ b/bzrlib/repository.py 2011-06-18 13:57:17 +0000
@@ -522,21 +522,21 @@
if revid and committers:
result['committers'] = 0
if revid and revid != _mod_revision.NULL_REVISION:
+ graph = self.get_graph()
if committers:
all_committers = set()
- revisions = self.get_ancestry(revid)
- # pop the leading None
- revisions.pop(0)
- first_revision = None
+ revisions = [r for (r, p) in graph.iter_ancestry([revid])
+ if r != _mod_revision.NULL_REVISION]
+ last_revision = None
if not committers:
# ignore the revisions in the middle - just grab first and last
revisions = revisions[0], revisions[-1]
for revision in self.get_revisions(revisions):
- if not first_revision:
- first_revision = revision
+ if not last_revision:
+ last_revision = revision
if committers:
all_committers.add(revision.committer)
- last_revision = revision
+ first_revision = revision
if committers:
result['committers'] = len(all_committers)
result['firstrev'] = (first_revision.timestamp,
@@ -1056,6 +1056,8 @@
raise NotImplementedError(self.revision_trees)
@needs_read_lock
+ @symbol_versioning.deprecated_method(
+ symbol_versioning.deprecated_in((2, 4, 0)))
def get_ancestry(self, revision_id, topo_sorted=True):
"""Return a list of revision-ids integrated by a revision.
@@ -1065,6 +1067,8 @@
This is topologically sorted.
"""
+ if 'evil' in debug.debug_flags:
+ mutter_callsite(2, "get_ancestry is linear with history.")
if _mod_revision.is_null(revision_id):
return [None]
if not self.has_revision(revision_id):
=== modified file 'bzrlib/revisiontree.py'
--- a/bzrlib/revisiontree.py 2011-05-13 14:02:14 +0000
+++ b/bzrlib/revisiontree.py 2011-06-16 11:58:04 +0000
@@ -179,10 +179,6 @@
def _file_size(self, entry, stat_value):
return entry.text_size
- def _get_ancestors(self, default_revision):
- return set(self._repository.get_ancestry(self._revision_id,
- topo_sorted=False))
-
def walkdirs(self, prefix=""):
_directory = 'directory'
inv = self.inventory
=== modified file 'bzrlib/sign_my_commits.py'
--- a/bzrlib/sign_my_commits.py 2011-04-07 10:36:24 +0000
+++ b/bzrlib/sign_my_commits.py 2011-06-19 17:10:31 +0000
@@ -21,7 +21,9 @@
lazy_import(globals(), """
from bzrlib import (
bzrdir as _mod_bzrdir,
+ errors,
gpg,
+ revision as _mod_revision,
)
""")
from bzrlib.commands import Command
@@ -64,9 +66,16 @@
count = 0
repo.lock_write()
try:
+ graph = repo.get_graph()
repo.start_write_group()
try:
- for rev_id in repo.get_ancestry(branch.last_revision())[1:]:
+ for rev_id, parents in graph.iter_ancestry(
+ [branch.last_revision()]):
+ if _mod_revision.is_null(rev_id):
+ continue
+ if parents is None:
+ # Ignore ghosts
+ continue
if repo.has_signature_for_revision_id(rev_id):
continue
rev = repo.get_revision(rev_id)
=== modified file 'bzrlib/tests/blackbox/test_sign_my_commits.py'
--- a/bzrlib/tests/blackbox/test_sign_my_commits.py 2010-01-25 17:48:22 +0000
+++ b/bzrlib/tests/blackbox/test_sign_my_commits.py 2011-06-19 16:31:57 +0000
@@ -17,14 +17,10 @@
"""Black-box tests for bzr sign-my-commits."""
-import os
-
from bzrlib import (
gpg,
tests,
)
-from bzrlib.testament import Testament
-from bzrlib.workingtree import WorkingTree
class SignMyCommits(tests.TestCaseWithTransport):
@@ -45,7 +41,8 @@
wt.commit("base C", allow_pointless=True, rev_id='C')
wt.commit("base D", allow_pointless=True, rev_id='D',
committer='Alternate <alt at foo.com>')
-
+ wt.add_parent_tree_id("aghost")
+ wt.commit("base E", allow_pointless=True, rev_id='E')
return wt
def assertUnsigned(self, repo, revision_id):
@@ -109,8 +106,11 @@
out = self.run_bzr('sign-my-commits --dry-run')[0]
- self.assertEquals('A\nB\nC\nSigned 3 revisions\n', out)
+ outlines = out.splitlines()
+ self.assertEquals(5, len(outlines))
+ self.assertEquals('Signed 4 revisions', outlines[-1])
self.assertUnsigned(repo, 'A')
self.assertUnsigned(repo, 'B')
self.assertUnsigned(repo, 'C')
self.assertUnsigned(repo, 'D')
+ self.assertUnsigned(repo, 'E')
=== modified file 'bzrlib/tests/matchers.py'
--- a/bzrlib/tests/matchers.py 2010-05-06 11:08:10 +0000
+++ b/bzrlib/tests/matchers.py 2011-06-19 12:45:11 +0000
@@ -27,9 +27,14 @@
"""
__all__ = [
+ 'MatchesAncestry',
'ReturnsUnlockable',
]
+from bzrlib import (
+ revision as _mod_revision,
+ )
+
from testtools.matchers import Mismatch, Matcher
@@ -66,3 +71,45 @@
def describe(self):
return "%s is locked" % self.lockable_thing
+
+
+class _AncestryMismatch(Mismatch):
+ """Ancestry matching mismatch."""
+
+ def __init__(self, tip_revision, got, expected):
+ self.tip_revision = tip_revision
+ self.got = got
+ self.expected = expected
+
+ def describe(self):
+ return "mismatched ancestry for revision %r was %r, expected %r" % (
+ self.tip_revision, self.got, self.expected)
+
+
+class MatchesAncestry(Matcher):
+ """A matcher that checks the ancestry of a particular revision.
+
+ :ivar graph: Graph in which to check the ancestry
+ :ivar revision_id: Revision id of the revision
+ """
+
+ def __init__(self, repository, revision_id):
+ Matcher.__init__(self)
+ self.repository = repository
+ self.revision_id = revision_id
+
+ def __str__(self):
+ return ('MatchesAncestry(repository=%r, revision_id=%r)' % (
+ self.repository, self.revision_id))
+
+ def match(self, expected):
+ self.repository.lock_read()
+ try:
+ graph = self.repository.get_graph()
+ got = [r for r, p in graph.iter_ancestry([self.revision_id])]
+ if _mod_revision.NULL_REVISION in got:
+ got.remove(_mod_revision.NULL_REVISION)
+ finally:
+ self.repository.unlock()
+ if sorted(got) != sorted(expected):
+ return _AncestryMismatch(self.revision_id, sorted(got), sorted(expected))
=== modified file 'bzrlib/tests/per_interrepository/test_interrepository.py'
--- a/bzrlib/tests/per_interrepository/test_interrepository.py 2011-05-18 11:43:37 +0000
+++ b/bzrlib/tests/per_interrepository/test_interrepository.py 2011-06-16 15:29:10 +0000
@@ -27,6 +27,7 @@
TestNotApplicable,
TestSkipped,
)
+from bzrlib.tests.matchers import MatchesAncestry
from bzrlib.tests.per_interrepository import (
TestCaseWithInterRepository,
)
@@ -200,5 +201,5 @@
rev = missing_ghost.get_revision('ghost')
inv = missing_ghost.get_inventory('ghost')
# rev must not be corrupt now
- self.assertEqual([None, 'ghost', 'references', 'tip'],
- missing_ghost.get_ancestry('tip'))
+ self.assertThat(['ghost', 'references', 'tip'],
+ MatchesAncestry(missing_ghost, 'tip'))
=== modified file 'bzrlib/tests/per_repository/test_fileid_involved.py'
--- a/bzrlib/tests/per_repository/test_fileid_involved.py 2011-04-19 10:42:59 +0000
+++ b/bzrlib/tests/per_repository/test_fileid_involved.py 2011-06-16 13:29:36 +0000
@@ -214,16 +214,15 @@
if len(history) < 2: return
+ graph = self.branch.repository.get_graph()
for start in range(0,len(history)-1):
start_id = history[start]
for end in range(start+1,len(history)):
end_id = history[end]
- old_revs = set(self.branch.repository.get_ancestry(start_id))
- new_revs = set(self.branch.repository.get_ancestry(end_id))
+ unique_revs = graph.find_unique_ancestors(end_id, [start_id])
l1 = self.branch.repository.fileids_altered_by_revision_ids(
- new_revs.difference(old_revs))
+ unique_revs)
l1 = set(l1.keys())
-
l2 = self.compare_tree_fileids(self.branch, start_id, end_id)
self.assertEquals(l1, l2)
@@ -305,11 +304,11 @@
history = self.branch.revision_history()
old_rev = history[0]
new_rev = history[1]
- old_revs = set(self.branch.repository.get_ancestry(old_rev))
- new_revs = set(self.branch.repository.get_ancestry(new_rev))
+ graph = self.branch.repository.get_graph()
+ unique_revs = graph.find_unique_ancestors(new_rev, [old_rev])
l1 = self.branch.repository.fileids_altered_by_revision_ids(
- new_revs.difference(old_revs))
+ unique_revs)
l1 = set(l1.keys())
l2 = self.compare_tree_fileids(self.branch, old_rev, new_rev)
=== modified file 'bzrlib/tests/per_repository_vf/test_reconcile.py'
--- a/bzrlib/tests/per_repository_vf/test_reconcile.py 2011-04-19 12:41:46 +0000
+++ b/bzrlib/tests/per_repository_vf/test_reconcile.py 2011-06-19 15:23:02 +0000
@@ -30,6 +30,7 @@
TestCaseWithRepository,
all_repository_vf_format_scenarios,
)
+from bzrlib.tests.matchers import MatchesAncestry
from bzrlib.tests.scenarios import load_tests_apply_scenarios
from bzrlib.uncommit import uncommit
@@ -194,8 +195,7 @@
**kwargs):
# actual low level test.
repo = aBzrDir.open_repository()
- if ([None, 'missing', 'references_missing']
- != repo.get_ancestry('references_missing')):
+ if not repo.has_revision('missing'):
# the repo handles ghosts without corruption, so reconcile has
# nothing to do here. Specifically, this test has the inventory
# 'missing' present and the revision 'missing' missing, so clearly
@@ -215,8 +215,7 @@
self.check_missing_was_removed(repo)
# and the parent list for 'references_missing' should have that
# revision a ghost now.
- self.assertEqual([None, 'references_missing'],
- repo.get_ancestry('references_missing'))
+ self.assertFalse(repo.has_revision('missing'))
def check_missing_was_removed(self, repo):
if repo._reconcile_backsup_inventory:
@@ -265,17 +264,17 @@
# now the current inventory should still have 'ghost'
repo = d.open_repository()
repo.get_inventory('ghost')
- self.assertEqual([None, 'ghost'], repo.get_ancestry('ghost'))
+ self.assertThat(['ghost', 'the_ghost'], MatchesAncestry(repo, 'ghost'))
def test_reweave_inventory_fixes_ancestryfor_a_present_ghost(self):
d = bzrlib.bzrdir.BzrDir.open(self.get_url('inventory_ghost_present'))
repo = d.open_repository()
- ghost_ancestry = repo.get_ancestry('ghost')
- if ghost_ancestry == [None, 'the_ghost', 'ghost']:
+ m = MatchesAncestry(repo, 'ghost')
+ if m.match(['the_ghost', 'ghost']) is None:
# the repo handles ghosts without corruption, so reconcile has
# nothing to do
return
- self.assertEqual([None, 'ghost'], ghost_ancestry)
+ self.assertThat(['ghost'], m)
reconciler = repo.reconcile()
# this is a data corrupting error, so a normal reconcile should fix it.
# one inconsistent parents should have been found : the
@@ -287,8 +286,10 @@
repo = d.open_repository()
repo.get_inventory('ghost')
repo.get_inventory('the_ghost')
- self.assertEqual([None, 'the_ghost', 'ghost'], repo.get_ancestry('ghost'))
- self.assertEqual([None, 'the_ghost'], repo.get_ancestry('the_ghost'))
+ self.assertThat(['the_ghost', 'ghost'],
+ MatchesAncestry(repo, 'ghost'))
+ self.assertThat(['the_ghost'],
+ MatchesAncestry(repo, 'the_ghost'))
def test_text_from_ghost_revision(self):
repo = self.make_repository('text-from-ghost')
=== modified file 'bzrlib/tests/per_repository_vf/test_repository.py'
--- a/bzrlib/tests/per_repository_vf/test_repository.py 2011-05-13 09:35:35 +0000
+++ b/bzrlib/tests/per_repository_vf/test_repository.py 2011-06-19 15:23:02 +0000
@@ -27,6 +27,8 @@
vf_repository,
)
+from bzrlib.symbol_versioning import deprecated_in
+from bzrlib.tests.matchers import MatchesAncestry
from bzrlib.tests.per_repository_vf import (
TestCaseWithRepository,
all_repository_vf_format_scenarios,
@@ -384,13 +386,18 @@
def test_get_ancestry_missing_revision(self):
# get_ancestry(revision that is in some data but not fully installed
# -> NoSuchRevision
+ repo = self.bzrdir.open_repository()
self.assertRaises(errors.NoSuchRevision,
- self.bzrdir.open_repository().get_ancestry, 'orphan')
+ self.applyDeprecated, deprecated_in((2, 4, 0)),
+ repo.get_ancestry, 'orphan')
def test_get_unordered_ancestry(self):
repo = self.bzrdir.open_repository()
- self.assertEqual(set(repo.get_ancestry('rev3')),
- set(repo.get_ancestry('rev3', topo_sorted=False)))
+ self.assertEqual(
+ set(self.applyDeprecated(deprecated_in((2, 4, 0)),
+ repo.get_ancestry, 'rev3')),
+ set(self.applyDeprecated(deprecated_in((2, 4, 0)),
+ repo.get_ancestry, 'rev3', topo_sorted=False)))
def test_reserved_id(self):
repo = self.make_repository('repository')
@@ -457,9 +464,10 @@
def test_corrupt_revision_access_asserts_if_reported_wrong(self):
repo_url = self.get_url('inventory_with_unnecessary_ghost')
repo = _mod_repository.Repository.open(repo_url)
+ m = MatchesAncestry(repo, 'ghost')
reported_wrong = False
try:
- if repo.get_ancestry('ghost') != [None, 'the_ghost', 'ghost']:
+ if m.match(['the_ghost', 'ghost']) is not None:
reported_wrong = True
except errors.CorruptRepository:
# caught the bad data:
=== modified file 'bzrlib/tests/test_ancestry.py'
--- a/bzrlib/tests/test_ancestry.py 2011-01-12 01:01:53 +0000
+++ b/bzrlib/tests/test_ancestry.py 2011-06-16 15:29:10 +0000
@@ -15,25 +15,22 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+from bzrlib.branchbuilder import BranchBuilder
from bzrlib.tests import TestCaseWithMemoryTransport
-from bzrlib.branchbuilder import BranchBuilder
+from bzrlib.tests.matchers import MatchesAncestry
class TestAncestry(TestCaseWithMemoryTransport):
- def assertAncestryEqual(self, expected, revision_id, branch):
- """Assert that the ancestry of revision_id in branch is as expected."""
- ancestry = branch.repository.get_ancestry(revision_id)
- self.assertEqual(expected, ancestry)
-
def test_straightline_ancestry(self):
"""Test ancestry file when just committing."""
builder = BranchBuilder(self.get_transport())
rev_id_one = builder.build_commit()
rev_id_two = builder.build_commit()
branch = builder.get_branch()
- self.assertAncestryEqual([None, rev_id_one, rev_id_two],
- rev_id_two, branch)
- self.assertAncestryEqual([None, rev_id_one], rev_id_one, branch)
+ self.assertThat([rev_id_one, rev_id_two],
+ MatchesAncestry(branch.repository, rev_id_two))
+ self.assertThat([rev_id_one],
+ MatchesAncestry(branch.repository, rev_id_one))
# TODO: check that ancestry is updated to include indirectly merged revisions
=== modified file 'bzrlib/tests/test_commit.py'
--- a/bzrlib/tests/test_commit.py 2011-05-13 12:51:05 +0000
+++ b/bzrlib/tests/test_commit.py 2011-06-16 15:29:10 +0000
@@ -26,13 +26,18 @@
from bzrlib.bzrdir import BzrDirMetaFormat1
from bzrlib.commit import Commit, NullCommitReporter
from bzrlib.config import BranchConfig
-from bzrlib.errors import (PointlessCommit, BzrError, SigningFailed,
- LockContention)
+from bzrlib.errors import (
+ PointlessCommit,
+ BzrError,
+ SigningFailed,
+ LockContention,
+ )
from bzrlib.tests import (
SymlinkFeature,
TestCaseWithTransport,
test_foreign,
)
+from bzrlib.tests.matchers import MatchesAncestry
# TODO: Test commit with some added, and added-but-missing files
@@ -357,8 +362,8 @@
eq = self.assertEquals
eq(b.revision_history(), rev_ids)
for i in range(4):
- anc = b.repository.get_ancestry(rev_ids[i])
- eq(anc, [None] + rev_ids[:i+1])
+ self.assertThat(rev_ids[:i+1],
+ MatchesAncestry(b.repository, rev_ids[i]))
def test_commit_new_subdir_child_selective(self):
wt = self.make_branch_and_tree('.')
=== modified file 'bzrlib/tests/test_graph.py'
--- a/bzrlib/tests/test_graph.py 2011-02-19 17:37:45 +0000
+++ b/bzrlib/tests/test_graph.py 2011-06-16 13:26:38 +0000
@@ -21,7 +21,6 @@
)
from bzrlib.revision import NULL_REVISION
from bzrlib.tests import TestCaseWithMemoryTransport
-from bzrlib.symbol_versioning import deprecated_in
# Ancestry 1:
=== modified file 'bzrlib/tests/test_matchers.py'
--- a/bzrlib/tests/test_matchers.py 2010-05-06 11:08:10 +0000
+++ b/bzrlib/tests/test_matchers.py 2011-06-19 15:23:02 +0000
@@ -18,7 +18,10 @@
from testtools.matchers import *
-from bzrlib.tests import TestCase
+from bzrlib.tests import (
+ TestCase,
+ TestCaseWithTransport,
+ )
from bzrlib.tests.matchers import *
@@ -62,3 +65,42 @@
self.assertNotEqual(None, mismatch)
self.assertThat(mismatch.describe(), Equals("I am da tree is locked"))
+
+class TestMatchesAncestry(TestCaseWithTransport):
+
+ def test__str__(self):
+ matcher = MatchesAncestry("A repository", "arevid")
+ self.assertEqual(
+ "MatchesAncestry(repository='A repository', "
+ "revision_id='arevid')",
+ str(matcher))
+
+ def test_match(self):
+ b = self.make_branch_builder('.')
+ b.start_series()
+ revid1 = b.build_commit()
+ revid2 = b.build_commit()
+ b.finish_series()
+ branch = b.get_branch()
+ m = MatchesAncestry(branch.repository, revid2)
+ self.assertThat([revid2, revid1], m)
+ self.assertThat([revid1, revid2], m)
+ m = MatchesAncestry(branch.repository, revid1)
+ self.assertThat([revid1], m)
+ m = MatchesAncestry(branch.repository, "unknown")
+ self.assertThat(["unknown"], m)
+
+ def test_mismatch(self):
+ b = self.make_branch_builder('.')
+ b.start_series()
+ revid1 = b.build_commit()
+ revid2 = b.build_commit()
+ b.finish_series()
+ branch = b.get_branch()
+ m = MatchesAncestry(branch.repository, revid1)
+ mismatch = m.match([])
+ self.assertIsNot(None, mismatch)
+ self.assertEquals(
+ "mismatched ancestry for revision '%s' was ['%s'], expected []" % (
+ revid1, revid1),
+ mismatch.describe())
=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py 2011-04-27 10:55:49 +0000
+++ b/bzrlib/tests/test_remote.py 2011-06-19 17:49:43 +0000
@@ -32,7 +32,7 @@
config,
controldir,
errors,
- graph,
+ graph as _mod_graph,
inventory,
inventory_delta,
remote,
@@ -3244,12 +3244,14 @@
_, stacked = branch_factory()
source = stacked.repository._get_source(target_repository_format)
tip = stacked.last_revision()
- revs = stacked.repository.get_ancestry(tip)
- search = graph.PendingAncestryResult([tip], stacked.repository)
+ stacked.repository._ensure_real()
+ graph = stacked.repository.get_graph()
+ revs = [r for (r,ps) in graph.iter_ancestry([tip])
+ if r != NULL_REVISION]
+ revs.reverse()
+ search = _mod_graph.PendingAncestryResult([tip], stacked.repository)
self.reset_smart_call_log()
stream = source.get_stream(search)
- if None in revs:
- revs.remove(None)
# We trust that if a revision is in the stream the rest of the new
# content for it is too, as per our main fetch tests; here we are
# checking that the revisions are actually included at all, and their
@@ -3294,7 +3296,7 @@
self.assertEqual(expected_revs, rev_ord)
# Getting topological sort requires VFS calls still - one of which is
# pushing up from the bound branch.
- self.assertLength(13, self.hpss_calls)
+ self.assertLength(14, self.hpss_calls)
def test_stacked_get_stream_groupcompress(self):
# Repository._get_source.get_stream() from a stacked repository with
@@ -3358,7 +3360,7 @@
remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
self.hpss_calls = []
local.repository.fetch(remote_branch.repository,
- fetch_spec=graph.EverythingResult(remote_branch.repository))
+ fetch_spec=_mod_graph.EverythingResult(remote_branch.repository))
self.assertEqual(['Repository.get_stream_1.19'], self.hpss_calls)
def override_verb(self, verb_name, verb):
@@ -3394,7 +3396,7 @@
remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
self.hpss_calls = []
local.repository.fetch(remote_branch.repository,
- fetch_spec=graph.EverythingResult(remote_branch.repository))
+ fetch_spec=_mod_graph.EverythingResult(remote_branch.repository))
# make sure the overridden verb was used
self.assertLength(1, verb_log)
# more than one HPSS call is needed, but because it's a VFS callback
=== modified file 'bzrlib/tests/test_revision.py'
--- a/bzrlib/tests/test_revision.py 2011-01-12 01:01:53 +0000
+++ b/bzrlib/tests/test_revision.py 2011-06-19 16:23:04 +0000
@@ -27,7 +27,7 @@
)
from bzrlib.revision import NULL_REVISION
from bzrlib.tests import TestCase, TestCaseWithTransport
-from bzrlib.trace import mutter
+from bzrlib.tests.matchers import MatchesAncestry
# We're allowed to test deprecated interfaces
warnings.filterwarnings('ignore',
@@ -104,7 +104,7 @@
('a at u-0-5', ['a at u-0-0', 'a at u-0-1', 'a at u-0-2', 'a at u-0-3', 'a at u-0-4',
'b at u-0-3', 'b at u-0-4',
'b at u-0-5', 'a at u-0-5']),
- ('b at u-0-6', ['a at u-0-0', 'a at u-0-1', 'a at u-0-2',
+ ('b at u-0-6', ['a at u-0-0', 'a at u-0-1', 'a at u-0-2', 'a at u-0-4',
'b at u-0-3', 'b at u-0-4',
'b at u-0-5', 'b at u-0-6']),
]
@@ -116,10 +116,8 @@
continue
if rev_id in br2_only and not branch is br2:
continue
- mutter('ancestry of {%s}: %r',
- rev_id, branch.repository.get_ancestry(rev_id))
- result = sorted(branch.repository.get_ancestry(rev_id))
- self.assertEquals(result, [None] + sorted(anc))
+ self.assertThat(anc,
+ MatchesAncestry(branch.repository, rev_id))
class TestIntermediateRevisions(TestCaseWithTransport):
=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py 2011-06-16 07:51:28 +0000
+++ b/bzrlib/workingtree.py 2011-06-18 13:57:17 +0000
@@ -496,13 +496,6 @@
finally:
file.close()
- def _get_ancestors(self, default_revision):
- ancestors = set([default_revision])
- for parent_id in self.get_parent_ids():
- ancestors.update(self.branch.repository.get_ancestry(
- parent_id, topo_sorted=False))
- return ancestors
-
def get_parent_ids(self):
"""See Tree.get_parent_ids.
=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py 2011-05-20 10:49:09 +0000
+++ b/bzrlib/workingtree_4.py 2011-06-16 11:58:04 +0000
@@ -1713,9 +1713,6 @@
annotations = self._repository.texts.annotate(text_key)
return [(key[-1], line) for (key, line) in annotations]
- def _get_ancestors(self, default_revision):
- return set(self._repository.get_ancestry(self._revision_id,
- topo_sorted=False))
def _comparison_data(self, entry, path):
"""See Tree._comparison_data."""
if entry is None:
=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- a/doc/en/release-notes/bzr-2.4.txt 2011-06-17 15:07:25 +0000
+++ b/doc/en/release-notes/bzr-2.4.txt 2011-06-18 13:57:17 +0000
@@ -194,6 +194,10 @@
Use ``Graph.iter_lefthand_ancestry`` instead.
(Jelmer Vernooij, #739481)
+* ``Repository.get_ancestry`` has been deprecated. Use
+ ``Graph.iter_ancestry`` instead.
+ (Jelmer Vernooij, #784511)
+
Internals
*********
More information about the bazaar-commits
mailing list