/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: 2006-06-10 23:16:19 UTC
  • mfrom: (1759 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1761.
  • Revision ID: mbp@sourcefrog.net-20060610231619-05b997deeb005d02
[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
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
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
1464
1478
 
1465
1479
    def _convert_working_inv(self):
1466
1480
        inv = serializer_v4.read_inventory(self.branch.control_files.get('inventory'))
1467
 
        new_inv_xml = serializer_v5.write_inventory_to_string(inv)
 
1481
        new_inv_xml = bzrlib.xml5.serializer_v5.write_inventory_to_string(inv)
1468
1482
        # FIXME inventory is a working tree change.
1469
1483
        self.branch.control_files.put('inventory', new_inv_xml)
1470
1484
 
1538
1552
    def _load_updated_inventory(self, rev_id):
1539
1553
        assert rev_id in self.converted_revs
1540
1554
        inv_xml = self.inv_weave.get_text(rev_id)
1541
 
        inv = serializer_v5.read_inventory_from_string(inv_xml)
 
1555
        inv = bzrlib.xml5.serializer_v5.read_inventory_from_string(inv_xml)
1542
1556
        return inv
1543
1557
 
1544
1558
    def _convert_one_rev(self, rev_id):
1561
1575
                assert hasattr(ie, 'revision'), \
1562
1576
                    'no revision on {%s} in {%s}' % \
1563
1577
                    (file_id, rev.revision_id)
1564
 
        new_inv_xml = serializer_v5.write_inventory_to_string(inv)
 
1578
        new_inv_xml = bzrlib.xml5.serializer_v5.write_inventory_to_string(inv)
1565
1579
        new_inv_sha1 = sha_string(new_inv_xml)
1566
1580
        self.inv_weave.add_lines(rev.revision_id, 
1567
1581
                                 present_parents,
1672
1686
            store_transport = self.bzrdir.transport.clone(store_name)
1673
1687
            store = TransportStore(store_transport, prefixed=True)
1674
1688
            for urlfilename in store_transport.list_dir('.'):
1675
 
                filename = urlunescape(urlfilename)
 
1689
                filename = urlutils.unescape(urlfilename)
1676
1690
                if (filename.endswith(".weave") or
1677
1691
                    filename.endswith(".gz") or
1678
1692
                    filename.endswith(".sig")):