14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
from __future__ import absolute_import
20
22
from ..lazy_import import lazy_import
21
23
lazy_import(globals(), """
25
26
from breezy import (
1332
1338
# do a two-way diff against our original content
1333
1339
current_nodes = set()
1334
for name, sizes in self._names.items():
1340
for name, sizes in viewitems(self._names):
1335
1341
current_nodes.add(
1336
1342
(name, b' '.join(b'%d' % size for size in sizes)))
1544
1550
# FIXME: just drop the transient index.
1545
1551
# forget what names there are
1546
1552
if self._new_pack is not None:
1547
with contextlib.ExitStack() as stack:
1548
stack.callback(setattr, self, '_new_pack', None)
1549
# If we aborted while in the middle of finishing the write
1550
# group, _remove_pack_indices could fail because the indexes are
1551
# already gone. But they're not there we shouldn't fail in this
1552
# case, so we pass ignore_missing=True.
1553
stack.callback(self._remove_pack_indices, self._new_pack,
1554
ignore_missing=True)
1555
self._new_pack.abort()
1553
operation = cleanup.OperationWithCleanups(self._new_pack.abort)
1554
operation.add_cleanup(setattr, self, '_new_pack', None)
1555
# If we aborted while in the middle of finishing the write
1556
# group, _remove_pack_indices could fail because the indexes are
1557
# already gone. But they're not there we shouldn't fail in this
1558
# case, so we pass ignore_missing=True.
1559
operation.add_cleanup(self._remove_pack_indices, self._new_pack,
1560
ignore_missing=True)
1561
operation.run_simple()
1556
1562
for resumed_pack in self._resumed_packs:
1557
with contextlib.ExitStack() as stack:
1558
# See comment in previous finally block.
1559
stack.callback(self._remove_pack_indices, resumed_pack,
1560
ignore_missing=True)
1561
resumed_pack.abort()
1563
operation = cleanup.OperationWithCleanups(resumed_pack.abort)
1564
# See comment in previous finally block.
1565
operation.add_cleanup(self._remove_pack_indices, resumed_pack,
1566
ignore_missing=True)
1567
operation.run_simple()
1562
1568
del self._resumed_packs[:]
1564
1570
def _remove_resumed_pack_indices(self):
1958
1964
self._reload_func = reload_func
1959
1965
self._flush_func = flush_func
1961
def add_raw_record(self, key, size, raw_data):
1962
"""Add raw knit bytes to a storage area.
1964
The data is spooled to the container writer in one bytes-record per
1967
:param key: key of the data segment
1968
:param size: length of the data segment
1969
:param raw_data: A bytestring containing the data.
1970
:return: An opaque index memo For _DirectPackAccess the memo is
1971
(index, pos, length), where the index field is the write_index
1972
object supplied to the PackAccess object.
1974
p_offset, p_length = self._container_writer.add_bytes_record(
1976
return (self._write_index, p_offset, p_length)
1978
1967
def add_raw_records(self, key_sizes, raw_data):
1979
1968
"""Add raw knit bytes to a storage area.
1989
1978
length), where the index field is the write_index object supplied
1990
1979
to the PackAccess object.
1992
raw_data = b''.join(raw_data)
1993
1981
if not isinstance(raw_data, bytes):
1994
1982
raise AssertionError(
1995
1983
'data must be plain bytes was %s' % type(raw_data))
1998
1986
for key, size in key_sizes:
2000
self.add_raw_record(key, size, [raw_data[offset:offset + size]]))
1987
p_offset, p_length = self._container_writer.add_bytes_record(
1988
raw_data[offset:offset + size], [])
1990
result.append((self._write_index, p_offset, p_length))
2004
1993
def flush(self):