148
149
if self._partial_revision_history_cache[-1] == _mod_revision.NULL_REVISION:
149
150
self._partial_revision_history_cache.pop()
152
def _get_check_refs(self):
153
"""Get the references needed for check().
157
revid = self.last_revision()
158
return [('revision-existence', revid), ('lefthand-distance', revid)]
152
161
def open(base, _unsupported=False, possible_transports=None):
153
162
"""Open the branch rooted at base.
437
446
# start_revision_id.
438
447
if self._merge_sorted_revisions_cache is None:
439
448
last_revision = self.last_revision()
440
graph = self.repository.get_graph()
441
parent_map = dict(((key, value) for key, value in
442
graph.iter_ancestry([last_revision]) if value is not None))
443
revision_graph = repository._strip_NULL_ghosts(parent_map)
444
revs = tsort.merge_sort(revision_graph, last_revision, None,
446
# Drop the sequence # before caching
447
self._merge_sorted_revisions_cache = [r[1:] for r in revs]
449
last_key = (last_revision,)
450
known_graph = self.repository.revisions.get_known_graph_ancestry(
452
self._merge_sorted_revisions_cache = known_graph.merge_sort(
449
454
filtered = self._filter_merge_sorted_revisions(
450
455
self._merge_sorted_revisions_cache, start_revision_id,
451
456
stop_revision_id, stop_rule)
461
466
"""Iterate over an inclusive range of sorted revisions."""
462
467
rev_iter = iter(merge_sorted_revisions)
463
468
if start_revision_id is not None:
464
for rev_id, depth, revno, end_of_merge in rev_iter:
469
for node in rev_iter:
470
rev_id = node.key[-1]
465
471
if rev_id != start_revision_id:
468
474
# The decision to include the start or not
469
475
# depends on the stop_rule if a stop is provided
471
iter([(rev_id, depth, revno, end_of_merge)]),
476
# so pop this node back into the iterator
477
rev_iter = chain(iter([node]), rev_iter)
474
479
if stop_revision_id is None:
475
for rev_id, depth, revno, end_of_merge in rev_iter:
476
yield rev_id, depth, revno, end_of_merge
481
for node in rev_iter:
482
rev_id = node.key[-1]
483
yield (rev_id, node.merge_depth, node.revno,
477
485
elif stop_rule == 'exclude':
478
for rev_id, depth, revno, end_of_merge in rev_iter:
486
for node in rev_iter:
487
rev_id = node.key[-1]
479
488
if rev_id == stop_revision_id:
481
yield rev_id, depth, revno, end_of_merge
490
yield (rev_id, node.merge_depth, node.revno,
482
492
elif stop_rule == 'include':
483
for rev_id, depth, revno, end_of_merge in rev_iter:
484
yield rev_id, depth, revno, end_of_merge
493
for node in rev_iter:
494
rev_id = node.key[-1]
495
yield (rev_id, node.merge_depth, node.revno,
485
497
if rev_id == stop_revision_id:
487
499
elif stop_rule == 'with-merges':
490
502
left_parent = stop_rev.parent_ids[0]
492
504
left_parent = _mod_revision.NULL_REVISION
493
for rev_id, depth, revno, end_of_merge in rev_iter:
505
for node in rev_iter:
506
rev_id = node.key[-1]
494
507
if rev_id == left_parent:
496
yield rev_id, depth, revno, end_of_merge
509
yield (rev_id, node.merge_depth, node.revno,
498
512
raise ValueError('invalid stop_rule %r' % stop_rule)
669
686
except (errors.NotStacked, errors.UnstackableBranchFormat,
670
687
errors.UnstackableRepositoryFormat):
673
# XXX: Lock correctness - should unlock our old repo if we were
675
# repositories don't offer an interface to remove fallback
676
# repositories today; take the conceptually simpler option and just
678
self.repository = self.bzrdir.find_repository()
679
self.repository.lock_write()
680
# for every revision reference the branch has, ensure it is pulled
682
source_repository = self._get_fallback_repository(old_url)
683
for revision_id in chain([self.last_revision()],
684
self.tags.get_reverse_tag_dict()):
685
self.repository.fetch(source_repository, revision_id,
688
691
self._activate_fallback_location(url)
689
692
# write this out after the repository is stacked to avoid setting a
690
693
# stacked config that doesn't work.
691
694
self._set_config_location('stacked_on_location', url)
697
"""Change a branch to be unstacked, copying data as needed.
699
Don't call this directly, use set_stacked_on_url(None).
701
pb = ui.ui_factory.nested_progress_bar()
703
pb.update("Unstacking")
704
# The basic approach here is to fetch the tip of the branch,
705
# including all available ghosts, from the existing stacked
706
# repository into a new repository object without the fallbacks.
708
# XXX: See <https://launchpad.net/bugs/397286> - this may not be
709
# correct for CHKMap repostiories
710
old_repository = self.repository
711
if len(old_repository._fallback_repositories) != 1:
712
raise AssertionError("can't cope with fallback repositories "
713
"of %r" % (self.repository,))
714
# unlock it, including unlocking the fallback
715
old_repository.unlock()
716
old_repository.lock_read()
718
# Repositories don't offer an interface to remove fallback
719
# repositories today; take the conceptually simpler option and just
720
# reopen it. We reopen it starting from the URL so that we
721
# get a separate connection for RemoteRepositories and can
722
# stream from one of them to the other. This does mean doing
723
# separate SSH connection setup, but unstacking is not a
724
# common operation so it's tolerable.
725
new_bzrdir = bzrdir.BzrDir.open(self.bzrdir.root_transport.base)
726
new_repository = new_bzrdir.find_repository()
727
self.repository = new_repository
728
if self.repository._fallback_repositories:
729
raise AssertionError("didn't expect %r to have "
730
"fallback_repositories"
731
% (self.repository,))
732
# this is not paired with an unlock because it's just restoring
733
# the previous state; the lock's released when set_stacked_on_url
735
self.repository.lock_write()
736
# XXX: If you unstack a branch while it has a working tree
737
# with a pending merge, the pending-merged revisions will no
738
# longer be present. You can (probably) revert and remerge.
740
# XXX: This only fetches up to the tip of the repository; it
741
# doesn't bring across any tags. That's fairly consistent
742
# with how branch works, but perhaps not ideal.
743
self.repository.fetch(old_repository,
744
revision_id=self.last_revision(),
747
old_repository.unlock()
694
751
def _set_tags_bytes(self, bytes):
695
752
"""Mirror method for _get_tags_bytes.
1178
1238
Callers will typically also want to check the repository.
1240
:param refs: Calculated refs for this branch as specified by
1241
branch._get_check_refs()
1180
1242
:return: A BranchCheckResult.
1182
ret = BranchCheckResult(self)
1183
mainline_parent_id = None
1244
result = BranchCheckResult(self)
1184
1245
last_revno, last_revision_id = self.last_revision_info()
1185
real_rev_history = []
1187
for revid in self.repository.iter_reverse_revision_history(
1189
real_rev_history.append(revid)
1190
except errors.RevisionNotPresent:
1191
ret.ghosts_in_mainline = True
1193
ret.ghosts_in_mainline = False
1194
real_rev_history.reverse()
1195
if len(real_rev_history) != last_revno:
1196
raise errors.BzrCheckError('revno does not match len(mainline)'
1197
' %s != %s' % (last_revno, len(real_rev_history)))
1198
# TODO: We should probably also check that real_rev_history actually
1199
# matches self.revision_history()
1200
for revision_id in real_rev_history:
1202
revision = self.repository.get_revision(revision_id)
1203
except errors.NoSuchRevision, e:
1204
raise errors.BzrCheckError("mainline revision {%s} not in repository"
1206
# In general the first entry on the revision history has no parents.
1207
# But it's not illegal for it to have parents listed; this can happen
1208
# in imports from Arch when the parents weren't reachable.
1209
if mainline_parent_id is not None:
1210
if mainline_parent_id not in revision.parent_ids:
1211
raise errors.BzrCheckError("previous revision {%s} not listed among "
1213
% (mainline_parent_id, revision_id))
1214
mainline_parent_id = revision_id
1246
actual_revno = refs[('lefthand-distance', last_revision_id)]
1247
if actual_revno != last_revno:
1248
result.errors.append(errors.BzrCheckError(
1249
'revno does not match len(mainline) %s != %s' % (
1250
last_revno, actual_revno)))
1251
# TODO: We should probably also check that self.revision_history
1252
# matches the repository for older branch formats.
1253
# If looking for the code that cross-checks repository parents against
1254
# the iter_reverse_revision_history output, that is now a repository
1217
1258
def _get_checkout_format(self):
1218
1259
"""Return the most suitable metadir for a checkout of this branch.
1243
1284
# clone call. Or something. 20090224 RBC/spiv.
1244
1285
if revision_id is None:
1245
1286
revision_id = self.last_revision()
1247
dir_to = self.bzrdir.clone_on_transport(to_transport,
1248
revision_id=revision_id, stacked_on=stacked_on,
1249
create_prefix=create_prefix, use_existing_dir=use_existing_dir)
1250
except errors.FileExists:
1251
if not use_existing_dir:
1253
except errors.NoSuchFile:
1254
if not create_prefix:
1287
dir_to = self.bzrdir.clone_on_transport(to_transport,
1288
revision_id=revision_id, stacked_on=stacked_on,
1289
create_prefix=create_prefix, use_existing_dir=use_existing_dir)
1256
1290
return dir_to.open_branch()
1258
1292
def create_checkout(self, to_location, revision_id=None,
2803
2837
:param verbose: Requests more detailed display of what was checked,
2806
note('checked branch %s format %s',
2808
self.branch._format)
2809
if self.ghosts_in_mainline:
2810
note('branch contains ghosts in mainline')
2840
note('checked branch %s format %s', self.branch.base,
2841
self.branch._format)
2842
for error in self.errors:
2843
note('found error:%s', error)
2813
2846
class Converter5to6(object):