mercurial/revlogutils/docket.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Mon, 29 Mar 2021 20:46:56 +0200
changeset 47266 921648d31553
parent 47255 ff9fd7107d11
child 47312 7ea39d633cf3
permissions -rw-r--r--
changelogv2: use a dedicated version number If we want to change the format, we need a new version number. We start with that. Differential Revision: https://phab.mercurial-scm.org/D10663
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47234
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     1
# docket - code related to revlog "docket"
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     2
#
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     3
# Copyright 2021 Pierre-Yves David <pierre-yves.david@octobus.net>
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     4
#
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     7
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     8
### Revlog docket file
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     9
#
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    10
# The revlog is stored on disk using multiple files:
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    11
#
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    12
# * a small docket file, containing metadata and a pointer,
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    13
#
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    14
# * an index file, containing fixed width information about revisions,
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    15
#
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    16
# * a data file, containing variable width data for these revisions,
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    17
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    18
from __future__ import absolute_import
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    19
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    20
import struct
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    21
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    22
from .. import (
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    23
    error,
47255
ff9fd7107d11 revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47242
diff changeset
    24
    util,
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    25
)
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    26
47234
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    27
from . import (
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    28
    constants,
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    29
)
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    30
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    31
# Docket format
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    32
#
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    33
# * 4 bytes: revlog version
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    34
#          |   This is mandatory as docket must be compatible with the previous
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    35
#          |   revlog index header.
47242
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
    36
# * 8 bytes: size of index-data
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
    37
# * 8 bytes: pending size of index-data
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
    38
# * 8 bytes: size of data
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
    39
# * 8 bytes: pending size of data
47255
ff9fd7107d11 revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47242
diff changeset
    40
# * 1 bytes: default compression header
ff9fd7107d11 revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47242
diff changeset
    41
S_HEADER = struct.Struct(constants.INDEX_HEADER.format + 'LLLLc')
47234
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    42
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    43
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    44
class RevlogDocket(object):
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    45
    """metadata associated with revlog"""
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    46
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    47
    def __init__(
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    48
        self,
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    49
        revlog,
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    50
        use_pending=False,
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    51
        version_header=None,
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    52
        index_end=0,
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    53
        pending_index_end=0,
47242
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
    54
        data_end=0,
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
    55
        pending_data_end=0,
47255
ff9fd7107d11 revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47242
diff changeset
    56
        default_compression_header=None,
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    57
    ):
47234
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    58
        self._version_header = version_header
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    59
        self._read_only = bool(use_pending)
47234
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    60
        self._dirty = False
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    61
        self._radix = revlog.radix
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    62
        self._path = revlog._docket_file
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    63
        self._opener = revlog.opener
47242
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
    64
        # thes asserts should be True as long as we have a single index filename
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    65
        assert index_end <= pending_index_end
47242
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
    66
        assert data_end <= pending_data_end
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    67
        self._initial_index_end = index_end
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    68
        self._pending_index_end = pending_index_end
47242
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
    69
        self._initial_data_end = data_end
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
    70
        self._pending_data_end = pending_data_end
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    71
        if use_pending:
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    72
            self._index_end = self._pending_index_end
47242
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
    73
            self._data_end = self._pending_data_end
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    74
        else:
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
    75
            self._index_end = self._initial_index_end
47242
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
    76
            self._data_end = self._initial_data_end
47255
ff9fd7107d11 revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47242
diff changeset
    77
        self.default_compression_header = default_compression_header
47234
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    78
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    79
    def index_filepath(self):
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    80
        """file path to the current index file associated to this docket"""
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    81
        # very simplistic version at first
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    82
        return b"%s.idx" % self._radix
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    83
47238
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
    84
    @property
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
    85
    def index_end(self):
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
    86
        return self._index_end
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
    87
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
    88
    @index_end.setter
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
    89
    def index_end(self, new_size):
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
    90
        if new_size != self._index_end:
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
    91
            self._index_end = new_size
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
    92
            self._dirty = True
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
    93
47242
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
    94
    @property
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
    95
    def data_end(self):
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
    96
        return self._data_end
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
    97
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
    98
    @data_end.setter
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
    99
    def data_end(self, new_size):
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
   100
        if new_size != self._data_end:
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
   101
            self._data_end = new_size
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
   102
            self._dirty = True
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
   103
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   104
    def write(self, transaction, pending=False, stripping=False):
47234
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   105
        """write the modification of disk if any
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   106
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   107
        This make the new content visible to all process"""
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   108
        if not self._dirty:
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   109
            return False
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   110
        else:
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   111
            if self._read_only:
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   112
                msg = b'writing read-only docket: %s'
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   113
                msg %= self._path
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   114
                raise error.ProgrammingError(msg)
47238
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
   115
            if not stripping:
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
   116
                # XXX we could, leverage the docket while stripping. However it
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
   117
                # is not powerfull enough at the time of this comment
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
   118
                transaction.addbackup(self._path, location=b'store')
47234
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   119
            with self._opener(self._path, mode=b'w', atomictemp=True) as f:
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   120
                f.write(self._serialize(pending=pending))
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   121
            # if pending we still need to the write final data eventually
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   122
            self._dirty = pending
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   123
            return True
47234
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   124
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   125
    def _serialize(self, pending=False):
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   126
        if pending:
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   127
            official_index_end = self._initial_index_end
47242
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
   128
            official_data_end = self._initial_data_end
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   129
        else:
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   130
            official_index_end = self._index_end
47242
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
   131
            official_data_end = self._data_end
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   132
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   133
        # this assert should be True as long as we have a single index filename
47242
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
   134
        assert official_data_end <= self._data_end
47238
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
   135
        data = (
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
   136
            self._version_header,
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   137
            official_index_end,
47238
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
   138
            self._index_end,
47242
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
   139
            official_data_end,
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
   140
            self._data_end,
47255
ff9fd7107d11 revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47242
diff changeset
   141
            self.default_compression_header,
47238
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
   142
        )
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
   143
        return S_HEADER.pack(*data)
47234
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   144
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   145
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   146
def default_docket(revlog, version_header):
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   147
    """given a revlog version a new docket object for the given revlog"""
47266
921648d31553 changelogv2: use a dedicated version number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47255
diff changeset
   148
    rl_version = version_header & 0xFFFF
921648d31553 changelogv2: use a dedicated version number
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47255
diff changeset
   149
    if rl_version not in (constants.REVLOGV2, constants.CHANGELOGV2):
47234
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   150
        return None
47255
ff9fd7107d11 revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47242
diff changeset
   151
    comp = util.compengines[revlog._compengine].revlogheader()
ff9fd7107d11 revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47242
diff changeset
   152
    docket = RevlogDocket(
ff9fd7107d11 revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47242
diff changeset
   153
        revlog,
ff9fd7107d11 revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47242
diff changeset
   154
        version_header=version_header,
ff9fd7107d11 revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47242
diff changeset
   155
        default_compression_header=comp,
ff9fd7107d11 revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47242
diff changeset
   156
    )
47234
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   157
    docket._dirty = True
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   158
    return docket
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   159
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   160
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   161
def parse_docket(revlog, data, use_pending=False):
47234
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   162
    """given some docket data return a docket object for the given revlog"""
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   163
    header = S_HEADER.unpack(data[: S_HEADER.size])
47242
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
   164
    version_header = header[0]
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
   165
    index_size = header[1]
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
   166
    pending_index_size = header[2]
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
   167
    data_size = header[3]
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
   168
    pending_data_size = header[4]
47255
ff9fd7107d11 revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47242
diff changeset
   169
    default_compression_header = header[5]
47234
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   170
    docket = RevlogDocket(
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   171
        revlog,
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   172
        use_pending=use_pending,
47234
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   173
        version_header=version_header,
47238
6597255a4f94 revlogv2: track current index size in the docket
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47234
diff changeset
   174
        index_end=index_size,
47241
2219853a1503 revlogv2: track pending write in the docket and expose it to hooks
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47238
diff changeset
   175
        pending_index_end=pending_index_size,
47242
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
   176
        data_end=data_size,
4abd474a10af revlogv2: also keep track for the size of the "data" file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47241
diff changeset
   177
        pending_data_end=pending_data_size,
47255
ff9fd7107d11 revlog: implement a "default compression" mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47242
diff changeset
   178
        default_compression_header=default_compression_header,
47234
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   179
    )
616b8f412676 revlogv2: introduce a very basic docket file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   180
    return docket