/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: 2019-05-20 03:57:29 UTC
  • mto: This revision was merged to the branch mainline in revision 7328.
  • Revision ID: jelmer@jelmer.uk-20190520035729-9rxvefxkvbbivygy
use default_user_agent function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
129
129
        """
130
130
        return list(self.get_branches().values())
131
131
 
132
 
    def branch_names(self):
133
 
        """List all branch names in this control directory.
134
 
 
135
 
        :return: List of branch names
136
 
        """
137
 
        try:
138
 
            self.get_branch_reference()
139
 
        except (errors.NotBranchError, errors.NoRepositoryPresent):
140
 
            return []
141
 
        else:
142
 
            return [""]
143
 
 
144
132
    def get_branches(self):
145
133
        """Get all branches in this control directory, as a dictionary.
146
134
 
164
152
        this in the future - for instance to make bzr talk with svn working
165
153
        trees.
166
154
        """
167
 
        return self._format.is_control_filename(filename)
 
155
        raise NotImplementedError(self.is_control_filename)
168
156
 
169
157
    def needs_format_conversion(self, format=None):
170
158
        """Return true if this controldir needs convert_format run on it.
412
400
        raise NotImplementedError(self.sprout)
413
401
 
414
402
    def push_branch(self, source, revision_id=None, overwrite=False,
415
 
                    remember=False, create_prefix=False, lossy=False,
416
 
                    tag_selector=None):
 
403
                    remember=False, create_prefix=False, lossy=False):
417
404
        """Push the source branch into this ControlDir."""
418
405
        br_to = None
419
406
        # If we can open a branch, use its direct repository, otherwise see
437
424
                # revision
438
425
                revision_id = source.last_revision()
439
426
            repository_to.fetch(source.repository, revision_id=revision_id)
440
 
            br_to = source.sprout(
441
 
                self, revision_id=revision_id, lossy=lossy,
442
 
                tag_selector=tag_selector)
 
427
            br_to = source.sprout(self, revision_id=revision_id, lossy=lossy)
443
428
            if source.get_push_location() is None or remember:
444
429
                # FIXME: Should be done only if we succeed ? -- vila 2012-01-18
445
430
                source.set_push_location(br_to.base)
458
443
            try:
459
444
                tree_to = self.open_workingtree()
460
445
            except errors.NotLocalUrl:
461
 
                push_result.branch_push_result = source.push(
462
 
                    br_to, overwrite, stop_revision=revision_id, lossy=lossy,
463
 
                    tag_selector=tag_selector)
 
446
                push_result.branch_push_result = source.push(br_to,
 
447
                                                             overwrite, stop_revision=revision_id, lossy=lossy)
464
448
                push_result.workingtree_updated = False
465
449
            except errors.NoWorkingTree:
466
 
                push_result.branch_push_result = source.push(
467
 
                    br_to, overwrite, stop_revision=revision_id, lossy=lossy,
468
 
                    tag_selector=tag_selector)
 
450
                push_result.branch_push_result = source.push(br_to,
 
451
                                                             overwrite, stop_revision=revision_id, lossy=lossy)
469
452
                push_result.workingtree_updated = None  # Not applicable
470
453
            else:
471
454
                with tree_to.lock_write():
472
455
                    push_result.branch_push_result = source.push(
473
456
                        tree_to.branch, overwrite, stop_revision=revision_id,
474
 
                        lossy=lossy, tag_selector=tag_selector)
 
457
                        lossy=lossy)
475
458
                    tree_to.update()
476
459
                push_result.workingtree_updated = True
477
460
            push_result.old_revno = push_result.branch_push_result.old_revno
510
493
        raise NotImplementedError(self.check_conversion_target)
511
494
 
512
495
    def clone(self, url, revision_id=None, force_new_repo=False,
513
 
              preserve_stacking=False, tag_selector=None):
 
496
              preserve_stacking=False):
514
497
        """Clone this controldir and its contents to url verbatim.
515
498
 
516
499
        :param url: The url create the clone at.  If url's last component does
526
509
        return self.clone_on_transport(_mod_transport.get_transport(url),
527
510
                                       revision_id=revision_id,
528
511
                                       force_new_repo=force_new_repo,
529
 
                                       preserve_stacking=preserve_stacking,
530
 
                                       tag_selector=tag_selector)
 
512
                                       preserve_stacking=preserve_stacking)
531
513
 
532
514
    def clone_on_transport(self, transport, revision_id=None,
533
515
                           force_new_repo=False, preserve_stacking=False, stacked_on=None,
534
 
                           create_prefix=False, use_existing_dir=True, no_tree=False,
535
 
                           tag_selector=None):
 
516
                           create_prefix=False, use_existing_dir=True, no_tree=False):
536
517
        """Clone this controldir and its contents to transport verbatim.
537
518
 
538
519
        :param transport: The transport for the location to produce the clone
580
561
            recurse = True
581
562
            try:
582
563
                controldir = klass.open_from_transport(current_transport)
583
 
            except (errors.NotBranchError, errors.PermissionDenied,
584
 
                    errors.UnknownFormatError):
 
564
            except (errors.NotBranchError, errors.PermissionDenied):
585
565
                pass
586
566
            else:
587
567
                recurse, value = evaluate(controldir)
808
788
            a_transport = new_t
809
789
 
810
790
    @classmethod
811
 
    def open_tree_or_branch(klass, location, name=None):
 
791
    def open_tree_or_branch(klass, location):
812
792
        """Return the branch and working tree at a location.
813
793
 
814
794
        If there is no tree at the location, tree will be None.
817
797
        :return: (tree, branch)
818
798
        """
819
799
        controldir = klass.open(location)
820
 
        return controldir._get_tree_branch(name=name)
 
800
        return controldir._get_tree_branch()
821
801
 
822
802
    @classmethod
823
803
    def open_containing_tree_or_branch(klass, location,
1047
1027
    _default_format = None
1048
1028
    """The default format used for new control directories."""
1049
1029
 
 
1030
    _server_probers = []
 
1031
    """The registered server format probers, e.g. RemoteBzrProber.
 
1032
 
 
1033
    This is a list of Prober-derived classes.
 
1034
    """
 
1035
 
1050
1036
    _probers = []
1051
1037
    """The registered format probers, e.g. BzrProber.
1052
1038
 
1137
1123
        """
1138
1124
        klass._probers.remove(prober)
1139
1125
 
 
1126
    @classmethod
 
1127
    def register_server_prober(klass, prober):
 
1128
        """Register a control format prober for client-server environments.
 
1129
 
 
1130
        These probers will be used before ones registered with
 
1131
        register_prober.  This gives implementations that decide to the
 
1132
        chance to grab it before anything looks at the contents of the format
 
1133
        file.
 
1134
        """
 
1135
        klass._server_probers.append(prober)
 
1136
 
1140
1137
    def __str__(self):
1141
1138
        # Trim the newline
1142
1139
        return self.get_format_description().rstrip()
1143
1140
 
1144
1141
    @classmethod
1145
1142
    def all_probers(klass):
1146
 
        return klass._probers
 
1143
        return klass._server_probers + klass._probers
1147
1144
 
1148
1145
    @classmethod
1149
1146
    def known_formats(klass):
1158
1155
    def find_format(klass, transport, probers=None):
1159
1156
        """Return the format present at transport."""
1160
1157
        if probers is None:
1161
 
            probers = sorted(
1162
 
                klass.all_probers(),
1163
 
                key=lambda prober: prober.priority(transport))
 
1158
            probers = klass.all_probers()
1164
1159
        for prober_kls in probers:
1165
1160
            prober = prober_kls()
1166
1161
            try:
1251
1246
        """
1252
1247
        raise NotImplementedError(self.supports_transport)
1253
1248
 
1254
 
    @classmethod
1255
 
    def is_control_filename(klass, filename):
1256
 
        """True if filename is the name of a path which is reserved for
1257
 
        controldirs.
1258
 
 
1259
 
        :param filename: A filename within the root transport of this
1260
 
            controldir.
1261
 
 
1262
 
        This is true IF and ONLY IF the filename is part of the namespace reserved
1263
 
        for bzr control dirs. Currently this is the '.bzr' directory in the root
1264
 
        of the root_transport. it is expected that plugins will need to extend
1265
 
        this in the future - for instance to make bzr talk with svn working
1266
 
        trees.
1267
 
        """
1268
 
        raise NotImplementedError(self.is_control_filename)
1269
 
 
1270
1249
 
1271
1250
class Prober(object):
1272
1251
    """Abstract class that can be used to detect a particular kind of
1280
1259
    probers that detect .bzr/ directories and Bazaar smart servers,
1281
1260
    respectively.
1282
1261
 
1283
 
    Probers should be registered using the register_prober methods on
1284
 
    ControlDirFormat.
 
1262
    Probers should be registered using the register_server_prober or
 
1263
    register_prober methods on ControlDirFormat.
1285
1264
    """
1286
1265
 
1287
1266
    def probe_transport(self, transport):
1305
1284
        """
1306
1285
        raise NotImplementedError(klass.known_formats)
1307
1286
 
1308
 
    @classmethod
1309
 
    def priority(klass, transport):
1310
 
        """Priority of this prober.
1311
 
 
1312
 
        A lower value means the prober gets checked first.
1313
 
 
1314
 
        Other conventions:
1315
 
 
1316
 
        -10: This is a "server" prober
1317
 
        0: No priority set
1318
 
        10: This is a regular file-based prober
1319
 
        100: This is a prober for an unsupported format
1320
 
        """
1321
 
        return 0
1322
 
 
1323
1287
 
1324
1288
class ControlDirFormatInfo(object):
1325
1289
 
1497
1461
 
1498
1462
def is_control_filename(filename):
1499
1463
    """Check if filename is used for control directories."""
1500
 
    # TODO(jelmer): Instead, have a function that returns all control
1501
 
    # filenames.
1502
 
    for key, format in format_registry.items():
1503
 
        if format().is_control_filename(filename):
1504
 
            return True
1505
 
    else:
1506
 
        return False
 
1464
    # TODO(jelmer): Allow registration by other VCSes
 
1465
    return filename == '.bzr'
1507
1466
 
1508
1467
 
1509
1468
class RepositoryAcquisitionPolicy(object):