15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from cStringIO import StringIO
20
18
from bzrlib.lazy_import import lazy_import
21
19
lazy_import(globals(), """
22
from warnings import warn
25
20
from bzrlib import (
34
28
revision as _mod_revision,
41
from bzrlib.config import BranchConfig, TreeConfig
42
from bzrlib.lockable_files import LockableFiles, TransportLock
34
from bzrlib.config import BranchConfig
43
35
from bzrlib.tag import (
49
41
from bzrlib.decorators import needs_read_lock, needs_write_lock
50
from bzrlib.errors import (BzrError, BzrCheckError, DivergedBranches,
51
HistoryMissing, InvalidRevisionId,
52
InvalidRevisionNumber, LockError, NoSuchFile,
53
NoSuchRevision, NotVersionedError,
54
NotBranchError, UninitializableFormat,
55
UnlistableStore, UnlistableBranch,
57
42
from bzrlib.hooks import Hooks
58
from bzrlib.symbol_versioning import (deprecated_function,
62
zero_eight, zero_nine, zero_sixteen,
43
from bzrlib.symbol_versioning import (deprecated_method,
65
46
from bzrlib.trace import mutter, mutter_callsite, note, is_quiet
279
260
if last_revision is None:
280
261
pb.update('get source history')
281
262
last_revision = from_branch.last_revision()
282
if last_revision is None:
283
last_revision = _mod_revision.NULL_REVISION
263
last_revision = _mod_revision.ensure_null(last_revision)
284
264
return self.repository.fetch(from_branch.repository,
285
265
revision_id=last_revision,
338
318
assert isinstance(revno, int)
339
319
rh = self.revision_history()
340
320
if not (1 <= revno <= len(rh)):
341
raise InvalidRevisionNumber(revno)
321
raise errors.InvalidRevisionNumber(revno)
342
322
return self.repository.get_revision_delta(rh[revno-1])
344
324
@deprecated_method(zero_sixteen)
464
444
common_index = min(self_len, other_len) -1
465
445
if common_index >= 0 and \
466
446
self_history[common_index] != other_history[common_index]:
467
raise DivergedBranches(self, other)
447
raise errors.DivergedBranches(self, other)
469
449
if stop_revision is None:
470
450
stop_revision = other_len
643
623
Zero (the NULL revision) is considered invalid
645
625
if revno < 1 or revno > self.revno():
646
raise InvalidRevisionNumber(revno)
626
raise errors.InvalidRevisionNumber(revno)
649
629
def clone(self, to_bzrdir, revision_id=None):
755
735
def create_checkout(self, to_location, revision_id=None,
756
lightweight=False, accelerator_tree=None):
736
lightweight=False, accelerator_tree=None,
757
738
"""Create a checkout of a branch.
759
740
:param to_location: The url to produce the checkout at
764
745
contents more quickly than the revision tree, i.e. a workingtree.
765
746
The revision tree will be used for cases where accelerator_tree's
766
747
content is different.
748
:param hardlink: If true, hard-link files from accelerator_tree,
767
750
:return: The tree of the created checkout
769
752
t = transport.get_transport(to_location)
785
768
tree = checkout.create_workingtree(revision_id,
786
769
from_branch=from_branch,
787
accelerator_tree=accelerator_tree)
770
accelerator_tree=accelerator_tree,
788
772
basis_tree = tree.basis_tree()
789
773
basis_tree.lock_read()
847
831
transport = a_bzrdir.get_branch_transport(None)
848
832
format_string = transport.get("format").read()
849
833
return klass._formats[format_string]
851
raise NotBranchError(path=transport.base)
834
except errors.NoSuchFile:
835
raise errors.NotBranchError(path=transport.base)
853
raise errors.UnknownFormatError(format=format_string)
837
raise errors.UnknownFormatError(format=format_string, kind='branch')
856
840
def get_default_format(klass):
1136
1120
_control_files=control_files,
1137
1121
a_bzrdir=a_bzrdir,
1138
1122
_repository=a_bzrdir.find_repository())
1140
raise NotBranchError(path=transport.base)
1123
except errors.NoSuchFile:
1124
raise errors.NotBranchError(path=transport.base)
1143
1127
class BzrBranchFormat6(BzrBranchFormat5):
1409
1393
configured to check constraints on history, in which case this may not
1396
revision_id = _mod_revision.ensure_null(revision_id)
1412
1397
history = self._lefthand_history(revision_id)
1413
1398
assert len(history) == revno, '%d != %d' % (len(history), revno)
1414
1399
self.set_revision_history(history)
1425
1410
if 'evil' in debug.debug_flags:
1426
1411
mutter_callsite(4, "_lefthand_history scales with history.")
1427
1412
# stop_revision must be a descendant of last_revision
1428
stop_graph = self.repository.get_revision_graph(revision_id)
1429
if (last_rev is not None and last_rev != _mod_revision.NULL_REVISION
1430
and last_rev not in stop_graph):
1431
# our previous tip is not merged into stop_revision
1432
raise errors.DivergedBranches(self, other_branch)
1413
graph = self.repository.get_graph()
1414
if last_rev is not None:
1415
if not graph.is_ancestor(last_rev, revision_id):
1416
# our previous tip is not merged into stop_revision
1417
raise errors.DivergedBranches(self, other_branch)
1433
1418
# make a new revision history from the graph
1419
parents_map = graph.get_parent_map([revision_id])
1420
if revision_id not in parents_map:
1421
raise errors.NoSuchRevision(self, revision_id)
1434
1422
current_rev_id = revision_id
1435
1423
new_history = []
1436
while current_rev_id not in (None, _mod_revision.NULL_REVISION):
1424
# Do not include ghosts or graph origin in revision_history
1425
while (current_rev_id in parents_map and
1426
len(parents_map[current_rev_id]) > 0):
1437
1427
new_history.append(current_rev_id)
1438
current_rev_id_parents = stop_graph[current_rev_id]
1440
current_rev_id = current_rev_id_parents[0]
1442
current_rev_id = None
1428
current_rev_id = parents_map[current_rev_id][0]
1429
parents_map = graph.get_parent_map([current_rev_id])
1443
1430
new_history.reverse()
1444
1431
return new_history
1839
1826
Intended to be called by set_last_revision_info and
1840
1827
_write_revision_history.
1842
if revision_id is None:
1843
revision_id = 'null:'
1829
assert revision_id is not None, "Use NULL_REVISION, not None"
1844
1830
out_string = '%d %s\n' % (revno, revision_id)
1845
1831
self.control_files.put_bytes('last-revision', out_string)
1847
1833
@needs_write_lock
1848
1834
def set_last_revision_info(self, revno, revision_id):
1835
revision_id = _mod_revision.ensure_null(revision_id)
1849
1836
if self._get_append_revisions_only():
1850
1837
self._check_history_violation(revision_id)
1851
1838
self._write_last_revision_info(revno, revision_id)
1974
1961
def _make_tags(self):
1975
1962
return BasicTags(self)
1965
def generate_revision_history(self, revision_id, last_rev=None,
1967
"""See BzrBranch5.generate_revision_history"""
1968
history = self._lefthand_history(revision_id, last_rev, other_branch)
1969
revno = len(history)
1970
self.set_last_revision_info(revno, revision_id)
1978
1973
######################################################################
1979
1974
# results of operations