21
21
from warnings import warn
24
from bzrlib import bzrdir, errors, lockdir, osutils, revision, \
28
36
from bzrlib.config import TreeConfig
29
37
from bzrlib.decorators import needs_read_lock, needs_write_lock
30
38
import bzrlib.errors as errors
300
308
raise errors.UpgradeRequired(self.base)
302
310
def last_revision(self):
303
"""Return last patch hash, or None if no history."""
311
"""Return last revision id, or None"""
304
312
ph = self.revision_history()
363
371
raise NotImplementedError('pull is abstract')
365
373
def basis_tree(self):
366
"""Return `Tree` object for last revision.
368
If there are no revisions yet, return an `EmptyTree`.
374
"""Return `Tree` object for last revision."""
370
375
return self.repository.revision_tree(self.last_revision())
372
377
def rename_one(self, from_rel, to_rel):
537
542
rev = self.repository.get_revision(revision_id)
538
543
new_history = rev.get_history(self.repository)[1:]
539
544
destination.set_revision_history(new_history)
540
parent = self.get_parent()
542
destination.set_parent(parent)
546
parent = self.get_parent()
547
except errors.InaccessibleParent, e:
548
mutter('parent was not accessible to copy: %s', e)
551
destination.set_parent(parent)
571
580
mainline_parent_id = revision_id
572
581
return BranchCheckResult(self)
583
def create_checkout(self, to_location, revision_id=None,
585
"""Create a checkout of a branch.
587
:param to_location: The url to produce the checkout at
588
:param revision_id: The revision to check out
589
:param lightweight: If True, produce a lightweight checkout, otherwise,
590
produce a bound branch (heavyweight checkout)
591
:return: The tree of the created checkout
594
t = transport.get_transport(to_location)
597
except errors.FileExists:
599
checkout = bzrdir.BzrDirMetaFormat1().initialize_on_transport(t)
600
BranchReferenceFormat().initialize(checkout, self)
602
checkout_branch = bzrdir.BzrDir.create_branch_convenience(
603
to_location, force_new_tree=False)
604
checkout = checkout_branch.bzrdir
605
checkout_branch.bind(self)
606
if revision_id is not None:
607
rh = checkout_branch.revision_history()
608
new_rh = rh[:rh.index(revision_id) + 1]
609
checkout_branch.set_revision_history(new_rh)
610
return checkout.create_workingtree(revision_id)
575
613
class BranchFormat(object):
576
614
"""An encapsulation of the initialization and open routines for a format.
1063
1101
transaction = self.get_transaction()
1064
1102
history = transaction.map.find_revision_history()
1065
1103
if history is not None:
1066
mutter("cache hit for revision-history in %s", self)
1104
# mutter("cache hit for revision-history in %s", self)
1067
1105
return list(history)
1068
history = [l.rstrip('\r\n') for l in
1069
self.control_files.get_utf8('revision-history').readlines()]
1106
decode_utf8 = cache_utf8.decode
1107
history = [decode_utf8(l.rstrip('\r\n')) for l in
1108
self.control_files.get('revision-history').readlines()]
1070
1109
transaction.map.add_revision_history(history)
1071
1110
# this call is disabled because revision_history is
1072
1111
# not really an object yet, and the transaction is for objects.
1173
1212
# turn it into a url
1174
1213
if parent.startswith('/'):
1175
1214
parent = urlutils.local_path_to_url(parent.decode('utf8'))
1176
return urlutils.join(self.base[:-1], parent)
1216
return urlutils.join(self.base[:-1], parent)
1217
except errors.InvalidURLJoin, e:
1218
raise errors.InaccessibleParent(parent, self.base)
1179
1221
def get_push_location(self):