40
40
This has some shortcuts for reading and writing them.
42
FILE_SUFFIX = '.weave'
44
43
def __init__(self, transport, prefixed=False, precious=False,
45
44
dir_mode=None, file_mode=None):
51
50
def filename(self, file_id):
52
51
"""Return the path relative to the transport root."""
54
return hash_prefix(file_id) + urllib.quote(file_id) + WeaveStore.FILE_SUFFIX
53
return hash_prefix(file_id) + urllib.quote(file_id)
56
return urllib.quote(file_id) + WeaveStore.FILE_SUFFIX
55
return urllib.quote(file_id)
58
57
def __iter__(self):
59
l = len(WeaveStore.FILE_SUFFIX)
58
suffixes = WeaveFile.get_suffixes()
60
60
for relpath in self._iter_files_recursive():
61
if relpath.endswith(WeaveStore.FILE_SUFFIX):
62
yield os.path.basename(relpath[:-l])
61
for suffix in suffixes:
62
if relpath.endswith(suffix):
63
id = os.path.basename(relpath[:-len(suffix)])
64
68
def has_id(self, fileid):
65
return self._transport.has(self.filename(fileid))
67
def _get(self, file_id):
68
return self._transport.get(self.filename(file_id))
70
def _put(self, file_id, weave):
72
write_weave_v5(weave, f)
74
# less round trips to mkdir on failure than mkdir always
76
return self._transport.put(self.filename(file_id), f, mode=self._file_mode)
78
if not self._prefixed:
80
self._transport.mkdir(hash_prefix(file_id), mode=self._dir_mode)
81
return self._transport.put(self.filename(file_id), f, mode=self._file_mode)
69
suffixes = WeaveFile.get_suffixes()
70
filename = self.filename(fileid)
71
for suffix in suffixes:
72
if not self._transport.has(filename + suffix):
83
76
def get_weave(self, file_id, transaction):
84
77
weave = transaction.map.find_weave(file_id)
137
130
def _put_weave(self, file_id, weave, transaction):
138
131
"""Preserved here for upgrades-to-weaves to use."""
139
self._put(file_id, weave)
132
myweave = self._make_new_versionedfile(file_id)
141
135
@deprecated_method(zero_eight)
142
136
def add_text(self, file_id, rev_id, new_lines, parents, transaction):
194
188
pb.update('copy', count, len(file_ids))
195
189
# if we have it in cache, its faster.
196
if from_transaction and from_transaction.map.find_weave(f):
197
mutter("cache hit in %s for %s", from_store, f)
198
weave = from_transaction.map.find_weave(f)
199
# joining is fast with knits, and bearable for weaves -
200
# indeed the new case can be optimised
201
target = self._make_new_versionedfile(f)
190
if not from_transaction:
204
191
from bzrlib.transactions import PassThroughTransaction
205
self._put(f, from_store.get_weave(f, PassThroughTransaction()))
192
from_transaction = PassThroughTransaction()
193
# joining is fast with knits, and bearable for weaves -
194
# indeed the new case can be optimised
195
target = self._make_new_versionedfile(f)
196
target.join(from_store.get_weave(f, from_transaction))