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()
534
542
rev = self.repository.get_revision(revision_id)
535
543
new_history = rev.get_history(self.repository)[1:]
536
544
destination.set_revision_history(new_history)
537
parent = self.get_parent()
539
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)
568
580
mainline_parent_id = revision_id
569
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)
572
613
class BranchFormat(object):
573
614
"""An encapsulation of the initialization and open routines for a format.
1060
1101
transaction = self.get_transaction()
1061
1102
history = transaction.map.find_revision_history()
1062
1103
if history is not None:
1063
mutter("cache hit for revision-history in %s", self)
1104
# mutter("cache hit for revision-history in %s", self)
1064
1105
return list(history)
1065
history = [l.rstrip('\r\n') for l in
1066
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()]
1067
1109
transaction.map.add_revision_history(history)
1068
1110
# this call is disabled because revision_history is
1069
1111
# not really an object yet, and the transaction is for objects.
1170
1212
# turn it into a url
1171
1213
if parent.startswith('/'):
1172
1214
parent = urlutils.local_path_to_url(parent.decode('utf8'))
1173
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)
1176
1221
def get_push_location(self):