/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/bzr/pack_repo.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-05 07:32:38 UTC
  • mto: (7290.1.21 work)
  • mto: This revision was merged to the branch mainline in revision 7311.
  • Revision ID: jelmer@jelmer.uk-20190305073238-zlqn981opwnqsmzi
Add appveyor configuration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
import re
18
20
import sys
19
21
 
20
22
from ..lazy_import import lazy_import
21
23
lazy_import(globals(), """
22
 
import contextlib
23
24
import time
24
25
 
25
26
from breezy import (
 
27
    cleanup,
26
28
    config,
27
29
    debug,
28
30
    graph,
58
60
    MetaDirRepository,
59
61
    RepositoryFormatMetaDir,
60
62
    )
 
63
from ..sixish import (
 
64
    reraise,
 
65
    viewitems,
 
66
    )
61
67
from ..bzr.vf_repository import (
62
68
    MetaDirVersionedFileRepository,
63
69
    MetaDirVersionedFileRepositoryFormat,
1331
1337
 
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)))
1337
1343
 
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[:]
1563
1569
 
1564
1570
    def _remove_resumed_pack_indices(self):
1958
1964
        self._reload_func = reload_func
1959
1965
        self._flush_func = flush_func
1960
1966
 
1961
 
    def add_raw_record(self, key, size, raw_data):
1962
 
        """Add raw knit bytes to a storage area.
1963
 
 
1964
 
        The data is spooled to the container writer in one bytes-record per
1965
 
        raw data item.
1966
 
 
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.
1973
 
        """
1974
 
        p_offset, p_length = self._container_writer.add_bytes_record(
1975
 
            raw_data, size, [])
1976
 
        return (self._write_index, p_offset, p_length)
1977
 
 
1978
1967
    def add_raw_records(self, key_sizes, raw_data):
1979
1968
        """Add raw knit bytes to a storage area.
1980
1969
 
1989
1978
            length), where the index field is the write_index object supplied
1990
1979
            to the PackAccess object.
1991
1980
        """
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))
1996
1984
        result = []
1997
1985
        offset = 0
1998
1986
        for key, size in key_sizes:
1999
 
            result.append(
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], [])
2001
1989
            offset += size
 
1990
            result.append((self._write_index, p_offset, p_length))
2002
1991
        return result
2003
1992
 
2004
1993
    def flush(self):
2093
2082
                is_error = True
2094
2083
        if is_error:
2095
2084
            # GZ 2017-03-27: No real reason this needs the original traceback.
2096
 
            raise retry_exc.exc_info[1]
 
2085
            reraise(*retry_exc.exc_info)