mercurial/revlogutils/__init__.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Tue, 14 Dec 2021 23:56:38 +0100
changeset 48499 52034c42c09d
parent 47399 34cc102c73f5
child 48875 6000f5b25c9b
permissions -rw-r--r--
rank: add a "rank" value to the revlog-entry tuple The rank of a revision is the size of sub-graph it defines as a head. In other words, the rank of X is the size of `ancestors(X)` (X included). This is a property that can help various algorithm and we intend to store it in changelog-v2. We start with adding this new information to the "entry tuple", with a default value. We will start to compute and persist the rank later. Differential Revision: https://phab.mercurial-scm.org/D11936
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43524
a7c0c5b5a50f revlog: introduce an explicit NodeMap class for pure code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 39329
diff changeset
     1
# mercurial.revlogutils -- basic utilities for revlog
a7c0c5b5a50f revlog: introduce an explicit NodeMap class for pure code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 39329
diff changeset
     2
#
a7c0c5b5a50f revlog: introduce an explicit NodeMap class for pure code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 39329
diff changeset
     3
# Copyright 2019 Pierre-Yves David <pierre-yves.david@octobus.net>
a7c0c5b5a50f revlog: introduce an explicit NodeMap class for pure code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 39329
diff changeset
     4
#
a7c0c5b5a50f revlog: introduce an explicit NodeMap class for pure code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 39329
diff changeset
     5
# This software may be used and distributed according to the terms of the
a7c0c5b5a50f revlog: introduce an explicit NodeMap class for pure code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 39329
diff changeset
     6
# GNU General Public License version 2 or any later version.
a7c0c5b5a50f revlog: introduce an explicit NodeMap class for pure code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 39329
diff changeset
     7
a7c0c5b5a50f revlog: introduce an explicit NodeMap class for pure code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 39329
diff changeset
     8
from __future__ import absolute_import
47394
ac60a1366a49 revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
     9
47399
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    10
from ..thirdparty import attr
47394
ac60a1366a49 revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
    11
from ..interfaces import repository
ac60a1366a49 revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
    12
47395
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    13
# See mercurial.revlogutils.constants for doc
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    14
COMP_MODE_INLINE = 2
48499
52034c42c09d rank: add a "rank" value to the revlog-entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47399
diff changeset
    15
RANK_UNKNOWN = -1
47395
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    16
47394
ac60a1366a49 revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
    17
ac60a1366a49 revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
    18
def offset_type(offset, type):
ac60a1366a49 revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
    19
    if (type & ~repository.REVISION_FLAGS_KNOWN) != 0:
ac60a1366a49 revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
    20
        raise ValueError(b'unknown revlog index flags: %d' % type)
ac60a1366a49 revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
    21
    return int(int(offset) << 16 | type)
47395
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    22
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    23
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    24
def entry(
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    25
    data_offset,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    26
    data_compressed_length,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    27
    data_delta_base,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    28
    link_rev,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    29
    parent_rev_1,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    30
    parent_rev_2,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    31
    node_id,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    32
    flags=0,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    33
    data_uncompressed_length=-1,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    34
    data_compression_mode=COMP_MODE_INLINE,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    35
    sidedata_offset=0,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    36
    sidedata_compressed_length=0,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    37
    sidedata_compression_mode=COMP_MODE_INLINE,
48499
52034c42c09d rank: add a "rank" value to the revlog-entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47399
diff changeset
    38
    rank=RANK_UNKNOWN,
47395
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    39
):
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    40
    """Build one entry from symbolic name
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    41
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    42
    This is useful to abstract the actual detail of how we build the entry
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    43
    tuple for caller who don't care about it.
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    44
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    45
    This should always be called using keyword arguments. Some arguments have
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    46
    default value, this match the value used by index version that does not store such data.
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    47
    """
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    48
    return (
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    49
        offset_type(data_offset, flags),
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    50
        data_compressed_length,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    51
        data_uncompressed_length,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    52
        data_delta_base,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    53
        link_rev,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    54
        parent_rev_1,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    55
        parent_rev_2,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    56
        node_id,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    57
        sidedata_offset,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    58
        sidedata_compressed_length,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    59
        data_compression_mode,
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    60
        sidedata_compression_mode,
48499
52034c42c09d rank: add a "rank" value to the revlog-entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47399
diff changeset
    61
        rank,
47395
a669404f0f4a revlog: add a function to build index entry tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    62
    )
47399
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    63
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    64
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    65
@attr.s(slots=True, frozen=True)
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    66
class revisioninfo(object):
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    67
    """Information about a revision that allows building its fulltext
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    68
    node:       expected hash of the revision
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    69
    p1, p2:     parent revs of the revision
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    70
    btext:      built text cache consisting of a one-element list
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    71
    cachedelta: (baserev, uncompressed_delta) or None
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    72
    flags:      flags associated to the revision storage
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    73
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    74
    One of btext[0] or cachedelta must be set.
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    75
    """
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    76
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    77
    node = attr.ib()
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    78
    p1 = attr.ib()
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    79
    p2 = attr.ib()
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    80
    btext = attr.ib()
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    81
    textlen = attr.ib()
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    82
    cachedelta = attr.ib()
34cc102c73f5 revlog: move `revisioninfo` in `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47395
diff changeset
    83
    flags = attr.ib()