1255
1255
encode_utf8 = cache_utf8.encode
1256
for version_id, options, pos, size, parents in versions:
1257
line = "\n%s %s %s %s %s :" % (encode_utf8(version_id),
1261
self._version_list_to_index(parents))
1262
assert isinstance(line, str), \
1263
'content must be utf-8 encoded: %r' % (line,)
1265
if not self._need_to_create:
1266
self._transport.append_bytes(self._filename, ''.join(lines))
1269
sio.write(self.HEADER)
1270
sio.writelines(lines)
1272
self._transport.put_file_non_atomic(self._filename, sio,
1273
create_parent_dir=self._create_parent_dir,
1274
mode=self._file_mode,
1275
dir_mode=self._dir_mode)
1276
self._need_to_create = False
1278
# cache after writing, so that a failed write leads to missing cache
1279
# entries not extra ones. XXX TODO: RBC 20060502 in the event of a
1280
# failure, reload the index or flush it or some such, to prevent
1281
# writing records that did complete twice.
1282
for version_id, options, pos, size, parents in versions:
1283
self._cache_version(version_id, options, pos, size, parents)
1256
orig_history = self._history[:]
1257
orig_cache = self._cache.copy()
1260
for version_id, options, pos, size, parents in versions:
1261
line = "\n%s %s %s %s %s :" % (encode_utf8(version_id),
1265
self._version_list_to_index(parents))
1266
assert isinstance(line, str), \
1267
'content must be utf-8 encoded: %r' % (line,)
1269
self._cache_version(version_id, options, pos, size, parents)
1270
if not self._need_to_create:
1271
self._transport.append_bytes(self._filename, ''.join(lines))
1274
sio.write(self.HEADER)
1275
sio.writelines(lines)
1277
self._transport.put_file_non_atomic(self._filename, sio,
1278
create_parent_dir=self._create_parent_dir,
1279
mode=self._file_mode,
1280
dir_mode=self._dir_mode)
1281
self._need_to_create = False
1283
# If any problems happen, restore the original values and re-raise
1284
self._history = orig_history
1285
self._cache = orig_cache
1285
1288
def has_version(self, version_id):
1286
1289
"""True if the version is in the index."""
1287
1290
return (version_id in self._cache)