~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/controldir.py

  • Committer: Gordon Tyler
  • Date: 2011-01-16 01:12:01 UTC
  • mfrom: (5615 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5632.
  • Revision ID: gordon@doxxx.net-20110116011201-x11yqb3svkjt3j4d
Merged from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2010 Canonical Ltd
 
1
# Copyright (C) 2010, 2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
27
27
import textwrap
28
28
 
29
29
from bzrlib import (
 
30
    cleanup,
30
31
    errors,
31
32
    graph,
32
 
    registry,
33
33
    revision as _mod_revision,
34
 
    symbol_versioning,
35
34
    urlutils,
36
35
    )
37
36
from bzrlib.push import (
47
46
 
48
47
""")
49
48
 
 
49
from bzrlib import registry
 
50
 
50
51
 
51
52
class ControlComponent(object):
52
53
    """Abstract base class for control directory components.
143
144
        """Destroy the repository in this ControlDir."""
144
145
        raise NotImplementedError(self.destroy_repository)
145
146
 
146
 
    def create_branch(self, name=None):
 
147
    def create_branch(self, name=None, repository=None):
147
148
        """Create a branch in this ControlDir.
148
149
 
149
150
        :param name: Name of the colocated branch to create, None for
364
365
        :param create_tree_if_local: If true, a working-tree will be created
365
366
            when working locally.
366
367
        """
 
368
        operation = cleanup.OperationWithCleanups(self._sprout)
 
369
        return operation.run(url, revision_id=revision_id,
 
370
            force_new_repo=force_new_repo, recurse=recurse,
 
371
            possible_transports=possible_transports,
 
372
            accelerator_tree=accelerator_tree, hardlink=hardlink,
 
373
            stacked=stacked, source_branch=source_branch,
 
374
            create_tree_if_local=create_tree_if_local)
 
375
 
 
376
    def _sprout(self, op, url, revision_id=None, force_new_repo=False,
 
377
               recurse='down', possible_transports=None,
 
378
               accelerator_tree=None, hardlink=False, stacked=False,
 
379
               source_branch=None, create_tree_if_local=True):
 
380
        add_cleanup = op.add_cleanup
367
381
        target_transport = get_transport(url, possible_transports)
368
382
        target_transport.ensure_base()
369
383
        cloning_format = self.cloning_metadir(stacked)
373
387
        # even if the origin was stacked
374
388
        stacked_branch_url = None
375
389
        if source_branch is not None:
 
390
            add_cleanup(source_branch.lock_read().unlock)
376
391
            if stacked:
377
392
                stacked_branch_url = self.root_transport.base
378
393
            source_repository = source_branch.repository
388
403
                    source_repository = self.open_repository()
389
404
                except errors.NoRepositoryPresent:
390
405
                    source_repository = None
 
406
                else:
 
407
                    add_cleanup(source_repository.lock_read().unlock)
 
408
            else:
 
409
                add_cleanup(source_branch.lock_read().unlock)
391
410
        repository_policy = result.determine_repository_policy(
392
411
            force_new_repo, stacked_branch_url, require_stacking=stacked)
393
412
        result_repo, is_new_repo = repository_policy.acquire_repository()
 
413
        add_cleanup(result_repo.lock_write().unlock)
394
414
        is_stacked = stacked or (len(result_repo._fallback_repositories) != 0)
395
415
        if is_new_repo and revision_id is not None and not is_stacked:
396
416
            fetch_spec = graph.PendingAncestryResult(
412
432
            result_branch = result.create_branch()
413
433
        else:
414
434
            result_branch = source_branch.sprout(result,
415
 
                revision_id=revision_id, repository_policy=repository_policy)
 
435
                revision_id=revision_id, repository_policy=repository_policy,
 
436
                repository=result_repo)
416
437
        mutter("created new branch %r" % (result_branch,))
417
438
 
418
439
        # Create/update the result working tree
420
441
            isinstance(target_transport, local.LocalTransport) and
421
442
            (result_repo is None or result_repo.make_working_trees())):
422
443
            wt = result.create_workingtree(accelerator_tree=accelerator_tree,
423
 
                hardlink=hardlink)
 
444
                hardlink=hardlink, from_branch=result_branch)
424
445
            wt.lock_write()
425
446
            try:
426
447
                if wt.path2id('') is None: