~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

Merge bzr.dev and tree-file-ids-as-tuples.

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
 
1460
1473
        if lightweight:
1461
 
            checkout = format.initialize_on_transport(t)
1462
 
            from_branch = BranchReferenceFormat().initialize(checkout, 
1463
 
                target_branch=self)
 
1474
            from_branch = checkout.set_branch_reference(target_branch=self)
1464
1475
        else:
1465
 
            checkout_branch = controldir.ControlDir.create_branch_convenience(
1466
 
                to_location, force_new_tree=False, format=format)
1467
 
            checkout = checkout_branch.bzrdir
 
1476
            policy = checkout.determine_repository_policy()
 
1477
            repo = policy.acquire_repository()[0]
 
1478
            checkout_branch = checkout.create_branch()
1468
1479
            checkout_branch.bind(self)
1469
1480
            # pull up to the specified revision_id to set the initial
1470
1481
            # branch tip correctly, and seed it with history.
1471
1482
            checkout_branch.pull(self, stop_revision=revision_id)
1472
 
            from_branch=None
 
1483
            from_branch = None
1473
1484
        tree = checkout.create_workingtree(revision_id,
1474
1485
                                           from_branch=from_branch,
1475
1486
                                           accelerator_tree=accelerator_tree,
2038
2049
        :param name: Name of colocated branch to create, if any
2039
2050
        :return: a branch in this format
2040
2051
        """
 
2052
        if name is None:
 
2053
            name = a_bzrdir._get_selected_branch()
2041
2054
        mutter('creating branch %r in %s', self, a_bzrdir.user_url)
2042
2055
        branch_transport = a_bzrdir.get_branch_transport(self, name=name)
2043
2056
        control_files = lockable_files.LockableFiles(branch_transport,
2060
2073
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
2061
2074
            found_repository=None, possible_transports=None):
2062
2075
        """See BranchFormat.open()."""
 
2076
        if name is None:
 
2077
            name = a_bzrdir._get_selected_branch()
2063
2078
        if not _found:
2064
2079
            format = BranchFormatMetadir.find_format(a_bzrdir, name=name)
2065
2080
            if format.__class__ != self.__class__:
2305
2320
        mutter('creating branch reference in %s', a_bzrdir.user_url)
2306
2321
        if a_bzrdir._format.fixed_components:
2307
2322
            raise errors.IncompatibleFormat(self, a_bzrdir._format)
 
2323
        if name is None:
 
2324
            name = a_bzrdir._get_selected_branch()
2308
2325
        branch_transport = a_bzrdir.get_branch_transport(self, name=name)
2309
2326
        branch_transport.put_bytes('location',
2310
2327
            target_branch.user_url)
2311
2328
        branch_transport.put_bytes('format', self.as_string())
2312
 
        branch = self.open(
2313
 
            a_bzrdir, name, _found=True,
 
2329
        branch = self.open(a_bzrdir, name, _found=True,
2314
2330
            possible_transports=[target_branch.bzrdir.root_transport])
2315
2331
        self._run_post_branch_init_hooks(a_bzrdir, name, branch)
2316
2332
        return branch
2342
2358
            a_bzrdir.
2343
2359
        :param possible_transports: An optional reusable transports list.
2344
2360
        """
 
2361
        if name is None:
 
2362
            name = a_bzrdir._get_selected_branch()
2345
2363
        if not _found:
2346
2364
            format = BranchFormatMetadir.find_format(a_bzrdir, name=name)
2347
2365
            if format.__class__ != self.__class__:
2351
2369
            location = self.get_reference(a_bzrdir, name)
2352
2370
        real_bzrdir = controldir.ControlDir.open(
2353
2371
            location, possible_transports=possible_transports)
2354
 
        result = real_bzrdir.open_branch(name=name, 
2355
 
            ignore_fallbacks=ignore_fallbacks,
 
2372
        result = real_bzrdir.open_branch(ignore_fallbacks=ignore_fallbacks,
2356
2373
            possible_transports=possible_transports)
2357
2374
        # this changes the behaviour of result.clone to create a new reference
2358
2375
        # rather than a copy of the content of the branch.
2445
2462
        """Create new branch object at a particular location."""
2446
2463
        if a_bzrdir is None:
2447
2464
            raise ValueError('a_bzrdir must be supplied')
2448
 
        else:
2449
 
            self.bzrdir = a_bzrdir
 
2465
        if name is None:
 
2466
            raise ValueError('name must be supplied')
 
2467
        self.bzrdir = a_bzrdir
2450
2468
        self._user_transport = self.bzrdir.transport.clone('..')
2451
 
        if name is not None:
 
2469
        if name != "":
2452
2470
            self._user_transport.set_segment_parameter(
2453
2471
                "branch", urlutils.escape(name))
2454
2472
        self._base = self._user_transport.base