125
117
return self.get_weave_prelude(file_id, transaction)
126
118
except NoSuchFile:
127
# We can cache here, because we know that there
128
# is no complete object, since we got NoSuchFile
129
weave = Weave(weave_name=file_id)
130
transaction.map.add_weave(file_id, weave)
131
transaction.register_clean(weave, precious=self._precious)
119
# returns more than needed - harmless as its empty.
120
return self._new_weave(file_id, transaction)
122
def _new_weave(self, file_id, transaction):
123
"""Make a new weave for file_id and return it."""
124
weave = WeaveFile(self.filename(file_id), self._transport, self._file_mode)
125
# ensure that the directories are created.
126
# this is so that weave does not encounter ENOTDIR etc.
127
weave_stream = self._weave_to_stream(weave)
128
self._put(file_id, weave_stream)
129
transaction.map.add_weave(file_id, weave)
130
transaction.register_clean(weave, precious=self._precious)
134
133
def get_weave_or_empty(self, file_id, transaction):
135
134
"""Return a weave, or an empty one if it doesn't exist."""
137
136
return self.get_weave(file_id, transaction)
138
137
except NoSuchFile:
139
weave = Weave(weave_name=file_id)
140
transaction.map.add_weave(file_id, weave)
141
transaction.register_clean(weave, precious=self._precious)
138
return self._new_weave(file_id, transaction)
140
@deprecated_method(zero_eight)
144
141
def put_weave(self, file_id, weave, transaction):
145
"""Write back a modified weave"""
142
"""This is a deprecated API: It writes an entire collection of ids out.
144
This became inappropriate when we made a versioned file api which
145
tracks the state of the collection of versions for a single id.
147
Its maintained for backwards compatability but will only work on
148
weave stores - pre 0.8 repositories.
150
self._put_weave(self, file_id, weave, transaction)
152
def _put_weave(self, file_id, weave, transaction):
153
"""Preserved here for upgrades-to-weaves to use."""
146
154
transaction.register_dirty(weave)
147
# TODO FOR WRITE TRANSACTIONS: this should be done in a callback
148
# from the transaction, when it decides to save.
155
weave_stream = self._weave_to_stream(weave)
156
self._put(file_id, weave_stream)
158
def _weave_to_stream(self, weave):
159
"""Make a stream from a weave."""
150
161
write_weave_v5(weave, sio)
152
self._put(file_id, sio)
165
@deprecated_method(zero_eight)
154
166
def add_text(self, file_id, rev_id, new_lines, parents, transaction):
155
w = self.get_weave_or_empty(file_id, transaction)
156
w.add_lines(rev_id, parents, new_lines)
157
self.put_weave(file_id, w, transaction)
167
"""This method was a shorthand for
169
vfile = self.get_weave_or_empty(file_id, transaction)
170
vfile.add_lines(rev_id, parents, new_lines)
172
vfile = self.get_weave_or_empty(file_id, transaction)
173
vfile.add_lines(rev_id, parents, new_lines)
175
@deprecated_method(zero_eight)
159
176
def add_identical_text(self, file_id, old_rev_id, new_rev_id, parents,
161
w = self.get_weave_or_empty(file_id, transaction)
162
parent_idxs = map(w.lookup, parents)
163
w.add_identical(old_rev_id, new_rev_id, parent_idxs)
164
self.put_weave(file_id, w, transaction)
178
"""This method was a shorthand for
180
vfile = self.get_weave_or_empty(file_id, transaction)
181
vfile.clone_text(new_rev_id, old_rev_id, parents)
183
vfile = self.get_weave_or_empty(file_id, transaction)
184
vfile.clone_text(new_rev_id, old_rev_id, parents)
166
def copy_multi(self, from_store, file_ids, pb=None):
186
def copy_multi(self, from_store, file_ids, pb=None, from_transaction=None):
167
187
assert isinstance(from_store, WeaveStore)
168
188
for count, f in enumerate(file_ids):
169
189
mutter("copy weave {%s} into %s", f, self)
171
191
pb.update('copy', count, len(file_ids))
172
self._put(f, from_store._get(f))
192
# if we have it in cache, its faster.
193
if from_transaction and from_transaction.map.find_weave(f):
194
mutter("cache hit in %s for %s", from_store, f)
195
weave = from_transaction.map.find_weave(f)
196
weave_stream = self._weave_to_stream(weave)
197
self._put(f, weave_stream)
199
self._put(f, from_store._get(f))