/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/controldir.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-11 04:08:32 UTC
  • mto: (7143.16.20 even-more-cleanups)
  • mto: This revision was merged to the branch mainline in revision 7175.
  • Revision ID: jelmer@jelmer.uk-20181111040832-nsljjynzzwmznf3h
Run autopep8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
131
131
 
132
132
    def get_branches(self):
133
133
        """Get all branches in this control directory, as a dictionary.
134
 
        
 
134
 
135
135
        :return: Dictionary mapping branch names to instances.
136
136
        """
137
137
        try:
138
 
           return { "": self.open_branch() }
 
138
            return {"": self.open_branch()}
139
139
        except (errors.NotBranchError, errors.NoRepositoryPresent):
140
 
           return {}
 
140
            return {}
141
141
 
142
142
    def is_control_filename(self, filename):
143
143
        """True if filename is the name of a path which is reserved for
201
201
        raise NotImplementedError(self.destroy_branch)
202
202
 
203
203
    def create_workingtree(self, revision_id=None, from_branch=None,
204
 
        accelerator_tree=None, hardlink=False):
 
204
                           accelerator_tree=None, hardlink=False):
205
205
        """Create a working tree at this ControlDir.
206
206
 
207
207
        :param revision_id: create it as of this revision id.
400
400
        raise NotImplementedError(self.sprout)
401
401
 
402
402
    def push_branch(self, source, revision_id=None, overwrite=False,
403
 
        remember=False, create_prefix=False, lossy=False):
 
403
                    remember=False, create_prefix=False, lossy=False):
404
404
        """Push the source branch into this ControlDir."""
405
405
        br_to = None
406
406
        # If we can open a branch, use its direct repository, otherwise see
443
443
            try:
444
444
                tree_to = self.open_workingtree()
445
445
            except errors.NotLocalUrl:
446
 
                push_result.branch_push_result = source.push(br_to, 
447
 
                    overwrite, stop_revision=revision_id, lossy=lossy)
 
446
                push_result.branch_push_result = source.push(br_to,
 
447
                                                             overwrite, stop_revision=revision_id, lossy=lossy)
448
448
                push_result.workingtree_updated = False
449
449
            except errors.NoWorkingTree:
450
450
                push_result.branch_push_result = source.push(br_to,
451
 
                    overwrite, stop_revision=revision_id, lossy=lossy)
452
 
                push_result.workingtree_updated = None # Not applicable
 
451
                                                             overwrite, stop_revision=revision_id, lossy=lossy)
 
452
                push_result.workingtree_updated = None  # Not applicable
453
453
            else:
454
454
                with tree_to.lock_write():
455
455
                    push_result.branch_push_result = source.push(
512
512
                                       preserve_stacking=preserve_stacking)
513
513
 
514
514
    def clone_on_transport(self, transport, revision_id=None,
515
 
        force_new_repo=False, preserve_stacking=False, stacked_on=None,
516
 
        create_prefix=False, use_existing_dir=True, no_tree=False):
 
515
                           force_new_repo=False, preserve_stacking=False, stacked_on=None,
 
516
                           create_prefix=False, use_existing_dir=True, no_tree=False):
517
517
        """Clone this controldir and its contents to transport verbatim.
518
518
 
519
519
        :param transport: The transport for the location to produce the clone
686
686
        if not isinstance(t, local.LocalTransport):
687
687
            raise errors.NotLocalUrl(base)
688
688
        controldir = klass.create_branch_and_repo(base,
689
 
                                               force_new_repo=True,
690
 
                                               format=format).controldir
 
689
                                                  force_new_repo=True,
 
690
                                                  format=format).controldir
691
691
        return controldir.create_workingtree()
692
692
 
693
693
    @classmethod
704
704
        """
705
705
        t = _mod_transport.get_transport(base, possible_transports)
706
706
        return klass.open_from_transport(t, probers=probers,
707
 
                _unsupported=_unsupported)
 
707
                                         _unsupported=_unsupported)
708
708
 
709
709
    @classmethod
710
710
    def open_from_transport(klass, transport, _unsupported=False,
719
719
        # Keep initial base since 'transport' may be modified while following
720
720
        # the redirections.
721
721
        base = transport.base
 
722
 
722
723
        def find_format(transport):
723
724
            return transport, ControlDirFormat.find_format(transport,
724
 
                probers=probers)
 
725
                                                           probers=probers)
725
726
 
726
727
        def redirected(transport, e, redirection_notice):
727
728
            redirected_transport = transport._redirected_to(e.source, e.target)
728
729
            if redirected_transport is None:
729
730
                raise errors.NotBranchError(base)
730
731
            trace.note(gettext('{0} is{1} redirected to {2}').format(
731
 
                 transport.base, e.permanently, redirected_transport.base))
 
732
                transport.base, e.permanently, redirected_transport.base))
732
733
            return redirected_transport
733
734
 
734
735
        try:
800
801
 
801
802
    @classmethod
802
803
    def open_containing_tree_or_branch(klass, location,
803
 
            possible_transports=None):
 
804
                                       possible_transports=None):
804
805
        """Return the branch and working tree contained by a location.
805
806
 
806
807
        Returns (tree, branch, relpath).
810
811
        relpath is the portion of the path that is contained by the branch.
811
812
        """
812
813
        controldir, relpath = klass.open_containing(location,
813
 
            possible_transports=possible_transports)
 
814
                                                    possible_transports=possible_transports)
814
815
        tree, branch = controldir._get_tree_branch()
815
816
        return tree, branch, relpath
816
817
 
850
851
        """
851
852
        if klass is not ControlDir:
852
853
            raise AssertionError("ControlDir.create always creates the"
853
 
                "default format, not one of %r" % klass)
 
854
                                 "default format, not one of %r" % klass)
854
855
        t = _mod_transport.get_transport(base, possible_transports)
855
856
        t.ensure_base()
856
857
        if format is None:
865
866
        """Create the default hooks."""
866
867
        hooks.Hooks.__init__(self, "breezy.controldir", "ControlDir.hooks")
867
868
        self.add_hook('pre_open',
868
 
            "Invoked before attempting to open a ControlDir with the transport "
869
 
            "that the open will use.", (1, 14))
 
869
                      "Invoked before attempting to open a ControlDir with the transport "
 
870
                      "that the open will use.", (1, 14))
870
871
        self.add_hook('post_repo_init',
871
 
            "Invoked after a repository has been initialized. "
872
 
            "post_repo_init is called with a "
873
 
            "breezy.controldir.RepoInitHookParams.",
874
 
            (2, 2))
 
872
                      "Invoked after a repository has been initialized. "
 
873
                      "post_repo_init is called with a "
 
874
                      "breezy.controldir.RepoInitHookParams.",
 
875
                      (2, 2))
 
876
 
875
877
 
876
878
# install the default hooks
877
879
ControlDir.hooks = ControlDirHooks()
896
898
        return True
897
899
 
898
900
    def check_support_status(self, allow_unsupported, recommend_upgrade=True,
899
 
        basedir=None):
 
901
                             basedir=None):
900
902
        """Give an error or warning on old formats.
901
903
 
902
904
        :param allow_unsupported: If true, allow opening
997
999
 
998
1000
    def step(self, message):
999
1001
        """Update the pb by a step."""
1000
 
        self.count +=1
 
1002
        self.count += 1
1001
1003
        self.pb.update(message, self.count, self.total)
1002
1004
 
1003
1005
 
1085
1087
        return self.is_supported()
1086
1088
 
1087
1089
    def check_support_status(self, allow_unsupported, recommend_upgrade=True,
1088
 
        basedir=None):
 
1090
                             basedir=None):
1089
1091
        """Give an error or warning on old formats.
1090
1092
 
1091
1093
        :param allow_unsupported: If true, allow opening
1105
1107
 
1106
1108
    def same_model(self, target_format):
1107
1109
        return (self.repository_format.rich_root_data ==
1108
 
            target_format.rich_root_data)
 
1110
                target_format.rich_root_data)
1109
1111
 
1110
1112
    @classmethod
1111
1113
    def register_prober(klass, prober):
1181
1183
        raise NotImplementedError(self.initialize_on_transport)
1182
1184
 
1183
1185
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
1184
 
        create_prefix=False, force_new_repo=False, stacked_on=None,
1185
 
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
1186
 
        shared_repo=False, vfs_only=False):
 
1186
                                   create_prefix=False, force_new_repo=False, stacked_on=None,
 
1187
                                   stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
 
1188
                                   shared_repo=False, vfs_only=False):
1187
1189
        """Create this format on transport.
1188
1190
 
1189
1191
        The directory to initialize will be created.
1315
1317
        supplied directly.
1316
1318
        """
1317
1319
        registry.Registry.register(self, key, factory, help,
1318
 
            ControlDirFormatInfo(native, deprecated, hidden, experimental))
 
1320
                                   ControlDirFormatInfo(native, deprecated, hidden, experimental))
1319
1321
        self._registration_order.append(key)
1320
1322
 
1321
1323
    def register_alias(self, key, target, hidden=False):
1327
1329
        """
1328
1330
        info = self.get_info(target)
1329
1331
        registry.Registry.register_alias(self, key, target,
1330
 
                ControlDirFormatInfo(
1331
 
                    native=info.native, deprecated=info.deprecated,
1332
 
                    hidden=hidden, experimental=info.experimental))
 
1332
                                         ControlDirFormatInfo(
 
1333
                                             native=info.native, deprecated=info.deprecated,
 
1334
                                             hidden=hidden, experimental=info.experimental))
1333
1335
 
1334
1336
    def register_lazy(self, key, module_name, member_name, help, native=True,
1335
 
        deprecated=False, hidden=False, experimental=False):
 
1337
                      deprecated=False, hidden=False, experimental=False):
1336
1338
        registry.Registry.register_lazy(self, key, module_name, member_name,
1337
 
            help, ControlDirFormatInfo(native, deprecated, hidden, experimental))
 
1339
                                        help, ControlDirFormatInfo(native, deprecated, hidden, experimental))
1338
1340
        self._registration_order.append(key)
1339
1341
 
1340
1342
    def set_default(self, key):
1376
1378
            if info.native:
1377
1379
                help = '(native) ' + help
1378
1380
            return ':%s:\n%s\n\n' % (key,
1379
 
                textwrap.fill(help, initial_indent='    ',
1380
 
                    subsequent_indent='    ',
1381
 
                    break_long_words=False))
 
1381
                                     textwrap.fill(help, initial_indent='    ',
 
1382
                                                   subsequent_indent='    ',
 
1383
                                                   break_long_words=False))
1382
1384
        if default_realkey is not None:
1383
1385
            output += wrapped(default_realkey, '(default) %s' % default_help,
1384
1386
                              self.get_info('default'))
1413
1415
            other_output += \
1414
1416
                "\nNo deprecated formats are available.\n\n"
1415
1417
        other_output += \
1416
 
                "\nSee :doc:`formats-help` for more about storage formats."
 
1418
            "\nSee :doc:`formats-help` for more about storage formats."
1417
1419
 
1418
1420
        if topic == 'other-formats':
1419
1421
            return other_output
1451
1453
    def __repr__(self):
1452
1454
        if self.repository:
1453
1455
            return "<%s for %s>" % (self.__class__.__name__,
1454
 
                self.repository)
 
1456
                                    self.repository)
1455
1457
        else:
1456
1458
            return "<%s for %s>" % (self.__class__.__name__,
1457
 
                self.controldir)
 
1459
                                    self.controldir)
1458
1460
 
1459
1461
 
1460
1462
def is_control_filename(filename):
1470
1472
    for a branch that is being created.  The most basic policy decision is
1471
1473
    whether to create a new repository or use an existing one.
1472
1474
    """
 
1475
 
1473
1476
    def __init__(self, stack_on, stack_on_pwd, require_stacking):
1474
1477
        """Constructor.
1475
1478
 
1494
1497
        else:
1495
1498
            try:
1496
1499
                stack_on = urlutils.rebase_url(self._stack_on,
1497
 
                    self._stack_on_pwd,
1498
 
                    branch.user_url)
 
1500
                                               self._stack_on_pwd,
 
1501
                                               branch.user_url)
1499
1502
            except urlutils.InvalidRebaseURLs:
1500
1503
                stack_on = self._get_full_stack_on()
1501
1504
        try:
1525
1528
            return
1526
1529
        try:
1527
1530
            stacked_dir = ControlDir.open(
1528
 
                    stack_on, possible_transports=possible_transports)
 
1531
                stack_on, possible_transports=possible_transports)
1529
1532
        except errors.JailBreak:
1530
1533
            # We keep the stacking details, but we are in the server code so
1531
1534
            # actually stacking is not needed.
1543
1546
            self._require_stacking = True
1544
1547
 
1545
1548
    def acquire_repository(self, make_working_trees=None, shared=False,
1546
 
            possible_transports=None):
 
1549
                           possible_transports=None):
1547
1550
        """Acquire a repository for this controlrdir.
1548
1551
 
1549
1552
        Implementations may create a new repository or use a pre-exising
1555
1558
        :return: A repository, is_new_flag (True if the repository was
1556
1559
            created).
1557
1560
        """
1558
 
        raise NotImplementedError(RepositoryAcquisitionPolicy.acquire_repository)
 
1561
        raise NotImplementedError(
 
1562
            RepositoryAcquisitionPolicy.acquire_repository)
1559
1563
 
1560
1564
 
1561
1565
# Please register new formats after old formats so that formats