91
91
self._revision_history_cache = None
92
92
self._revision_id_to_revno_cache = None
93
93
self._partial_revision_id_to_revno_cache = {}
94
self._partial_revision_history_cache = []
94
95
self._last_revision_info_cache = None
95
96
self._merge_sorted_revisions_cache = None
125
126
raise errors.UnstackableRepositoryFormat(self.repository._format,
126
127
self.repository.base)
129
def _extend_partial_history(self, stop_index=None, stop_revision=None):
130
"""Extend the partial history to include a given index
132
If a stop_index is supplied, stop when that index has been reached.
133
If a stop_revision is supplied, stop when that revision is
134
encountered. Otherwise, stop when the beginning of history is
137
:param stop_index: The index which should be present. When it is
138
present, history extension will stop.
139
:param stop_revision: The revision id which should be present. When
140
it is encountered, history extension will stop.
142
if len(self._partial_revision_history_cache) == 0:
143
self._partial_revision_history_cache = [self.last_revision()]
144
repository._iter_for_revno(
145
self.repository, self._partial_revision_history_cache,
146
stop_index=stop_index, stop_revision=stop_revision)
147
if self._partial_revision_history_cache[-1] == _mod_revision.NULL_REVISION:
148
self._partial_revision_history_cache.pop()
129
151
def open(base, _unsupported=False, possible_transports=None):
130
152
"""Open the branch rooted at base.
499
521
raise errors.UpgradeRequired(self.base)
523
def set_append_revisions_only(self, enabled):
524
if not self._format.supports_set_append_revisions_only():
525
raise errors.UpgradeRequired(self.base)
530
self.get_config().set_user_option('append_revisions_only', value,
501
533
def set_reference_info(self, file_id, tree_path, branch_location):
502
534
"""Set the branch location to use for a tree reference."""
503
535
raise errors.UnsupportedOperation(self.set_reference_info, self)
698
730
self._revision_id_to_revno_cache = None
699
731
self._last_revision_info_cache = None
700
732
self._merge_sorted_revisions_cache = None
733
self._partial_revision_history_cache = []
734
self._partial_revision_id_to_revno_cache = {}
702
736
def _gen_revision_history(self):
703
737
"""Return sequence of revision hashes on to this branch.
742
776
"""Older format branches cannot bind or unbind."""
743
777
raise errors.UpgradeRequired(self.base)
745
def set_append_revisions_only(self, enabled):
746
"""Older format branches are never restricted to append-only"""
747
raise errors.UpgradeRequired(self.base)
749
779
def last_revision(self):
750
780
"""Return last revision id, or NULL_REVISION."""
751
781
return self.last_revision_info()[1]
831
861
except ValueError:
832
862
raise errors.NoSuchRevision(self, revision_id)
834
865
def get_rev_id(self, revno, history=None):
835
866
"""Find the revision id of the specified revno."""
837
868
return _mod_revision.NULL_REVISION
839
history = self.revision_history()
840
if revno <= 0 or revno > len(history):
869
last_revno, last_revid = self.last_revision_info()
870
if revno == last_revno:
872
if revno <= 0 or revno > last_revno:
841
873
raise errors.NoSuchRevision(self, revno)
842
return history[revno - 1]
874
distance_from_last = last_revno - revno
875
if len(self._partial_revision_history_cache) <= distance_from_last:
876
self._extend_partial_history(distance_from_last)
877
return self._partial_revision_history_cache[distance_from_last]
844
879
@needs_write_lock
845
880
def pull(self, source, overwrite=False, stop_revision=None,
1085
1120
source_revno, source_revision_id = self.last_revision_info()
1086
1121
if revision_id is None:
1087
1122
revno, revision_id = source_revno, source_revision_id
1088
elif source_revision_id == revision_id:
1089
# we know the revno without needing to walk all of history
1090
revno = source_revno
1092
# To figure out the revno for a random revision, we need to build
1093
# the revision history, and count its length.
1094
# We don't care about the order, just how long it is.
1095
# Alternatively, we could start at the current location, and count
1096
# backwards. But there is no guarantee that we will find it since
1097
# it may be a merged revision.
1098
revno = len(list(self.repository.iter_reverse_revision_history(
1124
graph = self.repository.get_graph()
1126
revno = graph.find_distance_to_null(revision_id,
1127
[(source_revision_id, source_revno)])
1128
except errors.GhostRevisionsHaveNoRevno:
1129
# Default to 1, if we can't find anything else
1100
1131
destination.set_last_revision_info(revno, revision_id)
1102
1133
@needs_read_lock
1148
1179
:return: A BranchCheckResult.
1181
ret = BranchCheckResult(self)
1150
1182
mainline_parent_id = None
1151
1183
last_revno, last_revision_id = self.last_revision_info()
1152
real_rev_history = list(self.repository.iter_reverse_revision_history(
1184
real_rev_history = []
1186
for revid in self.repository.iter_reverse_revision_history(
1188
real_rev_history.append(revid)
1189
except errors.RevisionNotPresent:
1190
ret.ghosts_in_mainline = True
1192
ret.ghosts_in_mainline = False
1154
1193
real_rev_history.reverse()
1155
1194
if len(real_rev_history) != last_revno:
1156
1195
raise errors.BzrCheckError('revno does not match len(mainline)'
1172
1211
"parents of {%s}"
1173
1212
% (mainline_parent_id, revision_id))
1174
1213
mainline_parent_id = revision_id
1175
return BranchCheckResult(self)
1177
1216
def _get_checkout_format(self):
1178
1217
"""Return the most suitable metadir for a checkout of this branch.
1503
1544
def set_default_format(klass, format):
1504
1545
klass._default_format = format
1547
def supports_set_append_revisions_only(self):
1548
"""True if this format supports set_append_revisions_only."""
1506
1551
def supports_stacking(self):
1507
1552
"""True if this format records a stacked-on branch."""
2372
2425
self._ignore_fallbacks = kwargs.get('ignore_fallbacks', False)
2373
2426
super(BzrBranch8, self).__init__(*args, **kwargs)
2374
2427
self._last_revision_info_cache = None
2375
self._partial_revision_history_cache = []
2376
2428
self._reference_info = None
2378
2430
def _clear_cached_state(self):
2379
2431
super(BzrBranch8, self)._clear_cached_state()
2380
2432
self._last_revision_info_cache = None
2381
self._partial_revision_history_cache = []
2382
2433
self._reference_info = None
2384
2435
def _last_revision_info(self):
2440
2491
self._extend_partial_history(stop_index=last_revno-1)
2441
2492
return list(reversed(self._partial_revision_history_cache))
2443
def _extend_partial_history(self, stop_index=None, stop_revision=None):
2444
"""Extend the partial history to include a given index
2446
If a stop_index is supplied, stop when that index has been reached.
2447
If a stop_revision is supplied, stop when that revision is
2448
encountered. Otherwise, stop when the beginning of history is
2451
:param stop_index: The index which should be present. When it is
2452
present, history extension will stop.
2453
:param revision_id: The revision id which should be present. When
2454
it is encountered, history extension will stop.
2456
repo = self.repository
2457
if len(self._partial_revision_history_cache) == 0:
2458
iterator = repo.iter_reverse_revision_history(self.last_revision())
2460
start_revision = self._partial_revision_history_cache[-1]
2461
iterator = repo.iter_reverse_revision_history(start_revision)
2462
#skip the last revision in the list
2463
next_revision = iterator.next()
2464
for revision_id in iterator:
2465
self._partial_revision_history_cache.append(revision_id)
2466
if (stop_index is not None and
2467
len(self._partial_revision_history_cache) > stop_index):
2469
if revision_id == stop_revision:
2472
2494
def _write_revision_history(self, history):
2473
2495
"""Factored out of set_revision_history.
2617
2639
raise errors.NotStacked(self)
2618
2640
return stacked_url
2620
def set_append_revisions_only(self, enabled):
2625
self.get_config().set_user_option('append_revisions_only', value,
2628
2642
def _get_append_revisions_only(self):
2629
2643
value = self.get_config().get_user_option('append_revisions_only')
2630
2644
return value == 'True'
2781
2795
def __init__(self, branch):
2782
2796
self.branch = branch
2797
self.ghosts_in_mainline = False
2784
2799
def report_results(self, verbose):
2785
2800
"""Report the check results via trace.note.
2790
2805
note('checked branch %s format %s',
2791
2806
self.branch.base,
2792
2807
self.branch._format)
2808
if self.ghosts_in_mainline:
2809
note('branch contains ghosts in mainline')
2795
2812
class Converter5to6(object):