15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from copy import deepcopy
19
18
from cStringIO import StringIO
20
from unittest import TestSuite
20
from bzrlib.lazy_import import lazy_import
21
lazy_import(globals(), """
21
22
from warnings import warn
24
25
from bzrlib import (
28
config as _mod_config,
33
revision as _mod_revision,
36
from bzrlib.config import TreeConfig
40
from bzrlib.config import BranchConfig, TreeConfig
41
from bzrlib.lockable_files import LockableFiles, TransportLock
42
from bzrlib.tag import (
37
48
from bzrlib.decorators import needs_read_lock, needs_write_lock
38
import bzrlib.errors as errors
39
from bzrlib.errors import (BzrError, BzrCheckError, DivergedBranches,
40
HistoryMissing, InvalidRevisionId,
41
InvalidRevisionNumber, LockError, NoSuchFile,
49
from bzrlib.errors import (BzrError, BzrCheckError, DivergedBranches,
50
HistoryMissing, InvalidRevisionId,
51
InvalidRevisionNumber, LockError, NoSuchFile,
42
52
NoSuchRevision, NoWorkingTree, NotVersionedError,
43
NotBranchError, UninitializableFormat,
44
UnlistableStore, UnlistableBranch,
53
NotBranchError, UninitializableFormat,
54
UnlistableStore, UnlistableBranch,
46
from bzrlib.lockable_files import LockableFiles, TransportLock
56
from bzrlib.hooks import Hooks
47
57
from bzrlib.symbol_versioning import (deprecated_function,
49
59
DEPRECATED_PARAMETER,
51
zero_eight, zero_nine,
61
zero_eight, zero_nine, zero_sixteen,
53
63
from bzrlib.trace import mutter, note
56
66
BZR_BRANCH_FORMAT_4 = "Bazaar-NG branch, format 0.0.4\n"
57
67
BZR_BRANCH_FORMAT_5 = "Bazaar-NG branch, format 5\n"
58
BZR_BRANCH_FORMAT_6 = "Bazaar-NG branch, format 6\n"
68
BZR_BRANCH_FORMAT_6 = "Bazaar Branch Format 6 (bzr 0.15)\n"
61
71
# TODO: Maybe include checks for common corruption of newlines, etc?
709
957
def __str__(self):
710
958
return self.get_format_string().rstrip()
960
def supports_tags(self):
961
"""True if this format supports tags stored in the branch"""
962
return False # by default
964
# XXX: Probably doesn't really belong here -- mbp 20070212
965
def _initialize_control_files(self, a_bzrdir, utf8_files, lock_filename,
967
branch_transport = a_bzrdir.get_branch_transport(self)
968
control_files = lockable_files.LockableFiles(branch_transport,
969
lock_filename, lock_class)
970
control_files.create_lock()
971
control_files.lock_write()
973
for filename, content in utf8_files:
974
control_files.put_utf8(filename, content)
976
control_files.unlock()
979
class BranchHooks(Hooks):
980
"""A dictionary mapping hook name to a list of callables for branch hooks.
982
e.g. ['set_rh'] Is the list of items to be called when the
983
set_revision_history function is invoked.
987
"""Create the default hooks.
989
These are all empty initially, because by default nothing should get
993
# Introduced in 0.15:
994
# invoked whenever the revision history has been set
995
# with set_revision_history. The api signature is
996
# (branch, revision_history), and the branch will
999
# invoked after a push operation completes.
1000
# the api signature is
1002
# containing the members
1003
# (source, local, master, old_revno, old_revid, new_revno, new_revid)
1004
# where local is the local target branch or None, master is the target
1005
# master branch, and the rest should be self explanatory. The source
1006
# is read locked and the target branches write locked. Source will
1007
# be the local low-latency branch.
1008
self['post_push'] = []
1009
# invoked after a pull operation completes.
1010
# the api signature is
1012
# containing the members
1013
# (source, local, master, old_revno, old_revid, new_revno, new_revid)
1014
# where local is the local branch or None, master is the target
1015
# master branch, and the rest should be self explanatory. The source
1016
# is read locked and the target branches write locked. The local
1017
# branch is the low-latency branch.
1018
self['post_pull'] = []
1019
# invoked after a commit operation completes.
1020
# the api signature is
1021
# (local, master, old_revno, old_revid, new_revno, new_revid)
1022
# old_revid is NULL_REVISION for the first commit to a branch.
1023
self['post_commit'] = []
1024
# invoked after a uncommit operation completes.
1025
# the api signature is
1026
# (local, master, old_revno, old_revid, new_revno, new_revid) where
1027
# local is the local branch or None, master is the target branch,
1028
# and an empty branch recieves new_revno of 0, new_revid of None.
1029
self['post_uncommit'] = []
1032
# install the default hooks into the Branch class.
1033
Branch.hooks = BranchHooks()
713
1036
class BzrBranchFormat4(BranchFormat):
714
1037
"""Bzr branch format 4.
912
1270
it's writable, and can be accessed via the normal filesystem API.
915
def __init__(self, transport=DEPRECATED_PARAMETER, init=DEPRECATED_PARAMETER,
916
relax_version_check=DEPRECATED_PARAMETER, _format=None,
1273
def __init__(self, _format=None,
917
1274
_control_files=None, a_bzrdir=None, _repository=None):
918
"""Create new branch object at a particular location.
920
transport -- A Transport object, defining how to access files.
922
init -- If True, create new control files in a previously
923
unversioned directory. If False, the branch must already
926
relax_version_check -- If true, the usual check for the branch
927
version is not applied. This is intended only for
928
upgrade/recovery type use; it's not guaranteed that
929
all operations will work on old format branches.
1275
"""Create new branch object at a particular location."""
1276
Branch.__init__(self)
931
1277
if a_bzrdir is None:
932
self.bzrdir = bzrdir.BzrDir.open(transport.base)
1278
raise ValueError('a_bzrdir must be supplied')
934
1280
self.bzrdir = a_bzrdir
935
self._transport = self.bzrdir.transport.clone('..')
936
self._base = self._transport.base
1281
# self._transport used to point to the directory containing the
1282
# control directory, but was not used - now it's just the transport
1283
# for the branch control files. mbp 20070212
1284
self._base = self.bzrdir.transport.clone('..').base
937
1285
self._format = _format
938
1286
if _control_files is None:
939
1287
raise ValueError('BzrBranch _control_files is None')
940
1288
self.control_files = _control_files
941
if deprecated_passed(init):
942
warn("BzrBranch.__init__(..., init=XXX): The init parameter is "
943
"deprecated as of bzr 0.8. Please use Branch.create().",
947
# this is slower than before deprecation, oh well never mind.
949
self._initialize(transport.base)
950
self._check_format(_format)
951
if deprecated_passed(relax_version_check):
952
warn("BzrBranch.__init__(..., relax_version_check=XXX_: The "
953
"relax_version_check parameter is deprecated as of bzr 0.8. "
954
"Please use BzrDir.open_downlevel, or a BzrBranchFormat's "
958
if (not relax_version_check
959
and not self._format.is_supported()):
960
raise errors.UnsupportedFormatError(format=fmt)
961
if deprecated_passed(transport):
962
warn("BzrBranch.__init__(transport=XXX...): The transport "
963
"parameter is deprecated as of bzr 0.8. "
964
"Please use Branch.open, or bzrdir.open_branch().",
1289
self._transport = _control_files._transport
967
1290
self.repository = _repository
969
1292
def __str__(self):
1068
1359
@needs_write_lock
1069
1360
def append_revision(self, *revision_ids):
1070
1361
"""See Branch.append_revision."""
1362
revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
1071
1363
for revision_id in revision_ids:
1364
_mod_revision.check_not_reserved_id(revision_id)
1072
1365
mutter("add {%s} to revision-history" % revision_id)
1073
1366
rev_history = self.revision_history()
1074
1367
rev_history.extend(revision_ids)
1075
1368
self.set_revision_history(rev_history)
1370
def _write_revision_history(self, history):
1371
"""Factored out of set_revision_history.
1373
This performs the actual writing to disk.
1374
It is intended to be called by BzrBranch5.set_revision_history."""
1375
self.control_files.put_bytes(
1376
'revision-history', '\n'.join(history))
1077
1378
@needs_write_lock
1078
1379
def set_revision_history(self, rev_history):
1079
1380
"""See Branch.set_revision_history."""
1080
self.control_files.put_utf8(
1081
'revision-history', '\n'.join(rev_history))
1082
transaction = self.get_transaction()
1083
history = transaction.map.find_revision_history()
1084
if history is not None:
1085
# update the revision history in the identity map.
1086
history[:] = list(rev_history)
1087
# this call is disabled because revision_history is
1088
# not really an object yet, and the transaction is for objects.
1089
# transaction.register_dirty(history)
1091
transaction.map.add_revision_history(rev_history)
1092
# this call is disabled because revision_history is
1093
# not really an object yet, and the transaction is for objects.
1094
# transaction.register_clean(history)
1097
def revision_history(self):
1098
"""See Branch.revision_history."""
1099
transaction = self.get_transaction()
1100
history = transaction.map.find_revision_history()
1101
if history is not None:
1102
# mutter("cache hit for revision-history in %s", self)
1103
return list(history)
1104
decode_utf8 = cache_utf8.decode
1105
history = [decode_utf8(l.rstrip('\r\n')) for l in
1106
self.control_files.get('revision-history').readlines()]
1107
transaction.map.add_revision_history(history)
1108
# this call is disabled because revision_history is
1109
# not really an object yet, and the transaction is for objects.
1110
# transaction.register_clean(history, precious=True)
1111
return list(history)
1381
rev_history = [osutils.safe_revision_id(r) for r in rev_history]
1382
self._clear_cached_state()
1383
self._write_revision_history(rev_history)
1384
self._cache_revision_history(rev_history)
1385
for hook in Branch.hooks['set_rh']:
1386
hook(self, rev_history)
1113
1388
@needs_write_lock
1114
def generate_revision_history(self, revision_id, last_rev=None,
1116
"""Create a new revision history that will finish with revision_id.
1118
:param revision_id: the new tip to use.
1119
:param last_rev: The previous last_revision. If not None, then this
1120
must be a ancestory of revision_id, or DivergedBranches is raised.
1121
:param other_branch: The other branch that DivergedBranches should
1122
raise with respect to.
1389
def set_last_revision_info(self, revno, revision_id):
1390
revision_id = osutils.safe_revision_id(revision_id)
1391
history = self._lefthand_history(revision_id)
1392
assert len(history) == revno, '%d != %d' % (len(history), revno)
1393
self.set_revision_history(history)
1395
def _gen_revision_history(self):
1396
history = self.control_files.get('revision-history').read().split('\n')
1397
if history[-1:] == ['']:
1398
# There shouldn't be a trailing newline, but just in case.
1402
def _lefthand_history(self, revision_id, last_rev=None,
1124
1404
# stop_revision must be a descendant of last_revision
1125
1405
stop_graph = self.repository.get_revision_graph(revision_id)
1126
1406
if last_rev is not None and last_rev not in stop_graph:
1179
1477
return self.bzrdir.open_workingtree()
1181
1479
@needs_write_lock
1182
def pull(self, source, overwrite=False, stop_revision=None):
1183
"""See Branch.pull."""
1480
def pull(self, source, overwrite=False, stop_revision=None,
1481
_hook_master=None, run_hooks=True):
1484
:param _hook_master: Private parameter - set the branch to
1485
be supplied as the master to push hooks.
1486
:param run_hooks: Private parameter - if false, this branch
1487
is being called because it's the master of the primary branch,
1488
so it should not run its hooks.
1490
result = PullResult()
1491
result.source_branch = source
1492
result.target_branch = self
1184
1493
source.lock_read()
1186
old_count = len(self.revision_history())
1495
result.old_revno, result.old_revid = self.last_revision_info()
1188
1497
self.update_revisions(source, stop_revision)
1189
1498
except DivergedBranches:
1190
1499
if not overwrite:
1193
self.set_revision_history(source.revision_history())
1194
new_count = len(self.revision_history())
1195
return new_count - old_count
1502
if stop_revision is None:
1503
stop_revision = source.last_revision()
1504
self.generate_revision_history(stop_revision)
1505
result.tag_conflicts = source.tags.merge_to(self.tags)
1506
result.new_revno, result.new_revid = self.last_revision_info()
1508
result.master_branch = _hook_master
1509
result.local_branch = self
1511
result.master_branch = self
1512
result.local_branch = None
1514
for hook in Branch.hooks['post_pull']:
1197
1517
source.unlock()
1520
def _get_parent_location(self):
1521
_locs = ['parent', 'pull', 'x-pull']
1524
return self.control_files.get(l).read().strip('\n')
1530
def push(self, target, overwrite=False, stop_revision=None,
1531
_override_hook_source_branch=None):
1534
This is the basic concrete implementation of push()
1536
:param _override_hook_source_branch: If specified, run
1537
the hooks passing this Branch as the source, rather than self.
1538
This is for use of RemoteBranch, where push is delegated to the
1539
underlying vfs-based Branch.
1541
# TODO: Public option to disable running hooks - should be trivial but
1545
result = self._push_with_bound_branches(target, overwrite,
1547
_override_hook_source_branch=_override_hook_source_branch)
1552
def _push_with_bound_branches(self, target, overwrite,
1554
_override_hook_source_branch=None):
1555
"""Push from self into target, and into target's master if any.
1557
This is on the base BzrBranch class even though it doesn't support
1558
bound branches because the *target* might be bound.
1561
if _override_hook_source_branch:
1562
result.source_branch = _override_hook_source_branch
1563
for hook in Branch.hooks['post_push']:
1566
bound_location = target.get_bound_location()
1567
if bound_location and target.base != bound_location:
1568
# there is a master branch.
1570
# XXX: Why the second check? Is it even supported for a branch to
1571
# be bound to itself? -- mbp 20070507
1572
master_branch = target.get_master_branch()
1573
master_branch.lock_write()
1575
# push into the master from this branch.
1576
self._basic_push(master_branch, overwrite, stop_revision)
1577
# and push into the target branch from this. Note that we push from
1578
# this branch again, because its considered the highest bandwidth
1580
result = self._basic_push(target, overwrite, stop_revision)
1581
result.master_branch = master_branch
1582
result.local_branch = target
1586
master_branch.unlock()
1589
result = self._basic_push(target, overwrite, stop_revision)
1590
# TODO: Why set master_branch and local_branch if there's no
1591
# binding? Maybe cleaner to just leave them unset? -- mbp
1593
result.master_branch = target
1594
result.local_branch = None
1598
def _basic_push(self, target, overwrite, stop_revision):
1599
"""Basic implementation of push without bound branches or hooks.
1601
Must be called with self read locked and target write locked.
1603
result = PushResult()
1604
result.source_branch = self
1605
result.target_branch = target
1606
result.old_revno, result.old_revid = target.last_revision_info()
1608
target.update_revisions(self, stop_revision)
1609
except DivergedBranches:
1613
target.set_revision_history(self.revision_history())
1614
result.tag_conflicts = self.tags.merge_to(target.tags)
1615
result.new_revno, result.new_revid = target.last_revision_info()
1199
1618
def get_parent(self):
1200
1619
"""See Branch.get_parent."""
1202
_locs = ['parent', 'pull', 'x-pull']
1203
1621
assert self.base[-1] == '/'
1206
parent = self.control_files.get(l).read().strip('\n')
1209
# This is an old-format absolute path to a local branch
1210
# turn it into a url
1211
if parent.startswith('/'):
1212
parent = urlutils.local_path_to_url(parent.decode('utf8'))
1214
return urlutils.join(self.base[:-1], parent)
1215
except errors.InvalidURLJoin, e:
1216
raise errors.InaccessibleParent(parent, self.base)
1219
def get_push_location(self):
1220
"""See Branch.get_push_location."""
1221
push_loc = self.get_config().get_user_option('push_location')
1622
parent = self._get_parent_location()
1625
# This is an old-format absolute path to a local branch
1626
# turn it into a url
1627
if parent.startswith('/'):
1628
parent = urlutils.local_path_to_url(parent.decode('utf8'))
1630
return urlutils.join(self.base[:-1], parent)
1631
except errors.InvalidURLJoin, e:
1632
raise errors.InaccessibleParent(parent, self.base)
1224
1634
def set_push_location(self, location):
1225
1635
"""See Branch.set_push_location."""
1226
self.get_config().set_user_option('push_location', location,
1636
self.get_config().set_user_option(
1637
'push_location', location,
1638
store=_mod_config.STORE_LOCATION_NORECURSE)
1229
1640
@needs_write_lock
1230
1641
def set_parent(self, url):
1382
1812
if master is not None:
1383
1813
old_tip = self.last_revision()
1384
1814
self.pull(master, overwrite=True)
1385
if old_tip in self.repository.get_ancestry(self.last_revision()):
1815
if old_tip in self.repository.get_ancestry(self.last_revision(),
1391
class BranchTestProviderAdapter(object):
1392
"""A tool to generate a suite testing multiple branch formats at once.
1394
This is done by copying the test once for each transport and injecting
1395
the transport_server, transport_readonly_server, and branch_format
1396
classes into each copy. Each copy is also given a new id() to make it
1400
def __init__(self, transport_server, transport_readonly_server, formats):
1401
self._transport_server = transport_server
1402
self._transport_readonly_server = transport_readonly_server
1403
self._formats = formats
1405
def adapt(self, test):
1406
result = TestSuite()
1407
for branch_format, bzrdir_format in self._formats:
1408
new_test = deepcopy(test)
1409
new_test.transport_server = self._transport_server
1410
new_test.transport_readonly_server = self._transport_readonly_server
1411
new_test.bzrdir_format = bzrdir_format
1412
new_test.branch_format = branch_format
1413
def make_new_test_id():
1414
new_id = "%s(%s)" % (new_test.id(), branch_format.__class__.__name__)
1415
return lambda: new_id
1416
new_test.id = make_new_test_id()
1417
result.addTest(new_test)
1822
class BzrBranchExperimental(BzrBranch5):
1823
"""Bzr experimental branch format
1826
- a revision-history file.
1828
- a lock dir guarding the branch itself
1829
- all of this stored in a branch/ subdirectory
1830
- works with shared repositories.
1831
- a tag dictionary in the branch
1833
This format is new in bzr 0.15, but shouldn't be used for real data,
1836
This class acts as it's own BranchFormat.
1839
_matchingbzrdir = bzrdir.BzrDirMetaFormat1()
1842
def get_format_string(cls):
1843
"""See BranchFormat.get_format_string()."""
1844
return "Bazaar-NG branch format experimental\n"
1847
def get_format_description(cls):
1848
"""See BranchFormat.get_format_description()."""
1849
return "Experimental branch format"
1852
def get_reference(cls, a_bzrdir):
1853
"""Get the target reference of the branch in a_bzrdir.
1855
format probing must have been completed before calling
1856
this method - it is assumed that the format of the branch
1857
in a_bzrdir is correct.
1859
:param a_bzrdir: The bzrdir to get the branch data from.
1860
:return: None if the branch is not a reference branch.
1865
def _initialize_control_files(cls, a_bzrdir, utf8_files, lock_filename,
1867
branch_transport = a_bzrdir.get_branch_transport(cls)
1868
control_files = lockable_files.LockableFiles(branch_transport,
1869
lock_filename, lock_class)
1870
control_files.create_lock()
1871
control_files.lock_write()
1873
for filename, content in utf8_files:
1874
control_files.put_utf8(filename, content)
1876
control_files.unlock()
1879
def initialize(cls, a_bzrdir):
1880
"""Create a branch of this format in a_bzrdir."""
1881
utf8_files = [('format', cls.get_format_string()),
1882
('revision-history', ''),
1883
('branch-name', ''),
1886
cls._initialize_control_files(a_bzrdir, utf8_files,
1887
'lock', lockdir.LockDir)
1888
return cls.open(a_bzrdir, _found=True)
1891
def open(cls, a_bzrdir, _found=False):
1892
"""Return the branch object for a_bzrdir
1894
_found is a private parameter, do not use it. It is used to indicate
1895
if format probing has already be done.
1898
format = BranchFormat.find_format(a_bzrdir)
1899
assert format.__class__ == cls
1900
transport = a_bzrdir.get_branch_transport(None)
1901
control_files = lockable_files.LockableFiles(transport, 'lock',
1903
return cls(_format=cls,
1904
_control_files=control_files,
1906
_repository=a_bzrdir.find_repository())
1909
def is_supported(cls):
1912
def _make_tags(self):
1913
return BasicTags(self)
1916
def supports_tags(cls):
1920
BranchFormat.register_format(BzrBranchExperimental)
1923
class BzrBranch6(BzrBranch5):
1926
def last_revision_info(self):
1927
revision_string = self.control_files.get('last-revision').read()
1928
revno, revision_id = revision_string.rstrip('\n').split(' ', 1)
1929
revision_id = cache_utf8.get_cached_utf8(revision_id)
1931
return revno, revision_id
1933
def last_revision(self):
1934
"""Return last revision id, or None"""
1935
revision_id = self.last_revision_info()[1]
1936
if revision_id == _mod_revision.NULL_REVISION:
1940
def _write_last_revision_info(self, revno, revision_id):
1941
"""Simply write out the revision id, with no checks.
1943
Use set_last_revision_info to perform this safely.
1945
Does not update the revision_history cache.
1946
Intended to be called by set_last_revision_info and
1947
_write_revision_history.
1949
if revision_id is None:
1950
revision_id = 'null:'
1951
out_string = '%d %s\n' % (revno, revision_id)
1952
self.control_files.put_bytes('last-revision', out_string)
1955
def set_last_revision_info(self, revno, revision_id):
1956
revision_id = osutils.safe_revision_id(revision_id)
1957
if self._get_append_revisions_only():
1958
self._check_history_violation(revision_id)
1959
self._write_last_revision_info(revno, revision_id)
1960
self._clear_cached_state()
1962
def _check_history_violation(self, revision_id):
1963
last_revision = self.last_revision()
1964
if last_revision is None:
1966
if last_revision not in self._lefthand_history(revision_id):
1967
raise errors.AppendRevisionsOnlyViolation(self.base)
1969
def _gen_revision_history(self):
1970
"""Generate the revision history from last revision
1972
history = list(self.repository.iter_reverse_revision_history(
1973
self.last_revision()))
1977
def _write_revision_history(self, history):
1978
"""Factored out of set_revision_history.
1980
This performs the actual writing to disk, with format-specific checks.
1981
It is intended to be called by BzrBranch5.set_revision_history.
1983
if len(history) == 0:
1984
last_revision = 'null:'
1986
if history != self._lefthand_history(history[-1]):
1987
raise errors.NotLefthandHistory(history)
1988
last_revision = history[-1]
1989
if self._get_append_revisions_only():
1990
self._check_history_violation(last_revision)
1991
self._write_last_revision_info(len(history), last_revision)
1994
def append_revision(self, *revision_ids):
1995
revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
1996
if len(revision_ids) == 0:
1998
prev_revno, prev_revision = self.last_revision_info()
1999
for revision in self.repository.get_revisions(revision_ids):
2000
if prev_revision == _mod_revision.NULL_REVISION:
2001
if revision.parent_ids != []:
2002
raise errors.NotLeftParentDescendant(self, prev_revision,
2003
revision.revision_id)
2005
if revision.parent_ids[0] != prev_revision:
2006
raise errors.NotLeftParentDescendant(self, prev_revision,
2007
revision.revision_id)
2008
prev_revision = revision.revision_id
2009
self.set_last_revision_info(prev_revno + len(revision_ids),
2013
def _set_parent_location(self, url):
2014
"""Set the parent branch"""
2015
self._set_config_location('parent_location', url, make_relative=True)
2018
def _get_parent_location(self):
2019
"""Set the parent branch"""
2020
return self._get_config_location('parent_location')
2022
def set_push_location(self, location):
2023
"""See Branch.set_push_location."""
2024
self._set_config_location('push_location', location)
2026
def set_bound_location(self, location):
2027
"""See Branch.set_push_location."""
2029
config = self.get_config()
2030
if location is None:
2031
if config.get_user_option('bound') != 'True':
2034
config.set_user_option('bound', 'False')
2037
self._set_config_location('bound_location', location,
2039
config.set_user_option('bound', 'True')
2042
def _get_bound_location(self, bound):
2043
"""Return the bound location in the config file.
2045
Return None if the bound parameter does not match"""
2046
config = self.get_config()
2047
config_bound = (config.get_user_option('bound') == 'True')
2048
if config_bound != bound:
2050
return self._get_config_location('bound_location', config=config)
2052
def get_bound_location(self):
2053
"""See Branch.set_push_location."""
2054
return self._get_bound_location(True)
2056
def get_old_bound_location(self):
2057
"""See Branch.get_old_bound_location"""
2058
return self._get_bound_location(False)
2060
def set_append_revisions_only(self, enabled):
2065
self.get_config().set_user_option('append_revisions_only', value)
2067
def _get_append_revisions_only(self):
2068
value = self.get_config().get_user_option('append_revisions_only')
2069
return value == 'True'
2071
def _synchronize_history(self, destination, revision_id):
2072
"""Synchronize last revision and revision history between branches.
2074
This version is most efficient when the destination is also a
2075
BzrBranch6, but works for BzrBranch5, as long as the destination's
2076
repository contains all the lefthand ancestors of the intended
2077
last_revision. If not, set_last_revision_info will fail.
2079
:param destination: The branch to copy the history into
2080
:param revision_id: The revision-id to truncate history at. May
2081
be None to copy complete history.
2083
if revision_id is None:
2084
revno, revision_id = self.last_revision_info()
2086
# To figure out the revno for a random revision, we need to build
2087
# the revision history, and count its length.
2088
# We don't care about the order, just how long it is.
2089
# Alternatively, we could start at the current location, and count
2090
# backwards. But there is no guarantee that we will find it since
2091
# it may be a merged revision.
2092
revno = len(list(self.repository.iter_reverse_revision_history(
2094
destination.set_last_revision_info(revno, revision_id)
2096
def _make_tags(self):
2097
return BasicTags(self)
2100
######################################################################
2101
# results of operations
2104
class _Result(object):
2106
def _show_tag_conficts(self, to_file):
2107
if not getattr(self, 'tag_conflicts', None):
2109
to_file.write('Conflicting tags:\n')
2110
for name, value1, value2 in self.tag_conflicts:
2111
to_file.write(' %s\n' % (name, ))
2114
class PullResult(_Result):
2115
"""Result of a Branch.pull operation.
2117
:ivar old_revno: Revision number before pull.
2118
:ivar new_revno: Revision number after pull.
2119
:ivar old_revid: Tip revision id before pull.
2120
:ivar new_revid: Tip revision id after pull.
2121
:ivar source_branch: Source (local) branch object.
2122
:ivar master_branch: Master branch of the target, or None.
2123
:ivar target_branch: Target/destination branch object.
2127
# DEPRECATED: pull used to return the change in revno
2128
return self.new_revno - self.old_revno
2130
def report(self, to_file):
2131
if self.old_revid == self.new_revid:
2132
to_file.write('No revisions to pull.\n')
2134
to_file.write('Now on revision %d.\n' % self.new_revno)
2135
self._show_tag_conficts(to_file)
2138
class PushResult(_Result):
2139
"""Result of a Branch.push operation.
2141
:ivar old_revno: Revision number before push.
2142
:ivar new_revno: Revision number after push.
2143
:ivar old_revid: Tip revision id before push.
2144
:ivar new_revid: Tip revision id after push.
2145
:ivar source_branch: Source branch object.
2146
:ivar master_branch: Master branch of the target, or None.
2147
:ivar target_branch: Target/destination branch object.
2151
# DEPRECATED: push used to return the change in revno
2152
return self.new_revno - self.old_revno
2154
def report(self, to_file):
2155
"""Write a human-readable description of the result."""
2156
if self.old_revid == self.new_revid:
2157
to_file.write('No new revisions to push.\n')
2159
to_file.write('Pushed up to revision %d.\n' % self.new_revno)
2160
self._show_tag_conficts(to_file)
1421
2163
class BranchCheckResult(object):