/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/store/versioned/__init__.py

  • Committer: Robert Collins
  • Date: 2008-04-08 00:57:07 UTC
  • mto: This revision was merged to the branch mainline in revision 3350.
  • Revision ID: robertc@robertcollins.net-20080408005707-jzx5nkcjvsiw7r12
 * ``VersionedFileStore`` no longer uses the transaction parameter given
   to most methods; amongst other things this means that the
   get_weave_or_empty method no longer guarantees errors on a missing weave
   in a readonly transaction, and no longer caches versioned file instances
   which reduces memory pressure (but requires more careful management by
   callers to preserve performance.  (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
        # Used for passing get_scope to versioned file constructors;
58
58
        self.get_scope = None
59
59
 
60
 
    def _clear_cache_id(self, file_id, transaction):
61
 
        """WARNING may lead to inconsistent object references for file_id.
62
 
 
63
 
        Remove file_id from the transaction map. 
64
 
 
65
 
        NOT in the transaction api because theres no reliable way to clear
66
 
        callers. So its here for very specialised use rather than having an
67
 
        'api' that isn't.
68
 
        """
69
 
        weave = transaction.map.find_weave(file_id)
70
 
        if weave is not None:
71
 
            mutter("old data in transaction in %s for %s", self, file_id)
72
 
            # FIXME abstraction violation - transaction now has stale data.
73
 
            transaction.map.remove_object(weave)
74
 
 
75
60
    def filename(self, file_id):
76
61
        """Return the path relative to the transport root."""
77
62
        return self._relpath(file_id)
110
95
        filename = self.filename(file_id)
111
96
        for suffix in suffixes:
112
97
            self._transport.delete(filename + suffix)
113
 
        self._clear_cache_id(file_id, transaction)
114
98
 
115
99
    def _get(self, file_id):
116
100
        return self._transport.get(self.filename(file_id))
132
116
        file_id. This is used to reduce duplicate filename calculations when
133
117
        using 'get_weave_or_empty'. FOR INTERNAL USE ONLY.
134
118
        """
135
 
        weave = transaction.map.find_weave(file_id)
136
 
        if weave is not None:
137
 
            #mutter("cache hit in %s for %s", self, file_id)
138
 
            return weave
139
119
        if _filename is None:
140
120
            _filename = self.filename(file_id)
141
121
        if transaction.writeable():
142
122
            w = self._versionedfile_class(_filename, self._transport, self._file_mode,
143
123
                get_scope=self.get_scope, **self._versionedfile_kwargs)
144
 
            transaction.map.add_weave(file_id, w)
145
 
            transaction.register_dirty(w)
146
124
        else:
147
125
            w = self._versionedfile_class(_filename,
148
126
                                          self._transport,
151
129
                                          access_mode='r',
152
130
                                          get_scope=self.get_scope,
153
131
                                          **self._versionedfile_kwargs)
154
 
            transaction.map.add_weave(file_id, w)
155
 
            transaction.register_clean(w, precious=self._precious)
156
132
        return w
157
133
 
158
134
    def _make_new_versionedfile(self, file_id, transaction,
197
173
        except errors.NoSuchFile:
198
174
            weave = self._make_new_versionedfile(file_id, transaction,
199
175
                known_missing=True, _filename=_filename)
200
 
            transaction.map.add_weave(file_id, weave)
201
 
            # has to be dirty - its able to mutate on its own.
202
 
            transaction.register_dirty(weave)
203
176
            return weave
204
177
 
205
178
    def _put_weave(self, file_id, weave, transaction):
209
182
 
210
183
    def copy(self, source, result_id, transaction):
211
184
        """Copy the source versioned file to result_id in this store."""
212
 
        self._clear_cache_id(result_id, transaction)
213
185
        source.copy_to(self.filename(result_id), self._transport)
214
186
 
215
187
    def copy_all_ids(self, store_from, pb=None, from_transaction=None,