1438
1439
[parents_provider, other_repository._make_parents_provider()])
1439
1440
return graph.Graph(parents_provider)
1442
def get_versioned_file_checker(self, revisions, revision_versions_cache):
1443
return VersionedFileChecker(revisions, revision_versions_cache, self)
1441
1445
@needs_write_lock
1442
1446
def set_make_working_trees(self, new_value):
1443
1447
"""Set the policy flag for making working trees when creating branches.
1516
1517
revision_id.decode('ascii')
1517
1518
except UnicodeDecodeError:
1518
1519
raise errors.NonAsciiRevisionId(method, self)
1521
def revision_graph_can_have_wrong_parents(self):
1522
"""Is it possible for this repository to have a revision graph with
1525
If True, then this repository must also implement
1526
_find_inconsistent_revision_parents so that check and reconcile can
1527
check for inconsistencies before proceeding with other checks that may
1528
depend on the revision index being consistent.
1530
raise NotImplementedError(self.revision_graph_can_have_wrong_parents)
1522
1532
# remove these delegates a while after bzr 0.15
1523
1533
def __make_delegated(name, from_module):
1524
1534
def _deprecated_repository_forwarder():
2407
2417
if _unescape_re is None:
2408
2418
_unescape_re = re.compile('\&([^;]*);')
2409
2419
return _unescape_re.sub(_unescaper, data)
2422
class _RevisionTextVersionCache(object):
2423
"""A cache of the versionedfile versions for revision and file-id."""
2425
def __init__(self, repository):
2426
self.repository = repository
2427
self.revision_versions = {}
2429
def add_revision_text_versions(self, tree):
2430
"""Cache text version data from the supplied revision tree"""
2432
for path, entry in tree.iter_entries_by_dir():
2433
inv_revisions[entry.file_id] = entry.revision
2434
self.revision_versions[tree.get_revision_id()] = inv_revisions
2435
return inv_revisions
2437
def get_text_version(self, file_id, revision_id):
2438
"""Determine the text version for a given file-id and revision-id"""
2440
inv_revisions = self.revision_versions[revision_id]
2442
tree = self.repository.revision_tree(revision_id)
2443
inv_revisions = self.add_revision_text_versions(tree)
2444
return inv_revisions.get(file_id)
2447
class VersionedFileChecker(object):
2449
def __init__(self, planned_revisions, revision_versions, repository):
2450
self.planned_revisions = planned_revisions
2451
self.revision_versions = revision_versions
2452
self.repository = repository
2454
def calculate_file_version_parents(self, revision_id, file_id):
2455
text_revision = self.revision_versions.get_text_version(
2456
file_id, revision_id)
2457
if text_revision is None:
2459
parents_of_text_revision = self.repository.get_parents(
2461
parents_from_inventories = []
2462
for parent in parents_of_text_revision:
2463
if parent == _mod_revision.NULL_REVISION:
2466
inventory = self.repository.get_inventory(parent)
2467
except errors.RevisionNotPresent:
2471
introduced_in = inventory[file_id].revision
2472
except errors.NoSuchId:
2475
parents_from_inventories.append(introduced_in)
2476
graph = self.repository.get_graph()
2477
heads = set(graph.heads(parents_from_inventories))
2479
for parent in parents_from_inventories:
2480
if parent in heads and parent not in new_parents:
2481
new_parents.append(parent)
2484
def check_file_version_parents(self, weave, file_id):
2486
for num, revision_id in enumerate(self.planned_revisions):
2487
correct_parents = self.calculate_file_version_parents(
2488
revision_id, file_id)
2489
if correct_parents is None:
2491
text_revision = self.revision_versions.get_text_version(
2492
file_id, revision_id)
2493
knit_parents = weave.get_parents(text_revision)
2494
if correct_parents != knit_parents:
2495
result[revision_id] = (knit_parents, correct_parents)