~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Vincent Ladeuil
  • Date: 2012-02-14 17:22:37 UTC
  • mfrom: (6466 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120214172237-7dv7er3n4uy8d5m4
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1457
1457
        t = transport.get_transport(to_location)
1458
1458
        t.ensure_base()
1459
1459
        format = self._get_checkout_format(lightweight=lightweight)
 
1460
        try:
 
1461
            checkout = format.initialize_on_transport(t)
 
1462
        except errors.AlreadyControlDirError:
 
1463
            # It's fine if the control directory already exists,
 
1464
            # as long as there is no existing branch and working tree.
 
1465
            checkout = controldir.ControlDir.open_from_transport(t)
 
1466
            try:
 
1467
                checkout.open_branch()
 
1468
            except errors.NotBranchError:
 
1469
                pass
 
1470
            else:
 
1471
                raise errors.AlreadyControlDirError(t.base)
 
1472
            if checkout.control_transport.base == self.bzrdir.control_transport.base:
 
1473
                # When checking out to the same control directory,
 
1474
                # always create a lightweight checkout
 
1475
                lightweight = True
 
1476
 
1460
1477
        if lightweight:
1461
 
            checkout = format.initialize_on_transport(t)
1462
 
            from_branch = BranchReferenceFormat().initialize(checkout, 
1463
 
                target_branch=self)
 
1478
            from_branch = checkout.set_branch_reference(target_branch=self)
1464
1479
        else:
1465
 
            checkout_branch = controldir.ControlDir.create_branch_convenience(
1466
 
                to_location, force_new_tree=False, format=format)
1467
 
            checkout = checkout_branch.bzrdir
 
1480
            policy = checkout.determine_repository_policy()
 
1481
            repo = policy.acquire_repository()[0]
 
1482
            checkout_branch = checkout.create_branch()
1468
1483
            checkout_branch.bind(self)
1469
1484
            # pull up to the specified revision_id to set the initial
1470
1485
            # branch tip correctly, and seed it with history.
1471
1486
            checkout_branch.pull(self, stop_revision=revision_id)
1472
 
            from_branch=None
 
1487
            from_branch = None
1473
1488
        tree = checkout.create_workingtree(revision_id,
1474
1489
                                           from_branch=from_branch,
1475
1490
                                           accelerator_tree=accelerator_tree,
2038
2053
        :param name: Name of colocated branch to create, if any
2039
2054
        :return: a branch in this format
2040
2055
        """
 
2056
        if name is None:
 
2057
            name = a_bzrdir._get_selected_branch()
2041
2058
        mutter('creating branch %r in %s', self, a_bzrdir.user_url)
2042
2059
        branch_transport = a_bzrdir.get_branch_transport(self, name=name)
2043
2060
        control_files = lockable_files.LockableFiles(branch_transport,
2060
2077
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
2061
2078
            found_repository=None, possible_transports=None):
2062
2079
        """See BranchFormat.open()."""
 
2080
        if name is None:
 
2081
            name = a_bzrdir._get_selected_branch()
2063
2082
        if not _found:
2064
2083
            format = BranchFormatMetadir.find_format(a_bzrdir, name=name)
2065
2084
            if format.__class__ != self.__class__:
2305
2324
        mutter('creating branch reference in %s', a_bzrdir.user_url)
2306
2325
        if a_bzrdir._format.fixed_components:
2307
2326
            raise errors.IncompatibleFormat(self, a_bzrdir._format)
 
2327
        if name is None:
 
2328
            name = a_bzrdir._get_selected_branch()
2308
2329
        branch_transport = a_bzrdir.get_branch_transport(self, name=name)
2309
2330
        branch_transport.put_bytes('location',
2310
2331
            target_branch.user_url)
2311
2332
        branch_transport.put_bytes('format', self.as_string())
2312
 
        branch = self.open(
2313
 
            a_bzrdir, name, _found=True,
 
2333
        branch = self.open(a_bzrdir, name, _found=True,
2314
2334
            possible_transports=[target_branch.bzrdir.root_transport])
2315
2335
        self._run_post_branch_init_hooks(a_bzrdir, name, branch)
2316
2336
        return branch
2342
2362
            a_bzrdir.
2343
2363
        :param possible_transports: An optional reusable transports list.
2344
2364
        """
 
2365
        if name is None:
 
2366
            name = a_bzrdir._get_selected_branch()
2345
2367
        if not _found:
2346
2368
            format = BranchFormatMetadir.find_format(a_bzrdir, name=name)
2347
2369
            if format.__class__ != self.__class__:
2351
2373
            location = self.get_reference(a_bzrdir, name)
2352
2374
        real_bzrdir = controldir.ControlDir.open(
2353
2375
            location, possible_transports=possible_transports)
2354
 
        result = real_bzrdir.open_branch(name=name, 
2355
 
            ignore_fallbacks=ignore_fallbacks,
 
2376
        result = real_bzrdir.open_branch(ignore_fallbacks=ignore_fallbacks,
2356
2377
            possible_transports=possible_transports)
2357
2378
        # this changes the behaviour of result.clone to create a new reference
2358
2379
        # rather than a copy of the content of the branch.
2445
2466
        """Create new branch object at a particular location."""
2446
2467
        if a_bzrdir is None:
2447
2468
            raise ValueError('a_bzrdir must be supplied')
2448
 
        else:
2449
 
            self.bzrdir = a_bzrdir
 
2469
        if name is None:
 
2470
            raise ValueError('name must be supplied')
 
2471
        self.bzrdir = a_bzrdir
2450
2472
        self._user_transport = self.bzrdir.transport.clone('..')
2451
 
        if name is not None:
 
2473
        if name != "":
2452
2474
            self._user_transport.set_segment_parameter(
2453
2475
                "branch", urlutils.escape(name))
2454
2476
        self._base = self._user_transport.base