/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-17 00:47:52 UTC
  • mfrom: (7182 work)
  • mto: This revision was merged to the branch mainline in revision 7305.
  • Revision ID: jelmer@jelmer.uk-20181117004752-6ywampe5pfywlby4
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
    errors,
50
50
    registry,
51
51
    )
52
 
from .sixish import (
53
 
    viewitems,
54
 
    )
55
52
 
56
53
 
57
54
class MustHaveWorkingTree(errors.BzrError):
134
131
 
135
132
    def get_branches(self):
136
133
        """Get all branches in this control directory, as a dictionary.
137
 
        
 
134
 
138
135
        :return: Dictionary mapping branch names to instances.
139
136
        """
140
137
        try:
141
 
           return { "": self.open_branch() }
 
138
            return {"": self.open_branch()}
142
139
        except (errors.NotBranchError, errors.NoRepositoryPresent):
143
 
           return {}
 
140
            return {}
144
141
 
145
142
    def is_control_filename(self, filename):
146
143
        """True if filename is the name of a path which is reserved for
197
194
    def destroy_branch(self, name=None):
198
195
        """Destroy a branch in this ControlDir.
199
196
 
200
 
        :param name: Name of the branch to destroy, None for the 
 
197
        :param name: Name of the branch to destroy, None for the
201
198
            user selected branch or "" for the active branch.
202
199
        :raise NotBranchError: When the branch does not exist
203
200
        """
204
201
        raise NotImplementedError(self.destroy_branch)
205
202
 
206
203
    def create_workingtree(self, revision_id=None, from_branch=None,
207
 
        accelerator_tree=None, hardlink=False):
 
204
                           accelerator_tree=None, hardlink=False):
208
205
        """Create a working tree at this ControlDir.
209
206
 
210
207
        :param revision_id: create it as of this revision id.
211
 
        :param from_branch: override controldir branch 
 
208
        :param from_branch: override controldir branch
212
209
            (for lightweight checkouts)
213
210
        :param accelerator_tree: A tree which can be used for retrieving file
214
211
            contents more quickly than the revision tree, i.e. a workingtree.
403
400
        raise NotImplementedError(self.sprout)
404
401
 
405
402
    def push_branch(self, source, revision_id=None, overwrite=False,
406
 
        remember=False, create_prefix=False, lossy=False):
 
403
                    remember=False, create_prefix=False, lossy=False):
407
404
        """Push the source branch into this ControlDir."""
408
405
        br_to = None
409
406
        # If we can open a branch, use its direct repository, otherwise see
446
443
            try:
447
444
                tree_to = self.open_workingtree()
448
445
            except errors.NotLocalUrl:
449
 
                push_result.branch_push_result = source.push(br_to, 
450
 
                    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)
451
448
                push_result.workingtree_updated = False
452
449
            except errors.NoWorkingTree:
453
450
                push_result.branch_push_result = source.push(br_to,
454
 
                    overwrite, stop_revision=revision_id, lossy=lossy)
455
 
                push_result.workingtree_updated = None # Not applicable
 
451
                                                             overwrite, stop_revision=revision_id, lossy=lossy)
 
452
                push_result.workingtree_updated = None  # Not applicable
456
453
            else:
457
454
                with tree_to.lock_write():
458
455
                    push_result.branch_push_result = source.push(
515
512
                                       preserve_stacking=preserve_stacking)
516
513
 
517
514
    def clone_on_transport(self, transport, revision_id=None,
518
 
        force_new_repo=False, preserve_stacking=False, stacked_on=None,
519
 
        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):
520
517
        """Clone this controldir and its contents to transport verbatim.
521
518
 
522
519
        :param transport: The transport for the location to produce the clone
689
686
        if not isinstance(t, local.LocalTransport):
690
687
            raise errors.NotLocalUrl(base)
691
688
        controldir = klass.create_branch_and_repo(base,
692
 
                                               force_new_repo=True,
693
 
                                               format=format).controldir
 
689
                                                  force_new_repo=True,
 
690
                                                  format=format).controldir
694
691
        return controldir.create_workingtree()
695
692
 
696
693
    @classmethod
707
704
        """
708
705
        t = _mod_transport.get_transport(base, possible_transports)
709
706
        return klass.open_from_transport(t, probers=probers,
710
 
                _unsupported=_unsupported)
 
707
                                         _unsupported=_unsupported)
711
708
 
712
709
    @classmethod
713
710
    def open_from_transport(klass, transport, _unsupported=False,
722
719
        # Keep initial base since 'transport' may be modified while following
723
720
        # the redirections.
724
721
        base = transport.base
 
722
 
725
723
        def find_format(transport):
726
724
            return transport, ControlDirFormat.find_format(transport,
727
 
                probers=probers)
 
725
                                                           probers=probers)
728
726
 
729
727
        def redirected(transport, e, redirection_notice):
730
728
            redirected_transport = transport._redirected_to(e.source, e.target)
731
729
            if redirected_transport is None:
732
730
                raise errors.NotBranchError(base)
733
731
            trace.note(gettext('{0} is{1} redirected to {2}').format(
734
 
                 transport.base, e.permanently, redirected_transport.base))
 
732
                transport.base, e.permanently, redirected_transport.base))
735
733
            return redirected_transport
736
734
 
737
735
        try:
775
773
            try:
776
774
                result = klass.open_from_transport(a_transport)
777
775
                return result, urlutils.unescape(a_transport.relpath(url))
778
 
            except errors.NotBranchError as e:
 
776
            except errors.NotBranchError:
779
777
                pass
780
778
            except errors.PermissionDenied:
781
779
                pass
803
801
 
804
802
    @classmethod
805
803
    def open_containing_tree_or_branch(klass, location,
806
 
            possible_transports=None):
 
804
                                       possible_transports=None):
807
805
        """Return the branch and working tree contained by a location.
808
806
 
809
807
        Returns (tree, branch, relpath).
813
811
        relpath is the portion of the path that is contained by the branch.
814
812
        """
815
813
        controldir, relpath = klass.open_containing(location,
816
 
            possible_transports=possible_transports)
 
814
                                                    possible_transports=possible_transports)
817
815
        tree, branch = controldir._get_tree_branch()
818
816
        return tree, branch, relpath
819
817
 
853
851
        """
854
852
        if klass is not ControlDir:
855
853
            raise AssertionError("ControlDir.create always creates the"
856
 
                "default format, not one of %r" % klass)
 
854
                                 "default format, not one of %r" % klass)
857
855
        t = _mod_transport.get_transport(base, possible_transports)
858
856
        t.ensure_base()
859
857
        if format is None:
868
866
        """Create the default hooks."""
869
867
        hooks.Hooks.__init__(self, "breezy.controldir", "ControlDir.hooks")
870
868
        self.add_hook('pre_open',
871
 
            "Invoked before attempting to open a ControlDir with the transport "
872
 
            "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))
873
871
        self.add_hook('post_repo_init',
874
 
            "Invoked after a repository has been initialized. "
875
 
            "post_repo_init is called with a "
876
 
            "breezy.controldir.RepoInitHookParams.",
877
 
            (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
 
878
877
 
879
878
# install the default hooks
880
879
ControlDir.hooks = ControlDirHooks()
899
898
        return True
900
899
 
901
900
    def check_support_status(self, allow_unsupported, recommend_upgrade=True,
902
 
        basedir=None):
 
901
                             basedir=None):
903
902
        """Give an error or warning on old formats.
904
903
 
905
904
        :param allow_unsupported: If true, allow opening
1000
999
 
1001
1000
    def step(self, message):
1002
1001
        """Update the pb by a step."""
1003
 
        self.count +=1
 
1002
        self.count += 1
1004
1003
        self.pb.update(message, self.count, self.total)
1005
1004
 
1006
1005
 
1088
1087
        return self.is_supported()
1089
1088
 
1090
1089
    def check_support_status(self, allow_unsupported, recommend_upgrade=True,
1091
 
        basedir=None):
 
1090
                             basedir=None):
1092
1091
        """Give an error or warning on old formats.
1093
1092
 
1094
1093
        :param allow_unsupported: If true, allow opening
1108
1107
 
1109
1108
    def same_model(self, target_format):
1110
1109
        return (self.repository_format.rich_root_data ==
1111
 
            target_format.rich_root_data)
 
1110
                target_format.rich_root_data)
1112
1111
 
1113
1112
    @classmethod
1114
1113
    def register_prober(klass, prober):
1184
1183
        raise NotImplementedError(self.initialize_on_transport)
1185
1184
 
1186
1185
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
1187
 
        create_prefix=False, force_new_repo=False, stacked_on=None,
1188
 
        stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
1189
 
        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):
1190
1189
        """Create this format on transport.
1191
1190
 
1192
1191
        The directory to initialize will be created.
1318
1317
        supplied directly.
1319
1318
        """
1320
1319
        registry.Registry.register(self, key, factory, help,
1321
 
            ControlDirFormatInfo(native, deprecated, hidden, experimental))
 
1320
                                   ControlDirFormatInfo(native, deprecated, hidden, experimental))
1322
1321
        self._registration_order.append(key)
1323
1322
 
1324
1323
    def register_alias(self, key, target, hidden=False):
1330
1329
        """
1331
1330
        info = self.get_info(target)
1332
1331
        registry.Registry.register_alias(self, key, target,
1333
 
                ControlDirFormatInfo(
1334
 
                    native=info.native, deprecated=info.deprecated,
1335
 
                    hidden=hidden, experimental=info.experimental))
 
1332
                                         ControlDirFormatInfo(
 
1333
                                             native=info.native, deprecated=info.deprecated,
 
1334
                                             hidden=hidden, experimental=info.experimental))
1336
1335
 
1337
1336
    def register_lazy(self, key, module_name, member_name, help, native=True,
1338
 
        deprecated=False, hidden=False, experimental=False):
 
1337
                      deprecated=False, hidden=False, experimental=False):
1339
1338
        registry.Registry.register_lazy(self, key, module_name, member_name,
1340
 
            help, ControlDirFormatInfo(native, deprecated, hidden, experimental))
 
1339
                                        help, ControlDirFormatInfo(native, deprecated, hidden, experimental))
1341
1340
        self._registration_order.append(key)
1342
1341
 
1343
1342
    def set_default(self, key):
1379
1378
            if info.native:
1380
1379
                help = '(native) ' + help
1381
1380
            return ':%s:\n%s\n\n' % (key,
1382
 
                textwrap.fill(help, initial_indent='    ',
1383
 
                    subsequent_indent='    ',
1384
 
                    break_long_words=False))
 
1381
                                     textwrap.fill(help, initial_indent='    ',
 
1382
                                                   subsequent_indent='    ',
 
1383
                                                   break_long_words=False))
1385
1384
        if default_realkey is not None:
1386
1385
            output += wrapped(default_realkey, '(default) %s' % default_help,
1387
1386
                              self.get_info('default'))
1416
1415
            other_output += \
1417
1416
                "\nNo deprecated formats are available.\n\n"
1418
1417
        other_output += \
1419
 
                "\nSee :doc:`formats-help` for more about storage formats."
 
1418
            "\nSee :doc:`formats-help` for more about storage formats."
1420
1419
 
1421
1420
        if topic == 'other-formats':
1422
1421
            return other_output
1454
1453
    def __repr__(self):
1455
1454
        if self.repository:
1456
1455
            return "<%s for %s>" % (self.__class__.__name__,
1457
 
                self.repository)
 
1456
                                    self.repository)
1458
1457
        else:
1459
1458
            return "<%s for %s>" % (self.__class__.__name__,
1460
 
                self.controldir)
 
1459
                                    self.controldir)
1461
1460
 
1462
1461
 
1463
1462
def is_control_filename(filename):
1473
1472
    for a branch that is being created.  The most basic policy decision is
1474
1473
    whether to create a new repository or use an existing one.
1475
1474
    """
 
1475
 
1476
1476
    def __init__(self, stack_on, stack_on_pwd, require_stacking):
1477
1477
        """Constructor.
1478
1478
 
1497
1497
        else:
1498
1498
            try:
1499
1499
                stack_on = urlutils.rebase_url(self._stack_on,
1500
 
                    self._stack_on_pwd,
1501
 
                    branch.user_url)
 
1500
                                               self._stack_on_pwd,
 
1501
                                               branch.user_url)
1502
1502
            except urlutils.InvalidRebaseURLs:
1503
1503
                stack_on = self._get_full_stack_on()
1504
1504
        try:
1528
1528
            return
1529
1529
        try:
1530
1530
            stacked_dir = ControlDir.open(
1531
 
                    stack_on, possible_transports=possible_transports)
 
1531
                stack_on, possible_transports=possible_transports)
1532
1532
        except errors.JailBreak:
1533
1533
            # We keep the stacking details, but we are in the server code so
1534
1534
            # actually stacking is not needed.
1546
1546
            self._require_stacking = True
1547
1547
 
1548
1548
    def acquire_repository(self, make_working_trees=None, shared=False,
1549
 
            possible_transports=None):
 
1549
                           possible_transports=None):
1550
1550
        """Acquire a repository for this controlrdir.
1551
1551
 
1552
1552
        Implementations may create a new repository or use a pre-exising
1558
1558
        :return: A repository, is_new_flag (True if the repository was
1559
1559
            created).
1560
1560
        """
1561
 
        raise NotImplementedError(RepositoryAcquisitionPolicy.acquire_repository)
 
1561
        raise NotImplementedError(
 
1562
            RepositoryAcquisitionPolicy.acquire_repository)
1562
1563
 
1563
1564
 
1564
1565
# Please register new formats after old formats so that formats