~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-15 13:20:18 UTC
  • mfrom: (1924 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1926.
  • Revision ID: john@arbash-meinel.com-20060815132018-b753fd07689ac31a
[merge] bzr.dev 1924

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
import bzrlib
24
24
from bzrlib import (
25
 
    bzrdir,
26
 
    cache_utf8,
27
 
    errors,
28
 
    lockdir,
29
 
    osutils,
30
 
    revision,
31
 
    tree,
32
 
    ui,
33
 
    urlutils,
34
 
    )
 
25
        bzrdir,
 
26
        cache_utf8,
 
27
        errors,
 
28
        lockdir,
 
29
        osutils,
 
30
        revision,
 
31
        tree,
 
32
        ui,
 
33
        urlutils,
 
34
        )
35
35
from bzrlib.config import TreeConfig
36
36
from bzrlib.decorators import needs_read_lock, needs_write_lock
37
37
import bzrlib.errors as errors
541
541
                rev = self.repository.get_revision(revision_id)
542
542
                new_history = rev.get_history(self.repository)[1:]
543
543
        destination.set_revision_history(new_history)
544
 
        parent = self.get_parent()
545
 
        if parent:
546
 
            destination.set_parent(parent)
 
544
        try:
 
545
            parent = self.get_parent()
 
546
        except errors.InaccessibleParent, e:
 
547
            mutter('parent was not accessible to copy: %s', e)
 
548
        else:
 
549
            if parent:
 
550
                destination.set_parent(parent)
547
551
 
548
552
    @needs_read_lock
549
553
    def check(self):
575
579
            mainline_parent_id = revision_id
576
580
        return BranchCheckResult(self)
577
581
 
 
582
    def create_checkout(self, to_location, revision_id=None, 
 
583
                        lightweight=False):
 
584
        """Create a checkout of a branch.
 
585
        
 
586
        :param to_location: The url to produce the checkout at
 
587
        :param revision_id: The revision to check out
 
588
        :param lightweight: If True, produce a lightweight checkout, otherwise,
 
589
        produce a bound branch (heavyweight checkout)
 
590
        :return: The tree of the created checkout
 
591
        """
 
592
        if lightweight:
 
593
            t = transport.get_transport(to_location)
 
594
            try:
 
595
                t.mkdir('.')
 
596
            except errors.FileExists:
 
597
                pass
 
598
            checkout = bzrdir.BzrDirMetaFormat1().initialize_on_transport(t)
 
599
            BranchReferenceFormat().initialize(checkout, self)
 
600
        else:
 
601
            checkout_branch = bzrdir.BzrDir.create_branch_convenience(
 
602
                to_location, force_new_tree=False)
 
603
            checkout = checkout_branch.bzrdir
 
604
            checkout_branch.bind(self)
 
605
            if revision_id is not None:
 
606
                rh = checkout_branch.revision_history()
 
607
                new_rh = rh[:rh.index(revision_id) + 1]
 
608
                checkout_branch.set_revision_history(new_rh)
 
609
        return checkout.create_workingtree(revision_id)
 
610
 
578
611
 
579
612
class BranchFormat(object):
580
613
    """An encapsulation of the initialization and open routines for a format.
1067
1100
        transaction = self.get_transaction()
1068
1101
        history = transaction.map.find_revision_history()
1069
1102
        if history is not None:
1070
 
            mutter("cache hit for revision-history in %s", self)
 
1103
            # mutter("cache hit for revision-history in %s", self)
1071
1104
            return list(history)
1072
1105
        decode_utf8 = cache_utf8.decode
1073
1106
        history = [decode_utf8(l.rstrip('\r\n')) for l in
1178
1211
            # turn it into a url
1179
1212
            if parent.startswith('/'):
1180
1213
                parent = urlutils.local_path_to_url(parent.decode('utf8'))
1181
 
            return urlutils.join(self.base[:-1], parent)
 
1214
            try:
 
1215
                return urlutils.join(self.base[:-1], parent)
 
1216
            except errors.InvalidURLJoin, e:
 
1217
                raise errors.InaccessibleParent(parent, self.base)
1182
1218
        return None
1183
1219
 
1184
1220
    def get_push_location(self):