/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: Martin Pool
  • Date: 2008-05-27 03:00:53 UTC
  • mfrom: (3452 +trunk)
  • mto: (3724.1.1 lock-hooks)
  • mto: This revision was merged to the branch mainline in revision 3730.
  • Revision ID: mbp@sourcefrog.net-20080527030053-0mct6dypek0ysjc3
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
        self._precious = precious
55
55
        self._versionedfile_class = versionedfile_class
56
56
        self._versionedfile_kwargs = versionedfile_kwargs
57
 
 
58
 
    def _clear_cache_id(self, file_id, transaction):
59
 
        """WARNING may lead to inconsistent object references for file_id.
60
 
 
61
 
        Remove file_id from the transaction map. 
62
 
 
63
 
        NOT in the transaction api because theres no reliable way to clear
64
 
        callers. So its here for very specialised use rather than having an
65
 
        'api' that isn't.
66
 
        """
67
 
        weave = transaction.map.find_weave(file_id)
68
 
        if weave is not None:
69
 
            mutter("old data in transaction in %s for %s", self, file_id)
70
 
            # FIXME abstraction violation - transaction now has stale data.
71
 
            transaction.map.remove_object(weave)
 
57
        # Used for passing get_scope to versioned file constructors;
 
58
        self.get_scope = None
72
59
 
73
60
    def filename(self, file_id):
74
61
        """Return the path relative to the transport root."""
108
95
        filename = self.filename(file_id)
109
96
        for suffix in suffixes:
110
97
            self._transport.delete(filename + suffix)
111
 
        self._clear_cache_id(file_id, transaction)
112
98
 
113
99
    def _get(self, file_id):
114
100
        return self._transport.get(self.filename(file_id))
130
116
        file_id. This is used to reduce duplicate filename calculations when
131
117
        using 'get_weave_or_empty'. FOR INTERNAL USE ONLY.
132
118
        """
133
 
        weave = transaction.map.find_weave(file_id)
134
 
        if weave is not None:
135
 
            #mutter("cache hit in %s for %s", self, file_id)
136
 
            return weave
137
119
        if _filename is None:
138
120
            _filename = self.filename(file_id)
139
121
        if transaction.writeable():
140
122
            w = self._versionedfile_class(_filename, self._transport, self._file_mode,
141
 
                                          **self._versionedfile_kwargs)
142
 
            transaction.map.add_weave(file_id, w)
143
 
            transaction.register_dirty(w)
 
123
                get_scope=self.get_scope, **self._versionedfile_kwargs)
144
124
        else:
145
125
            w = self._versionedfile_class(_filename,
146
126
                                          self._transport,
147
127
                                          self._file_mode,
148
128
                                          create=False,
149
129
                                          access_mode='r',
 
130
                                          get_scope=self.get_scope,
150
131
                                          **self._versionedfile_kwargs)
151
 
            transaction.map.add_weave(file_id, w)
152
 
            transaction.register_clean(w, precious=self._precious)
153
132
        return w
154
133
 
155
134
    def _make_new_versionedfile(self, file_id, transaction,
168
147
            # we try without making the directory first because thats optimising
169
148
            # for the common case.
170
149
            weave = self._versionedfile_class(_filename, self._transport, self._file_mode, create=True,
171
 
                                              **self._versionedfile_kwargs)
 
150
                get_scope=self.get_scope, **self._versionedfile_kwargs)
172
151
        except errors.NoSuchFile:
173
152
            if not self._prefixed:
174
153
                # unexpected error - NoSuchFile is expected to be raised on a
175
154
                # missing dir only and that only occurs when we are prefixed.
176
155
                raise
177
156
            self._transport.mkdir(self.hash_prefix(file_id), mode=self._dir_mode)
178
 
            weave = self._versionedfile_class(_filename, self._transport, 
 
157
            weave = self._versionedfile_class(_filename, self._transport,
179
158
                                              self._file_mode, create=True,
 
159
                                              get_scope=self.get_scope,
180
160
                                              **self._versionedfile_kwargs)
181
161
        return weave
182
162
 
193
173
        except errors.NoSuchFile:
194
174
            weave = self._make_new_versionedfile(file_id, transaction,
195
175
                known_missing=True, _filename=_filename)
196
 
            transaction.map.add_weave(file_id, weave)
197
 
            # has to be dirty - its able to mutate on its own.
198
 
            transaction.register_dirty(weave)
199
176
            return weave
200
177
 
201
178
    def _put_weave(self, file_id, weave, transaction):
202
179
        """Preserved here for upgrades-to-weaves to use."""
203
180
        myweave = self._make_new_versionedfile(file_id, transaction)
204
 
        myweave.join(weave)
 
181
        myweave.insert_record_stream(weave.get_record_stream(weave.versions(),
 
182
            'topological', False))
205
183
 
206
184
    def copy(self, source, result_id, transaction):
207
185
        """Copy the source versioned file to result_id in this store."""
208
 
        self._clear_cache_id(result_id, transaction)
209
186
        source.copy_to(self.filename(result_id), self._transport)
210
187
 
211
188
    def copy_all_ids(self, store_from, pb=None, from_transaction=None,
238
215
        :param from_transaction: required current transaction in from_store.
239
216
        """
240
217
        from bzrlib.transactions import PassThroughTransaction
241
 
        assert isinstance(from_store, WeaveStore)
242
218
        if from_transaction is None:
243
219
            warn("WeaveStore.copy_multi without a from_transaction parameter "
244
220
                 "is deprecated. Please provide a from_transaction.",
263
239
                # joining is fast with knits, and bearable for weaves -
264
240
                # indeed the new case can be optimised if needed.
265
241
                target = self._make_new_versionedfile(f, to_transaction)
266
 
                target.join(from_store.get_weave(f, from_transaction))
 
242
                source = from_store.get_weave(f, from_transaction)
 
243
                target.insert_record_stream(source.get_record_stream(
 
244
                    source.versions(), 'topological', False))
267
245
        finally:
268
246
            pb.finished()
269
247