~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: John Arbash Meinel
  • Date: 2005-07-11 19:21:13 UTC
  • mto: (1185.11.1)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: john@arbash-meinel.com-20050711192113-d6b6674f9393497b
Changed the format for abspath. Updated branch to use a hidden _transport

Show diffs side-by-side

added added

removed removed

Lines of Context:
164
164
        In the test suite, creation of new trees is tested using the
165
165
        `ScratchBranch` class.
166
166
        """
167
 
        from bzrlib.store import CompressedTextStore
168
 
 
169
167
        if isinstance(transport, basestring):
170
168
            from transport import transport as get_transport
171
169
            transport = get_transport(transport)
172
170
 
173
 
        self.transport = transport
 
171
        self._transport = transport
174
172
        if init:
175
173
            self._make_control()
176
174
 
256
254
 
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))
260
258
 
261
259
 
262
260
    def controlfile(self, file_or_path, mode='r'):
278
276
 
279
277
        # TODO: Try to use transport.put() rather than branch.controlfile(mode='w')
280
278
        if mode == 'rb': 
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')
289
287
        else:
290
288
            raise BzrError("invalid controlfile mode %r" % mode)
291
289
 
294
292
        from bzrlib.inventory import Inventory
295
293
        from bzrlib.xml import pack_xml
296
294
        
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',
307
305
                  'branch-lock',
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)
311
309
 
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'))
314
312
 
315
313
 
333
331
 
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
 
335
 
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))
339
339
 
340
340
        self.text_store = get_store('text-store')
341
341
        self.revision_store = get_store('revision-store')
377
377
            sio = StringIO()
378
378
            pack_xml(inv, sio)
379
379
            sio.seek(0)
380
 
            self.transport.put(self._rel_controlfilename('inventory'), sio)
 
380
            self._transport.put(self._rel_controlfilename('inventory'), sio)
381
381
        finally:
382
382
            self.unlock()
383
383
        
565
565
 
566
566
        self.lock_write()
567
567
        try:
568
 
            self.transport.put(self._rel_controlfilename('revision-history'),
 
568
            self._transport.put(self._rel_controlfilename('revision-history'),
569
569
                    '\n'.join(rev_history))
570
570
        finally:
571
571
            self.unlock()
1207
1207
        directory but not yet committed.
1208
1208
        """
1209
1209
        cfn = self._rel_controlfilename('pending-merges')
1210
 
        if not self.transport.has(cfn):
 
1210
        if not self._transport.has(cfn):
1211
1211
            return []
1212
1212
        p = []
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()
1236
1236
        try:
1237
 
            self.transport.put(self._rel_controlfilename('pending-merges'),
 
1237
            self._transport.put(self._rel_controlfilename('pending-merges'),
1238
1238
                    '\n'.join(rev_list))
1239
1239
        finally:
1240
1240
            self.unlock()
1272
1272
        # to test remote branches.
1273
1273
        self.base = base
1274
1274
        for d in dirs:
1275
 
            self.transport.mkdir(d)
 
1275
            self._transport.mkdir(d)
1276
1276
            
1277
1277
        for f in files:
1278
 
            self.transport.put(f, 'content of %s' % f)
 
1278
            self._transport.put(f, 'content of %s' % f)
1279
1279
 
1280
1280
 
1281
1281
    def clone(self):