~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Aaron Bentley
  • Date: 2006-08-16 19:13:00 UTC
  • mfrom: (1934 +trunk)
  • mto: (1910.2.43 format-bumps)
  • mto: This revision was merged to the branch mainline in revision 1935.
  • Revision ID: abentley@panoramicfeedback.com-20060816191300-045772b26b975d1c
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from warnings import warn
22
22
 
23
23
import bzrlib
24
 
from bzrlib import bzrdir, errors, lockdir, osutils, revision, \
25
 
        tree, \
26
 
        ui, \
27
 
        urlutils
 
24
from bzrlib import (
 
25
        bzrdir,
 
26
        cache_utf8,
 
27
        errors,
 
28
        lockdir,
 
29
        osutils,
 
30
        revision,
 
31
        transport,
 
32
        tree,
 
33
        ui,
 
34
        urlutils,
 
35
        )
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)
301
309
 
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()
305
313
        if ph:
306
314
            return ph[-1]
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()
538
 
        if parent:
539
 
            destination.set_parent(parent)
 
545
        try:
 
546
            parent = self.get_parent()
 
547
        except errors.InaccessibleParent, e:
 
548
            mutter('parent was not accessible to copy: %s', e)
 
549
        else:
 
550
            if parent:
 
551
                destination.set_parent(parent)
540
552
 
541
553
    @needs_read_lock
542
554
    def check(self):
568
580
            mainline_parent_id = revision_id
569
581
        return BranchCheckResult(self)
570
582
 
 
583
    def create_checkout(self, to_location, revision_id=None, 
 
584
                        lightweight=False):
 
585
        """Create a checkout of a branch.
 
586
        
 
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
 
592
        """
 
593
        if lightweight:
 
594
            t = transport.get_transport(to_location)
 
595
            try:
 
596
                t.mkdir('.')
 
597
            except errors.FileExists:
 
598
                pass
 
599
            checkout = bzrdir.BzrDirMetaFormat1().initialize_on_transport(t)
 
600
            BranchReferenceFormat().initialize(checkout, self)
 
601
        else:
 
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)
 
611
 
571
612
 
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)
 
1215
            try:
 
1216
                return urlutils.join(self.base[:-1], parent)
 
1217
            except errors.InvalidURLJoin, e:
 
1218
                raise errors.InaccessibleParent(parent, self.base)
1174
1219
        return None
1175
1220
 
1176
1221
    def get_push_location(self):