30
26
from bzrlib.decorators import needs_read_lock, needs_write_lock
31
27
from bzrlib.delta import compare_trees
32
28
import bzrlib.errors as errors
33
from bzrlib.errors import (BzrError, InvalidRevisionNumber, InvalidRevisionId,
34
NoSuchRevision, HistoryMissing, NotBranchError,
35
DivergedBranches, LockError,
36
UninitializableFormat,
38
UnlistableBranch, NoSuchFile, NotVersionedError,
29
from bzrlib.errors import (InvalidRevisionNumber,
40
import bzrlib.inventory as inventory
41
from bzrlib.inventory import Inventory
42
34
from bzrlib.lockable_files import LockableFiles, TransportLock
43
35
from bzrlib.lockdir import LockDir
44
from bzrlib.osutils import (isdir, quotefn,
45
rename, splitpath, sha_file,
46
file_kind, abspath, normpath, pathjoin,
36
from bzrlib.osutils import (
50
from bzrlib.repository import Repository
51
39
from bzrlib.revision import (
56
from bzrlib.store import copy_all
57
from bzrlib.symbol_versioning import *
58
from bzrlib.textui import show_status
42
from bzrlib.symbol_versioning import (deprecated_function,
59
48
from bzrlib.trace import mutter, note
60
import bzrlib.transactions as transactions
61
from bzrlib.transport import Transport, get_transport
62
from bzrlib.tree import EmptyTree, RevisionTree
49
from bzrlib.tree import EmptyTree
50
import bzrlib.ui as ui
64
51
import bzrlib.urlutils as urlutils
68
54
BZR_BRANCH_FORMAT_4 = "Bazaar-NG branch, format 0.0.4\n"
362
348
assert isinstance(stop_revision, int)
363
349
if stop_revision > other_len:
364
raise bzrlib.errors.NoSuchRevision(self, stop_revision)
350
raise errors.NoSuchRevision(self, stop_revision)
365
351
return other_history[self_len:stop_revision]
367
353
def update_revisions(self, other, stop_revision=None):
564
550
In particular this checks that revisions given in the revision-history
565
551
do actually match up in the revision graph, and that they're all
566
552
present in the repository.
554
Callers will typically also want to check the repository.
568
556
:return: A BranchCheckResult.
573
561
revision = self.repository.get_revision(revision_id)
574
562
except errors.NoSuchRevision, e:
575
raise BzrCheckError("mainline revision {%s} not in repository"
563
raise errors.BzrCheckError("mainline revision {%s} not in repository"
577
565
# In general the first entry on the revision history has no parents.
578
566
# But it's not illegal for it to have parents listed; this can happen
579
567
# in imports from Arch when the parents weren't reachable.
580
568
if mainline_parent_id is not None:
581
569
if mainline_parent_id not in revision.parent_ids:
582
raise BzrCheckError("previous revision {%s} not listed among "
570
raise errors.BzrCheckError("previous revision {%s} not listed among "
583
571
"parents of {%s}"
584
572
% (mainline_parent_id, revision_id))
585
573
mainline_parent_id = revision_id
899
887
self._base = self._transport.base
900
888
self._format = _format
901
889
if _control_files is None:
902
raise BzrBadParameterMissing('_control_files')
890
raise ValueError('BzrBranch _control_files is None')
903
891
self.control_files = _control_files
904
892
if deprecated_passed(init):
905
893
warn("BzrBranch.__init__(..., init=XXX): The init parameter is "
921
909
if (not relax_version_check
922
910
and not self._format.is_supported()):
923
911
raise errors.UnsupportedFormatError(
924
'sorry, branch format %r not supported' % fmt,
912
'sorry, branch format %r not supported' % self._format,
925
913
['use a different bzr version',
926
914
'or remove the .bzr directory'
927
915
' and "bzr init" again'])
1152
1140
@deprecated_method(zero_eight)
1153
1141
def working_tree(self):
1154
1142
"""Create a Working tree object for this branch."""
1155
from bzrlib.workingtree import WorkingTree
1156
1143
from bzrlib.transport.local import LocalTransport
1157
1144
if (self.base.find('://') != -1 or
1158
1145
not isinstance(self._transport, LocalTransport)):
1180
1167
def get_parent(self):
1181
1168
"""See Branch.get_parent."""
1183
1169
_locs = ['parent', 'pull', 'x-pull']
1184
1170
assert self.base[-1] == '/'
1185
1171
for l in _locs:
1187
return urlutils.join(self.base[:-1],
1173
return urlutils.join(self.base[:-1],
1188
1174
self.control_files.get(l).read().strip('\n'))
1189
1175
except NoSuchFile:
1420
1406
@deprecated_function(zero_eight)
1421
def ScratchBranch(*args, **kwargs):
1422
"""See bzrlib.bzrdir.ScratchDir."""
1423
d = ScratchDir(*args, **kwargs)
1424
return d.open_branch()
1427
@deprecated_function(zero_eight)
1428
1407
def is_control_file(*args, **kwargs):
1429
1408
"""See bzrlib.workingtree.is_control_file."""
1430
1409
return bzrlib.workingtree.is_control_file(*args, **kwargs)