/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: Jelmer Vernooij
  • Date: 2006-06-13 13:24:40 UTC
  • mfrom: (1767 +trunk)
  • mto: (1769.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 1770.
  • Revision ID: jelmer@samba.org-20060613132440-24e222a86f948f60
[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
import bzrlib.errors as errors
30
30
from bzrlib.lockable_files import LockableFiles, TransportLock
31
31
from bzrlib.lockdir import LockDir
32
 
from bzrlib.osutils import safe_unicode
33
32
from bzrlib.osutils import (
34
33
                            abspath,
35
34
                            pathjoin,
43
42
from bzrlib.symbol_versioning import *
44
43
from bzrlib.trace import mutter
45
44
from bzrlib.transactions import WriteTransaction
46
 
from bzrlib.transport import get_transport, urlunescape
 
45
from bzrlib.transport import get_transport
47
46
from bzrlib.transport.local import LocalTransport
 
47
import bzrlib.urlutils as urlutils
48
48
from bzrlib.weave import Weave
49
49
from bzrlib.xml4 import serializer_v4
50
 
from bzrlib.xml5 import serializer_v5
 
50
import bzrlib.xml5
51
51
 
52
52
 
53
53
class BzrDir(object):
173
173
                    basis_repo = None
174
174
        return basis_repo, basis_branch, basis_tree
175
175
 
 
176
    # TODO: This should be given a Transport, and should chdir up; otherwise
 
177
    # this will open a new connection.
176
178
    def _make_tail(self, url):
177
 
        segments = url.split('/')
178
 
        if segments and segments[-1] not in ('', '.'):
179
 
            parent = '/'.join(segments[:-1])
180
 
            t = bzrlib.transport.get_transport(parent)
 
179
        head, tail = urlutils.split(url)
 
180
        if tail and tail != '.':
 
181
            t = bzrlib.transport.get_transport(head)
181
182
            try:
182
 
                t.mkdir(segments[-1])
 
183
                t.mkdir(tail)
183
184
            except errors.FileExists:
184
185
                pass
185
186
 
 
187
    # TODO: Should take a Transport
186
188
    @classmethod
187
189
    def create(cls, base):
188
190
        """Create a new BzrDir at the url 'base'.
196
198
        if cls is not BzrDir:
197
199
            raise AssertionError("BzrDir.create always creates the default format, "
198
200
                    "not one of %r" % cls)
199
 
        segments = base.split('/')
200
 
        if segments and segments[-1] not in ('', '.'):
201
 
            parent = '/'.join(segments[:-1])
202
 
            t = bzrlib.transport.get_transport(parent)
 
201
        head, tail = urlutils.split(base)
 
202
        if tail and tail != '.':
 
203
            t = bzrlib.transport.get_transport(head)
203
204
            try:
204
 
                t.mkdir(segments[-1])
 
205
                t.mkdir(tail)
205
206
            except errors.FileExists:
206
207
                pass
207
208
        return BzrDirFormat.get_default_format().initialize(safe_unicode(base))
343
344
            pass
344
345
        next_transport = self.root_transport.clone('..')
345
346
        while True:
 
347
            # find the next containing bzrdir
346
348
            try:
347
349
                found_bzrdir = BzrDir.open_containing_from_transport(
348
350
                    next_transport)[0]
349
351
            except errors.NotBranchError:
 
352
                # none found
350
353
                raise errors.NoRepositoryPresent(self)
 
354
            # does it have a repository ?
351
355
            try:
352
356
                repository = found_bzrdir.open_repository()
353
357
            except errors.NoRepositoryPresent:
354
358
                next_transport = found_bzrdir.root_transport.clone('..')
355
 
                continue
 
359
                if (found_bzrdir.root_transport.base == next_transport.base):
 
360
                    # top of the file system
 
361
                    break
 
362
                else:
 
363
                    continue
356
364
            if ((found_bzrdir.root_transport.base == 
357
365
                 self.root_transport.base) or repository.is_shared()):
358
366
                return repository
365
373
 
366
374
        Note that bzr dirs that do not support format strings will raise
367
375
        IncompatibleFormat if the branch format they are given has
368
 
        a format string, and vice verca.
 
376
        a format string, and vice versa.
369
377
 
370
378
        If branch_format is None, the transport is returned with no 
371
379
        checking. if it is not None, then the returned transport is
378
386
 
379
387
        Note that bzr dirs that do not support format strings will raise
380
388
        IncompatibleFormat if the repository format they are given has
381
 
        a format string, and vice verca.
 
389
        a format string, and vice versa.
382
390
 
383
391
        If repository_format is None, the transport is returned with no 
384
392
        checking. if it is not None, then the returned transport is
391
399
 
392
400
        Note that bzr dirs that do not support format strings will raise
393
401
        IncompatibleFormat if the workingtree format they are given has
394
 
        a format string, and vice verca.
 
402
        a format string, and vice versa.
395
403
 
396
404
        If workingtree_format is None, the transport is returned with no 
397
405
        checking. if it is not None, then the returned transport is
426
434
        # this might be better on the BzrDirFormat class because it refers to 
427
435
        # all the possible bzrdir disk formats. 
428
436
        # This method is tested via the workingtree is_control_filename tests- 
429
 
        # it was extractd from WorkingTree.is_control_filename. If the methods
 
437
        # it was extracted from WorkingTree.is_control_filename. If the methods
430
438
        # contract is extended beyond the current trivial  implementation please
431
439
        # add new tests for it to the appropriate place.
432
440
        return filename == '.bzr' or filename.startswith('.bzr/')
489
497
        If there is one and it is either an unrecognised format or an unsupported 
490
498
        format, UnknownFormatError or UnsupportedFormatError are raised.
491
499
        If there is one, it is returned, along with the unused portion of url.
 
500
 
 
501
        :return: The BzrDir that contains the path, and a Unicode path 
 
502
                for the rest of the URL.
492
503
        """
493
504
        # this gets the normalised url back. I.e. '.' -> the full path.
494
505
        url = a_transport.base
496
507
            try:
497
508
                format = BzrDirFormat.find_format(a_transport)
498
509
                BzrDir._check_supported(format, False)
499
 
                return format.open(a_transport), a_transport.relpath(url)
 
510
                return format.open(a_transport), urlutils.unescape(a_transport.relpath(url))
500
511
            except errors.NotBranchError, e:
501
 
                mutter('not a branch in: %r %s', a_transport.base, e)
 
512
                ## mutter('not a branch in: %r %s', a_transport.base, e)
 
513
                pass
502
514
            new_t = a_transport.clone('..')
503
515
            if new_t.base == a_transport.base:
504
516
                # reached the root, whatever that may be
595
607
            result.create_repository()
596
608
        elif source_repository is not None and result_repo is None:
597
609
            # have source, and want to make a new target repo
598
 
            # we dont clone the repo because that preserves attributes
 
610
            # we don't clone the repo because that preserves attributes
599
611
            # like is_shared(), and we have not yet implemented a 
600
612
            # repository sprout().
601
613
            result_repo = result.create_repository()
610
622
            source_branch.sprout(result, revision_id=revision_id)
611
623
        else:
612
624
            result.create_branch()
 
625
        # TODO: jam 20060426 we probably need a test in here in the
 
626
        #       case that the newly sprouted branch is a remote one
613
627
        if result_repo is None or result_repo.make_working_trees():
614
628
            result.create_workingtree()
615
629
        return result
980
994
        This returns a bzrlib.bzrdir.Converter object.
981
995
 
982
996
        This should return the best upgrader to step this format towards the
983
 
        current default format. In the case of plugins we can/shouold provide
 
997
        current default format. In the case of plugins we can/should provide
984
998
        some means for them to extend the range of returnable converters.
985
999
 
986
 
        :param format: Optional format to override the default foramt of the 
 
1000
        :param format: Optional format to override the default format of the 
987
1001
                       library.
988
1002
        """
989
1003
        raise NotImplementedError(self.get_converter)
998
1012
 
999
1013
    def initialize_on_transport(self, transport):
1000
1014
        """Initialize a new bzrdir in the base directory of a Transport."""
1001
 
        # Since we don'transport have a .bzr directory, inherit the
 
1015
        # Since we don't have a .bzr directory, inherit the
1002
1016
        # mode from the root directory
1003
1017
        temp_control = LockableFiles(transport, '', TransportLock)
1004
1018
        temp_control._transport.mkdir('.bzr',
1005
 
                                      # FIXME: RBC 20060121 dont peek under
 
1019
                                      # FIXME: RBC 20060121 don't peek under
1006
1020
                                      # the covers
1007
1021
                                      mode=temp_control._dir_mode)
1008
1022
        file_mode = temp_control._file_mode
1513
1527
 
1514
1528
    def _convert_working_inv(self):
1515
1529
        inv = serializer_v4.read_inventory(self.branch.control_files.get('inventory'))
1516
 
        new_inv_xml = serializer_v5.write_inventory_to_string(inv)
 
1530
        new_inv_xml = bzrlib.xml5.serializer_v5.write_inventory_to_string(inv)
1517
1531
        # FIXME inventory is a working tree change.
1518
1532
        self.branch.control_files.put('inventory', new_inv_xml)
1519
1533
 
1587
1601
    def _load_updated_inventory(self, rev_id):
1588
1602
        assert rev_id in self.converted_revs
1589
1603
        inv_xml = self.inv_weave.get_text(rev_id)
1590
 
        inv = serializer_v5.read_inventory_from_string(inv_xml)
 
1604
        inv = bzrlib.xml5.serializer_v5.read_inventory_from_string(inv_xml)
1591
1605
        return inv
1592
1606
 
1593
1607
    def _convert_one_rev(self, rev_id):
1610
1624
                assert hasattr(ie, 'revision'), \
1611
1625
                    'no revision on {%s} in {%s}' % \
1612
1626
                    (file_id, rev.revision_id)
1613
 
        new_inv_xml = serializer_v5.write_inventory_to_string(inv)
 
1627
        new_inv_xml = bzrlib.xml5.serializer_v5.write_inventory_to_string(inv)
1614
1628
        new_inv_sha1 = sha_string(new_inv_xml)
1615
1629
        self.inv_weave.add_lines(rev.revision_id, 
1616
1630
                                 present_parents,
1721
1735
            store_transport = self.bzrdir.transport.clone(store_name)
1722
1736
            store = TransportStore(store_transport, prefixed=True)
1723
1737
            for urlfilename in store_transport.list_dir('.'):
1724
 
                filename = urlunescape(urlfilename)
 
1738
                filename = urlutils.unescape(urlfilename)
1725
1739
                if (filename.endswith(".weave") or
1726
1740
                    filename.endswith(".gz") or
1727
1741
                    filename.endswith(".sig")):