Rev 2396: Do some Branch controlfile operations direct to the Transport, not in http://sourcefrog.net/bzr/no-controlfiles
Martin Pool
mbp at sourcefrog.net
Wed Apr 4 14:09:05 BST 2007
At http://sourcefrog.net/bzr/no-controlfiles
------------------------------------------------------------
revno: 2396
revision-id: mbp at sourcefrog.net-20070404130829-pwu65c1xf5hcsszi
parent: pqm at pqm.ubuntu.com-20070404022946-b93fc2e49b3bb195
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: no-controlfiles
timestamp: Wed 2007-04-04 23:08:29 +1000
message:
Do some Branch controlfile operations direct to the Transport, not
through LockableFiles.
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2007-03-28 23:28:21 +0000
+++ b/bzrlib/branch.py 2007-04-04 13:08:29 +0000
@@ -823,15 +823,18 @@
'branch4': ('branch-lock', lockable_files.TransportLock),
}
lock_name, lock_class = lock_map[lock_type]
+ self._transport = branch_transport
control_files = lockable_files.LockableFiles(branch_transport,
lock_name, lock_class)
control_files.create_lock()
control_files.lock_write()
if set_format:
- control_files.put_utf8('format', self.get_format_string())
+ utf8_files[:0] = [('format', self.get_format_string())]
try:
- for file, content in utf8_files:
- control_files.put_utf8(file, content)
+ for name, content in utf8_files:
+ self._transport.put_bytes_non_atomic(name,
+ content.encode('utf-8'),
+ mode=control_files._file_mode)
finally:
control_files.unlock()
return self.open(a_bzrdir, _found=True)
@@ -1049,6 +1052,7 @@
transport = a_bzrdir.get_branch_transport(None)
control_files = lockable_files.LockableFiles(transport, 'lock',
lockdir.LockDir)
+ # XXX: isn't this redundant with the base format class? mbp 20070404
return BzrBranch5(_format=self,
_control_files=control_files,
a_bzrdir=a_bzrdir,
@@ -1094,6 +1098,8 @@
transport = a_bzrdir.get_branch_transport(None)
control_files = lockable_files.LockableFiles(transport, 'lock',
lockdir.LockDir)
+ # XXX: isn't this redundant with the base open method?
+ # mbp 20070404
return BzrBranch6(_format=self,
_control_files=control_files,
a_bzrdir=a_bzrdir,
@@ -1130,9 +1136,13 @@
raise errors.UninitializableFormat(self)
mutter('creating branch reference in %s', a_bzrdir.transport.base)
branch_transport = a_bzrdir.get_branch_transport(self)
- branch_transport.put_bytes('location',
- target_branch.bzrdir.root_transport.base)
- branch_transport.put_bytes('format', self.get_format_string())
+ for name, content in [
+ ('location', target_branch.bzrdir.root_transport.base),
+ ('format', self.get_format_string()),
+ ]:
+ # FIXME: We need to determine and set the right mode for the
+ # files.
+ branch_transport.put_bytes(name, content)
return self.open(a_bzrdir, _found=True)
def __init__(self):
@@ -1223,7 +1233,7 @@
def abspath(self, name):
"""See Branch.abspath."""
- return self.control_files._transport.abspath(name)
+ return self._transport.abspath(name)
@deprecated_method(zero_sixteen)
@@ -1292,8 +1302,9 @@
This performs the actual writing to disk.
It is intended to be called by BzrBranch5.set_revision_history."""
- self.control_files.put_bytes(
- 'revision-history', '\n'.join(history))
+ self._transport.put_bytes(
+ 'revision-history', '\n'.join(history),
+ mode=self.control_files._file_mode)
@needs_write_lock
def set_revision_history(self, rev_history):
@@ -1312,7 +1323,7 @@
self.set_revision_history(history)
def _gen_revision_history(self):
- history = self.control_files.get('revision-history').read().split('\n')
+ history = self._transport.get_bytes('revision-history').split('\n')
if history[-1:] == ['']:
# There shouldn't be a trailing newline, but just in case.
history.pop()
@@ -1438,7 +1449,7 @@
_locs = ['parent', 'pull', 'x-pull']
for l in _locs:
try:
- return self.control_files.get(l).read().strip('\n')
+ return self._transport.get_bytes(l).strip('\n')
except NoSuchFile:
pass
return None
@@ -1529,16 +1540,11 @@
def _set_parent_location(self, url):
if url is None:
- self.control_files._transport.delete('parent')
+ self._transport.delete('parent')
else:
assert isinstance(url, str)
- self.control_files.put_bytes('parent', url + '\n')
-
- @deprecated_function(zero_nine)
- def tree_config(self):
- """DEPRECATED; call get_config instead.
- TreeConfig has become part of BranchConfig."""
- return TreeConfig(self)
+ self._transport.put_bytes('parent', url + '\n',
+ mode=self.control_files._file_mode)
class BzrBranch5(BzrBranch):
@@ -1608,7 +1614,7 @@
def get_bound_location(self):
try:
- return self.control_files.get_utf8('bound').read()[:-1]
+ return self._transport.get_bytes('bound')[:-1]
except errors.NoSuchFile:
return None
@@ -1639,10 +1645,11 @@
:param location: URL to the target branch
"""
if location:
- self.control_files.put_utf8('bound', location+'\n')
+ self._transport.put_bytes('bound', location+'\n',
+ mode=self.control_files._file_mode)
else:
try:
- self.control_files._transport.delete('bound')
+ self._transport.delete('bound')
except NoSuchFile:
return False
return True
@@ -1750,7 +1757,8 @@
control_files.lock_write()
try:
for filename, content in utf8_files:
- control_files.put_utf8(filename, content)
+ branch_transport.put_bytes(filename, content.encode('utf-8'),
+ mode=control_files._file_mode)
finally:
control_files.unlock()
@@ -1803,7 +1811,7 @@
@needs_read_lock
def last_revision_info(self):
- revision_string = self.control_files.get('last-revision').read()
+ revision_string = self._transport.get_bytes('last-revision')
revno, revision_id = revision_string.rstrip('\n').split(' ', 1)
revision_id = cache_utf8.get_cached_utf8(revision_id)
revno = int(revno)
@@ -1828,7 +1836,8 @@
if revision_id is None:
revision_id = 'null:'
out_string = '%d %s\n' % (revno, revision_id)
- self.control_files.put_bytes('last-revision', out_string)
+ self._transport.put_bytes('last-revision', out_string,
+ mode=self.control_files._file_mode)
@needs_write_lock
def set_last_revision_info(self, revno, revision_id):
@@ -2103,11 +2112,12 @@
new_branch.tags._set_tag_dict({})
# Copying done; now update target format
- new_branch.control_files.put_utf8('format',
- format.get_format_string())
+ new_branch._transport.put_bytes('format',
+ format.get_format_string(),
+ mode=new_branch.control_files._file_mode)
# Clean up old files
- new_branch.control_files._transport.delete('revision-history')
+ new_branch._transport.delete('revision-history')
try:
branch.set_parent(None)
except NoSuchFile:
More information about the bazaar-commits
mailing list