1471
1472
[parents_provider, other_repository._make_parents_provider()])
1472
1473
return graph.Graph(parents_provider)
1475
def get_versioned_file_checker(self, revisions, revision_versions_cache):
1476
return VersionedFileChecker(revisions, revision_versions_cache, self)
1474
1478
@needs_write_lock
1475
1479
def set_make_working_trees(self, new_value):
1476
1480
"""Set the policy flag for making working trees when creating branches.
1549
1550
revision_id.decode('ascii')
1550
1551
except UnicodeDecodeError:
1551
1552
raise errors.NonAsciiRevisionId(method, self)
1554
def revision_graph_can_have_wrong_parents(self):
1555
"""Is it possible for this repository to have a revision graph with
1558
If True, then this repository must also implement
1559
_find_inconsistent_revision_parents so that check and reconcile can
1560
check for inconsistencies before proceeding with other checks that may
1561
depend on the revision index being consistent.
1563
raise NotImplementedError(self.revision_graph_can_have_wrong_parents)
1555
1565
# remove these delegates a while after bzr 0.15
1556
1566
def __make_delegated(name, from_module):
1557
1567
def _deprecated_repository_forwarder():
2471
2481
if _unescape_re is None:
2472
2482
_unescape_re = re.compile('\&([^;]*);')
2473
2483
return _unescape_re.sub(_unescaper, data)
2486
class _RevisionTextVersionCache(object):
2487
"""A cache of the versionedfile versions for revision and file-id."""
2489
def __init__(self, repository):
2490
self.repository = repository
2491
self.revision_versions = {}
2493
def add_revision_text_versions(self, tree):
2494
"""Cache text version data from the supplied revision tree"""
2496
for path, entry in tree.iter_entries_by_dir():
2497
inv_revisions[entry.file_id] = entry.revision
2498
self.revision_versions[tree.get_revision_id()] = inv_revisions
2499
return inv_revisions
2501
def get_text_version(self, file_id, revision_id):
2502
"""Determine the text version for a given file-id and revision-id"""
2504
inv_revisions = self.revision_versions[revision_id]
2506
tree = self.repository.revision_tree(revision_id)
2507
inv_revisions = self.add_revision_text_versions(tree)
2508
return inv_revisions.get(file_id)
2511
class VersionedFileChecker(object):
2513
def __init__(self, planned_revisions, revision_versions, repository):
2514
self.planned_revisions = planned_revisions
2515
self.revision_versions = revision_versions
2516
self.repository = repository
2518
def calculate_file_version_parents(self, revision_id, file_id):
2519
text_revision = self.revision_versions.get_text_version(
2520
file_id, revision_id)
2521
if text_revision is None:
2523
parents_of_text_revision = self.repository.get_parents(
2525
parents_from_inventories = []
2526
for parent in parents_of_text_revision:
2527
if parent == _mod_revision.NULL_REVISION:
2530
inventory = self.repository.get_inventory(parent)
2531
except errors.RevisionNotPresent:
2535
introduced_in = inventory[file_id].revision
2536
except errors.NoSuchId:
2539
parents_from_inventories.append(introduced_in)
2540
graph = self.repository.get_graph()
2541
heads = set(graph.heads(parents_from_inventories))
2543
for parent in parents_from_inventories:
2544
if parent in heads and parent not in new_parents:
2545
new_parents.append(parent)
2548
def check_file_version_parents(self, weave, file_id):
2550
for num, revision_id in enumerate(self.planned_revisions):
2551
correct_parents = self.calculate_file_version_parents(
2552
revision_id, file_id)
2553
if correct_parents is None:
2555
text_revision = self.revision_versions.get_text_version(
2556
file_id, revision_id)
2557
knit_parents = weave.get_parents(text_revision)
2558
if correct_parents != knit_parents:
2559
result[revision_id] = (knit_parents, correct_parents)