295
295
return self._transport.get(relpath)
296
296
elif mode == 'wb':
297
return self._transport.open(relpath)
297
raise BzrError("Branch.controlfile(mode='wb') is not supported, use put_controlfile")
298
298
elif mode == 'r':
299
return codecs.getreader('utf-8')(self._transport.get(relpath))
299
return self._transport.get(relpath, decode=True)
300
300
elif mode == 'w':
301
return codecs.getwriter(bzrlib.user_encoding)(
302
self._transport.open(relpath), errors='replace')
301
raise BzrError("Branch.controlfile(mode='w') is not supported, use put_controlfile")
302
#return codecs.getwriter('utf-8')(
303
# self._transport.open(relpath), errors='replace')
304
305
raise BzrError("invalid controlfile mode %r" % mode)
307
def put_controlfile(self, file_or_path, f, encode=True):
308
"""Write an entry as a controlfile.
310
:param file_or_path: This is the sub-path underneath the bzr control directory
311
:param f: A file-like or string object whose contents should be placed
312
in the appropriate location.
313
:param encode: If true, encode the contents as utf-8
315
self._transport.put(self._rel_controlfilename(file_or_path), f, encode=encode)
307
317
def _make_control(self):
308
318
from bzrlib.inventory import Inventory
309
319
from bzrlib.xml import pack_xml
320
from cStringIO import StringIO
311
322
self._transport.mkdir(self.controlfilename([]))
312
323
self._transport.put(self._rel_controlfilename('README'),
324
335
mutter('created control directory in ' + self._transport.base)
326
337
# TODO: Try and do this with self._transport.put() instead
327
pack_xml(Inventory(), self.controlfile('inventory','w'))
339
pack_xml(Inventory(), sio)
340
self.put_controlfile('inventory', sio)
330
343
def _check_format(self):