766
766
"""Print `file` to stdout."""
767
767
raise NotImplementedError(self.print_file)
769
@deprecated_method(deprecated_in((2, 4, 0)))
770
def set_revision_history(self, rev_history):
771
"""See Branch.set_revision_history."""
772
self._set_revision_history(rev_history)
775
def _set_revision_history(self, rev_history):
776
if len(rev_history) == 0:
777
revid = _mod_revision.NULL_REVISION
779
revid = rev_history[-1]
780
if rev_history != self._lefthand_history(revid):
781
raise errors.NotLefthandHistory(rev_history)
782
self.set_last_revision_info(len(rev_history), revid)
783
self._cache_revision_history(rev_history)
784
for hook in Branch.hooks['set_rh']:
785
hook(self, rev_history)
769
787
@needs_write_lock
770
788
def set_last_revision_info(self, revno, revision_id):
771
789
"""Set the last revision of this branch.
1034
1062
def _read_last_revision_info(self):
1035
1063
raise NotImplementedError(self._read_last_revision_info)
1065
@deprecated_method(deprecated_in((2, 4, 0)))
1066
def import_last_revision_info(self, source_repo, revno, revid):
1067
"""Set the last revision info, importing from another repo if necessary.
1069
:param source_repo: Source repository to optionally fetch from
1070
:param revno: Revision number of the new tip
1071
:param revid: Revision id of the new tip
1073
if not self.repository.has_same_location(source_repo):
1074
self.repository.fetch(source_repo, revision_id=revid)
1075
self.set_last_revision_info(revno, revid)
1037
1077
def import_last_revision_info_and_tags(self, source, revno, revid,
1039
1079
"""Set the last revision info, importing from another repo if necessary.
1577
1617
def __ne__(self, other):
1578
1618
return not (self == other)
1621
@deprecated_method(deprecated_in((2, 4, 0)))
1622
def get_default_format(klass):
1623
"""Return the current default format."""
1624
return format_registry.get_default()
1627
@deprecated_method(deprecated_in((2, 4, 0)))
1628
def get_formats(klass):
1629
"""Get all the known formats.
1631
Warning: This triggers a load of all lazy registered formats: do not
1632
use except when that is desireed.
1634
return format_registry._get_all()
1580
1636
def get_reference(self, controldir, name=None):
1581
1637
"""Get the target reference of the branch in controldir.
1671
1727
raise NotImplementedError(self.open)
1730
@deprecated_method(deprecated_in((2, 4, 0)))
1731
def register_format(klass, format):
1732
"""Register a metadir format.
1734
See MetaDirBranchFormatFactory for the ability to register a format
1735
without loading the code the format needs until it is actually used.
1737
format_registry.register(format)
1740
@deprecated_method(deprecated_in((2, 4, 0)))
1741
def set_default_format(klass, format):
1742
format_registry.set_default(format)
1673
1744
def supports_set_append_revisions_only(self):
1674
1745
"""True if this format supports set_append_revisions_only."""
2039
2121
recommend_upgrade=recommend_upgrade, basedir=basedir)
2124
class BzrBranchFormat5(BranchFormatMetadir):
2125
"""Bzr branch format 5.
2128
- a revision-history file.
2130
- a lock dir guarding the branch itself
2131
- all of this stored in a branch/ subdirectory
2132
- works with shared repositories.
2134
This format is new in bzr 0.8.
2137
def _branch_class(self):
2141
def get_format_string(cls):
2142
"""See BranchFormat.get_format_string()."""
2143
return "Bazaar-NG branch format 5\n"
2145
def get_format_description(self):
2146
"""See BranchFormat.get_format_description()."""
2147
return "Branch format 5"
2149
def initialize(self, a_bzrdir, name=None, repository=None,
2150
append_revisions_only=None):
2151
"""Create a branch of this format in a_bzrdir."""
2152
if append_revisions_only:
2153
raise errors.UpgradeRequired(a_bzrdir.user_url)
2154
utf8_files = [('revision-history', ''),
2155
('branch-name', ''),
2157
return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
2159
def supports_tags(self):
2042
2163
class BzrBranchFormat6(BranchFormatMetadir):
2043
2164
"""Branch format with last-revision and tags.
2623
2749
self.control_transport.put_bytes('format', self._format.as_string())
2752
class FullHistoryBzrBranch(BzrBranch):
2753
"""Bzr branch which contains the full revision history."""
2756
def set_last_revision_info(self, revno, revision_id):
2757
if not revision_id or not isinstance(revision_id, basestring):
2758
raise errors.InvalidRevisionId(revision_id=revision_id, branch=self)
2759
revision_id = _mod_revision.ensure_null(revision_id)
2760
# this old format stores the full history, but this api doesn't
2761
# provide it, so we must generate, and might as well check it's
2763
history = self._lefthand_history(revision_id)
2764
if len(history) != revno:
2765
raise AssertionError('%d != %d' % (len(history), revno))
2766
self._set_revision_history(history)
2768
def _read_last_revision_info(self):
2769
rh = self._revision_history()
2772
return (revno, rh[-1])
2774
return (0, _mod_revision.NULL_REVISION)
2776
@deprecated_method(deprecated_in((2, 4, 0)))
2778
def set_revision_history(self, rev_history):
2779
"""See Branch.set_revision_history."""
2780
self._set_revision_history(rev_history)
2782
def _set_revision_history(self, rev_history):
2783
if 'evil' in debug.debug_flags:
2784
mutter_callsite(3, "set_revision_history scales with history.")
2785
check_not_reserved_id = _mod_revision.check_not_reserved_id
2786
for rev_id in rev_history:
2787
check_not_reserved_id(rev_id)
2788
if Branch.hooks['post_change_branch_tip']:
2789
# Don't calculate the last_revision_info() if there are no hooks
2791
old_revno, old_revid = self.last_revision_info()
2792
if len(rev_history) == 0:
2793
revid = _mod_revision.NULL_REVISION
2795
revid = rev_history[-1]
2796
self._run_pre_change_branch_tip_hooks(len(rev_history), revid)
2797
self._write_revision_history(rev_history)
2798
self._clear_cached_state()
2799
self._cache_revision_history(rev_history)
2800
for hook in Branch.hooks['set_rh']:
2801
hook(self, rev_history)
2802
if Branch.hooks['post_change_branch_tip']:
2803
self._run_post_change_branch_tip_hooks(old_revno, old_revid)
2805
def _write_revision_history(self, history):
2806
"""Factored out of set_revision_history.
2808
This performs the actual writing to disk.
2809
It is intended to be called by set_revision_history."""
2810
self._transport.put_bytes(
2811
'revision-history', '\n'.join(history),
2812
mode=self.bzrdir._get_file_mode())
2814
def _gen_revision_history(self):
2815
history = self._transport.get_bytes('revision-history').split('\n')
2816
if history[-1:] == ['']:
2817
# There shouldn't be a trailing newline, but just in case.
2821
def _synchronize_history(self, destination, revision_id):
2822
if not isinstance(destination, FullHistoryBzrBranch):
2823
super(BzrBranch, self)._synchronize_history(
2824
destination, revision_id)
2826
if revision_id == _mod_revision.NULL_REVISION:
2829
new_history = self._revision_history()
2830
if revision_id is not None and new_history != []:
2832
new_history = new_history[:new_history.index(revision_id) + 1]
2834
rev = self.repository.get_revision(revision_id)
2835
new_history = rev.get_history(self.repository)[1:]
2836
destination._set_revision_history(new_history)
2839
def generate_revision_history(self, revision_id, last_rev=None,
2841
"""Create a new revision history that will finish with revision_id.
2843
:param revision_id: the new tip to use.
2844
:param last_rev: The previous last_revision. If not None, then this
2845
must be a ancestory of revision_id, or DivergedBranches is raised.
2846
:param other_branch: The other branch that DivergedBranches should
2847
raise with respect to.
2849
self._set_revision_history(self._lefthand_history(revision_id,
2850
last_rev, other_branch))
2853
class BzrBranch5(FullHistoryBzrBranch):
2854
"""A format 5 branch. This supports new features over plain branches.
2856
It has support for a master_branch which is the data for bound branches.
2626
2860
class BzrBranch8(BzrBranch):
2627
2861
"""A branch that stores tree-reference locations."""
3283
3516
result.target_branch = self.target
3284
3517
result.old_revno, result.old_revid = self.target.last_revision_info()
3285
3518
self.source.update_references(self.target)
3286
overwrite = _fix_overwrite_type(overwrite)
3287
3519
if result.old_revid != stop_revision:
3288
3520
# We assume that during 'push' this repository is closer than
3290
3522
graph = self.source.repository.get_graph(self.target.repository)
3291
self._update_revisions(stop_revision,
3292
overwrite=("history" in overwrite),
3523
self._update_revisions(stop_revision, overwrite=overwrite,
3294
3525
if self.source._push_should_merge_tags():
3295
3526
result.tag_updates, result.tag_conflicts = (
3296
self.source.tags.merge_to(
3297
self.target.tags, "tags" in overwrite))
3527
self.source.tags.merge_to(self.target.tags, overwrite))
3298
3528
result.new_revno, result.new_revid = self.target.last_revision_info()
3378
3608
# -- JRV20090506
3379
3609
result.old_revno, result.old_revid = \
3380
3610
self.target.last_revision_info()
3381
overwrite = _fix_overwrite_type(overwrite)
3382
self._update_revisions(stop_revision,
3383
overwrite=("history" in overwrite),
3611
self._update_revisions(stop_revision, overwrite=overwrite,
3385
3613
# TODO: The old revid should be specified when merging tags,
3386
3614
# so a tags implementation that versions tags can only
3387
3615
# pull in the most recent changes. -- JRV20090506
3388
3616
result.tag_updates, result.tag_conflicts = (
3389
self.source.tags.merge_to(self.target.tags,
3390
"tags" in overwrite,
3617
self.source.tags.merge_to(self.target.tags, overwrite,
3391
3618
ignore_master=not merge_tags_to_master))
3392
3619
result.new_revno, result.new_revid = self.target.last_revision_info()
3393
3620
if _hook_master: