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 = []
95
94
self._last_revision_info_cache = None
96
95
self._merge_sorted_revisions_cache = None
105
104
def _activate_fallback_location(self, url):
106
105
"""Activate the branch/repository from url as a fallback repository."""
107
106
repo = self._get_fallback_repository(url)
108
if repo.has_same_location(self.repository):
109
raise errors.UnstackableLocationError(self.base, url)
110
107
self.repository.add_fallback_repository(repo)
112
109
def break_lock(self):
128
125
raise errors.UnstackableRepositoryFormat(self.repository._format,
129
126
self.repository.base)
131
def _extend_partial_history(self, stop_index=None, stop_revision=None):
132
"""Extend the partial history to include a given index
134
If a stop_index is supplied, stop when that index has been reached.
135
If a stop_revision is supplied, stop when that revision is
136
encountered. Otherwise, stop when the beginning of history is
139
:param stop_index: The index which should be present. When it is
140
present, history extension will stop.
141
:param stop_revision: The revision id which should be present. When
142
it is encountered, history extension will stop.
144
if len(self._partial_revision_history_cache) == 0:
145
self._partial_revision_history_cache = [self.last_revision()]
146
repository._iter_for_revno(
147
self.repository, self._partial_revision_history_cache,
148
stop_index=stop_index, stop_revision=stop_revision)
149
if self._partial_revision_history_cache[-1] == _mod_revision.NULL_REVISION:
150
self._partial_revision_history_cache.pop()
153
129
def open(base, _unsupported=False, possible_transports=None):
154
130
"""Open the branch rooted at base.
523
499
raise errors.UpgradeRequired(self.base)
525
def set_append_revisions_only(self, enabled):
526
if not self._format.supports_set_append_revisions_only():
527
raise errors.UpgradeRequired(self.base)
532
self.get_config().set_user_option('append_revisions_only', value,
535
501
def set_reference_info(self, file_id, tree_path, branch_location):
536
502
"""Set the branch location to use for a tree reference."""
537
503
raise errors.UnsupportedOperation(self.set_reference_info, self)
732
698
self._revision_id_to_revno_cache = None
733
699
self._last_revision_info_cache = None
734
700
self._merge_sorted_revisions_cache = None
735
self._partial_revision_history_cache = []
736
self._partial_revision_id_to_revno_cache = {}
738
702
def _gen_revision_history(self):
739
703
"""Return sequence of revision hashes on to this branch.
778
742
"""Older format branches cannot bind or unbind."""
779
743
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)
781
749
def last_revision(self):
782
750
"""Return last revision id, or NULL_REVISION."""
783
751
return self.last_revision_info()[1]
863
831
except ValueError:
864
832
raise errors.NoSuchRevision(self, revision_id)
867
834
def get_rev_id(self, revno, history=None):
868
835
"""Find the revision id of the specified revno."""
870
837
return _mod_revision.NULL_REVISION
871
last_revno, last_revid = self.last_revision_info()
872
if revno == last_revno:
874
if revno <= 0 or revno > last_revno:
839
history = self.revision_history()
840
if revno <= 0 or revno > len(history):
875
841
raise errors.NoSuchRevision(self, revno)
876
distance_from_last = last_revno - revno
877
if len(self._partial_revision_history_cache) <= distance_from_last:
878
self._extend_partial_history(distance_from_last)
879
return self._partial_revision_history_cache[distance_from_last]
842
return history[revno - 1]
881
844
@needs_write_lock
882
845
def pull(self, source, overwrite=False, stop_revision=None,
1546
1507
def set_default_format(klass, format):
1547
1508
klass._default_format = format
1549
def supports_set_append_revisions_only(self):
1550
"""True if this format supports set_append_revisions_only."""
1553
1510
def supports_stacking(self):
1554
1511
"""True if this format records a stacked-on branch."""
2427
2376
self._ignore_fallbacks = kwargs.get('ignore_fallbacks', False)
2428
2377
super(BzrBranch8, self).__init__(*args, **kwargs)
2429
2378
self._last_revision_info_cache = None
2379
self._partial_revision_history_cache = []
2430
2380
self._reference_info = None
2432
2382
def _clear_cached_state(self):
2433
2383
super(BzrBranch8, self)._clear_cached_state()
2434
2384
self._last_revision_info_cache = None
2385
self._partial_revision_history_cache = []
2435
2386
self._reference_info = None
2437
2388
def _last_revision_info(self):
2493
2444
self._extend_partial_history(stop_index=last_revno-1)
2494
2445
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:
2496
2476
def _write_revision_history(self, history):
2497
2477
"""Factored out of set_revision_history.
2641
2621
raise errors.NotStacked(self)
2642
2622
return stacked_url
2624
def set_append_revisions_only(self, enabled):
2629
self.get_config().set_user_option('append_revisions_only', value,
2644
2632
def _get_append_revisions_only(self):
2645
2633
value = self.get_config().get_user_option('append_revisions_only')
2646
2634
return value == 'True'