164
164
In the test suite, creation of new trees is tested using the
165
165
`ScratchBranch` class.
167
from bzrlib.store import CompressedTextStore
169
167
if isinstance(transport, basestring):
170
168
from transport import transport as get_transport
171
169
transport = get_transport(transport)
173
self.transport = transport
171
self._transport = transport
175
173
self._make_control()
257
255
def controlfilename(self, file_or_path):
258
256
"""Return location relative to branch."""
259
return self.transport.abspath(self._rel_controlfilename(file_or_path))
257
return self._transport.abspath(self._rel_controlfilename(file_or_path))
262
260
def controlfile(self, file_or_path, mode='r'):
279
277
# TODO: Try to use transport.put() rather than branch.controlfile(mode='w')
281
return self.transport.get(relpath)
279
return self._transport.get(relpath)
282
280
elif mode == 'wb':
283
return self.transport.open(relpath)
281
return self._transport.open(relpath)
284
282
elif mode == 'r':
285
return codecs.getreader('utf-8')(self.transport.get(relpath))
283
return codecs.getreader('utf-8')(self._transport.get(relpath))
286
284
elif mode == 'w':
287
285
return codecs.getwriter(bzrlib.user_encoding)(
288
self.transport.open(relpath), errors='replace')
286
self._transport.open(relpath), errors='replace')
290
288
raise BzrError("invalid controlfile mode %r" % mode)
294
292
from bzrlib.inventory import Inventory
295
293
from bzrlib.xml import pack_xml
297
self.transport.mkdir(self.controlfilename([]))
298
self.transport.put(self._rel_controlfilename('README'),
295
self._transport.mkdir(self.controlfilename([]))
296
self._transport.put(self._rel_controlfilename('README'),
299
297
"This is a Bazaar-NG control directory.\n"
300
298
"Do not change any files in this directory.\n")
301
self.transport.put(self._rel_controlfilename('branch-format'),
299
self._transport.put(self._rel_controlfilename('branch-format'),
302
300
BZR_BRANCH_FORMAT)
303
301
for d in ('text-store', 'inventory-store', 'revision-store'):
304
self.transport.mkdir(self._rel_controlfilename(d))
302
self._transport.mkdir(self._rel_controlfilename(d))
305
303
for f in ('revision-history', 'merged-patches',
306
304
'pending-merged-patches', 'branch-name',
308
306
'pending-merges'):
309
self.transport.put(self._rel_controlfilename(f), '')
307
self._transport.put(self._rel_controlfilename(f), '')
310
308
mutter('created control directory in ' + self._transport.base)
312
# TODO: Try and do this with self.transport.put() instead
310
# TODO: Try and do this with self._transport.put() instead
313
311
pack_xml(Inventory(), self.controlfile('inventory','w'))
334
332
# We know that the format is the currently supported one.
335
333
# So create the rest of the entries.
334
from bzrlib.store import CompressedTextStore
336
336
def get_store(name):
337
337
relpath = self._rel_controlfilename(name)
338
return CompressedTextStore(self.transport.clone(relpath))
338
return CompressedTextStore(self._transport.clone(relpath))
340
340
self.text_store = get_store('text-store')
341
341
self.revision_store = get_store('revision-store')
1207
1207
directory but not yet committed.
1209
1209
cfn = self._rel_controlfilename('pending-merges')
1210
if not self.transport.has(cfn):
1210
if not self._transport.has(cfn):
1213
1213
for l in self.controlfile('pending-merges', 'r').readlines():
1234
1234
def set_pending_merges(self, rev_list):
1235
1235
self.lock_write()
1237
self.transport.put(self._rel_controlfilename('pending-merges'),
1237
self._transport.put(self._rel_controlfilename('pending-merges'),
1238
1238
'\n'.join(rev_list))