~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 22:24:03 UTC
  • mto: (1185.11.1)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: john@arbash-meinel.com-20050711222403-5dc86e254b69f7ab
Remote functionality work.
Added lock_read/write() to Transport.
Turns out that both urllib2 and urlgrabber don't let you
seek on files that are returned, and GzipFile wants to
seek on the file when it is read. So instead,
we check, and wrap in a StringIO when required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
137
137
    _lock_mode = None
138
138
    _lock_count = None
139
139
    _lock = None
 
140
    cache_root = None
140
141
    
141
142
    # Map some sort of prefix into a namespace
142
143
    # stuff like "revno:10", "revid:", etc.
188
189
        # See the earlier discussion about how major objects (like Branch)
189
190
        # should never expect their __del__ function to run.
190
191
        if self.cache_root is not None:
191
 
            from warnings import warn
192
 
            warn("branch %r auto-cleanup of cache files" % self)
 
192
            #from warnings import warn
 
193
            #warn("branch %r auto-cleanup of cache files" % self)
193
194
            try:
194
195
                import shutil
195
196
                shutil.rmtree(self.cache_root)
215
216
                                self._lock_mode)
216
217
            self._lock_count += 1
217
218
        else:
218
 
            from bzrlib.lock import WriteLock
219
 
 
220
 
            self._lock = WriteLock(self.controlfilename('branch-lock'))
 
219
            self._lock = self._transport.lock_write(
 
220
                    self._rel_controlfilename('branch-lock'))
221
221
            self._lock_mode = 'w'
222
222
            self._lock_count = 1
223
223
 
229
229
                   "invalid lock mode %r" % self._lock_mode
230
230
            self._lock_count += 1
231
231
        else:
232
 
            from bzrlib.lock import ReadLock
233
 
 
234
 
            self._lock = ReadLock(self.controlfilename('branch-lock'))
 
232
            self._lock = self._transport.lock_read(
 
233
                    self._rel_controlfilename('branch-lock'))
235
234
            self._lock_mode = 'r'
236
235
            self._lock_count = 1
237
236
                        
259
258
        """Return path relative to this branch of something inside it.
260
259
 
261
260
        Raises an error if path is not in this branch."""
262
 
        return _relpath(self._transport.base, path)
 
261
        return self._transport.relpath(path)
263
262
 
264
263
 
265
264
    def _rel_controlfilename(self, file_or_path):
365
364
        if self._transport.is_remote():
366
365
            import tempfile
367
366
            self.cache_root = tempfile.mkdtemp()
 
367
            mutter('Branch %r using caching in %r' % (self, self.cache_root))
368
368
        else:
369
369
            self.cache_root = None
370
370
 
373
373
            store = CompressedTextStore(self._transport.clone(relpath))
374
374
            if self._transport.is_remote():
375
375
                from meta_store import CachedStore
376
 
                cache_path = os.path.join(self.cache_root, store_name)
 
376
                cache_path = os.path.join(self.cache_root, name)
377
377
                os.mkdir(cache_path)
378
378
                store = CachedStore(store, cache_path)
379
379
            return store