~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/controldir.py

  • Committer: jelmer at samba
  • Date: 2011-10-11 12:01:51 UTC
  • mto: This revision was merged to the branch mainline in revision 6214.
  • Revision ID: jelmer@samba.org-20111011120151-l1aa35zasaocrev3
Fix tests and the like.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    ui,
35
35
    urlutils,
36
36
    )
 
37
from bzrlib.transport import local
37
38
from bzrlib.push import (
38
39
    PushResult,
39
40
    )
198
199
        raise NotImplementedError(self.destroy_workingtree_metadata)
199
200
 
200
201
    def find_branch_format(self, name=None):
201
 
        """Find the branch 'format' for this bzrdir.
 
202
        """Find the branch 'format' for this controldir.
202
203
 
203
204
        This might be a synthetic object for e.g. RemoteBranch and SVN.
204
205
        """
416
417
        return push_result
417
418
 
418
419
    def _get_tree_branch(self, name=None):
419
 
        """Return the branch and tree, if any, for this bzrdir.
 
420
        """Return the branch and tree, if any, for this controldir.
420
421
 
421
422
        :param name: Name of colocated branch to open.
422
423
 
441
442
        raise NotImplementedError(self.get_config)
442
443
 
443
444
    def check_conversion_target(self, target_format):
444
 
        """Check that a bzrdir as a whole can be converted to a new format."""
 
445
        """Check that a controldir as a whole can be converted to a new format."""
445
446
        raise NotImplementedError(self.check_conversion_target)
446
447
 
447
448
    def clone(self, url, revision_id=None, force_new_repo=False,
448
449
              preserve_stacking=False):
449
 
        """Clone this bzrdir and its contents to url verbatim.
 
450
        """Clone this controldir and its contents to url verbatim.
450
451
 
451
452
        :param url: The url create the clone at.  If url's last component does
452
453
            not exist, it will be created.
466
467
    def clone_on_transport(self, transport, revision_id=None,
467
468
        force_new_repo=False, preserve_stacking=False, stacked_on=None,
468
469
        create_prefix=False, use_existing_dir=True, no_tree=False):
469
 
        """Clone this bzrdir and its contents to transport verbatim.
 
470
        """Clone this controldir and its contents to transport verbatim.
470
471
 
471
472
        :param transport: The transport for the location to produce the clone
472
473
            at.  If the target directory does not exist, it will be created.
486
487
 
487
488
    @classmethod
488
489
    def find_bzrdirs(cls, transport, evaluate=None, list_current=None):
489
 
        """Find bzrdirs recursively from current location.
 
490
        """Find control dirs recursively from current location.
490
491
 
491
492
        This is intended primarily as a building block for more sophisticated
492
493
        functionality, like finding trees under a directory, or finding
493
494
        branches that use a given repository.
494
495
 
495
496
        :param evaluate: An optional callable that yields recurse, value,
496
 
            where recurse controls whether this bzrdir is recursed into
 
497
            where recurse controls whether this controldir is recursed into
497
498
            and value is the value to yield.  By default, all bzrdirs
498
 
            are recursed into, and the return value is the bzrdir.
 
499
            are recursed into, and the return value is the controldir.
499
500
        :param list_current: if supplied, use this function to list the current
500
501
            directory, instead of Transport.list_dir
501
502
        :return: a generator of found bzrdirs, or whatever evaluate returns.
504
505
            def list_current(transport):
505
506
                return transport.list_dir('')
506
507
        if evaluate is None:
507
 
            def evaluate(bzrdir):
508
 
                return True, bzrdir
 
508
            def evaluate(controldir):
 
509
                return True, controldir
509
510
 
510
511
        pending = [transport]
511
512
        while len(pending) > 0:
512
513
            current_transport = pending.pop()
513
514
            recurse = True
514
515
            try:
515
 
                bzrdir = cls.open_from_transport(current_transport)
 
516
                controldir = cls.open_from_transport(current_transport)
516
517
            except (errors.NotBranchError, errors.PermissionDenied):
517
518
                pass
518
519
            else:
519
 
                recurse, value = evaluate(bzrdir)
 
520
                recurse, value = evaluate(controldir)
520
521
                yield value
521
522
            try:
522
523
                subdirs = list_current(current_transport)
537
538
        To list all the branches that use a particular Repository, see
538
539
        Repository.find_branches
539
540
        """
540
 
        def evaluate(bzrdir):
 
541
        def evaluate(controldir):
541
542
            try:
542
 
                repository = bzrdir.open_repository()
 
543
                repository = controldir.open_repository()
543
544
            except errors.NoRepositoryPresent:
544
545
                pass
545
546
            else:
546
547
                return False, ([], repository)
547
 
            return True, (bzrdir.list_branches(), None)
 
548
            return True, (controldir.list_branches(), None)
548
549
        ret = []
549
550
        for branches, repo in cls.find_bzrdirs(
550
551
                transport, evaluate=evaluate):
560
561
 
561
562
        This will use the current default ControlDirFormat unless one is
562
563
        specified, and use whatever
563
 
        repository format that that uses via bzrdir.create_branch and
 
564
        repository format that that uses via controldir.create_branch and
564
565
        create_repository. If a shared repository is available that is used
565
566
        preferentially.
566
567
 
571
572
        :param format: If supplied, the format of branch to create.  If not
572
573
            supplied, the default is used.
573
574
        """
574
 
        bzrdir = cls.create(base, format)
575
 
        bzrdir._find_or_create_repository(force_new_repo)
576
 
        return bzrdir.create_branch()
 
575
        controldir = cls.create(base, format)
 
576
        controldir._find_or_create_repository(force_new_repo)
 
577
        return controldir.create_branch()
577
578
 
578
579
    @classmethod
579
580
    def create_branch_convenience(cls, base, force_new_repo=False,
587
588
 
588
589
        This will use the current default ControlDirFormat unless one is
589
590
        specified, and use whatever
590
 
        repository format that that uses via bzrdir.create_branch and
 
591
        repository format that that uses via ControlDir.create_branch and
591
592
        create_repository. If a shared repository is available that is used
592
593
        preferentially. Whatever repository is used, its tree creation policy
593
594
        is followed.
601
602
        :param force_new_repo: If True a new repository is always created.
602
603
        :param force_new_tree: If True or False force creation of a tree or
603
604
                               prevent such creation respectively.
604
 
        :param format: Override for the bzrdir format to create.
 
605
        :param format: Override for the controldir format to create.
605
606
        :param possible_transports: An optional reusable transports list.
606
607
        """
607
608
        if force_new_tree:
609
610
            t = _mod_transport.get_transport(base, possible_transports)
610
611
            if not isinstance(t, local.LocalTransport):
611
612
                raise errors.NotLocalUrl(base)
612
 
        bzrdir = cls.create(base, format, possible_transports)
613
 
        repo = bzrdir._find_or_create_repository(force_new_repo)
614
 
        result = bzrdir.create_branch()
 
613
        controldir = cls.create(base, format, possible_transports)
 
614
        repo = controldir._find_or_create_repository(force_new_repo)
 
615
        result = controldir.create_branch()
615
616
        if force_new_tree or (repo.make_working_trees() and
616
617
                              force_new_tree is None):
617
618
            try:
618
 
                bzrdir.create_workingtree()
 
619
                controldir.create_workingtree()
619
620
            except errors.NotLocalUrl:
620
621
                pass
621
622
        return result
631
632
        repository format that that uses for bzrdirformat.create_workingtree,
632
633
        create_branch and create_repository.
633
634
 
634
 
        :param format: Override for the bzrdir format to create.
 
635
        :param format: Override for the controldir format to create.
635
636
        :return: The WorkingTree object.
636
637
        """
637
 
        from bzrlib.transport import local
638
638
        t = _mod_transport.get_transport(base)
639
639
        if not isinstance(t, local.LocalTransport):
640
640
            raise errors.NotLocalUrl(base)
641
 
        bzrdir = cls.create_branch_and_repo(base,
 
641
        controldir = cls.create_branch_and_repo(base,
642
642
                                               force_new_repo=True,
643
643
                                               format=format).bzrdir
644
 
        return bzrdir.create_workingtree()
 
644
        return controldir.create_workingtree()
645
645
 
646
646
    @classmethod
647
647
    def open_unsupported(cls, base):
650
650
 
651
651
    @classmethod
652
652
    def open(cls, base, _unsupported=False, possible_transports=None):
653
 
        """Open an existing bzrdir, rooted at 'base' (url).
 
653
        """Open an existing controldir, rooted at 'base' (url).
654
654
 
655
655
        :param _unsupported: a private parameter to the ControlDir class.
656
656
        """
660
660
    @classmethod
661
661
    def open_from_transport(cls, transport, _unsupported=False,
662
662
                            _server_formats=True):
663
 
        """Open a bzrdir within a particular directory.
 
663
        """Open a controldir within a particular directory.
664
664
 
665
 
        :param transport: Transport containing the bzrdir.
 
665
        :param transport: Transport containing the controldir.
666
666
        :param _unsupported: private.
667
667
        """
668
668
        for hook in cls.hooks['pre_open']:
744
744
        raised
745
745
        :return: (tree, branch)
746
746
        """
747
 
        bzrdir = klass.open(location)
748
 
        return bzrdir._get_tree_branch()
 
747
        controldir = klass.open(location)
 
748
        return controldir._get_tree_branch()
749
749
 
750
750
    @classmethod
751
751
    def open_containing_tree_or_branch(klass, location):
757
757
        raised
758
758
        relpath is the portion of the path that is contained by the branch.
759
759
        """
760
 
        bzrdir, relpath = klass.open_containing(location)
761
 
        tree, branch = bzrdir._get_tree_branch()
 
760
        controldir, relpath = klass.open_containing(location)
 
761
        tree, branch = controldir._get_tree_branch()
762
762
        return tree, branch, relpath
763
763
 
764
764
    @classmethod
775
775
 
776
776
        If no tree, branch or repository is found, a NotBranchError is raised.
777
777
        """
778
 
        bzrdir, relpath = klass.open_containing(location)
 
778
        controldir, relpath = klass.open_containing(location)
779
779
        try:
780
 
            tree, branch = bzrdir._get_tree_branch()
 
780
            tree, branch = controldir._get_tree_branch()
781
781
        except errors.NotBranchError:
782
782
            try:
783
 
                repo = bzrdir.find_repository()
 
783
                repo = controldir.find_repository()
784
784
                return None, None, repo, relpath
785
785
            except (errors.NoRepositoryPresent):
786
786
                raise errors.NotBranchError(location)
1368
1368
            return output
1369
1369
 
1370
1370
 
 
1371
class RepoInitHookParams(object):
 
1372
    """Object holding parameters passed to `*_repo_init` hooks.
 
1373
 
 
1374
    There are 4 fields that hooks may wish to access:
 
1375
 
 
1376
    :ivar repository: Repository created
 
1377
    :ivar format: Repository format
 
1378
    :ivar bzrdir: The controldir for the repository
 
1379
    :ivar shared: The repository is shared
 
1380
    """
 
1381
 
 
1382
    def __init__(self, repository, format, controldir, shared):
 
1383
        """Create a group of RepoInitHook parameters.
 
1384
 
 
1385
        :param repository: Repository created
 
1386
        :param format: Repository format
 
1387
        :param controldir: The controldir for the repository
 
1388
        :param shared: The repository is shared
 
1389
        """
 
1390
        self.repository = repository
 
1391
        self.format = format
 
1392
        self.bzrdir = controldir
 
1393
        self.shared = shared
 
1394
 
 
1395
    def __eq__(self, other):
 
1396
        return self.__dict__ == other.__dict__
 
1397
 
 
1398
    def __repr__(self):
 
1399
        if self.repository:
 
1400
            return "<%s for %s>" % (self.__class__.__name__,
 
1401
                self.repository)
 
1402
        else:
 
1403
            return "<%s for %s>" % (self.__class__.__name__,
 
1404
                self.bzrdir)
 
1405
 
 
1406
 
1371
1407
# Please register new formats after old formats so that formats
1372
1408
# appear in chronological order and format descriptions can build
1373
1409
# on previous ones.