25
25
from warnings import warn
27
from bzrlib import errors
28
31
from bzrlib.weavefile import read_weave, write_weave_v5
29
32
from bzrlib.weave import WeaveFile, Weave
30
33
from bzrlib.store import TransportStore
70
73
def filename(self, file_id):
71
74
"""Return the path relative to the transport root."""
75
file_id = osutils.safe_file_id(file_id)
72
76
return self._relpath(file_id)
74
78
def __iter__(self):
86
90
break # only one suffix can match
88
def has_id(self, fileid):
92
def has_id(self, file_id):
93
file_id = osutils.safe_file_id(file_id)
89
94
suffixes = self._versionedfile_class.get_suffixes()
90
filename = self.filename(fileid)
95
filename = self.filename(file_id)
91
96
for suffix in suffixes:
92
97
if not self._transport.has(filename + suffix):
96
101
def get_empty(self, file_id, transaction):
97
102
"""Get an empty weave, which implies deleting the existing one first."""
103
file_id = osutils.safe_file_id(file_id)
98
104
if self.has_id(file_id):
99
105
self.delete(file_id, transaction)
100
106
return self.get_weave_or_empty(file_id, transaction)
102
108
def delete(self, file_id, transaction):
103
109
"""Remove file_id from the store."""
110
file_id = osutils.safe_file_id(file_id)
104
111
suffixes = self._versionedfile_class.get_suffixes()
105
112
filename = self.filename(file_id)
106
113
for suffix in suffixes:
127
134
file_id. This is used to reduce duplicate filename calculations when
128
135
using 'get_weave_or_empty'. FOR INTERNAL USE ONLY.
137
file_id = osutils.safe_file_id(file_id)
130
138
weave = transaction.map.find_weave(file_id)
131
139
if weave is not None:
132
140
#mutter("cache hit in %s for %s", self, file_id)
156
164
Returned as a list of lines.
166
file_id = osutils.safe_file_id(file_id)
158
167
w = self.get_weave(file_id, transaction)
159
168
return w.get_lines(rev_id)
193
202
# of calculating the filename before doing a cache lookup is more than
194
203
# compensated for by not calculating the filename when making new
195
204
# versioned files.
205
file_id = osutils.safe_file_id(file_id)
196
206
_filename = self.filename(file_id)
198
208
return self.get_weave(file_id, transaction, _filename=_filename)
214
224
Its maintained for backwards compatability but will only work on
215
225
weave stores - pre 0.8 repositories.
227
file_id = osutils.safe_file_id(file_id)
217
228
self._put_weave(file_id, weave, transaction)
219
230
def _put_weave(self, file_id, weave, transaction):
228
239
vfile = self.get_weave_or_empty(file_id, transaction)
229
240
vfile.add_lines(rev_id, parents, new_lines)
242
file_id = osutils.safe_file_id(file_id)
231
243
vfile = self.get_weave_or_empty(file_id, transaction)
232
244
vfile.add_lines(rev_id, parents, new_lines)
239
251
vfile = self.get_weave_or_empty(file_id, transaction)
240
252
vfile.clone_text(new_rev_id, old_rev_id, parents)
254
file_id = osutils.safe_file_id(file_id)
255
old_rev_id = osutils.safe_revision_id(old_rev_id)
256
new_rev_id = osutils.safe_revision_id(new_rev_id)
242
257
vfile = self.get_weave_or_empty(file_id, transaction)
243
258
vfile.clone_text(new_rev_id, old_rev_id, parents)
294
309
# so again with the passthrough
295
310
to_transaction = PassThroughTransaction()
296
311
pb = bzrlib.ui.ui_factory.nested_progress_bar()
297
for count, f in enumerate(file_ids):
298
mutter("copy weave {%s} into %s", f, self)
299
pb.update('copy', count, len(file_ids))
300
# if we have it in cache, its faster.
301
# joining is fast with knits, and bearable for weaves -
302
# indeed the new case can be optimised if needed.
303
target = self._make_new_versionedfile(f, to_transaction)
304
target.join(from_store.get_weave(f, from_transaction))
313
file_ids = [osutils.safe_file_id(f) for f in file_ids]
314
for count, f in enumerate(file_ids):
315
mutter("copy weave {%s} into %s", f, self)
316
pb.update('copy', count, len(file_ids))
317
# if we have it in cache, its faster.
318
# joining is fast with knits, and bearable for weaves -
319
# indeed the new case can be optimised if needed.
320
target = self._make_new_versionedfile(f, to_transaction)
321
target.join(from_store.get_weave(f, from_transaction))
307
325
def total_size(self):
308
326
count, bytes = super(VersionedFileStore, self).total_size()