28
28
from bzrlib.config import TreeConfig
29
29
from bzrlib.decorators import needs_read_lock, needs_write_lock
30
from bzrlib.delta import compare_trees
31
from bzrlib.errors import (InvalidRevisionNumber,
30
import bzrlib.errors as errors
31
from bzrlib.errors import (BzrError, BzrCheckError, DivergedBranches,
32
HistoryMissing, InvalidRevisionId,
33
InvalidRevisionNumber, LockError, NoSuchFile,
34
NoSuchRevision, NoWorkingTree, NotVersionedError,
35
NotBranchError, UninitializableFormat,
36
UnlistableStore, UnlistableBranch,
36
38
from bzrlib.lockable_files import LockableFiles, TransportLock
37
39
from bzrlib.symbol_versioning import (deprecated_function,
260
def get_revision_delta(self, revno):
261
"""Return the delta for one revision.
263
The delta is relative to its mainline predecessor, or the
264
empty tree for revision 1.
266
assert isinstance(revno, int)
267
rh = self.revision_history()
268
if not (1 <= revno <= len(rh)):
269
raise InvalidRevisionNumber(revno)
270
return self.repository.get_revision_delta(rh[revno-1])
258
272
def get_root_id(self):
259
273
"""Return the id of this branches root"""
260
274
raise NotImplementedError('get_root_id is abstract')
299
313
If self and other have not diverged, return a list of the revisions
300
314
present in other, but missing from self.
302
>>> from bzrlib.workingtree import WorkingTree
303
>>> bzrlib.trace.silent = True
304
>>> d1 = bzrdir.ScratchDir()
305
>>> br1 = d1.open_branch()
306
>>> wt1 = d1.open_workingtree()
307
>>> d2 = bzrdir.ScratchDir()
308
>>> br2 = d2.open_branch()
309
>>> wt2 = d2.open_workingtree()
310
>>> br1.missing_revisions(br2)
312
>>> wt2.commit("lala!", rev_id="REVISION-ID-1")
313
>>> br1.missing_revisions(br2)
315
>>> br2.missing_revisions(br1)
317
>>> wt1.commit("lala!", rev_id="REVISION-ID-1")
318
>>> br1.missing_revisions(br2)
320
>>> wt2.commit("lala!", rev_id="REVISION-ID-2A")
321
>>> br1.missing_revisions(br2)
323
>>> wt1.commit("lala!", rev_id="REVISION-ID-2B")
324
>>> br1.missing_revisions(br2)
325
Traceback (most recent call last):
326
DivergedBranches: These branches have diverged. Try merge.
328
316
self_history = self.revision_history()
329
317
self_len = len(self_history)
901
889
if (not relax_version_check
902
890
and not self._format.is_supported()):
903
raise errors.UnsupportedFormatError(
904
'sorry, branch format %r not supported' % self._format,
905
['use a different bzr version',
906
'or remove the .bzr directory'
907
' and "bzr init" again'])
891
raise errors.UnsupportedFormatError(format=fmt)
908
892
if deprecated_passed(transport):
909
893
warn("BzrBranch.__init__(transport=XXX...): The transport "
910
894
"parameter is deprecated as of bzr 0.8. "
1049
1033
# not really an object yet, and the transaction is for objects.
1050
1034
# transaction.register_clean(history)
1052
def get_revision_delta(self, revno):
1053
"""Return the delta for one revision.
1055
The delta is relative to its mainline predecessor, or the
1056
empty tree for revision 1.
1058
assert isinstance(revno, int)
1059
rh = self.revision_history()
1060
if not (1 <= revno <= len(rh)):
1061
raise InvalidRevisionNumber(revno)
1063
# revno is 1-based; list is 0-based
1065
new_tree = self.repository.revision_tree(rh[revno-1])
1067
old_tree = tree.EmptyTree()
1069
old_tree = self.repository.revision_tree(rh[revno-2])
1070
return compare_trees(old_tree, new_tree)
1072
1036
@needs_read_lock
1073
1037
def revision_history(self):
1074
1038
"""See Branch.revision_history."""
1132
1096
@deprecated_method(zero_eight)
1133
1097
def working_tree(self):
1134
1098
"""Create a Working tree object for this branch."""
1135
1100
from bzrlib.transport.local import LocalTransport
1136
1101
if (self.base.find('://') != -1 or
1137
1102
not isinstance(self._transport, LocalTransport)):
1159
1124
def get_parent(self):
1160
1125
"""See Branch.get_parent."""
1161
1127
_locs = ['parent', 'pull', 'x-pull']
1162
1128
assert self.base[-1] == '/'
1163
1129
for l in _locs:
1165
return urlutils.join(self.base[:-1],
1166
self.control_files.get(l).read().strip('\n'))
1131
parent = self.control_files.get(l).read().strip('\n')
1167
1132
except NoSuchFile:
1134
# This is an old-format absolute path to a local branch
1135
# turn it into a url
1136
if parent.startswith('/'):
1137
parent = urlutils.local_path_to_url(parent.decode('utf8'))
1138
return urlutils.join(self.base[:-1], parent)
1171
1141
def get_push_location(self):