2039
2039
recommend_upgrade=recommend_upgrade, basedir=basedir)
2042
class BzrBranchFormat5(BranchFormatMetadir):
2043
"""Bzr branch format 5.
2046
- a revision-history file.
2048
- a lock dir guarding the branch itself
2049
- all of this stored in a branch/ subdirectory
2050
- works with shared repositories.
2052
This format is new in bzr 0.8.
2055
def _branch_class(self):
2059
def get_format_string(cls):
2060
"""See BranchFormat.get_format_string()."""
2061
return "Bazaar-NG branch format 5\n"
2063
def get_format_description(self):
2064
"""See BranchFormat.get_format_description()."""
2065
return "Branch format 5"
2067
def initialize(self, a_bzrdir, name=None, repository=None,
2068
append_revisions_only=None):
2069
"""Create a branch of this format in a_bzrdir."""
2070
if append_revisions_only:
2071
raise errors.UpgradeRequired(a_bzrdir.user_url)
2072
utf8_files = [('revision-history', ''),
2073
('branch-name', ''),
2075
return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
2077
def supports_tags(self):
2081
2042
class BzrBranchFormat6(BranchFormatMetadir):
2082
2043
"""Branch format with last-revision and tags.
2333
2294
# formats which have no format string are not discoverable
2334
2295
# and not independently creatable, so are not registered.
2335
__format5 = BzrBranchFormat5()
2336
2296
__format6 = BzrBranchFormat6()
2337
2297
__format7 = BzrBranchFormat7()
2338
2298
__format8 = BzrBranchFormat8()
2339
format_registry.register(__format5)
2299
format_registry.register_lazy(
2300
"Bazaar-NG branch format 5\n", "bzrlib.branchfmt.fullhistory", "BzrBranchFormat5")
2340
2301
format_registry.register(BranchReferenceFormat())
2341
2302
format_registry.register(__format6)
2342
2303
format_registry.register(__format7)
2662
2623
self.control_transport.put_bytes('format', self._format.as_string())
2665
class FullHistoryBzrBranch(BzrBranch):
2666
"""Bzr branch which contains the full revision history."""
2669
def set_last_revision_info(self, revno, revision_id):
2670
if not revision_id or not isinstance(revision_id, basestring):
2671
raise errors.InvalidRevisionId(revision_id=revision_id, branch=self)
2672
revision_id = _mod_revision.ensure_null(revision_id)
2673
# this old format stores the full history, but this api doesn't
2674
# provide it, so we must generate, and might as well check it's
2676
history = self._lefthand_history(revision_id)
2677
if len(history) != revno:
2678
raise AssertionError('%d != %d' % (len(history), revno))
2679
self._set_revision_history(history)
2681
def _read_last_revision_info(self):
2682
rh = self._revision_history()
2685
return (revno, rh[-1])
2687
return (0, _mod_revision.NULL_REVISION)
2689
def _set_revision_history(self, rev_history):
2690
if 'evil' in debug.debug_flags:
2691
mutter_callsite(3, "set_revision_history scales with history.")
2692
check_not_reserved_id = _mod_revision.check_not_reserved_id
2693
for rev_id in rev_history:
2694
check_not_reserved_id(rev_id)
2695
if Branch.hooks['post_change_branch_tip']:
2696
# Don't calculate the last_revision_info() if there are no hooks
2698
old_revno, old_revid = self.last_revision_info()
2699
if len(rev_history) == 0:
2700
revid = _mod_revision.NULL_REVISION
2702
revid = rev_history[-1]
2703
self._run_pre_change_branch_tip_hooks(len(rev_history), revid)
2704
self._write_revision_history(rev_history)
2705
self._clear_cached_state()
2706
self._cache_revision_history(rev_history)
2707
if Branch.hooks['post_change_branch_tip']:
2708
self._run_post_change_branch_tip_hooks(old_revno, old_revid)
2710
def _write_revision_history(self, history):
2711
"""Factored out of set_revision_history.
2713
This performs the actual writing to disk.
2714
It is intended to be called by set_revision_history."""
2715
self._transport.put_bytes(
2716
'revision-history', '\n'.join(history),
2717
mode=self.bzrdir._get_file_mode())
2719
def _gen_revision_history(self):
2720
history = self._transport.get_bytes('revision-history').split('\n')
2721
if history[-1:] == ['']:
2722
# There shouldn't be a trailing newline, but just in case.
2726
def _synchronize_history(self, destination, revision_id):
2727
if not isinstance(destination, FullHistoryBzrBranch):
2728
super(BzrBranch, self)._synchronize_history(
2729
destination, revision_id)
2731
if revision_id == _mod_revision.NULL_REVISION:
2734
new_history = self._revision_history()
2735
if revision_id is not None and new_history != []:
2737
new_history = new_history[:new_history.index(revision_id) + 1]
2739
rev = self.repository.get_revision(revision_id)
2740
new_history = rev.get_history(self.repository)[1:]
2741
destination._set_revision_history(new_history)
2744
def generate_revision_history(self, revision_id, last_rev=None,
2746
"""Create a new revision history that will finish with revision_id.
2748
:param revision_id: the new tip to use.
2749
:param last_rev: The previous last_revision. If not None, then this
2750
must be a ancestory of revision_id, or DivergedBranches is raised.
2751
:param other_branch: The other branch that DivergedBranches should
2752
raise with respect to.
2754
self._set_revision_history(self._lefthand_history(revision_id,
2755
last_rev, other_branch))
2758
class BzrBranch5(FullHistoryBzrBranch):
2759
"""A format 5 branch. This supports new features over plain branches.
2761
It has support for a master_branch which is the data for bound branches.
2765
2626
class BzrBranch8(BzrBranch):
2766
2627
"""A branch that stores tree-reference locations."""