/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 bzrlib/bzrdir.py

  • Committer: Martin Pool
  • Date: 2007-10-08 07:29:57 UTC
  • mfrom: (2894 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2895.
  • Revision ID: mbp@sourcefrog.net-20071008072957-uhm1gl1mqcsdc377
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
At format 7 this was split out into Branch, Repository and Checkout control
20
20
directories.
 
21
 
 
22
Note: This module has a lot of ``open`` functions/methods that return
 
23
references to in-memory objects. As a rule, there are no matching ``close``
 
24
methods. To free any associated resources, simply stop referencing the
 
25
objects returned.
21
26
"""
22
27
 
23
 
# TODO: Can we move specific formats into separate modules to make this file
24
 
# smaller?
 
28
# TODO: Move old formats into a plugin to make this file smaller.
25
29
 
26
30
from cStringIO import StringIO
27
31
import os
87
91
    transport
88
92
        the transport which this bzr dir is rooted at (i.e. file:///.../.bzr/)
89
93
    root_transport
90
 
        a transport connected to the directory this bzr was opened from.
 
94
        a transport connected to the directory this bzr was opened from
 
95
        (i.e. the parent directory holding the .bzr directory).
91
96
    """
92
97
 
93
98
    def break_lock(self):
150
155
    def clone(self, url, revision_id=None, force_new_repo=False):
151
156
        """Clone this bzrdir and its contents to url verbatim.
152
157
 
153
 
        If urls last component does not exist, it will be created.
 
158
        If url's last component does not exist, it will be created.
154
159
 
155
160
        if revision_id is not None, then the clone operation may tune
156
161
            itself to download less data.
219
224
    def create(cls, base, format=None, possible_transports=None):
220
225
        """Create a new BzrDir at the url 'base'.
221
226
        
222
 
        This will call the current default formats initialize with base
223
 
        as the only parameter.
224
 
 
225
227
        :param format: If supplied, the format of branch to create.  If not
226
228
            supplied, the default is used.
227
229
        :param possible_transports: If supplied, a list of transports that 
234
236
        t.ensure_base()
235
237
        if format is None:
236
238
            format = BzrDirFormat.get_default_format()
237
 
        return format.initialize(base, possible_transports)
 
239
        return format.initialize_on_transport(t)
238
240
 
239
241
    def create_branch(self):
240
242
        """Create a branch in this BzrDir.
241
243
 
242
 
        The bzrdirs format will control what branch format is created.
 
244
        The bzrdir's format will control what branch format is created.
243
245
        For more control see BranchFormatXX.create(a_bzrdir).
244
246
        """
245
247
        raise NotImplementedError(self.create_branch)
252
254
    def create_branch_and_repo(base, force_new_repo=False, format=None):
253
255
        """Create a new BzrDir, Branch and Repository at the url 'base'.
254
256
 
255
 
        This will use the current default BzrDirFormat, and use whatever 
 
257
        This will use the current default BzrDirFormat unless one is
 
258
        specified, and use whatever 
256
259
        repository format that that uses via bzrdir.create_branch and
257
260
        create_repository. If a shared repository is available that is used
258
261
        preferentially.
261
264
 
262
265
        :param base: The URL to create the branch at.
263
266
        :param force_new_repo: If True a new repository is always created.
 
267
        :param format: If supplied, the format of branch to create.  If not
 
268
            supplied, the default is used.
264
269
        """
265
270
        bzrdir = BzrDir.create(base, format)
266
271
        bzrdir._find_or_create_repository(force_new_repo)
285
290
        if possible, can be told explicitly whether to create a working tree or
286
291
        not.
287
292
 
288
 
        This will use the current default BzrDirFormat, and use whatever 
 
293
        This will use the current default BzrDirFormat unless one is
 
294
        specified, and use whatever 
289
295
        repository format that that uses via bzrdir.create_branch and
290
296
        create_repository. If a shared repository is available that is used
291
297
        preferentially. Whatever repository is used, its tree creation policy
300
306
        :param force_new_repo: If True a new repository is always created.
301
307
        :param force_new_tree: If True or False force creation of a tree or 
302
308
                               prevent such creation respectively.
303
 
        :param format: Override for the for the bzrdir format to create.
 
309
        :param format: Override for the bzrdir format to create.
304
310
        :param possible_transports: An optional reusable transports list.
305
311
        """
306
312
        if force_new_tree:
348
354
 
349
355
        'base' must be a local path or a file:// url.
350
356
 
351
 
        This will use the current default BzrDirFormat, and use whatever 
 
357
        This will use the current default BzrDirFormat unless one is
 
358
        specified, and use whatever 
352
359
        repository format that that uses for bzrdirformat.create_workingtree,
353
360
        create_branch and create_repository.
354
361
 
 
362
        :param format: Override for the bzrdir format to create.
355
363
        :return: The WorkingTree object.
356
364
        """
357
365
        t = get_transport(base)
369
377
        """
370
378
        raise NotImplementedError(self.create_workingtree)
371
379
 
372
 
    def retire_bzrdir(self):
 
380
    def retire_bzrdir(self, limit=10000):
373
381
        """Permanently disable the bzrdir.
374
382
 
375
383
        This is done by renaming it to give the user some ability to recover
377
385
 
378
386
        This will have horrible consequences if anyone has anything locked or
379
387
        in use.
 
388
        :param limit: number of times to retry
380
389
        """
381
 
        for i in xrange(10000):
 
390
        i  = 0
 
391
        while True:
382
392
            try:
383
393
                to_path = '.bzr.retired.%d' % i
384
394
                self.root_transport.rename('.bzr', to_path)
385
395
                note("renamed %s to %s"
386
396
                    % (self.root_transport.abspath('.bzr'), to_path))
387
 
                break
 
397
                return
388
398
            except (errors.TransportError, IOError, errors.PathError):
389
 
                pass
 
399
                i += 1
 
400
                if i > limit:
 
401
                    raise
 
402
                else:
 
403
                    pass
390
404
 
391
405
    def destroy_workingtree(self):
392
406
        """Destroy the working tree at this BzrDir.
404
418
        raise NotImplementedError(self.destroy_workingtree_metadata)
405
419
 
406
420
    def find_repository(self):
407
 
        """Find the repository that should be used for a_bzrdir.
 
421
        """Find the repository that should be used.
408
422
 
409
423
        This does not require a branch as we use it to find the repo for
410
424
        new branches as well as to hook existing branches up to their
457
471
        a format string, and vice versa.
458
472
 
459
473
        If branch_format is None, the transport is returned with no 
460
 
        checking. if it is not None, then the returned transport is
 
474
        checking. If it is not None, then the returned transport is
461
475
        guaranteed to point to an existing directory ready for use.
462
476
        """
463
477
        raise NotImplementedError(self.get_branch_transport)
470
484
        a format string, and vice versa.
471
485
 
472
486
        If repository_format is None, the transport is returned with no 
473
 
        checking. if it is not None, then the returned transport is
 
487
        checking. If it is not None, then the returned transport is
474
488
        guaranteed to point to an existing directory ready for use.
475
489
        """
476
490
        raise NotImplementedError(self.get_repository_transport)
483
497
        format string, and vice versa.
484
498
 
485
499
        If workingtree_format is None, the transport is returned with no 
486
 
        checking. if it is not None, then the returned transport is
 
500
        checking. If it is not None, then the returned transport is
487
501
        guaranteed to point to an existing directory ready for use.
488
502
        """
489
503
        raise NotImplementedError(self.get_workingtree_transport)
515
529
        # this might be better on the BzrDirFormat class because it refers to 
516
530
        # all the possible bzrdir disk formats. 
517
531
        # This method is tested via the workingtree is_control_filename tests- 
518
 
        # it was extracted from WorkingTree.is_control_filename. If the methods
519
 
        # contract is extended beyond the current trivial  implementation please
 
532
        # it was extracted from WorkingTree.is_control_filename. If the method's
 
533
        # contract is extended beyond the current trivial implementation, please
520
534
        # add new tests for it to the appropriate place.
521
535
        return filename == '.bzr' or filename.startswith('.bzr/')
522
536
 
538
552
        
539
553
    @staticmethod
540
554
    def open(base, _unsupported=False, possible_transports=None):
541
 
        """Open an existing bzrdir, rooted at 'base' (url)
 
555
        """Open an existing bzrdir, rooted at 'base' (url).
542
556
        
543
 
        _unsupported is a private parameter to the BzrDir class.
 
557
        :param _unsupported: a private parameter to the BzrDir class.
544
558
        """
545
559
        t = get_transport(base, possible_transports=possible_transports)
546
560
        return BzrDir.open_from_transport(t, _unsupported=_unsupported)
569
583
            note('%s is%s redirected to %s',
570
584
                 transport.base, e.permanently, target)
571
585
            # Let's try with a new transport
572
 
            qualified_target = e.get_target_url()[:-len(relpath)]
573
586
            # FIXME: If 'transport' has a qualifier, this should
574
587
            # be applied again to the new transport *iff* the
575
 
            # schemes used are the same. It's a bit tricky to
576
 
            # verify, so I'll punt for now
 
588
            # schemes used are the same. Uncomment this code
 
589
            # once the function (and tests) exist.
577
590
            # -- vila20070212
 
591
            #target = urlutils.copy_url_qualifiers(original, target)
578
592
            return get_transport(target)
579
593
 
580
594
        try:
609
623
    
610
624
    @staticmethod
611
625
    def open_containing_from_transport(a_transport):
612
 
        """Open an existing branch which contains a_transport.base
 
626
        """Open an existing branch which contains a_transport.base.
613
627
 
614
628
        This probes for a branch at a_transport, and searches upwards from there.
615
629
 
663
677
    def open_repository(self, _unsupported=False):
664
678
        """Open the repository object at this BzrDir if one is present.
665
679
 
666
 
        This will not follow the Branch object pointer - its strictly a direct
 
680
        This will not follow the Branch object pointer - it's strictly a direct
667
681
        open facility. Most client code should use open_branch().repository to
668
682
        get at a repository.
669
683
 
670
 
        _unsupported is a private parameter, not part of the api.
 
684
        :param _unsupported: a private parameter, not part of the api.
671
685
        TODO: static convenience version of this?
672
686
        """
673
687
        raise NotImplementedError(self.open_repository)
713
727
            return False
714
728
 
715
729
    def _cloning_metadir(self):
716
 
        """Produce a metadir suitable for cloning with"""
 
730
        """Produce a metadir suitable for cloning with."""
717
731
        result_format = self._format.__class__()
718
732
        try:
719
733
            try:
746
760
        """Produce a metadir suitable for cloning or sprouting with.
747
761
 
748
762
        These operations may produce workingtrees (yes, even though they're
749
 
        "cloning" something that doesn't have a tree, so a viable workingtree
 
763
        "cloning" something that doesn't have a tree), so a viable workingtree
750
764
        format must be selected.
751
765
        """
752
766
        format, repository = self._cloning_metadir()
765
779
        """Create a copy of this bzrdir prepared for use as a new line of
766
780
        development.
767
781
 
768
 
        If urls last component does not exist, it will be created.
 
782
        If url's last component does not exist, it will be created.
769
783
 
770
784
        Attributes related to the identity of the source branch like
771
785
        branch nickname will be cleaned, a working tree is created
1228
1242
     * a format string,
1229
1243
     * an open routine.
1230
1244
 
1231
 
    Formats are placed in an dict by their format string for reference 
 
1245
    Formats are placed in a dict by their format string for reference 
1232
1246
    during bzrdir opening. These should be subclasses of BzrDirFormat
1233
1247
    for consistency.
1234
1248
 
1445
1459
        klass._default_format = format
1446
1460
 
1447
1461
    def __str__(self):
1448
 
        return self.get_format_string()[:-1]
 
1462
        # Trim the newline
 
1463
        return self.get_format_string().rstrip()
1449
1464
 
1450
1465
    @classmethod
1451
1466
    def unregister_format(klass, format):