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,
1507
1544
def set_default_format(klass, format):
1508
1545
klass._default_format = format
1547
def supports_set_append_revisions_only(self):
1548
"""True if this format supports set_append_revisions_only."""
1510
1551
def supports_stacking(self):
1511
1552
"""True if this format records a stacked-on branch."""
2376
2425
self._ignore_fallbacks = kwargs.get('ignore_fallbacks', False)
2377
2426
super(BzrBranch8, self).__init__(*args, **kwargs)
2378
2427
self._last_revision_info_cache = None
2379
self._partial_revision_history_cache = []
2380
2428
self._reference_info = None
2382
2430
def _clear_cached_state(self):
2383
2431
super(BzrBranch8, self)._clear_cached_state()
2384
2432
self._last_revision_info_cache = None
2385
self._partial_revision_history_cache = []
2386
2433
self._reference_info = None
2388
2435
def _last_revision_info(self):
2444
2491
self._extend_partial_history(stop_index=last_revno-1)
2445
2492
return list(reversed(self._partial_revision_history_cache))
2447
def _extend_partial_history(self, stop_index=None, stop_revision=None):
2448
"""Extend the partial history to include a given index
2450
If a stop_index is supplied, stop when that index has been reached.
2451
If a stop_revision is supplied, stop when that revision is
2452
encountered. Otherwise, stop when the beginning of history is
2455
:param stop_index: The index which should be present. When it is
2456
present, history extension will stop.
2457
:param revision_id: The revision id which should be present. When
2458
it is encountered, history extension will stop.
2460
repo = self.repository
2461
if len(self._partial_revision_history_cache) == 0:
2462
iterator = repo.iter_reverse_revision_history(self.last_revision())
2464
start_revision = self._partial_revision_history_cache[-1]
2465
iterator = repo.iter_reverse_revision_history(start_revision)
2466
#skip the last revision in the list
2467
next_revision = iterator.next()
2468
for revision_id in iterator:
2469
self._partial_revision_history_cache.append(revision_id)
2470
if (stop_index is not None and
2471
len(self._partial_revision_history_cache) > stop_index):
2473
if revision_id == stop_revision:
2476
2494
def _write_revision_history(self, history):
2477
2495
"""Factored out of set_revision_history.
2621
2639
raise errors.NotStacked(self)
2622
2640
return stacked_url
2624
def set_append_revisions_only(self, enabled):
2629
self.get_config().set_user_option('append_revisions_only', value,
2632
2642
def _get_append_revisions_only(self):
2633
2643
value = self.get_config().get_user_option('append_revisions_only')
2634
2644
return value == 'True'