~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/controldir.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2010, 2011 Canonical Ltd
 
1
# Copyright (C) 2010, 2011, 2012 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
22
22
 
23
23
"""
24
24
 
 
25
from __future__ import absolute_import
 
26
 
25
27
from bzrlib.lazy_import import lazy_import
26
28
lazy_import(globals(), """
27
29
import textwrap
28
30
 
29
31
from bzrlib import (
30
32
    errors,
 
33
    hooks,
31
34
    revision as _mod_revision,
32
35
    transport as _mod_transport,
 
36
    trace,
33
37
    ui,
34
38
    urlutils,
35
39
    )
 
40
from bzrlib.transport import local
36
41
from bzrlib.push import (
37
42
    PushResult,
38
43
    )
39
44
 
 
45
from bzrlib.i18n import gettext
40
46
""")
41
47
 
42
48
from bzrlib import registry
102
108
        """Return a sequence of all branches local to this control directory.
103
109
 
104
110
        """
 
111
        return self.get_branches().values()
 
112
 
 
113
    def get_branches(self):
 
114
        """Get all branches in this control directory, as a dictionary.
 
115
        
 
116
        :return: Dictionary mapping branch names to instances.
 
117
        """
105
118
        try:
106
 
            return [self.open_branch()]
 
119
           return { "": self.open_branch() }
107
120
        except (errors.NotBranchError, errors.NoRepositoryPresent):
108
 
            return []
 
121
           return {}
109
122
 
110
123
    def is_control_filename(self, filename):
111
124
        """True if filename is the name of a path which is reserved for
150
163
        """Create a branch in this ControlDir.
151
164
 
152
165
        :param name: Name of the colocated branch to create, None for
153
 
            the default branch.
 
166
            the user selected branch or "" for the active branch.
154
167
        :param append_revisions_only: Whether this branch should only allow
155
168
            appending new revisions to its history.
156
169
 
162
175
    def destroy_branch(self, name=None):
163
176
        """Destroy a branch in this ControlDir.
164
177
 
165
 
        :param name: Name of the branch to destroy, None for the default 
166
 
            branch.
 
178
        :param name: Name of the branch to destroy, None for the 
 
179
            user selected branch or "" for the active branch.
 
180
        :raise NotBranchError: When the branch does not exist
167
181
        """
168
182
        raise NotImplementedError(self.destroy_branch)
169
183
 
197
211
        raise NotImplementedError(self.destroy_workingtree_metadata)
198
212
 
199
213
    def find_branch_format(self, name=None):
200
 
        """Find the branch 'format' for this bzrdir.
 
214
        """Find the branch 'format' for this controldir.
201
215
 
202
216
        This might be a synthetic object for e.g. RemoteBranch and SVN.
203
217
        """
217
231
            raise errors.NoColocatedBranchSupport(self)
218
232
        return None
219
233
 
 
234
    def set_branch_reference(self, target_branch, name=None):
 
235
        """Set the referenced URL for the branch in this controldir.
 
236
 
 
237
        :param name: Optional colocated branch name
 
238
        :param target_branch: Branch to reference
 
239
        :raises NoColocatedBranchSupport: If a branch name was specified
 
240
            but colocated branches are not supported.
 
241
        :return: The referencing branch
 
242
        """
 
243
        raise NotImplementedError(self.set_branch_reference)
 
244
 
220
245
    def open_branch(self, name=None, unsupported=False,
221
 
                    ignore_fallbacks=False):
 
246
                    ignore_fallbacks=False, possible_transports=None):
222
247
        """Open the branch object at this ControlDir if one is present.
223
248
 
224
 
        If unsupported is True, then no longer supported branch formats can
225
 
        still be opened.
226
 
 
227
 
        TODO: static convenience version of this?
 
249
        :param unsupported: if True, then no longer supported branch formats can
 
250
            still be opened.
 
251
        :param ignore_fallbacks: Whether to open fallback repositories
 
252
        :param possible_transports: Transports to use for opening e.g.
 
253
            fallback repositories.
228
254
        """
229
255
        raise NotImplementedError(self.open_branch)
230
256
 
236
262
        get at a repository.
237
263
 
238
264
        :param _unsupported: a private parameter, not part of the api.
239
 
 
240
 
        TODO: static convenience version of this?
241
265
        """
242
266
        raise NotImplementedError(self.open_repository)
243
267
 
250
274
        """
251
275
        raise NotImplementedError(self.find_repository)
252
276
 
253
 
    def open_workingtree(self, _unsupported=False,
 
277
    def open_workingtree(self, unsupported=False,
254
278
                         recommend_upgrade=True, from_branch=None):
255
279
        """Open the workingtree object at this ControlDir if one is present.
256
280
 
271
295
        branch and discards it, and that's somewhat expensive.)
272
296
        """
273
297
        try:
274
 
            self.open_branch(name)
 
298
            self.open_branch(name, ignore_fallbacks=True)
275
299
            return True
276
300
        except errors.NotBranchError:
277
301
            return False
279
303
    def _get_selected_branch(self):
280
304
        """Return the name of the branch selected by the user.
281
305
 
282
 
        :return: Name of the branch selected by the user, or None.
 
306
        :return: Name of the branch selected by the user, or "".
283
307
        """
284
308
        branch = self.root_transport.get_segment_parameters().get("branch")
285
 
        if branch is not None:
286
 
            branch = urlutils.unescape(branch)
287
 
        return branch
 
309
        if branch is None:
 
310
            branch = ""
 
311
        return urlutils.unescape(branch)
288
312
 
289
313
    def has_workingtree(self):
290
314
        """Tell if this controldir contains a working tree.
318
342
        raise NotImplementedError(self.cloning_metadir)
319
343
 
320
344
    def checkout_metadir(self):
321
 
        """Produce a metadir suitable for checkouts of this controldir."""
 
345
        """Produce a metadir suitable for checkouts of this controldir.
 
346
 
 
347
        :returns: A ControlDirFormat with all component formats
 
348
            either set appropriately or set to None if that component
 
349
            should not be created.
 
350
        """
322
351
        return self.cloning_metadir()
323
352
 
324
353
    def sprout(self, url, revision_id=None, force_new_repo=False,
377
406
            repository_to.fetch(source.repository, revision_id=revision_id)
378
407
            br_to = source.clone(self, revision_id=revision_id)
379
408
            if source.get_push_location() is None or remember:
 
409
                # FIXME: Should be done only if we succeed ? -- vila 2012-01-18
380
410
                source.set_push_location(br_to.base)
381
411
            push_result.stacked_on = None
382
412
            push_result.branch_push_result = None
388
418
        else:
389
419
            # We have successfully opened the branch, remember if necessary:
390
420
            if source.get_push_location() is None or remember:
 
421
                # FIXME: Should be done only if we succeed ? -- vila 2012-01-18
391
422
                source.set_push_location(br_to.base)
392
423
            try:
393
424
                tree_to = self.open_workingtree()
415
446
        return push_result
416
447
 
417
448
    def _get_tree_branch(self, name=None):
418
 
        """Return the branch and tree, if any, for this bzrdir.
 
449
        """Return the branch and tree, if any, for this controldir.
419
450
 
420
451
        :param name: Name of colocated branch to open.
421
452
 
440
471
        raise NotImplementedError(self.get_config)
441
472
 
442
473
    def check_conversion_target(self, target_format):
443
 
        """Check that a bzrdir as a whole can be converted to a new format."""
 
474
        """Check that a controldir as a whole can be converted to a new format."""
444
475
        raise NotImplementedError(self.check_conversion_target)
445
476
 
446
477
    def clone(self, url, revision_id=None, force_new_repo=False,
447
478
              preserve_stacking=False):
448
 
        """Clone this bzrdir and its contents to url verbatim.
 
479
        """Clone this controldir and its contents to url verbatim.
449
480
 
450
481
        :param url: The url create the clone at.  If url's last component does
451
482
            not exist, it will be created.
465
496
    def clone_on_transport(self, transport, revision_id=None,
466
497
        force_new_repo=False, preserve_stacking=False, stacked_on=None,
467
498
        create_prefix=False, use_existing_dir=True, no_tree=False):
468
 
        """Clone this bzrdir and its contents to transport verbatim.
 
499
        """Clone this controldir and its contents to transport verbatim.
469
500
 
470
501
        :param transport: The transport for the location to produce the clone
471
502
            at.  If the target directory does not exist, it will be created.
483
514
        """
484
515
        raise NotImplementedError(self.clone_on_transport)
485
516
 
 
517
    @classmethod
 
518
    def find_bzrdirs(klass, transport, evaluate=None, list_current=None):
 
519
        """Find control dirs recursively from current location.
 
520
 
 
521
        This is intended primarily as a building block for more sophisticated
 
522
        functionality, like finding trees under a directory, or finding
 
523
        branches that use a given repository.
 
524
 
 
525
        :param evaluate: An optional callable that yields recurse, value,
 
526
            where recurse controls whether this controldir is recursed into
 
527
            and value is the value to yield.  By default, all bzrdirs
 
528
            are recursed into, and the return value is the controldir.
 
529
        :param list_current: if supplied, use this function to list the current
 
530
            directory, instead of Transport.list_dir
 
531
        :return: a generator of found bzrdirs, or whatever evaluate returns.
 
532
        """
 
533
        if list_current is None:
 
534
            def list_current(transport):
 
535
                return transport.list_dir('')
 
536
        if evaluate is None:
 
537
            def evaluate(controldir):
 
538
                return True, controldir
 
539
 
 
540
        pending = [transport]
 
541
        while len(pending) > 0:
 
542
            current_transport = pending.pop()
 
543
            recurse = True
 
544
            try:
 
545
                controldir = klass.open_from_transport(current_transport)
 
546
            except (errors.NotBranchError, errors.PermissionDenied):
 
547
                pass
 
548
            else:
 
549
                recurse, value = evaluate(controldir)
 
550
                yield value
 
551
            try:
 
552
                subdirs = list_current(current_transport)
 
553
            except (errors.NoSuchFile, errors.PermissionDenied):
 
554
                continue
 
555
            if recurse:
 
556
                for subdir in sorted(subdirs, reverse=True):
 
557
                    pending.append(current_transport.clone(subdir))
 
558
 
 
559
    @classmethod
 
560
    def find_branches(klass, transport):
 
561
        """Find all branches under a transport.
 
562
 
 
563
        This will find all branches below the transport, including branches
 
564
        inside other branches.  Where possible, it will use
 
565
        Repository.find_branches.
 
566
 
 
567
        To list all the branches that use a particular Repository, see
 
568
        Repository.find_branches
 
569
        """
 
570
        def evaluate(controldir):
 
571
            try:
 
572
                repository = controldir.open_repository()
 
573
            except errors.NoRepositoryPresent:
 
574
                pass
 
575
            else:
 
576
                return False, ([], repository)
 
577
            return True, (controldir.list_branches(), None)
 
578
        ret = []
 
579
        for branches, repo in klass.find_bzrdirs(
 
580
                transport, evaluate=evaluate):
 
581
            if repo is not None:
 
582
                ret.extend(repo.find_branches())
 
583
            if branches is not None:
 
584
                ret.extend(branches)
 
585
        return ret
 
586
 
 
587
    @classmethod
 
588
    def create_branch_and_repo(klass, base, force_new_repo=False, format=None):
 
589
        """Create a new ControlDir, Branch and Repository at the url 'base'.
 
590
 
 
591
        This will use the current default ControlDirFormat unless one is
 
592
        specified, and use whatever
 
593
        repository format that that uses via controldir.create_branch and
 
594
        create_repository. If a shared repository is available that is used
 
595
        preferentially.
 
596
 
 
597
        The created Branch object is returned.
 
598
 
 
599
        :param base: The URL to create the branch at.
 
600
        :param force_new_repo: If True a new repository is always created.
 
601
        :param format: If supplied, the format of branch to create.  If not
 
602
            supplied, the default is used.
 
603
        """
 
604
        controldir = klass.create(base, format)
 
605
        controldir._find_or_create_repository(force_new_repo)
 
606
        return controldir.create_branch()
 
607
 
 
608
    @classmethod
 
609
    def create_branch_convenience(klass, base, force_new_repo=False,
 
610
                                  force_new_tree=None, format=None,
 
611
                                  possible_transports=None):
 
612
        """Create a new ControlDir, Branch and Repository at the url 'base'.
 
613
 
 
614
        This is a convenience function - it will use an existing repository
 
615
        if possible, can be told explicitly whether to create a working tree or
 
616
        not.
 
617
 
 
618
        This will use the current default ControlDirFormat unless one is
 
619
        specified, and use whatever
 
620
        repository format that that uses via ControlDir.create_branch and
 
621
        create_repository. If a shared repository is available that is used
 
622
        preferentially. Whatever repository is used, its tree creation policy
 
623
        is followed.
 
624
 
 
625
        The created Branch object is returned.
 
626
        If a working tree cannot be made due to base not being a file:// url,
 
627
        no error is raised unless force_new_tree is True, in which case no
 
628
        data is created on disk and NotLocalUrl is raised.
 
629
 
 
630
        :param base: The URL to create the branch at.
 
631
        :param force_new_repo: If True a new repository is always created.
 
632
        :param force_new_tree: If True or False force creation of a tree or
 
633
                               prevent such creation respectively.
 
634
        :param format: Override for the controldir format to create.
 
635
        :param possible_transports: An optional reusable transports list.
 
636
        """
 
637
        if force_new_tree:
 
638
            # check for non local urls
 
639
            t = _mod_transport.get_transport(base, possible_transports)
 
640
            if not isinstance(t, local.LocalTransport):
 
641
                raise errors.NotLocalUrl(base)
 
642
        controldir = klass.create(base, format, possible_transports)
 
643
        repo = controldir._find_or_create_repository(force_new_repo)
 
644
        result = controldir.create_branch()
 
645
        if force_new_tree or (repo.make_working_trees() and
 
646
                              force_new_tree is None):
 
647
            try:
 
648
                controldir.create_workingtree()
 
649
            except errors.NotLocalUrl:
 
650
                pass
 
651
        return result
 
652
 
 
653
    @classmethod
 
654
    def create_standalone_workingtree(klass, base, format=None):
 
655
        """Create a new ControlDir, WorkingTree, Branch and Repository at 'base'.
 
656
 
 
657
        'base' must be a local path or a file:// url.
 
658
 
 
659
        This will use the current default ControlDirFormat unless one is
 
660
        specified, and use whatever
 
661
        repository format that that uses for bzrdirformat.create_workingtree,
 
662
        create_branch and create_repository.
 
663
 
 
664
        :param format: Override for the controldir format to create.
 
665
        :return: The WorkingTree object.
 
666
        """
 
667
        t = _mod_transport.get_transport(base)
 
668
        if not isinstance(t, local.LocalTransport):
 
669
            raise errors.NotLocalUrl(base)
 
670
        controldir = klass.create_branch_and_repo(base,
 
671
                                               force_new_repo=True,
 
672
                                               format=format).bzrdir
 
673
        return controldir.create_workingtree()
 
674
 
 
675
    @classmethod
 
676
    def open_unsupported(klass, base):
 
677
        """Open a branch which is not supported."""
 
678
        return klass.open(base, _unsupported=True)
 
679
 
 
680
    @classmethod
 
681
    def open(klass, base, possible_transports=None, probers=None,
 
682
             _unsupported=False):
 
683
        """Open an existing controldir, rooted at 'base' (url).
 
684
 
 
685
        :param _unsupported: a private parameter to the ControlDir class.
 
686
        """
 
687
        t = _mod_transport.get_transport(base, possible_transports)
 
688
        return klass.open_from_transport(t, probers=probers,
 
689
                _unsupported=_unsupported)
 
690
 
 
691
    @classmethod
 
692
    def open_from_transport(klass, transport, _unsupported=False,
 
693
                            probers=None):
 
694
        """Open a controldir within a particular directory.
 
695
 
 
696
        :param transport: Transport containing the controldir.
 
697
        :param _unsupported: private.
 
698
        """
 
699
        for hook in klass.hooks['pre_open']:
 
700
            hook(transport)
 
701
        # Keep initial base since 'transport' may be modified while following
 
702
        # the redirections.
 
703
        base = transport.base
 
704
        def find_format(transport):
 
705
            return transport, ControlDirFormat.find_format(transport,
 
706
                probers=probers)
 
707
 
 
708
        def redirected(transport, e, redirection_notice):
 
709
            redirected_transport = transport._redirected_to(e.source, e.target)
 
710
            if redirected_transport is None:
 
711
                raise errors.NotBranchError(base)
 
712
            trace.note(gettext('{0} is{1} redirected to {2}').format(
 
713
                 transport.base, e.permanently, redirected_transport.base))
 
714
            return redirected_transport
 
715
 
 
716
        try:
 
717
            transport, format = _mod_transport.do_catching_redirections(
 
718
                find_format, transport, redirected)
 
719
        except errors.TooManyRedirections:
 
720
            raise errors.NotBranchError(base)
 
721
 
 
722
        format.check_support_status(_unsupported)
 
723
        return format.open(transport, _found=True)
 
724
 
 
725
    @classmethod
 
726
    def open_containing(klass, url, possible_transports=None):
 
727
        """Open an existing branch which contains url.
 
728
 
 
729
        :param url: url to search from.
 
730
 
 
731
        See open_containing_from_transport for more detail.
 
732
        """
 
733
        transport = _mod_transport.get_transport(url, possible_transports)
 
734
        return klass.open_containing_from_transport(transport)
 
735
 
 
736
    @classmethod
 
737
    def open_containing_from_transport(klass, a_transport):
 
738
        """Open an existing branch which contains a_transport.base.
 
739
 
 
740
        This probes for a branch at a_transport, and searches upwards from there.
 
741
 
 
742
        Basically we keep looking up until we find the control directory or
 
743
        run into the root.  If there isn't one, raises NotBranchError.
 
744
        If there is one and it is either an unrecognised format or an unsupported
 
745
        format, UnknownFormatError or UnsupportedFormatError are raised.
 
746
        If there is one, it is returned, along with the unused portion of url.
 
747
 
 
748
        :return: The ControlDir that contains the path, and a Unicode path
 
749
                for the rest of the URL.
 
750
        """
 
751
        # this gets the normalised url back. I.e. '.' -> the full path.
 
752
        url = a_transport.base
 
753
        while True:
 
754
            try:
 
755
                result = klass.open_from_transport(a_transport)
 
756
                return result, urlutils.unescape(a_transport.relpath(url))
 
757
            except errors.NotBranchError, e:
 
758
                pass
 
759
            except errors.PermissionDenied:
 
760
                pass
 
761
            try:
 
762
                new_t = a_transport.clone('..')
 
763
            except errors.InvalidURLJoin:
 
764
                # reached the root, whatever that may be
 
765
                raise errors.NotBranchError(path=url)
 
766
            if new_t.base == a_transport.base:
 
767
                # reached the root, whatever that may be
 
768
                raise errors.NotBranchError(path=url)
 
769
            a_transport = new_t
 
770
 
 
771
    @classmethod
 
772
    def open_tree_or_branch(klass, location):
 
773
        """Return the branch and working tree at a location.
 
774
 
 
775
        If there is no tree at the location, tree will be None.
 
776
        If there is no branch at the location, an exception will be
 
777
        raised
 
778
        :return: (tree, branch)
 
779
        """
 
780
        controldir = klass.open(location)
 
781
        return controldir._get_tree_branch()
 
782
 
 
783
    @classmethod
 
784
    def open_containing_tree_or_branch(klass, location,
 
785
            possible_transports=None):
 
786
        """Return the branch and working tree contained by a location.
 
787
 
 
788
        Returns (tree, branch, relpath).
 
789
        If there is no tree at containing the location, tree will be None.
 
790
        If there is no branch containing the location, an exception will be
 
791
        raised
 
792
        relpath is the portion of the path that is contained by the branch.
 
793
        """
 
794
        controldir, relpath = klass.open_containing(location,
 
795
            possible_transports=possible_transports)
 
796
        tree, branch = controldir._get_tree_branch()
 
797
        return tree, branch, relpath
 
798
 
 
799
    @classmethod
 
800
    def open_containing_tree_branch_or_repository(klass, location):
 
801
        """Return the working tree, branch and repo contained by a location.
 
802
 
 
803
        Returns (tree, branch, repository, relpath).
 
804
        If there is no tree containing the location, tree will be None.
 
805
        If there is no branch containing the location, branch will be None.
 
806
        If there is no repository containing the location, repository will be
 
807
        None.
 
808
        relpath is the portion of the path that is contained by the innermost
 
809
        ControlDir.
 
810
 
 
811
        If no tree, branch or repository is found, a NotBranchError is raised.
 
812
        """
 
813
        controldir, relpath = klass.open_containing(location)
 
814
        try:
 
815
            tree, branch = controldir._get_tree_branch()
 
816
        except errors.NotBranchError:
 
817
            try:
 
818
                repo = controldir.find_repository()
 
819
                return None, None, repo, relpath
 
820
            except (errors.NoRepositoryPresent):
 
821
                raise errors.NotBranchError(location)
 
822
        return tree, branch, branch.repository, relpath
 
823
 
 
824
    @classmethod
 
825
    def create(klass, base, format=None, possible_transports=None):
 
826
        """Create a new ControlDir at the url 'base'.
 
827
 
 
828
        :param format: If supplied, the format of branch to create.  If not
 
829
            supplied, the default is used.
 
830
        :param possible_transports: If supplied, a list of transports that
 
831
            can be reused to share a remote connection.
 
832
        """
 
833
        if klass is not ControlDir:
 
834
            raise AssertionError("ControlDir.create always creates the"
 
835
                "default format, not one of %r" % klass)
 
836
        t = _mod_transport.get_transport(base, possible_transports)
 
837
        t.ensure_base()
 
838
        if format is None:
 
839
            format = ControlDirFormat.get_default_format()
 
840
        return format.initialize_on_transport(t)
 
841
 
 
842
 
 
843
class ControlDirHooks(hooks.Hooks):
 
844
    """Hooks for ControlDir operations."""
 
845
 
 
846
    def __init__(self):
 
847
        """Create the default hooks."""
 
848
        hooks.Hooks.__init__(self, "bzrlib.controldir", "ControlDir.hooks")
 
849
        self.add_hook('pre_open',
 
850
            "Invoked before attempting to open a ControlDir with the transport "
 
851
            "that the open will use.", (1, 14))
 
852
        self.add_hook('post_repo_init',
 
853
            "Invoked after a repository has been initialized. "
 
854
            "post_repo_init is called with a "
 
855
            "bzrlib.controldir.RepoInitHookParams.",
 
856
            (2, 2))
 
857
 
 
858
# install the default hooks
 
859
ControlDir.hooks = ControlDirHooks()
 
860
 
486
861
 
487
862
class ControlComponentFormat(object):
488
 
    """A component that can live inside of a .bzr meta directory."""
 
863
    """A component that can live inside of a control directory."""
489
864
 
490
865
    upgrade_recommended = False
491
866
 
492
 
    def get_format_string(self):
493
 
        """Return the format of this format, if usable in meta directories."""
494
 
        raise NotImplementedError(self.get_format_string)
495
 
 
496
867
    def get_format_description(self):
497
868
        """Return the short description for this format."""
498
869
        raise NotImplementedError(self.get_format_description)
525
896
            ui.ui_factory.recommend_upgrade(
526
897
                self.get_format_description(), basedir)
527
898
 
 
899
    @classmethod
 
900
    def get_format_string(cls):
 
901
        raise NotImplementedError(cls.get_format_string)
 
902
 
528
903
 
529
904
class ControlComponentFormatRegistry(registry.FormatRegistry):
530
905
    """A registry for control components (branch, workingtree, repository)."""
753
1128
        return self.get_format_description().rstrip()
754
1129
 
755
1130
    @classmethod
 
1131
    def all_probers(klass):
 
1132
        return klass._server_probers + klass._probers
 
1133
 
 
1134
    @classmethod
756
1135
    def known_formats(klass):
757
1136
        """Return all the known formats.
758
1137
        """
759
1138
        result = set()
760
 
        for prober_kls in klass._probers + klass._server_probers:
 
1139
        for prober_kls in klass.all_probers():
761
1140
            result.update(prober_kls.known_formats())
762
1141
        return result
763
1142
 
764
1143
    @classmethod
765
 
    def find_format(klass, transport, _server_formats=True):
 
1144
    def find_format(klass, transport, probers=None):
766
1145
        """Return the format present at transport."""
767
 
        if _server_formats:
768
 
            _probers = klass._server_probers + klass._probers
769
 
        else:
770
 
            _probers = klass._probers
771
 
        for prober_kls in _probers:
 
1146
        if probers is None:
 
1147
            probers = klass.all_probers()
 
1148
        for prober_kls in probers:
772
1149
            prober = prober_kls()
773
1150
            try:
774
1151
                return prober.probe_transport(transport)
853
1230
        """Return the current default format."""
854
1231
        return klass._default_format
855
1232
 
 
1233
    def supports_transport(self, transport):
 
1234
        """Check if this format can be opened over a particular transport.
 
1235
        """
 
1236
        raise NotImplementedError(self.supports_transport)
 
1237
 
856
1238
 
857
1239
class Prober(object):
858
1240
    """Abstract class that can be used to detect a particular kind of
881
1263
        raise NotImplementedError(self.probe_transport)
882
1264
 
883
1265
    @classmethod
884
 
    def known_formats(cls):
 
1266
    def known_formats(klass):
885
1267
        """Return the control dir formats known by this prober.
886
1268
 
887
1269
        Multiple probers can return the same formats, so this should
889
1271
 
890
1272
        :return: A set of known formats.
891
1273
        """
892
 
        raise NotImplementedError(cls.known_formats)
 
1274
        raise NotImplementedError(klass.known_formats)
893
1275
 
894
1276
 
895
1277
class ControlDirFormatInfo(object):
1028
1410
            return output
1029
1411
 
1030
1412
 
 
1413
class RepoInitHookParams(object):
 
1414
    """Object holding parameters passed to `*_repo_init` hooks.
 
1415
 
 
1416
    There are 4 fields that hooks may wish to access:
 
1417
 
 
1418
    :ivar repository: Repository created
 
1419
    :ivar format: Repository format
 
1420
    :ivar bzrdir: The controldir for the repository
 
1421
    :ivar shared: The repository is shared
 
1422
    """
 
1423
 
 
1424
    def __init__(self, repository, format, controldir, shared):
 
1425
        """Create a group of RepoInitHook parameters.
 
1426
 
 
1427
        :param repository: Repository created
 
1428
        :param format: Repository format
 
1429
        :param controldir: The controldir for the repository
 
1430
        :param shared: The repository is shared
 
1431
        """
 
1432
        self.repository = repository
 
1433
        self.format = format
 
1434
        self.bzrdir = controldir
 
1435
        self.shared = shared
 
1436
 
 
1437
    def __eq__(self, other):
 
1438
        return self.__dict__ == other.__dict__
 
1439
 
 
1440
    def __repr__(self):
 
1441
        if self.repository:
 
1442
            return "<%s for %s>" % (self.__class__.__name__,
 
1443
                self.repository)
 
1444
        else:
 
1445
            return "<%s for %s>" % (self.__class__.__name__,
 
1446
                self.bzrdir)
 
1447
 
 
1448
 
1031
1449
# Please register new formats after old formats so that formats
1032
1450
# appear in chronological order and format descriptions can build
1033
1451
# on previous ones.