66
66
return self._transport.get(relpath)
68
raise BzrError("Branch.controlfile(mode='wb') is not supported, use put_controlfiles")
68
raise BzrError("Branch.controlfile(mode='wb') is not supported, use put[_utf8]")
70
70
# XXX: Do we really want errors='replace'? Perhaps it should be
71
71
# an error, or at least reported, if there's incorrectly-encoded
73
73
# <https://launchpad.net/products/bzr/+bug/3823>
74
74
return codecs.getreader('utf-8')(self._transport.get(relpath), errors='replace')
76
raise BzrError("Branch.controlfile(mode='w') is not supported, use put_controlfiles")
76
raise BzrError("Branch.controlfile(mode='w') is not supported, use put[_utf8]")
78
78
raise BzrError("invalid controlfile mode %r" % mode)
80
def put_controlfile(self, path, f, encode=True):
81
"""Write an entry as a controlfile.
80
def put(self, path, file):
83
83
:param path: The path to put the file, relative to the .bzr control
85
85
:param f: A file-like or string object whose contents should be copied.
86
:param encode: If true, encode the contents as utf-8
88
self.put_controlfiles([(path, f)], encode=encode)
90
def put_controlfiles(self, files, encode=True):
91
"""Write several entries as controlfiles.
93
:param files: A list of [(path, file)] pairs, where the path is the directory
94
underneath the bzr control directory
95
:param encode: If true, encode the contents as utf-8
87
self._transport.put(self._rel_controlfilename(path), file)
89
def put_utf8(self, path, file):
90
"""Write a file, encoding as utf-8.
92
:param path: The path to put the file, relative to the .bzr control
94
:param f: A file-like or string object whose contents should be copied.
101
if isinstance(f, basestring):
102
f = f.encode('utf-8', 'replace')
104
f = codecs.getwriter('utf-8')(f, errors='replace')
105
path = self._rel_controlfilename(path)
106
ctrl_files.append((path, f))
107
self._transport.put_multi(ctrl_files)
98
if isinstance(file, basestring):
99
file = file.encode('utf-8', 'replace')
101
file = codecs.getwriter('utf-8')(file, errors='replace')
109
104
def lock_write(self):
110
105
mutter("lock write: %s (%s)", self, self._lock_count)