~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 21:51:33 UTC
  • mto: (1185.11.1)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: john@arbash-meinel.com-20050711215132-00f679f5221df5c4
Branch objects now automatically create Cached stores if the protocol is_remote.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
            t = transport(root)
44
44
    return Branch(t, **args)
45
45
 
46
 
def find_cached_branch(f, cache_root, **args):
47
 
    from remotebranch import RemoteBranch
48
 
    br = find_branch(f, **args)
49
 
    def cacheify(br, store_name):
50
 
        from meta_store import CachedStore
51
 
        cache_path = os.path.join(cache_root, store_name)
52
 
        os.mkdir(cache_path)
53
 
        new_store = CachedStore(getattr(br, store_name), cache_path)
54
 
        setattr(br, store_name, new_store)
55
 
 
56
 
    if isinstance(br, RemoteBranch):
57
 
        cacheify(br, 'inventory_store')
58
 
        cacheify(br, 'text_store')
59
 
        cacheify(br, 'revision_store')
60
 
    return br
61
 
 
62
 
 
63
46
def _relpath(base, path):
64
47
    """Return path relative to base, or raise exception.
65
48
 
198
181
            warn("branch %r was not explicitly unlocked" % self)
199
182
            self._lock.unlock()
200
183
 
 
184
        # TODO: It might be best to do this somewhere else,
 
185
        # but it is nice for a Branch object to automatically
 
186
        # cache it's information.
 
187
        # Alternatively, we could have the Transport objects cache requests
 
188
        # See the earlier discussion about how major objects (like Branch)
 
189
        # should never expect their __del__ function to run.
 
190
        if self.cache_root is not None:
 
191
            from warnings import warn
 
192
            warn("branch %r auto-cleanup of cache files" % self)
 
193
            try:
 
194
                import shutil
 
195
                shutil.rmtree(self.cache_root)
 
196
            except:
 
197
                pass
 
198
            self.cache_root = None
 
199
 
201
200
    def _get_base(self):
202
201
        if self._transport:
203
202
            return self._transport.base
363
362
        # So create the rest of the entries.
364
363
        from bzrlib.store import CompressedTextStore
365
364
 
 
365
        if self._transport.is_remote():
 
366
            import tempfile
 
367
            self.cache_root = tempfile.mkdtemp()
 
368
        else:
 
369
            self.cache_root = None
 
370
 
366
371
        def get_store(name):
367
372
            relpath = self._rel_controlfilename(name)
368
 
            return CompressedTextStore(self._transport.clone(relpath))
 
373
            store = CompressedTextStore(self._transport.clone(relpath))
 
374
            if self._transport.is_remote():
 
375
                from meta_store import CachedStore
 
376
                cache_path = os.path.join(self.cache_root, store_name)
 
377
                os.mkdir(cache_path)
 
378
                store = CachedStore(store, cache_path)
 
379
            return store
369
380
 
370
381
        self.text_store = get_store('text-store')
371
382
        self.revision_store = get_store('revision-store')