~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/controldir.py

  • Committer: Jelmer Vernooij
  • Date: 2010-12-20 11:57:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5577.
  • Revision ID: jelmer@samba.org-20101220115714-2ru3hfappjweeg7q
Don't use no-plugins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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:
542
563
                branch = tree.branch
543
564
        return tree, branch
544
565
 
545
 
 
 
566
    def get_config(self):
 
567
        """Get configuration for this ControlDir."""
 
568
        raise NotImplementedError(self.get_config)
 
569
 
 
570
    def check_conversion_target(self, target_format):
 
571
        """Check that a bzrdir as a whole can be converted to a new format."""
 
572
        raise NotImplementedError(self.check_conversion_target)
 
573
 
 
574
    def clone(self, url, revision_id=None, force_new_repo=False,
 
575
              preserve_stacking=False):
 
576
        """Clone this bzrdir and its contents to url verbatim.
 
577
 
 
578
        :param url: The url create the clone at.  If url's last component does
 
579
            not exist, it will be created.
 
580
        :param revision_id: The tip revision-id to use for any branch or
 
581
            working tree.  If not None, then the clone operation may tune
 
582
            itself to download less data.
 
583
        :param force_new_repo: Do not use a shared repository for the target
 
584
                               even if one is available.
 
585
        :param preserve_stacking: When cloning a stacked branch, stack the
 
586
            new branch on top of the other branch's stacked-on branch.
 
587
        """
 
588
        return self.clone_on_transport(get_transport(url),
 
589
                                       revision_id=revision_id,
 
590
                                       force_new_repo=force_new_repo,
 
591
                                       preserve_stacking=preserve_stacking)
 
592
 
 
593
    def clone_on_transport(self, transport, revision_id=None,
 
594
        force_new_repo=False, preserve_stacking=False, stacked_on=None,
 
595
        create_prefix=False, use_existing_dir=True):
 
596
        """Clone this bzrdir and its contents to transport verbatim.
 
597
 
 
598
        :param transport: The transport for the location to produce the clone
 
599
            at.  If the target directory does not exist, it will be created.
 
600
        :param revision_id: The tip revision-id to use for any branch or
 
601
            working tree.  If not None, then the clone operation may tune
 
602
            itself to download less data.
 
603
        :param force_new_repo: Do not use a shared repository for the target,
 
604
                               even if one is available.
 
605
        :param preserve_stacking: When cloning a stacked branch, stack the
 
606
            new branch on top of the other branch's stacked-on branch.
 
607
        :param create_prefix: Create any missing directories leading up to
 
608
            to_transport.
 
609
        :param use_existing_dir: Use an existing directory if one exists.
 
610
        """
 
611
        raise NotImplementedError(self.clone_on_transport)
546
612
 
547
613
 
548
614
class ControlDirFormat(object):
562
628
    object will be created every system load.
563
629
 
564
630
    :cvar colocated_branches: Whether this formats supports colocated branches.
 
631
    :cvar supports_workingtrees: This control directory can co-exist with a
 
632
        working tree.
565
633
    """
566
634
 
567
635
    _default_format = None
589
657
    """Whether co-located branches are supported for this control dir format.
590
658
    """
591
659
 
 
660
    supports_workingtrees = True
 
661
 
592
662
    def get_format_description(self):
593
663
        """Return the short description for this format."""
594
664
        raise NotImplementedError(self.get_format_description)
918
988
# appear in chronological order and format descriptions can build
919
989
# on previous ones.
920
990
format_registry = ControlDirFormatRegistry()
 
991
 
 
992
network_format_registry = registry.FormatRegistry()
 
993
"""Registry of formats indexed by their network name.
 
994
 
 
995
The network name for a ControlDirFormat is an identifier that can be used when
 
996
referring to formats with smart server operations. See
 
997
ControlDirFormat.network_name() for more detail.
 
998
"""