18
18
from copy import deepcopy
19
19
from cStringIO import StringIO
24
20
from unittest import TestSuite
25
21
from warnings import warn
28
import bzrlib.bzrdir as bzrdir
24
from bzrlib import bzrdir, errors, lockdir, osutils, revision, \
29
28
from bzrlib.config import TreeConfig
30
29
from bzrlib.decorators import needs_read_lock, needs_write_lock
31
30
import bzrlib.errors as errors
36
35
NotBranchError, UninitializableFormat,
37
36
UnlistableStore, UnlistableBranch,
39
import bzrlib.inventory as inventory
40
from bzrlib.inventory import Inventory
41
38
from bzrlib.lockable_files import LockableFiles, TransportLock
42
from bzrlib.lockdir import LockDir
43
from bzrlib.osutils import (isdir, quotefn,
44
rename, splitpath, sha_file,
45
file_kind, abspath, normpath, pathjoin,
49
from bzrlib.repository import Repository
50
from bzrlib.revision import (
55
from bzrlib.store import copy_all
56
from bzrlib.symbol_versioning import *
57
from bzrlib.textui import show_status
39
from bzrlib.symbol_versioning import (deprecated_function,
58
45
from bzrlib.trace import mutter, note
59
import bzrlib.transactions as transactions
60
from bzrlib.transport import Transport, get_transport
62
import bzrlib.urlutils as urlutils
66
48
BZR_BRANCH_FORMAT_4 = "Bazaar-NG branch, format 0.0.4\n"
231
213
last_revision = from_history[-1]
233
215
# no history in the source branch
234
last_revision = NULL_REVISION
216
last_revision = revision.NULL_REVISION
235
217
return self.repository.fetch(from_branch.repository,
236
218
revision_id=last_revision,
331
313
If self and other have not diverged, return a list of the revisions
332
314
present in other, but missing from self.
334
>>> from bzrlib.workingtree import WorkingTree
335
>>> bzrlib.trace.silent = True
336
>>> d1 = bzrdir.ScratchDir()
337
>>> br1 = d1.open_branch()
338
>>> wt1 = d1.open_workingtree()
339
>>> d2 = bzrdir.ScratchDir()
340
>>> br2 = d2.open_branch()
341
>>> wt2 = d2.open_workingtree()
342
>>> br1.missing_revisions(br2)
344
>>> wt2.commit("lala!", rev_id="REVISION-ID-1")
346
>>> br1.missing_revisions(br2)
348
>>> br2.missing_revisions(br1)
350
>>> wt1.commit("lala!", rev_id="REVISION-ID-1")
352
>>> br1.missing_revisions(br2)
354
>>> wt2.commit("lala!", rev_id="REVISION-ID-2A")
356
>>> br1.missing_revisions(br2)
358
>>> wt1.commit("lala!", rev_id="REVISION-ID-2B")
360
>>> br1.missing_revisions(br2)
361
Traceback (most recent call last):
362
DivergedBranches: These branches have diverged. Try merge.
364
316
self_history = self.revision_history()
365
317
self_len = len(self_history)
376
328
assert isinstance(stop_revision, int)
377
329
if stop_revision > other_len:
378
raise bzrlib.errors.NoSuchRevision(self, stop_revision)
330
raise errors.NoSuchRevision(self, stop_revision)
379
331
return other_history[self_len:stop_revision]
381
333
def update_revisions(self, other, stop_revision=None):
578
530
In particular this checks that revisions given in the revision-history
579
531
do actually match up in the revision graph, and that they're all
580
532
present in the repository.
534
Callers will typically also want to check the repository.
582
536
:return: A BranchCheckResult.
587
541
revision = self.repository.get_revision(revision_id)
588
542
except errors.NoSuchRevision, e:
589
raise BzrCheckError("mainline revision {%s} not in repository"
543
raise errors.BzrCheckError("mainline revision {%s} not in repository"
591
545
# In general the first entry on the revision history has no parents.
592
546
# But it's not illegal for it to have parents listed; this can happen
593
547
# in imports from Arch when the parents weren't reachable.
594
548
if mainline_parent_id is not None:
595
549
if mainline_parent_id not in revision.parent_ids:
596
raise BzrCheckError("previous revision {%s} not listed among "
550
raise errors.BzrCheckError("previous revision {%s} not listed among "
597
551
"parents of {%s}"
598
552
% (mainline_parent_id, revision_id))
599
553
mainline_parent_id = revision_id
767
721
utf8_files = [('revision-history', ''),
768
722
('branch-name', ''),
770
control_files = LockableFiles(branch_transport, 'lock', LockDir)
724
control_files = LockableFiles(branch_transport, 'lock', lockdir.LockDir)
771
725
control_files.create_lock()
772
726
control_files.lock_write()
773
727
control_files.put_utf8('format', self.get_format_string())
792
746
format = BranchFormat.find_format(a_bzrdir)
793
747
assert format.__class__ == self.__class__
794
748
transport = a_bzrdir.get_branch_transport(None)
795
control_files = LockableFiles(transport, 'lock', LockDir)
749
control_files = LockableFiles(transport, 'lock', lockdir.LockDir)
796
750
return BzrBranch5(_format=self,
797
751
_control_files=control_files,
798
752
a_bzrdir=a_bzrdir,
913
867
self._base = self._transport.base
914
868
self._format = _format
915
869
if _control_files is None:
916
raise BzrBadParameterMissing('_control_files')
870
raise ValueError('BzrBranch _control_files is None')
917
871
self.control_files = _control_files
918
872
if deprecated_passed(init):
919
873
warn("BzrBranch.__init__(..., init=XXX): The init parameter is "
935
889
if (not relax_version_check
936
890
and not self._format.is_supported()):
937
raise errors.UnsupportedFormatError(
938
'sorry, branch format %r not supported' % fmt,
939
['use a different bzr version',
940
'or remove the .bzr directory'
941
' and "bzr init" again'])
891
raise errors.UnsupportedFormatError(format=fmt)
942
892
if deprecated_passed(transport):
943
893
warn("BzrBranch.__init__(transport=XXX...): The transport "
944
894
"parameter is deprecated as of bzr 0.8. "
1011
961
FIXME: DELETE THIS METHOD when pre 0.8 support is removed.
1013
963
if format is None:
1014
format = BzrBranchFormat.find_format(self.bzrdir)
964
format = BranchFormat.find_format(self.bzrdir)
1015
965
self._format = format
1016
966
mutter("got branch format %s", self._format)
1127
1077
# make a new revision history from the graph
1128
1078
current_rev_id = stop_revision
1129
1079
new_history = []
1130
while current_rev_id not in (None, NULL_REVISION):
1080
while current_rev_id not in (None, revision.NULL_REVISION):
1131
1081
new_history.append(current_rev_id)
1132
1082
current_rev_id_parents = stop_graph[current_rev_id]
1146
1096
@deprecated_method(zero_eight)
1147
1097
def working_tree(self):
1148
1098
"""Create a Working tree object for this branch."""
1149
from bzrlib.workingtree import WorkingTree
1150
1100
from bzrlib.transport.local import LocalTransport
1151
1101
if (self.base.find('://') != -1 or
1152
1102
not isinstance(self._transport, LocalTransport)):
1418
1368
@deprecated_function(zero_eight)
1419
def ScratchBranch(*args, **kwargs):
1420
"""See bzrlib.bzrdir.ScratchDir."""
1421
d = ScratchDir(*args, **kwargs)
1422
return d.open_branch()
1425
@deprecated_function(zero_eight)
1426
1369
def is_control_file(*args, **kwargs):
1427
1370
"""See bzrlib.workingtree.is_control_file."""
1428
1371
return bzrlib.workingtree.is_control_file(*args, **kwargs)