92
92
self._revision_id_to_revno_cache = None
93
93
self._partial_revision_id_to_revno_cache = {}
94
94
self._partial_revision_history_cache = []
95
self._tags_bytes = None
95
96
self._last_revision_info_cache = None
96
97
self._merge_sorted_revisions_cache = None
105
106
def _activate_fallback_location(self, url):
106
107
"""Activate the branch/repository from url as a fallback repository."""
108
for existing_fallback_repo in self.repository._fallback_repositories:
109
if existing_fallback_repo.user_url == url:
110
# This fallback is already configured. This probably only
111
# happens because BzrDir.sprout is a horrible mess. To avoid
112
# confusing _unstack we don't add this a second time.
113
mutter('duplicate activation of fallback %r on %r', url, self)
107
115
repo = self._get_fallback_repository(url)
108
116
if repo.has_same_location(self.repository):
109
117
raise errors.UnstackableLocationError(self.user_url, url)
239
248
:return: The bytes of the tags file.
240
249
:seealso: Branch._set_tags_bytes.
242
return self._transport.get_bytes('tags')
251
if self._tags_bytes is None:
252
self._tags_bytes = self._transport.get_bytes('tags')
253
return self._tags_bytes
244
255
def _get_nick(self, local=False, possible_transports=None):
245
256
config = self.get_config()
805
816
old_repository = self.repository
806
817
if len(old_repository._fallback_repositories) != 1:
807
818
raise AssertionError("can't cope with fallback repositories "
808
"of %r" % (self.repository,))
819
"of %r (fallbacks: %r)" % (old_repository,
820
old_repository._fallback_repositories))
809
821
# Open the new repository object.
810
822
# Repositories don't offer an interface to remove fallback
811
823
# repositories today; take the conceptually simpler option and just
877
889
:seealso: Branch._get_tags_bytes.
879
return _run_with_write_locked_target(self, self._transport.put_bytes,
891
return _run_with_write_locked_target(self, self._set_tags_bytes_locked,
894
def _set_tags_bytes_locked(self, bytes):
895
self._tags_bytes = bytes
896
return self._transport.put_bytes('tags', bytes)
882
898
def _cache_revision_history(self, rev_history):
883
899
"""Set the cached revision history to rev_history.
913
929
self._merge_sorted_revisions_cache = None
914
930
self._partial_revision_history_cache = []
915
931
self._partial_revision_id_to_revno_cache = {}
932
self._tags_bytes = None
917
934
def _gen_revision_history(self):
918
935
"""Return sequence of revision hashes on to this branch.
1259
1276
@needs_read_lock
1260
def sprout(self, to_bzrdir, revision_id=None, repository_policy=None):
1277
def sprout(self, to_bzrdir, revision_id=None, repository_policy=None,
1261
1279
"""Create a new line of development from the branch, into to_bzrdir.
1263
1281
to_bzrdir controls the branch format.
1268
1286
if (repository_policy is not None and
1269
1287
repository_policy.requires_stacking()):
1270
1288
to_bzrdir._format.require_stacking(_skip_repo=True)
1271
result = to_bzrdir.create_branch()
1289
result = to_bzrdir.create_branch(repository=repository)
1272
1290
result.lock_write()
1274
1292
if repository_policy is not None:
1362
1380
"""Return the most suitable metadir for a checkout of this branch.
1363
1381
Weaves are used if this branch's repository uses weaves.
1365
if isinstance(self.bzrdir, bzrdir.BzrDirPreSplitOut):
1366
from bzrlib.repofmt import weaverepo
1383
from bzrlib.plugins.weave_fmt.bzrdir import BzrDirPreSplitOut
1384
if isinstance(self.bzrdir, BzrDirPreSplitOut):
1385
from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
1367
1386
format = bzrdir.BzrDirMetaFormat1()
1368
format.repository_format = weaverepo.RepositoryFormat7()
1387
format.repository_format = RepositoryFormat7()
1370
1389
format = self.repository.bzrdir.checkout_metadir()
1371
1390
format.set_branch_format(self._format)
1374
1393
def create_clone_on_transport(self, to_transport, revision_id=None,
1375
stacked_on=None, create_prefix=False, use_existing_dir=False):
1394
stacked_on=None, create_prefix=False, use_existing_dir=False,
1376
1396
"""Create a clone of this branch and its bzrdir.
1378
1398
:param to_transport: The transport to clone onto.
1391
1411
revision_id = self.last_revision()
1392
1412
dir_to = self.bzrdir.clone_on_transport(to_transport,
1393
1413
revision_id=revision_id, stacked_on=stacked_on,
1394
create_prefix=create_prefix, use_existing_dir=use_existing_dir)
1414
create_prefix=create_prefix, use_existing_dir=use_existing_dir,
1395
1416
return dir_to.open_branch()
1397
1418
def create_checkout(self, to_location, revision_id=None,
1522
1543
* an open routine.
1524
1545
Formats are placed in an dict by their format string for reference
1525
during branch opening. Its not required that these be instances, they
1546
during branch opening. It's not required that these be instances, they
1526
1547
can be classes themselves with class methods - it simply depends on
1527
1548
whether state is needed for a given format or not.
1625
1646
def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
1626
lock_type='metadir', set_format=True):
1647
repository=None, lock_type='metadir',
1627
1649
"""Initialize a branch in a bzrdir, with specified files
1629
1651
:param a_bzrdir: The bzrdir to initialize the branch in
1665
1687
control_files.unlock()
1666
branch = self.open(a_bzrdir, name, _found=True)
1688
branch = self.open(a_bzrdir, name, _found=True,
1689
found_repository=repository)
1667
1690
self._run_post_branch_init_hooks(a_bzrdir, name, branch)
1670
def initialize(self, a_bzrdir, name=None):
1693
def initialize(self, a_bzrdir, name=None, repository=None):
1671
1694
"""Create a branch of this format in a_bzrdir.
1673
1696
:param name: Name of the colocated branch to create.
1708
1731
raise NotImplementedError(self.network_name)
1710
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False):
1733
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
1734
found_repository=None):
1711
1735
"""Return the branch object for a_bzrdir
1713
1737
:param a_bzrdir: A BzrDir that contains a branch.
1819
1843
"with a bzrlib.branch.PullResult object and only runs in the "
1820
1844
"bzr client.", (0, 15), None))
1821
1845
self.create_hook(HookPoint('pre_commit',
1822
"Called after a commit is calculated but before it is is "
1846
"Called after a commit is calculated but before it is "
1823
1847
"completed. pre_commit is called with (local, master, old_revno, "
1824
1848
"old_revid, future_revno, future_revid, tree_delta, future_tree"
1825
1849
"). old_revid is NULL_REVISION for the first commit to a branch, "
1995
2019
self.revision_id)
1998
class BzrBranchFormat4(BranchFormat):
1999
"""Bzr branch format 4.
2002
- a revision-history file.
2003
- a branch-lock lock file [ to be shared with the bzrdir ]
2006
def get_format_description(self):
2007
"""See BranchFormat.get_format_description()."""
2008
return "Branch format 4"
2010
def initialize(self, a_bzrdir, name=None):
2011
"""Create a branch of this format in a_bzrdir."""
2012
utf8_files = [('revision-history', ''),
2013
('branch-name', ''),
2015
return self._initialize_helper(a_bzrdir, utf8_files, name=name,
2016
lock_type='branch4', set_format=False)
2019
super(BzrBranchFormat4, self).__init__()
2020
self._matchingbzrdir = bzrdir.BzrDirFormat6()
2022
def network_name(self):
2023
"""The network name for this format is the control dirs disk label."""
2024
return self._matchingbzrdir.get_format_string()
2026
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False):
2027
"""See BranchFormat.open()."""
2029
# we are being called directly and must probe.
2030
raise NotImplementedError
2031
return BzrBranch(_format=self,
2032
_control_files=a_bzrdir._control_files,
2035
_repository=a_bzrdir.open_repository())
2038
return "Bazaar-NG branch format 4"
2041
2022
class BranchFormatMetadir(BranchFormat):
2042
2023
"""Common logic for meta-dir based branch formats."""
2053
2034
return self.get_format_string()
2055
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False):
2036
def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
2037
found_repository=None):
2056
2038
"""See BranchFormat.open()."""
2058
2040
format = BranchFormat.find_format(a_bzrdir, name=name)
2064
2046
control_files = lockable_files.LockableFiles(transport, 'lock',
2065
2047
lockdir.LockDir)
2048
if found_repository is None:
2049
found_repository = a_bzrdir.find_repository()
2066
2050
return self._branch_class()(_format=self,
2067
2051
_control_files=control_files,
2069
2053
a_bzrdir=a_bzrdir,
2070
_repository=a_bzrdir.find_repository(),
2054
_repository=found_repository,
2071
2055
ignore_fallbacks=ignore_fallbacks)
2072
2056
except errors.NoSuchFile:
2073
2057
raise errors.NotBranchError(path=transport.base, bzrdir=a_bzrdir)
2105
2089
"""See BranchFormat.get_format_description()."""
2106
2090
return "Branch format 5"
2108
def initialize(self, a_bzrdir, name=None):
2092
def initialize(self, a_bzrdir, name=None, repository=None):
2109
2093
"""Create a branch of this format in a_bzrdir."""
2110
2094
utf8_files = [('revision-history', ''),
2111
2095
('branch-name', ''),
2113
return self._initialize_helper(a_bzrdir, utf8_files, name)
2097
return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
2115
2099
def supports_tags(self):
2138
2122
"""See BranchFormat.get_format_description()."""
2139
2123
return "Branch format 6"
2141
def initialize(self, a_bzrdir, name=None):
2125
def initialize(self, a_bzrdir, name=None, repository=None):
2142
2126
"""Create a branch of this format in a_bzrdir."""
2143
2127
utf8_files = [('last-revision', '0 null:\n'),
2144
2128
('branch.conf', ''),
2147
return self._initialize_helper(a_bzrdir, utf8_files, name)
2131
return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
2149
2133
def make_tags(self, branch):
2150
2134
"""See bzrlib.branch.BranchFormat.make_tags()."""
2168
2152
"""See BranchFormat.get_format_description()."""
2169
2153
return "Branch format 8"
2171
def initialize(self, a_bzrdir, name=None):
2155
def initialize(self, a_bzrdir, name=None, repository=None):
2172
2156
"""Create a branch of this format in a_bzrdir."""
2173
2157
utf8_files = [('last-revision', '0 null:\n'),
2174
2158
('branch.conf', ''),
2176
2160
('references', '')
2178
return self._initialize_helper(a_bzrdir, utf8_files, name)
2162
return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
2180
2164
def __init__(self):
2181
2165
super(BzrBranchFormat8, self).__init__()
2204
2188
This format was introduced in bzr 1.6.
2207
def initialize(self, a_bzrdir, name=None):
2191
def initialize(self, a_bzrdir, name=None, repository=None):
2208
2192
"""Create a branch of this format in a_bzrdir."""
2209
2193
utf8_files = [('last-revision', '0 null:\n'),
2210
2194
('branch.conf', ''),
2213
return self._initialize_helper(a_bzrdir, utf8_files, name)
2197
return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
2215
2199
def _branch_class(self):
2216
2200
return BzrBranch7
2258
2242
transport = a_bzrdir.get_branch_transport(None, name=name)
2259
2243
location = transport.put_bytes('location', to_branch.base)
2261
def initialize(self, a_bzrdir, name=None, target_branch=None):
2245
def initialize(self, a_bzrdir, name=None, target_branch=None,
2262
2247
"""Create a branch of this format in a_bzrdir."""
2263
2248
if target_branch is None:
2264
2249
# this format does not implement branch itself, thus the implicit
2294
2279
def open(self, a_bzrdir, name=None, _found=False, location=None,
2295
possible_transports=None, ignore_fallbacks=False):
2280
possible_transports=None, ignore_fallbacks=False,
2281
found_repository=None):
2296
2282
"""Return the branch that the branch reference in a_bzrdir points at.
2298
2284
:param a_bzrdir: A BzrDir that contains a branch.
2350
2336
BranchFormat.register_format(__format7)
2351
2337
BranchFormat.register_format(__format8)
2352
2338
BranchFormat.set_default_format(__format7)
2353
_legacy_formats = [BzrBranchFormat4(),
2355
network_format_registry.register(
2356
_legacy_formats[0].network_name(), _legacy_formats[0].__class__)
2359
2341
class BranchWriteLockResult(LogicalLockResult):
3103
3085
:ivar tag_conflicts: A list of tag conflicts, see BasicTags.merge_to
3088
@deprecated_method(deprecated_in((2, 3, 0)))
3106
3089
def __int__(self):
3107
# DEPRECATED: pull used to return the change in revno
3090
"""Return the relative change in revno.
3092
:deprecated: Use `new_revno` and `old_revno` instead.
3108
3094
return self.new_revno - self.old_revno
3110
3096
def report(self, to_file):
3135
3121
target, otherwise it will be None.
3124
@deprecated_method(deprecated_in((2, 3, 0)))
3138
3125
def __int__(self):
3139
# DEPRECATED: push used to return the change in revno
3126
"""Return the relative change in revno.
3128
:deprecated: Use `new_revno` and `old_revno` instead.
3140
3130
return self.new_revno - self.old_revno
3142
3132
def report(self, to_file):
3472
3462
# push into the master from the source branch.
3473
3463
self.source._basic_push(master_branch, overwrite, stop_revision)
3474
3464
# and push into the target branch from the source. Note that we
3475
# push from the source branch again, because its considered the
3465
# push from the source branch again, because it's considered the
3476
3466
# highest bandwidth repository.
3477
3467
result = self.source._basic_push(self.target, overwrite,