/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/branch.py

  • Committer: Martin Pool
  • Date: 2008-05-22 05:48:22 UTC
  • mfrom: (3407.2.16 controlfiles)
  • mto: This revision was merged to the branch mainline in revision 3448.
  • Revision ID: mbp@sourcefrog.net-20080522054822-lrq17tx62wbfzj8r
merge further LockableFile deprecations

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
41
41
 
42
42
from bzrlib.decorators import needs_read_lock, needs_write_lock
43
43
from bzrlib.hooks import Hooks
 
44
from bzrlib.symbol_versioning import (
 
45
    deprecated_in,
 
46
    deprecated_method,
 
47
    )
44
48
from bzrlib.trace import mutter, mutter_callsite, note, is_quiet
45
49
 
46
50
 
218
222
        """
219
223
        self.control_files.dont_leave_in_place()
220
224
 
 
225
    @deprecated_method(deprecated_in((0, 16, 0)))
221
226
    def abspath(self, name):
222
227
        """Return absolute filename for something in the branch
223
228
        
903
908
        control_files.create_lock()
904
909
        control_files.lock_write()
905
910
        if set_format:
906
 
            control_files.put_utf8('format', self.get_format_string())
 
911
            utf8_files += [('format', self.get_format_string())]
907
912
        try:
908
 
            for file, content in utf8_files:
909
 
                control_files.put_utf8(file, content)
 
913
            for (filename, content) in utf8_files:
 
914
                branch_transport.put_bytes(
 
915
                    filename, content,
 
916
                    mode=control_files._file_mode)
910
917
        finally:
911
918
            control_files.unlock()
912
919
        return self.open(a_bzrdir, _found=True)
951
958
        """True if this format supports tags stored in the branch"""
952
959
        return False  # by default
953
960
 
954
 
    # XXX: Probably doesn't really belong here -- mbp 20070212
955
 
    def _initialize_control_files(self, a_bzrdir, utf8_files, lock_filename,
956
 
            lock_class):
957
 
        branch_transport = a_bzrdir.get_branch_transport(self)
958
 
        control_files = lockable_files.LockableFiles(branch_transport,
959
 
            lock_filename, lock_class)
960
 
        control_files.create_lock()
961
 
        control_files.lock_write()
962
 
        try:
963
 
            for filename, content in utf8_files:
964
 
                control_files.put_utf8(filename, content)
965
 
        finally:
966
 
            control_files.unlock()
967
 
 
968
961
 
969
962
class BranchHooks(Hooks):
970
963
    """A dictionary mapping hook name to a list of callables for branch hooks.
1320
1313
    Note that it's "local" in the context of the filesystem; it doesn't
1321
1314
    really matter if it's on an nfs/smb/afs/coda/... share, as long as
1322
1315
    it's writable, and can be accessed via the normal filesystem API.
 
1316
 
 
1317
    :ivar _transport: Transport for file operations on this branch's 
 
1318
        control files, typically pointing to the .bzr/branch directory.
 
1319
    :ivar repository: Repository for this branch.
 
1320
    :ivar base: The url of the base directory for this branch; the one 
 
1321
        containing the .bzr directory.
1323
1322
    """
1324
1323
    
1325
1324
    def __init__(self, _format=None,
1330
1329
            raise ValueError('a_bzrdir must be supplied')
1331
1330
        else:
1332
1331
            self.bzrdir = a_bzrdir
1333
 
        # self._transport used to point to the directory containing the
1334
 
        # control directory, but was not used - now it's just the transport
1335
 
        # for the branch control files.  mbp 20070212
1336
1332
        self._base = self.bzrdir.transport.clone('..').base
 
1333
        # XXX: We should be able to just do
 
1334
        #   self.base = self.bzrdir.root_transport.base
 
1335
        # but this does not quite work yet -- mbp 20080522
1337
1336
        self._format = _format
1338
1337
        if _control_files is None:
1339
1338
            raise ValueError('BzrBranch _control_files is None')
1352
1351
 
1353
1352
    base = property(_get_base, doc="The URL for the root of this branch.")
1354
1353
 
 
1354
    @deprecated_method(deprecated_in((0, 16, 0)))
1355
1355
    def abspath(self, name):
1356
1356
        """See Branch.abspath."""
1357
 
        return self.control_files._transport.abspath(name)
 
1357
        return self._transport.abspath(name)
1358
1358
 
1359
1359
    def is_locked(self):
1360
1360
        return self.control_files.is_locked()
1405
1405
 
1406
1406
        This performs the actual writing to disk.
1407
1407
        It is intended to be called by BzrBranch5.set_revision_history."""
1408
 
        self.control_files.put_bytes(
1409
 
            'revision-history', '\n'.join(history))
 
1408
        self._transport.put_bytes(
 
1409
            'revision-history', '\n'.join(history),
 
1410
            mode=self.control_files._file_mode)
1410
1411
 
1411
1412
    @needs_write_lock
1412
1413
    def set_revision_history(self, rev_history):
1454
1455
        self._run_post_change_branch_tip_hooks(old_revno, old_revid)
1455
1456
 
1456
1457
    def _gen_revision_history(self):
1457
 
        history = self.control_files.get('revision-history').read().split('\n')
 
1458
        history = self._transport.get_bytes('revision-history').split('\n')
1458
1459
        if history[-1:] == ['']:
1459
1460
            # There shouldn't be a trailing newline, but just in case.
1460
1461
            history.pop()
1586
1587
        _locs = ['parent', 'pull', 'x-pull']
1587
1588
        for l in _locs:
1588
1589
            try:
1589
 
                return self.control_files.get(l).read().strip('\n')
 
1590
                return self._transport.get_bytes(l).strip('\n')
1590
1591
            except errors.NoSuchFile:
1591
1592
                pass
1592
1593
        return None
1709
1710
        # read and rewrite the file. RBC 20060125
1710
1711
        if url is not None:
1711
1712
            if isinstance(url, unicode):
1712
 
                try: 
 
1713
                try:
1713
1714
                    url = url.encode('ascii')
1714
1715
                except UnicodeEncodeError:
1715
1716
                    raise errors.InvalidURL(url,
1720
1721
 
1721
1722
    def _set_parent_location(self, url):
1722
1723
        if url is None:
1723
 
            self.control_files._transport.delete('parent')
 
1724
            self._transport.delete('parent')
1724
1725
        else:
1725
 
            self.control_files.put_bytes('parent', url + '\n')
 
1726
            self._transport.put_bytes('parent', url + '\n',
 
1727
                mode=self.control_files._file_mode)
1726
1728
 
1727
1729
 
1728
1730
class BzrBranch5(BzrBranch):
1802
1804
        :param location: URL to the target branch
1803
1805
        """
1804
1806
        if location:
1805
 
            self.control_files.put_utf8('bound', location+'\n')
 
1807
            self._transport.put_bytes('bound', location+'\n',
 
1808
                mode=self.bzrdir._get_file_mode())
1806
1809
        else:
1807
1810
            try:
1808
 
                self.control_files._transport.delete('bound')
 
1811
                self._transport.delete('bound')
1809
1812
            except errors.NoSuchFile:
1810
1813
                return False
1811
1814
            return True
1882
1885
        return self._last_revision_info_cache
1883
1886
 
1884
1887
    def _last_revision_info(self):
1885
 
        revision_string = self.control_files.get('last-revision').read()
 
1888
        revision_string = self._transport.get_bytes('last-revision')
1886
1889
        revno, revision_id = revision_string.rstrip('\n').split(' ', 1)
1887
1890
        revision_id = cache_utf8.get_cached_utf8(revision_id)
1888
1891
        revno = int(revno)
1899
1902
        """
1900
1903
        revision_id = _mod_revision.ensure_null(revision_id)
1901
1904
        out_string = '%d %s\n' % (revno, revision_id)
1902
 
        self.control_files.put_bytes('last-revision', out_string)
 
1905
        self._transport.put_bytes('last-revision', out_string,
 
1906
            mode=self.control_files._file_mode)
1903
1907
 
1904
1908
    @needs_write_lock
1905
1909
    def set_last_revision_info(self, revno, revision_id):
2208
2212
        new_branch.tags._set_tag_dict({})
2209
2213
 
2210
2214
        # Copying done; now update target format
2211
 
        new_branch.control_files.put_utf8('format',
2212
 
            format.get_format_string())
 
2215
        new_branch._transport.put_bytes('format',
 
2216
            format.get_format_string(),
 
2217
            mode=new_branch.control_files._file_mode)
2213
2218
 
2214
2219
        # Clean up old files
2215
 
        new_branch.control_files._transport.delete('revision-history')
 
2220
        new_branch._transport.delete('revision-history')
2216
2221
        try:
2217
2222
            branch.set_parent(None)
2218
2223
        except errors.NoSuchFile: