287
287
relpath = self._rel_controlfilename(file_or_path)
288
288
#TODO: codecs.open() buffers linewise, so it was overloaded with
289
289
# a much larger buffer, do we need to do the same for getreader/getwriter?
291
# TODO: Try to use transport.put() rather than branch.controlfile(mode='w')
293
291
return self._transport.get(relpath)
294
292
elif mode == 'wb':
295
raise BzrError("Branch.controlfile(mode='wb') is not supported, use put_controlfile")
293
raise BzrError("Branch.controlfile(mode='wb') is not supported, use put_controlfiles")
296
294
elif mode == 'r':
297
return self._transport.get(relpath, decode=True)
295
return codecs.getreader('utf-8')(self._transport.get(relpath), errors='replace')
298
296
elif mode == 'w':
299
raise BzrError("Branch.controlfile(mode='w') is not supported, use put_controlfile")
300
#return codecs.getwriter('utf-8')(
301
# self._transport.open(relpath), errors='replace')
297
raise BzrError("Branch.controlfile(mode='w') is not supported, use put_controlfiles")
303
299
raise BzrError("invalid controlfile mode %r" % mode)
305
def put_controlfile(self, file_or_path, f, encode=True):
301
def put_controlfile(self, path, f, encode=True):
306
302
"""Write an entry as a controlfile.
308
:param file_or_path: This is the sub-path underneath the bzr control directory
309
:param f: A file-like or string object whose contents should be placed
310
in the appropriate location.
311
:param encode: If true, encode the contents as utf-8
313
self._transport.put(self._rel_controlfilename(file_or_path), f, encode=encode)
304
:param path: The path to put the file, relative to the .bzr control
306
:param f: A file-like or string object whose contents should be copied.
307
:param encode: If true, encode the contents as utf-8
309
self.put_controlfiles([(path, f)], encode=encode)
311
def put_controlfiles(self, files, encode=True):
312
"""Write several entries as controlfiles.
314
:param files: A list of [(path, file)] pairs, where the path is the directory
315
underneath the bzr control directory
316
:param encode: If true, encode the contents as utf-8
320
for path, f in files:
322
if isinstance(f, basestring):
323
f = f.encode('utf-8', 'replace')
325
f = codecs.getwriter('utf-8')(f, errors='replace')
326
path = self._rel_controlfilename(path)
327
ctrl_files.append((path, f))
328
self._transport.put_multi(ctrl_files)
315
330
def _make_control(self):
316
331
from bzrlib.inventory import Inventory