mercurial/pure/parsers.py
author Matt Harbison <matt_harbison@yahoo.com>
Wed, 24 Nov 2021 20:45:27 -0500
changeset 48351 981509bb10ac
parent 48266 749946b6a641
child 48378 3d6eb119200d
permissions -rw-r--r--
packaging: bump windows_curses to 2.3.0 This is required for Python 3.10 support. Differential Revision: https://phab.mercurial-scm.org/D11804
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
     1
# parsers.py - Python implementation of parsers.c
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
     2
#
46819
d4ba4d51f85f contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents: 46717
diff changeset
     3
# Copyright 2009 Olivia Mackall <olivia@selenic.com> and others
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
     4
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 7945
diff changeset
     5
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 8225
diff changeset
     6
# GNU General Public License version 2 or any later version.
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
     7
27339
6ab8c6511a6a parsers: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24634
diff changeset
     8
from __future__ import absolute_import
6ab8c6511a6a parsers: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24634
diff changeset
     9
48221
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
    10
import stat
27339
6ab8c6511a6a parsers: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24634
diff changeset
    11
import struct
6ab8c6511a6a parsers: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24634
diff changeset
    12
import zlib
6ab8c6511a6a parsers: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24634
diff changeset
    13
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46974
diff changeset
    14
from ..node import (
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46974
diff changeset
    15
    nullrev,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46974
diff changeset
    16
    sha1nodeconstants,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46974
diff changeset
    17
)
47566
3df817387ea3 parsers: move DirstateItem to attr.s
Augie Fackler <augie@google.com>
parents: 47540
diff changeset
    18
from ..thirdparty import attr
43525
845e5b313783 revlog: move the nodemap into the index object (for pure)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43106
diff changeset
    19
from .. import (
47235
6b1eae313b2f revlogv2: store version information in the docket only
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47143
diff changeset
    20
    error,
43525
845e5b313783 revlog: move the nodemap into the index object (for pure)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43106
diff changeset
    21
    pycompat,
47394
ac60a1366a49 revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47270
diff changeset
    22
    revlogutils,
43525
845e5b313783 revlog: move the nodemap into the index object (for pure)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43106
diff changeset
    23
    util,
845e5b313783 revlog: move the nodemap into the index object (for pure)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43106
diff changeset
    24
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39217
diff changeset
    25
44034
ab595920de0e revlogutils: move the NodeMap class in a dedicated nodemap module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43619
diff changeset
    26
from ..revlogutils import nodemap as nodemaputil
46857
cc65cea90edb revlog: move the details of revlog "v1" index inside revlog.utils.constants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46819
diff changeset
    27
from ..revlogutils import constants as revlog_constants
44034
ab595920de0e revlogutils: move the NodeMap class in a dedicated nodemap module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43619
diff changeset
    28
36958
644a02f6b34f util: prefer "bytesio" to "stringio"
Gregory Szorc <gregory.szorc@gmail.com>
parents: 34331
diff changeset
    29
stringio = pycompat.bytesio
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
    30
31220
37596c980662 parsers: alias long to int on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29133
diff changeset
    31
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
    32
_pack = struct.pack
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
    33
_unpack = struct.unpack
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
    34
_compress = zlib.compress
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
    35
_decompress = zlib.decompress
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
    36
47507
d4c795576aeb dirstate-entry: turn dirstate tuple into a real object (like in C)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47490
diff changeset
    37
47514
559aee84b889 dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47513
diff changeset
    38
# a special value used internally for `size` if the file come from the other parent
559aee84b889 dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47513
diff changeset
    39
FROM_P2 = -2
559aee84b889 dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47513
diff changeset
    40
47516
b8ffe85e399b dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47515
diff changeset
    41
# a special value used internally for `size` if the file is modified/merged/added
b8ffe85e399b dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47515
diff changeset
    42
NONNORMAL = -1
b8ffe85e399b dirstate-entry: `merged_removed` and `from_p2_removed` properties
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47515
diff changeset
    43
47540
1a6302427eb9 dirstate-item: use need_delay when packing dirstate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
    44
# a special value used internally for `time` if the time is ambigeous
1a6302427eb9 dirstate-item: use need_delay when packing dirstate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
    45
AMBIGUOUS_TIME = -1
1a6302427eb9 dirstate-item: use need_delay when packing dirstate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
    46
48221
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
    47
# Bits of the `flags` byte inside a node in the file format
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
    48
DIRSTATE_V2_WDIR_TRACKED = 1 << 0
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
    49
DIRSTATE_V2_P1_TRACKED = 1 << 1
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
    50
DIRSTATE_V2_P2_INFO = 1 << 2
48266
749946b6a641 dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48264
diff changeset
    51
DIRSTATE_V2_MODE_EXEC_PERM = 1 << 3
749946b6a641 dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48264
diff changeset
    52
DIRSTATE_V2_MODE_IS_SYMLINK = 1 << 4
749946b6a641 dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48264
diff changeset
    53
DIRSTATE_V2_HAS_FALLBACK_EXEC = 1 << 5
749946b6a641 dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48264
diff changeset
    54
DIRSTATE_V2_FALLBACK_EXEC = 1 << 6
749946b6a641 dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48264
diff changeset
    55
DIRSTATE_V2_HAS_FALLBACK_SYMLINK = 1 << 7
749946b6a641 dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48264
diff changeset
    56
DIRSTATE_V2_FALLBACK_SYMLINK = 1 << 8
749946b6a641 dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48264
diff changeset
    57
DIRSTATE_V2_EXPECTED_STATE_IS_MODIFIED = 1 << 9
749946b6a641 dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48264
diff changeset
    58
DIRSTATE_V2_HAS_MODE_AND_SIZE = 1 << 10
749946b6a641 dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48264
diff changeset
    59
DIRSTATE_V2_HAS_MTIME = 1 << 11
749946b6a641 dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48264
diff changeset
    60
DIRSTATE_V2_MTIME_SECOND_AMBIGUOUS = 1 << 12
749946b6a641 dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48264
diff changeset
    61
DIRSTATE_V2_DIRECTORY = 1 << 13
749946b6a641 dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48264
diff changeset
    62
DIRSTATE_V2_ALL_UNKNOWN_RECORDED = 1 << 14
749946b6a641 dirstate-v2: reorder flag to group related one together
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48264
diff changeset
    63
DIRSTATE_V2_ALL_IGNORED_RECORDED = 1 << 15
48221
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
    64
47514
559aee84b889 dirstate-entry: add a `from_p2` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47513
diff changeset
    65
47664
119b9c8db94d dirstate-item: use an explicit __init__ function instead of the attrs one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47569
diff changeset
    66
@attr.s(slots=True, init=False)
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47538
diff changeset
    67
class DirstateItem(object):
47507
d4c795576aeb dirstate-entry: turn dirstate tuple into a real object (like in C)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47490
diff changeset
    68
    """represent a dirstate entry
d4c795576aeb dirstate-entry: turn dirstate tuple into a real object (like in C)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47490
diff changeset
    69
48112
fabf687df0ff dirstate-item: update the attribute documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48111
diff changeset
    70
    It hold multiple attributes
fabf687df0ff dirstate-item: update the attribute documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48111
diff changeset
    71
fabf687df0ff dirstate-item: update the attribute documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48111
diff changeset
    72
    # about file tracking
fabf687df0ff dirstate-item: update the attribute documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48111
diff changeset
    73
    - wc_tracked: is the file tracked by the working copy
fabf687df0ff dirstate-item: update the attribute documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48111
diff changeset
    74
    - p1_tracked: is the file tracked in working copy first parent
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
    75
    - p2_info: the file has been involved in some merge operation. Either
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
    76
               because it was actually merged, or because the p2 version was
48188
77fc340acad7 dirstate-v2: Document flags/mode/size/mtime fields of tree nodes
Simon Sapin <simon.sapin@octobus.net>
parents: 48164
diff changeset
    77
               ahead, or because some rename moved it there. In either case
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
    78
               `hg status` will want it displayed as modified.
48112
fabf687df0ff dirstate-item: update the attribute documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48111
diff changeset
    79
fabf687df0ff dirstate-item: update the attribute documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48111
diff changeset
    80
    # about the file state expected from p1 manifest:
fabf687df0ff dirstate-item: update the attribute documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48111
diff changeset
    81
    - mode: the file mode in p1
fabf687df0ff dirstate-item: update the attribute documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48111
diff changeset
    82
    - size: the file size in p1
fabf687df0ff dirstate-item: update the attribute documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48111
diff changeset
    83
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
    84
    These value can be set to None, which mean we don't have a meaningful value
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
    85
    to compare with. Either because we don't really care about them as there
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
    86
    `status` is known without having to look at the disk or because we don't
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
    87
    know these right now and a full comparison will be needed to find out if
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
    88
    the file is clean.
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
    89
48112
fabf687df0ff dirstate-item: update the attribute documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48111
diff changeset
    90
    # about the file state on disk last time we saw it:
fabf687df0ff dirstate-item: update the attribute documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48111
diff changeset
    91
    - mtime: the last known clean mtime for the file.
fabf687df0ff dirstate-item: update the attribute documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48111
diff changeset
    92
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
    93
    This value can be set to None if no cachable state exist. Either because we
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
    94
    do not care (see previous section) or because we could not cache something
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
    95
    yet.
47490
084ed6a7c6fd dirstate: document the dirstatetuple content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    96
    """
084ed6a7c6fd dirstate: document the dirstatetuple content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47394
diff changeset
    97
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
    98
    _wc_tracked = attr.ib()
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
    99
    _p1_tracked = attr.ib()
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   100
    _p2_info = attr.ib()
47566
3df817387ea3 parsers: move DirstateItem to attr.s
Augie Fackler <augie@google.com>
parents: 47540
diff changeset
   101
    _mode = attr.ib()
3df817387ea3 parsers: move DirstateItem to attr.s
Augie Fackler <augie@google.com>
parents: 47540
diff changeset
   102
    _size = attr.ib()
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   103
    _mtime_s = attr.ib()
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   104
    _mtime_ns = attr.ib()
48252
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   105
    _fallback_exec = attr.ib()
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   106
    _fallback_symlink = attr.ib()
47507
d4c795576aeb dirstate-entry: turn dirstate tuple into a real object (like in C)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47490
diff changeset
   107
47895
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47890
diff changeset
   108
    def __init__(
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47890
diff changeset
   109
        self,
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47890
diff changeset
   110
        wc_tracked=False,
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47890
diff changeset
   111
        p1_tracked=False,
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   112
        p2_info=False,
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   113
        has_meaningful_data=True,
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   114
        has_meaningful_mtime=True,
47895
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47890
diff changeset
   115
        parentfiledata=None,
48253
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
   116
        fallback_exec=None,
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
   117
        fallback_symlink=None,
47895
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47890
diff changeset
   118
    ):
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   119
        self._wc_tracked = wc_tracked
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   120
        self._p1_tracked = p1_tracked
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   121
        self._p2_info = p2_info
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   122
48253
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
   123
        self._fallback_exec = fallback_exec
948570aa7630 dirstate: make DirstateItem constructor accept fallback value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48252
diff changeset
   124
        self._fallback_symlink = fallback_symlink
48252
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   125
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   126
        self._mode = None
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   127
        self._size = None
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   128
        self._mtime_s = None
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   129
        self._mtime_ns = None
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   130
        if parentfiledata is None:
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   131
            has_meaningful_mtime = False
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   132
            has_meaningful_data = False
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   133
        if has_meaningful_data:
47895
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47890
diff changeset
   134
            self._mode = parentfiledata[0]
22c39f8acf78 dirstate-item: feed more information to `__init__`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47890
diff changeset
   135
            self._size = parentfiledata[1]
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   136
        if has_meaningful_mtime:
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   137
            self._mtime_s, self._mtime_ns = parentfiledata[2]
47664
119b9c8db94d dirstate-item: use an explicit __init__ function instead of the attrs one
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47569
diff changeset
   138
47665
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47664
diff changeset
   139
    @classmethod
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   140
    def from_v2_data(cls, flags, size, mtime_s, mtime_ns):
48221
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   141
        """Build a new DirstateItem object from V2 data"""
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   142
        has_mode_size = bool(flags & DIRSTATE_V2_HAS_MODE_AND_SIZE)
48264
bb240915f69f dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48262
diff changeset
   143
        has_meaningful_mtime = bool(flags & DIRSTATE_V2_HAS_MTIME)
48261
9205d9be8b41 dirstate-v2: add a new MTIME_SECOND_AMBIGUOUS flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48260
diff changeset
   144
        if flags & DIRSTATE_V2_MTIME_SECOND_AMBIGUOUS:
9205d9be8b41 dirstate-v2: add a new MTIME_SECOND_AMBIGUOUS flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48260
diff changeset
   145
            # The current code is not able to do the more subtle comparison that the
9205d9be8b41 dirstate-v2: add a new MTIME_SECOND_AMBIGUOUS flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48260
diff changeset
   146
            # MTIME_SECOND_AMBIGUOUS requires. So we ignore the mtime
9205d9be8b41 dirstate-v2: add a new MTIME_SECOND_AMBIGUOUS flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48260
diff changeset
   147
            has_meaningful_mtime = False
48221
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   148
        mode = None
48250
1730b2fceaa1 dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48232
diff changeset
   149
1730b2fceaa1 dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48232
diff changeset
   150
        if flags & +DIRSTATE_V2_EXPECTED_STATE_IS_MODIFIED:
1730b2fceaa1 dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48232
diff changeset
   151
            # we do not have support for this flag in the code yet,
1730b2fceaa1 dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48232
diff changeset
   152
            # force a lookup for this file.
1730b2fceaa1 dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48232
diff changeset
   153
            has_mode_size = False
1730b2fceaa1 dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48232
diff changeset
   154
            has_meaningful_mtime = False
1730b2fceaa1 dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48232
diff changeset
   155
48254
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   156
        fallback_exec = None
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   157
        if flags & DIRSTATE_V2_HAS_FALLBACK_EXEC:
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   158
            fallback_exec = flags & DIRSTATE_V2_FALLBACK_EXEC
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   159
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   160
        fallback_symlink = None
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   161
        if flags & DIRSTATE_V2_HAS_FALLBACK_SYMLINK:
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   162
            fallback_symlink = flags & DIRSTATE_V2_FALLBACK_SYMLINK
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   163
48221
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   164
        if has_mode_size:
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   165
            assert stat.S_IXUSR == 0o100
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   166
            if flags & DIRSTATE_V2_MODE_EXEC_PERM:
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   167
                mode = 0o755
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   168
            else:
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   169
                mode = 0o644
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   170
            if flags & DIRSTATE_V2_MODE_IS_SYMLINK:
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   171
                mode |= stat.S_IFLNK
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   172
            else:
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   173
                mode |= stat.S_IFREG
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   174
        return cls(
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   175
            wc_tracked=bool(flags & DIRSTATE_V2_WDIR_TRACKED),
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   176
            p1_tracked=bool(flags & DIRSTATE_V2_P1_TRACKED),
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   177
            p2_info=bool(flags & DIRSTATE_V2_P2_INFO),
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   178
            has_meaningful_data=has_mode_size,
48250
1730b2fceaa1 dirstate-v2: adds a flag to mark a file as modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48232
diff changeset
   179
            has_meaningful_mtime=has_meaningful_mtime,
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   180
            parentfiledata=(mode, size, (mtime_s, mtime_ns)),
48254
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   181
            fallback_exec=fallback_exec,
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   182
            fallback_symlink=fallback_symlink,
48221
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   183
        )
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   184
a32a96079e2d dirstate-v2: initial Python parser
Simon Sapin <simon.sapin@octobus.net>
parents: 48188
diff changeset
   185
    @classmethod
47665
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47664
diff changeset
   186
    def from_v1_data(cls, state, mode, size, mtime):
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47664
diff changeset
   187
        """Build a new DirstateItem object from V1 data
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47664
diff changeset
   188
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47664
diff changeset
   189
        Since the dirstate-v1 format is frozen, the signature of this function
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47664
diff changeset
   190
        is not expected to change, unlike the __init__ one.
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47664
diff changeset
   191
        """
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   192
        if state == b'm':
48154
7a8c9869e4fe dirstate-item: replace call to new_merged
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48153
diff changeset
   193
            return cls(wc_tracked=True, p1_tracked=True, p2_info=True)
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   194
        elif state == b'a':
48156
d342815ff827 dirstate-item: replace call to new_added
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48155
diff changeset
   195
            return cls(wc_tracked=True)
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   196
        elif state == b'r':
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   197
            if size == NONNORMAL:
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   198
                p1_tracked = True
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   199
                p2_info = True
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   200
            elif size == FROM_P2:
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   201
                p1_tracked = False
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   202
                p2_info = True
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   203
            else:
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   204
                p1_tracked = True
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   205
                p2_info = False
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   206
            return cls(p1_tracked=p1_tracked, p2_info=p2_info)
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   207
        elif state == b'n':
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   208
            if size == FROM_P2:
48158
da304f78a0e1 dirstate-item: replace call to new_from_p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48157
diff changeset
   209
                return cls(wc_tracked=True, p2_info=True)
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   210
            elif size == NONNORMAL:
48160
898de425bcd6 dirstate-item: replace call to new_possibly_dirty
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48159
diff changeset
   211
                return cls(wc_tracked=True, p1_tracked=True)
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   212
            elif mtime == AMBIGUOUS_TIME:
48162
79ebbe19d9e3 dirstate-item: replace a call to new_normal
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48161
diff changeset
   213
                return cls(
79ebbe19d9e3 dirstate-item: replace a call to new_normal
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48161
diff changeset
   214
                    wc_tracked=True,
79ebbe19d9e3 dirstate-item: replace a call to new_normal
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48161
diff changeset
   215
                    p1_tracked=True,
79ebbe19d9e3 dirstate-item: replace a call to new_normal
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48161
diff changeset
   216
                    has_meaningful_mtime=False,
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   217
                    parentfiledata=(mode, size, (42, 0)),
48162
79ebbe19d9e3 dirstate-item: replace a call to new_normal
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48161
diff changeset
   218
                )
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   219
            else:
48163
d0081dbca442 dirstate-item: replace call to new_normal
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48162
diff changeset
   220
                return cls(
d0081dbca442 dirstate-item: replace call to new_normal
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48162
diff changeset
   221
                    wc_tracked=True,
d0081dbca442 dirstate-item: replace call to new_normal
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48162
diff changeset
   222
                    p1_tracked=True,
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   223
                    parentfiledata=(mode, size, (mtime, 0)),
48163
d0081dbca442 dirstate-item: replace call to new_normal
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48162
diff changeset
   224
                )
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   225
        else:
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   226
            raise RuntimeError(b'unknown state: %s' % state)
47665
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47664
diff changeset
   227
47666
e53256a9f9c5 dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47665
diff changeset
   228
    def set_possibly_dirty(self):
e53256a9f9c5 dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47665
diff changeset
   229
        """Mark a file as "possibly dirty"
e53256a9f9c5 dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47665
diff changeset
   230
e53256a9f9c5 dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47665
diff changeset
   231
        This means the next status call will have to actually check its content
e53256a9f9c5 dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47665
diff changeset
   232
        to make sure it is correct.
e53256a9f9c5 dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47665
diff changeset
   233
        """
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   234
        self._mtime_s = None
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   235
        self._mtime_ns = None
47666
e53256a9f9c5 dirstate-item: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47665
diff changeset
   236
47974
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47938
diff changeset
   237
    def set_clean(self, mode, size, mtime):
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47938
diff changeset
   238
        """mark a file as "clean" cancelling potential "possibly dirty call"
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47938
diff changeset
   239
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47938
diff changeset
   240
        Note: this function is a descendant of `dirstate.normal` and is
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47938
diff changeset
   241
        currently expected to be call on "normal" entry only. There are not
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47938
diff changeset
   242
        reason for this to not change in the future as long as the ccode is
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47938
diff changeset
   243
        updated to preserve the proper state of the non-normal files.
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47938
diff changeset
   244
        """
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47938
diff changeset
   245
        self._wc_tracked = True
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47938
diff changeset
   246
        self._p1_tracked = True
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47938
diff changeset
   247
        self._mode = mode
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47938
diff changeset
   248
        self._size = size
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   249
        self._mtime_s, self._mtime_ns = mtime
47974
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47938
diff changeset
   250
47990
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47974
diff changeset
   251
    def set_tracked(self):
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47974
diff changeset
   252
        """mark a file as tracked in the working copy
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47974
diff changeset
   253
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47974
diff changeset
   254
        This will ultimately be called by command like `hg add`.
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47974
diff changeset
   255
        """
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47974
diff changeset
   256
        self._wc_tracked = True
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   257
        # `set_tracked` is replacing various `normallookup` call. So we mark
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   258
        # the files as needing lookup
47990
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47974
diff changeset
   259
        #
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47974
diff changeset
   260
        # Consider dropping this in the future in favor of something less broad.
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   261
        self._mtime_s = None
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   262
        self._mtime_ns = None
47990
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47974
diff changeset
   263
47890
3853e6ee160d dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47686
diff changeset
   264
    def set_untracked(self):
3853e6ee160d dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47686
diff changeset
   265
        """mark a file as untracked in the working copy
3853e6ee160d dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47686
diff changeset
   266
3853e6ee160d dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47686
diff changeset
   267
        This will ultimately be called by command like `hg remove`.
3853e6ee160d dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47686
diff changeset
   268
        """
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   269
        self._wc_tracked = False
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   270
        self._mode = None
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   271
        self._size = None
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   272
        self._mtime_s = None
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   273
        self._mtime_ns = None
47890
3853e6ee160d dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47686
diff changeset
   274
48060
a660d8a53267 dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47990
diff changeset
   275
    def drop_merge_data(self):
a660d8a53267 dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47990
diff changeset
   276
        """remove all "merge-only" from a DirstateItem
a660d8a53267 dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47990
diff changeset
   277
a660d8a53267 dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47990
diff changeset
   278
        This is to be call by the dirstatemap code when the second parent is dropped
a660d8a53267 dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47990
diff changeset
   279
        """
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   280
        if self._p2_info:
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   281
            self._p2_info = False
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   282
            self._mode = None
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   283
            self._size = None
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   284
            self._mtime_s = None
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   285
            self._mtime_ns = None
48060
a660d8a53267 dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47990
diff changeset
   286
47512
769037a279ec dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47509
diff changeset
   287
    @property
47536
8e4b9fe31334 dirstate-entry: add a `mode` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47532
diff changeset
   288
    def mode(self):
47926
05f2be3affe3 dirstate-item: have all the logic go through the v1_ accessors
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47925
diff changeset
   289
        return self.v1_mode()
47536
8e4b9fe31334 dirstate-entry: add a `mode` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47532
diff changeset
   290
8e4b9fe31334 dirstate-entry: add a `mode` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47532
diff changeset
   291
    @property
47537
0e5800c88eb4 dirstate-entry: add a `size` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47536
diff changeset
   292
    def size(self):
47926
05f2be3affe3 dirstate-item: have all the logic go through the v1_ accessors
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47925
diff changeset
   293
        return self.v1_size()
47537
0e5800c88eb4 dirstate-entry: add a `size` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47536
diff changeset
   294
0e5800c88eb4 dirstate-entry: add a `size` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47536
diff changeset
   295
    @property
47538
77fce401a2bb dirstate-entry: add a `mtime` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47537
diff changeset
   296
    def mtime(self):
47926
05f2be3affe3 dirstate-item: have all the logic go through the v1_ accessors
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47925
diff changeset
   297
        return self.v1_mtime()
47538
77fce401a2bb dirstate-entry: add a `mtime` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47537
diff changeset
   298
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   299
    def mtime_likely_equal_to(self, other_mtime):
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   300
        self_sec = self._mtime_s
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   301
        if self_sec is None:
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   302
            return False
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   303
        self_ns = self._mtime_ns
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   304
        other_sec, other_ns = other_mtime
48262
68bb472aee9c dirstate: ignore sub-second component when either is zero in mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 48261
diff changeset
   305
        return self_sec == other_sec and (
68bb472aee9c dirstate: ignore sub-second component when either is zero in mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 48261
diff changeset
   306
            self_ns == other_ns or self_ns == 0 or other_ns == 0
68bb472aee9c dirstate: ignore sub-second component when either is zero in mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 48261
diff changeset
   307
        )
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   308
47538
77fce401a2bb dirstate-entry: add a `mtime` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47537
diff changeset
   309
    @property
47512
769037a279ec dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47509
diff changeset
   310
    def state(self):
769037a279ec dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47509
diff changeset
   311
        """
769037a279ec dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47509
diff changeset
   312
        States are:
769037a279ec dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47509
diff changeset
   313
          n  normal
769037a279ec dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47509
diff changeset
   314
          m  needs merging
769037a279ec dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47509
diff changeset
   315
          r  marked for removal
769037a279ec dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47509
diff changeset
   316
          a  marked for addition
769037a279ec dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47509
diff changeset
   317
769037a279ec dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47509
diff changeset
   318
        XXX This "state" is a bit obscure and mostly a direct expression of the
769037a279ec dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47509
diff changeset
   319
        dirstatev1 format. It would make sense to ultimately deprecate it in
769037a279ec dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47509
diff changeset
   320
        favor of the more "semantic" attributes.
769037a279ec dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47509
diff changeset
   321
        """
48111
d73b42f905f8 dirstate-item: use `any_tracked` more
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48110
diff changeset
   322
        if not self.any_tracked:
48088
418611f18fd8 dirstate-entry: use `?` for the state of entry without any tracking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48087
diff changeset
   323
            return b'?'
47926
05f2be3affe3 dirstate-item: have all the logic go through the v1_ accessors
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47925
diff changeset
   324
        return self.v1_state()
47512
769037a279ec dirstate-entry: add a `state` property (and use it)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47509
diff changeset
   325
47513
10e740292dff dirstate-entry: add a `merged` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47512
diff changeset
   326
    @property
48252
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   327
    def has_fallback_exec(self):
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   328
        """True if "fallback" information are available for the "exec" bit
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   329
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   330
        Fallback information can be stored in the dirstate to keep track of
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   331
        filesystem attribute tracked by Mercurial when the underlying file
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   332
        system or operating system does not support that property, (e.g.
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   333
        Windows).
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   334
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   335
        Not all version of the dirstate on-disk storage support preserving this
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   336
        information.
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   337
        """
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   338
        return self._fallback_exec is not None
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   339
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   340
    @property
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   341
    def fallback_exec(self):
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   342
        """ "fallback" information for the executable bit
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   343
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   344
        True if the file should be considered executable when we cannot get
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   345
        this information from the files system. False if it should be
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   346
        considered non-executable.
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   347
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   348
        See has_fallback_exec for details."""
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   349
        return self._fallback_exec
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   350
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   351
    @fallback_exec.setter
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   352
    def set_fallback_exec(self, value):
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   353
        """control "fallback" executable bit
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   354
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   355
        Set to:
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   356
        - True if the file should be considered executable,
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   357
        - False if the file should be considered non-executable,
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   358
        - None if we do not have valid fallback data.
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   359
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   360
        See has_fallback_exec for details."""
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   361
        if value is None:
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   362
            self._fallback_exec = None
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   363
        else:
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   364
            self._fallback_exec = bool(value)
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   365
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   366
    @property
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   367
    def has_fallback_symlink(self):
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   368
        """True if "fallback" information are available for symlink status
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   369
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   370
        Fallback information can be stored in the dirstate to keep track of
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   371
        filesystem attribute tracked by Mercurial when the underlying file
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   372
        system or operating system does not support that property, (e.g.
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   373
        Windows).
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   374
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   375
        Not all version of the dirstate on-disk storage support preserving this
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   376
        information."""
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   377
        return self._fallback_symlink is not None
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   378
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   379
    @property
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   380
    def fallback_symlink(self):
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   381
        """ "fallback" information for symlink status
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   382
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   383
        True if the file should be considered executable when we cannot get
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   384
        this information from the files system. False if it should be
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   385
        considered non-executable.
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   386
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   387
        See has_fallback_exec for details."""
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   388
        return self._fallback_symlink
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   389
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   390
    @fallback_symlink.setter
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   391
    def set_fallback_symlink(self, value):
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   392
        """control "fallback" symlink status
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   393
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   394
        Set to:
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   395
        - True if the file should be considered a symlink,
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   396
        - False if the file should be considered not a symlink,
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   397
        - None if we do not have valid fallback data.
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   398
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   399
        See has_fallback_symlink for details."""
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   400
        if value is None:
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   401
            self._fallback_symlink = None
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   402
        else:
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   403
            self._fallback_symlink = bool(value)
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   404
602c8e8411f5 dirstate: add a concept of "fallback" flags to dirstate item
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48251
diff changeset
   405
    @property
47531
f5b8f0b9c129 dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47526
diff changeset
   406
    def tracked(self):
f5b8f0b9c129 dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47526
diff changeset
   407
        """True is the file is tracked in the working copy"""
47928
f1033c2d9b66 dirstate-item: implement `tracked` in a simpler way
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47927
diff changeset
   408
        return self._wc_tracked
47531
f5b8f0b9c129 dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47526
diff changeset
   409
f5b8f0b9c129 dirstate-entry: add a `tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47526
diff changeset
   410
    @property
48087
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
   411
    def any_tracked(self):
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
   412
        """True is the file is tracked anywhere (wc or parents)"""
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   413
        return self._wc_tracked or self._p1_tracked or self._p2_info
48087
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
   414
79bc60ca5946 dirstate-item: introduce a `any_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48086
diff changeset
   415
    @property
47526
8bcae9bf9e8d dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47517
diff changeset
   416
    def added(self):
8bcae9bf9e8d dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47517
diff changeset
   417
        """True if the file has been added"""
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   418
        return self._wc_tracked and not (self._p1_tracked or self._p2_info)
47526
8bcae9bf9e8d dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47517
diff changeset
   419
8bcae9bf9e8d dirstate-entry: add a `added` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47517
diff changeset
   420
    @property
48086
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
   421
    def maybe_clean(self):
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
   422
        """True if the file has a chance to be in the "clean" state"""
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
   423
        if not self._wc_tracked:
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
   424
            return False
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   425
        elif not self._p1_tracked:
48086
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
   426
            return False
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   427
        elif self._p2_info:
48086
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
   428
            return False
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
   429
        return True
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
   430
80783e553bd5 dirstate-item: introduce a `maybe_clean` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48067
diff changeset
   431
    @property
48143
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
   432
    def p1_tracked(self):
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
   433
        """True if the file is tracked in the first parent manifest"""
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
   434
        return self._p1_tracked
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
   435
21542d4cb568 dirstate-item: introduce a `p1_tracked` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48142
diff changeset
   436
    @property
48142
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   437
    def p2_info(self):
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   438
        """True if the file needed to merge or apply any input from p2
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   439
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   440
        See the class documentation for details.
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   441
        """
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   442
        return self._wc_tracked and self._p2_info
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   443
fb3b41d583c2 dirstate-item: introduce a `p2_info` property that combine two others
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
   444
    @property
47515
c94d3ff46fd5 dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47514
diff changeset
   445
    def removed(self):
c94d3ff46fd5 dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47514
diff changeset
   446
        """True if the file has been removed"""
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   447
        return not self._wc_tracked and (self._p1_tracked or self._p2_info)
47515
c94d3ff46fd5 dirstate-entry: add a `removed` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47514
diff changeset
   448
48222
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   449
    def v2_data(self):
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   450
        """Returns (flags, mode, size, mtime) for v2 serialization"""
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   451
        flags = 0
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   452
        if self._wc_tracked:
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   453
            flags |= DIRSTATE_V2_WDIR_TRACKED
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   454
        if self._p1_tracked:
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   455
            flags |= DIRSTATE_V2_P1_TRACKED
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   456
        if self._p2_info:
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   457
            flags |= DIRSTATE_V2_P2_INFO
48229
db5897321351 dirstate-v2: Use attributes as intended instead of properties in v2_data()
Simon Sapin <simon.sapin@octobus.net>
parents: 48222
diff changeset
   458
        if self._mode is not None and self._size is not None:
48222
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   459
            flags |= DIRSTATE_V2_HAS_MODE_AND_SIZE
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   460
            if self.mode & stat.S_IXUSR:
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   461
                flags |= DIRSTATE_V2_MODE_EXEC_PERM
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   462
            if stat.S_ISLNK(self.mode):
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   463
                flags |= DIRSTATE_V2_MODE_IS_SYMLINK
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   464
        if self._mtime_s is not None:
48264
bb240915f69f dirstate-v2: adjust the meaning of directory flags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48262
diff changeset
   465
            flags |= DIRSTATE_V2_HAS_MTIME
48254
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   466
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   467
        if self._fallback_exec is not None:
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   468
            flags |= DIRSTATE_V2_HAS_FALLBACK_EXEC
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   469
            if self._fallback_exec:
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   470
                flags |= DIRSTATE_V2_FALLBACK_EXEC
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   471
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   472
        if self._fallback_symlink is not None:
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   473
            flags |= DIRSTATE_V2_HAS_FALLBACK_SYMLINK
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   474
            if self._fallback_symlink:
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   475
                flags |= DIRSTATE_V2_FALLBACK_SYMLINK
b874e8d81a98 dirstate-v2: preserve the fallback values on disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48253
diff changeset
   476
48251
dfc5a505ddc5 dirstate-v2: adds two flag to track the presence of some unrecorded files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   477
        # Note: we do not need to do anything regarding
dfc5a505ddc5 dirstate-v2: adds two flag to track the presence of some unrecorded files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   478
        # DIRSTATE_V2_ALL_UNKNOWN_RECORDED and DIRSTATE_V2_ALL_IGNORED_RECORDED
dfc5a505ddc5 dirstate-v2: adds two flag to track the presence of some unrecorded files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48250
diff changeset
   479
        # since we never set _DIRSTATE_V2_HAS_DIRCTORY_MTIME
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   480
        return (flags, self._size or 0, self._mtime_s or 0, self._mtime_ns or 0)
48222
7e78c72ee3ea dirstate-v2: Initial Python serializer
Raphaël Gomès <rgomes@octobus.net>
parents: 48221
diff changeset
   481
47509
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   482
    def v1_state(self):
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   483
        """return a "state" suitable for v1 serialization"""
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   484
        if not self.any_tracked:
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   485
            # the object has no state to record, this is -currently-
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   486
            # unsupported
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   487
            raise RuntimeError('untracked item')
47936
0d185f73c619 dirstate-item: implement v1_state with higher level block
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47935
diff changeset
   488
        elif self.removed:
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   489
            return b'r'
48152
8f88307f8e07 dirstate-item: replace another usage of `merged`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48150
diff changeset
   490
        elif self._p1_tracked and self._p2_info:
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   491
            return b'm'
47936
0d185f73c619 dirstate-item: implement v1_state with higher level block
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47935
diff changeset
   492
        elif self.added:
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   493
            return b'a'
47936
0d185f73c619 dirstate-item: implement v1_state with higher level block
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47935
diff changeset
   494
        else:
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   495
            return b'n'
47509
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   496
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   497
    def v1_mode(self):
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   498
        """return a "mode" suitable for v1 serialization"""
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   499
        return self._mode if self._mode is not None else 0
47509
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   500
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   501
    def v1_size(self):
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   502
        """return a "size" suitable for v1 serialization"""
48111
d73b42f905f8 dirstate-item: use `any_tracked` more
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48110
diff changeset
   503
        if not self.any_tracked:
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   504
            # the object has no state to record, this is -currently-
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   505
            # unsupported
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   506
            raise RuntimeError('untracked item')
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   507
        elif self.removed and self._p1_tracked and self._p2_info:
47937
dbf2d03850a2 dirstate-item: implement `v1_size` with higher level block
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47936
diff changeset
   508
            return NONNORMAL
48149
6ac2b417d5d7 dirstate-item: directly use `p2_info` in `v1_size`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48143
diff changeset
   509
        elif self._p2_info:
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   510
            return FROM_P2
47937
dbf2d03850a2 dirstate-item: implement `v1_size` with higher level block
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47936
diff changeset
   511
        elif self.removed:
dbf2d03850a2 dirstate-item: implement `v1_size` with higher level block
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47936
diff changeset
   512
            return 0
dbf2d03850a2 dirstate-item: implement `v1_size` with higher level block
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47936
diff changeset
   513
        elif self.added:
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   514
            return NONNORMAL
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   515
        elif self._size is None:
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   516
            return NONNORMAL
47937
dbf2d03850a2 dirstate-item: implement `v1_size` with higher level block
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47936
diff changeset
   517
        else:
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   518
            return self._size
47509
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   519
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   520
    def v1_mtime(self):
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   521
        """return a "mtime" suitable for v1 serialization"""
48111
d73b42f905f8 dirstate-item: use `any_tracked` more
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48110
diff changeset
   522
        if not self.any_tracked:
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   523
            # the object has no state to record, this is -currently-
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   524
            # unsupported
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   525
            raise RuntimeError('untracked item')
47938
508394e38580 dirstate-item: implement `v1_mtime` with higher level block
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47937
diff changeset
   526
        elif self.removed:
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   527
            return 0
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   528
        elif self._mtime_s is None:
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   529
            return AMBIGUOUS_TIME
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   530
        elif self._p2_info:
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   531
            return AMBIGUOUS_TIME
48138
38488d488ec1 dirstate-item: change the internal storage and constructor value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48113
diff changeset
   532
        elif not self._p1_tracked:
47938
508394e38580 dirstate-item: implement `v1_mtime` with higher level block
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47937
diff changeset
   533
            return AMBIGUOUS_TIME
47927
b81f52ca8075 dirstate-item: keep the full information in memory (for pure form)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47926
diff changeset
   534
        else:
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   535
            return self._mtime_s
47509
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   536
47532
ccbabaee5c36 dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47531
diff changeset
   537
    def need_delay(self, now):
ccbabaee5c36 dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47531
diff changeset
   538
        """True if the stored mtime would be ambiguous with the current time"""
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48254
diff changeset
   539
        return self.v1_state() == b'n' and self._mtime_s == now[0]
47532
ccbabaee5c36 dirstate-entry: add a `need_delay` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47531
diff changeset
   540
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39217
diff changeset
   541
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   542
def gettype(q):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   543
    return int(q & 0xFFFF)
7945
94d7e14cfa42 pure/parsers: fix circular imports, import mercurial modules properly
Matt Mackall <mpm@selenic.com>
parents: 7873
diff changeset
   544
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39217
diff changeset
   545
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   546
class BaseIndexObject(object):
47268
9d1a8829f959 revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47267
diff changeset
   547
    # Can I be passed to an algorithme implemented in Rust ?
9d1a8829f959 revlog: signal which revlog index are compatible with Rust
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47267
diff changeset
   548
    rust_ext_compat = 0
46635
e83327af26f1 pure-parsers: document index class constants
Raphaël Gomès <rgomes@octobus.net>
parents: 46407
diff changeset
   549
    # Format of an index entry according to Python's `struct` language
46860
1dc86c2a43ce revlog: directly use the Struct object for related operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46858
diff changeset
   550
    index_format = revlog_constants.INDEX_ENTRY_V1
46635
e83327af26f1 pure-parsers: document index class constants
Raphaël Gomès <rgomes@octobus.net>
parents: 46407
diff changeset
   551
    # Size of a C unsigned long long int, platform independent
e83327af26f1 pure-parsers: document index class constants
Raphaël Gomès <rgomes@octobus.net>
parents: 46407
diff changeset
   552
    big_int_size = struct.calcsize(b'>Q')
e83327af26f1 pure-parsers: document index class constants
Raphaël Gomès <rgomes@octobus.net>
parents: 46407
diff changeset
   553
    # Size of a C long int, platform independent
e83327af26f1 pure-parsers: document index class constants
Raphaël Gomès <rgomes@octobus.net>
parents: 46407
diff changeset
   554
    int_size = struct.calcsize(b'>i')
e83327af26f1 pure-parsers: document index class constants
Raphaël Gomès <rgomes@octobus.net>
parents: 46407
diff changeset
   555
    # An empty index entry, used as a default value to be overridden, or nullrev
47249
130c9f7ed914 revlog: add a "data compression mode" entry in the index tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47244
diff changeset
   556
    null_item = (
130c9f7ed914 revlog: add a "data compression mode" entry in the index tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47244
diff changeset
   557
        0,
130c9f7ed914 revlog: add a "data compression mode" entry in the index tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47244
diff changeset
   558
        0,
130c9f7ed914 revlog: add a "data compression mode" entry in the index tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47244
diff changeset
   559
        0,
130c9f7ed914 revlog: add a "data compression mode" entry in the index tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47244
diff changeset
   560
        -1,
130c9f7ed914 revlog: add a "data compression mode" entry in the index tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47244
diff changeset
   561
        -1,
130c9f7ed914 revlog: add a "data compression mode" entry in the index tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47244
diff changeset
   562
        -1,
130c9f7ed914 revlog: add a "data compression mode" entry in the index tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47244
diff changeset
   563
        -1,
130c9f7ed914 revlog: add a "data compression mode" entry in the index tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47244
diff changeset
   564
        sha1nodeconstants.nullid,
130c9f7ed914 revlog: add a "data compression mode" entry in the index tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47244
diff changeset
   565
        0,
130c9f7ed914 revlog: add a "data compression mode" entry in the index tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47244
diff changeset
   566
        0,
130c9f7ed914 revlog: add a "data compression mode" entry in the index tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47244
diff changeset
   567
        revlog_constants.COMP_MODE_INLINE,
47256
2b69555e4875 revlog: introduce a compression mode for sidedata in the revlog index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47251
diff changeset
   568
        revlog_constants.COMP_MODE_INLINE,
47249
130c9f7ed914 revlog: add a "data compression mode" entry in the index tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47244
diff changeset
   569
    )
46407
095fa99ae5f5 revlog: prepare pure parser for being overloaded
Raphaël Gomès <rgomes@octobus.net>
parents: 45942
diff changeset
   570
46974
3c9208702db3 revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46860
diff changeset
   571
    @util.propertycache
3c9208702db3 revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46860
diff changeset
   572
    def entry_size(self):
3c9208702db3 revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46860
diff changeset
   573
        return self.index_format.size
3c9208702db3 revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46860
diff changeset
   574
43574
02802fa87b74 revlog: deprecate direct `nodemap` access
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
   575
    @property
02802fa87b74 revlog: deprecate direct `nodemap` access
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
   576
    def nodemap(self):
43619
c207c46a86b9 py3: pass a bytes value for "msg" to nouideprecwarn()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43574
diff changeset
   577
        msg = b"index.nodemap is deprecated, use index.[has_node|rev|get_rev]"
43574
02802fa87b74 revlog: deprecate direct `nodemap` access
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
   578
        util.nouideprecwarn(msg, b'5.3', stacklevel=2)
02802fa87b74 revlog: deprecate direct `nodemap` access
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
   579
        return self._nodemap
02802fa87b74 revlog: deprecate direct `nodemap` access
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
   580
43525
845e5b313783 revlog: move the nodemap into the index object (for pure)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43106
diff changeset
   581
    @util.propertycache
43574
02802fa87b74 revlog: deprecate direct `nodemap` access
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
   582
    def _nodemap(self):
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46974
diff changeset
   583
        nodemap = nodemaputil.NodeMap({sha1nodeconstants.nullid: nullrev})
43525
845e5b313783 revlog: move the nodemap into the index object (for pure)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43106
diff changeset
   584
        for r in range(0, len(self)):
845e5b313783 revlog: move the nodemap into the index object (for pure)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43106
diff changeset
   585
            n = self[r][7]
845e5b313783 revlog: move the nodemap into the index object (for pure)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43106
diff changeset
   586
            nodemap[n] = r
845e5b313783 revlog: move the nodemap into the index object (for pure)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43106
diff changeset
   587
        return nodemap
845e5b313783 revlog: move the nodemap into the index object (for pure)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43106
diff changeset
   588
43534
0c659fc20207 index: add a `has_node` method (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43533
diff changeset
   589
    def has_node(self, node):
0c659fc20207 index: add a `has_node` method (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43533
diff changeset
   590
        """return True if the node exist in the index"""
43574
02802fa87b74 revlog: deprecate direct `nodemap` access
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
   591
        return node in self._nodemap
43534
0c659fc20207 index: add a `has_node` method (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43533
diff changeset
   592
43552
bd87114ce341 index: add a `rev` method (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43534
diff changeset
   593
    def rev(self, node):
bd87114ce341 index: add a `rev` method (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43534
diff changeset
   594
        """return a revision for a node
bd87114ce341 index: add a `rev` method (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43534
diff changeset
   595
bd87114ce341 index: add a `rev` method (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43534
diff changeset
   596
        If the node is unknown, raise a RevlogError"""
43574
02802fa87b74 revlog: deprecate direct `nodemap` access
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
   597
        return self._nodemap[node]
43552
bd87114ce341 index: add a `rev` method (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43534
diff changeset
   598
43554
b56de57c45ce index: add a `get_rev` method (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43552
diff changeset
   599
    def get_rev(self, node):
b56de57c45ce index: add a `get_rev` method (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43552
diff changeset
   600
        """return a revision for a node
b56de57c45ce index: add a `get_rev` method (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43552
diff changeset
   601
b56de57c45ce index: add a `get_rev` method (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43552
diff changeset
   602
        If the node is unknown, return None"""
43574
02802fa87b74 revlog: deprecate direct `nodemap` access
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
   603
        return self._nodemap.get(node)
43554
b56de57c45ce index: add a `get_rev` method (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43552
diff changeset
   604
43533
642433629e20 revlog: deal with nodemap deletion within the index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43531
diff changeset
   605
    def _stripnodes(self, start):
43574
02802fa87b74 revlog: deprecate direct `nodemap` access
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
   606
        if '_nodemap' in vars(self):
43533
642433629e20 revlog: deal with nodemap deletion within the index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43531
diff changeset
   607
            for r in range(start, len(self)):
642433629e20 revlog: deal with nodemap deletion within the index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43531
diff changeset
   608
                n = self[r][7]
43574
02802fa87b74 revlog: deprecate direct `nodemap` access
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
   609
                del self._nodemap[n]
43533
642433629e20 revlog: deal with nodemap deletion within the index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43531
diff changeset
   610
43525
845e5b313783 revlog: move the nodemap into the index object (for pure)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43106
diff changeset
   611
    def clearcaches(self):
43574
02802fa87b74 revlog: deprecate direct `nodemap` access
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
   612
        self.__dict__.pop('_nodemap', None)
43525
845e5b313783 revlog: move the nodemap into the index object (for pure)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43106
diff changeset
   613
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   614
    def __len__(self):
38851
781b2720d2ac index: don't include nullid in len()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38850
diff changeset
   615
        return self._lgt + len(self._extra)
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   616
38850
6104b203bec8 index: replace insert(-1, e) method by append(e) method
Martin von Zweigbergk <martinvonz@google.com>
parents: 38848
diff changeset
   617
    def append(self, tup):
43574
02802fa87b74 revlog: deprecate direct `nodemap` access
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
   618
        if '_nodemap' in vars(self):
02802fa87b74 revlog: deprecate direct `nodemap` access
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43554
diff changeset
   619
            self._nodemap[tup[7]] = len(self)
47267
55d280bc59fa revlog: pass around the `rev` we deal with when packing/unpacking entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47262
diff changeset
   620
        data = self._pack_entry(len(self), tup)
45936
0ce15a8c7b8b revlog: store new index entries as binary
Joerg Sonnenberger <joerg@bec.de>
parents: 45645
diff changeset
   621
        self._extra.append(data)
7945
94d7e14cfa42 pure/parsers: fix circular imports, import mercurial modules properly
Matt Mackall <mpm@selenic.com>
parents: 7873
diff changeset
   622
47267
55d280bc59fa revlog: pass around the `rev` we deal with when packing/unpacking entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47262
diff changeset
   623
    def _pack_entry(self, rev, entry):
47143
47ffc754989a revlog: always "append" full size tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47142
diff changeset
   624
        assert entry[8] == 0
47ffc754989a revlog: always "append" full size tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47142
diff changeset
   625
        assert entry[9] == 0
47ffc754989a revlog: always "append" full size tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47142
diff changeset
   626
        return self.index_format.pack(*entry[:8])
47ffc754989a revlog: always "append" full size tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47142
diff changeset
   627
39217
5961517fd2a8 index: rename _fix_index() since it no longer fixes the index
Martin von Zweigbergk <martinvonz@google.com>
parents: 39216
diff changeset
   628
    def _check_index(self, i):
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   629
        if not isinstance(i, int):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   630
            raise TypeError(b"expecting int indexes")
39216
ec6d5a9d1631 index: don't include nullid in boundary check in pure code
Martin von Zweigbergk <martinvonz@google.com>
parents: 39047
diff changeset
   631
        if i < 0 or i >= len(self):
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   632
            raise IndexError
7945
94d7e14cfa42 pure/parsers: fix circular imports, import mercurial modules properly
Matt Mackall <mpm@selenic.com>
parents: 7873
diff changeset
   633
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   634
    def __getitem__(self, i):
39047
a1f934573c0b parsers: adjust pure-python version to mimic a3dacabd476b
Augie Fackler <augie@google.com>
parents: 38851
diff changeset
   635
        if i == -1:
46407
095fa99ae5f5 revlog: prepare pure parser for being overloaded
Raphaël Gomès <rgomes@octobus.net>
parents: 45942
diff changeset
   636
            return self.null_item
39217
5961517fd2a8 index: rename _fix_index() since it no longer fixes the index
Martin von Zweigbergk <martinvonz@google.com>
parents: 39216
diff changeset
   637
        self._check_index(i)
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   638
        if i >= self._lgt:
45936
0ce15a8c7b8b revlog: store new index entries as binary
Joerg Sonnenberger <joerg@bec.de>
parents: 45645
diff changeset
   639
            data = self._extra[i - self._lgt]
0ce15a8c7b8b revlog: store new index entries as binary
Joerg Sonnenberger <joerg@bec.de>
parents: 45645
diff changeset
   640
        else:
0ce15a8c7b8b revlog: store new index entries as binary
Joerg Sonnenberger <joerg@bec.de>
parents: 45645
diff changeset
   641
            index = self._calculate_index(i)
46974
3c9208702db3 revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46860
diff changeset
   642
            data = self._data[index : index + self.entry_size]
47267
55d280bc59fa revlog: pass around the `rev` we deal with when packing/unpacking entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47262
diff changeset
   643
        r = self._unpack_entry(i, data)
45936
0ce15a8c7b8b revlog: store new index entries as binary
Joerg Sonnenberger <joerg@bec.de>
parents: 45645
diff changeset
   644
        if self._lgt and i == 0:
47394
ac60a1366a49 revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47270
diff changeset
   645
            offset = revlogutils.offset_type(0, gettype(r[0]))
ac60a1366a49 revlog: move `offset_type` to `revlogutils`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47270
diff changeset
   646
            r = (offset,) + r[1:]
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   647
        return r
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   648
47267
55d280bc59fa revlog: pass around the `rev` we deal with when packing/unpacking entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47262
diff changeset
   649
    def _unpack_entry(self, rev, data):
47142
4292bed8da7c revlog: make the index always return the same tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47078
diff changeset
   650
        r = self.index_format.unpack(data)
47256
2b69555e4875 revlog: introduce a compression mode for sidedata in the revlog index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47251
diff changeset
   651
        r = r + (
2b69555e4875 revlog: introduce a compression mode for sidedata in the revlog index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47251
diff changeset
   652
            0,
2b69555e4875 revlog: introduce a compression mode for sidedata in the revlog index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47251
diff changeset
   653
            0,
2b69555e4875 revlog: introduce a compression mode for sidedata in the revlog index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47251
diff changeset
   654
            revlog_constants.COMP_MODE_INLINE,
2b69555e4875 revlog: introduce a compression mode for sidedata in the revlog index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47251
diff changeset
   655
            revlog_constants.COMP_MODE_INLINE,
2b69555e4875 revlog: introduce a compression mode for sidedata in the revlog index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47251
diff changeset
   656
        )
47142
4292bed8da7c revlog: make the index always return the same tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47078
diff changeset
   657
        return r
4292bed8da7c revlog: make the index always return the same tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47078
diff changeset
   658
47037
d57386e5c80e revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47034
diff changeset
   659
    def pack_header(self, header):
d57386e5c80e revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47034
diff changeset
   660
        """pack header information as binary"""
d57386e5c80e revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47034
diff changeset
   661
        v_fmt = revlog_constants.INDEX_HEADER
d57386e5c80e revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47034
diff changeset
   662
        return v_fmt.pack(header)
d57386e5c80e revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47034
diff changeset
   663
d57386e5c80e revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47034
diff changeset
   664
    def entry_binary(self, rev):
47034
0d8ff1f4ab0c revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   665
        """return the raw binary string representing a revision"""
0d8ff1f4ab0c revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   666
        entry = self[rev]
47142
4292bed8da7c revlog: make the index always return the same tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47078
diff changeset
   667
        p = revlog_constants.INDEX_ENTRY_V1.pack(*entry[:8])
47034
0d8ff1f4ab0c revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   668
        if rev == 0:
47037
d57386e5c80e revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47034
diff changeset
   669
            p = p[revlog_constants.INDEX_HEADER.size :]
47034
0d8ff1f4ab0c revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   670
        return p
0d8ff1f4ab0c revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   671
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39217
diff changeset
   672
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   673
class IndexObject(BaseIndexObject):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   674
    def __init__(self, data):
47034
0d8ff1f4ab0c revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   675
        assert len(data) % self.entry_size == 0, (
0d8ff1f4ab0c revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   676
            len(data),
0d8ff1f4ab0c revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   677
            self.entry_size,
0d8ff1f4ab0c revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   678
            len(data) % self.entry_size,
0d8ff1f4ab0c revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   679
        )
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   680
        self._data = data
46974
3c9208702db3 revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46860
diff changeset
   681
        self._lgt = len(data) // self.entry_size
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   682
        self._extra = []
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   683
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   684
    def _calculate_index(self, i):
46974
3c9208702db3 revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46860
diff changeset
   685
        return i * self.entry_size
13253
61c9bc3da402 revlog: remove lazy index
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
   686
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   687
    def __delitem__(self, i):
34331
531332502568 style: always use `x is not None` instead of `not x is None`
Alex Gaynor <agaynor@mozilla.com>
parents: 32372
diff changeset
   688
        if not isinstance(i, slice) or not i.stop == -1 or i.step is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   689
            raise ValueError(b"deleting slices only supports a:-1 with step 1")
39217
5961517fd2a8 index: rename _fix_index() since it no longer fixes the index
Martin von Zweigbergk <martinvonz@google.com>
parents: 39216
diff changeset
   690
        i = i.start
5961517fd2a8 index: rename _fix_index() since it no longer fixes the index
Martin von Zweigbergk <martinvonz@google.com>
parents: 39216
diff changeset
   691
        self._check_index(i)
43533
642433629e20 revlog: deal with nodemap deletion within the index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43531
diff changeset
   692
        self._stripnodes(i)
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   693
        if i < self._lgt:
46974
3c9208702db3 revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46860
diff changeset
   694
            self._data = self._data[: i * self.entry_size]
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   695
            self._lgt = i
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   696
            self._extra = []
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   697
        else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39217
diff changeset
   698
            self._extra = self._extra[: i - self._lgt]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39217
diff changeset
   699
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   700
44313
6f9e8e142cea nodemap: add a (python) index class for persistent nodemap testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
   701
class PersistentNodeMapIndexObject(IndexObject):
6f9e8e142cea nodemap: add a (python) index class for persistent nodemap testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
   702
    """a Debug oriented class to test persistent nodemap
6f9e8e142cea nodemap: add a (python) index class for persistent nodemap testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
   703
6f9e8e142cea nodemap: add a (python) index class for persistent nodemap testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
   704
    We need a simple python object to test API and higher level behavior. See
6f9e8e142cea nodemap: add a (python) index class for persistent nodemap testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
   705
    the Rust implementation for  more serious usage. This should be used only
6f9e8e142cea nodemap: add a (python) index class for persistent nodemap testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
   706
    through the dedicated `devel.persistent-nodemap` config.
6f9e8e142cea nodemap: add a (python) index class for persistent nodemap testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
   707
    """
6f9e8e142cea nodemap: add a (python) index class for persistent nodemap testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
   708
44314
7f4f7ef3133e nodemap: add a optional `nodemap_add_full` method on indexes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44313
diff changeset
   709
    def nodemap_data_all(self):
7f4f7ef3133e nodemap: add a optional `nodemap_add_full` method on indexes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44313
diff changeset
   710
        """Return bytes containing a full serialization of a nodemap
7f4f7ef3133e nodemap: add a optional `nodemap_add_full` method on indexes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44313
diff changeset
   711
7f4f7ef3133e nodemap: add a optional `nodemap_add_full` method on indexes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44313
diff changeset
   712
        The nodemap should be valid for the full set of revisions in the
7f4f7ef3133e nodemap: add a optional `nodemap_add_full` method on indexes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44313
diff changeset
   713
        index."""
7f4f7ef3133e nodemap: add a optional `nodemap_add_full` method on indexes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44313
diff changeset
   714
        return nodemaputil.persistent_data(self)
7f4f7ef3133e nodemap: add a optional `nodemap_add_full` method on indexes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44313
diff changeset
   715
44333
50ad851efd9b nodemap: introduce append-only incremental update of the persistent data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44320
diff changeset
   716
    def nodemap_data_incremental(self):
50ad851efd9b nodemap: introduce append-only incremental update of the persistent data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44320
diff changeset
   717
        """Return bytes containing a incremental update to persistent nodemap
50ad851efd9b nodemap: introduce append-only incremental update of the persistent data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44320
diff changeset
   718
50ad851efd9b nodemap: introduce append-only incremental update of the persistent data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44320
diff changeset
   719
        This containst the data for an append-only update of the data provided
50ad851efd9b nodemap: introduce append-only incremental update of the persistent data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44320
diff changeset
   720
        in the last call to `update_nodemap_data`.
50ad851efd9b nodemap: introduce append-only incremental update of the persistent data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44320
diff changeset
   721
        """
50ad851efd9b nodemap: introduce append-only incremental update of the persistent data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44320
diff changeset
   722
        if self._nm_root is None:
50ad851efd9b nodemap: introduce append-only incremental update of the persistent data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44320
diff changeset
   723
            return None
44337
1d2b37def017 nodemap: double check the source docket when doing incremental update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44336
diff changeset
   724
        docket = self._nm_docket
44336
8374b69aef75 nodemap: track the total and unused amount of data in the rawdata file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44335
diff changeset
   725
        changed, data = nodemaputil.update_persistent_data(
44337
1d2b37def017 nodemap: double check the source docket when doing incremental update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44336
diff changeset
   726
            self, self._nm_root, self._nm_max_idx, self._nm_docket.tip_rev
44333
50ad851efd9b nodemap: introduce append-only incremental update of the persistent data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44320
diff changeset
   727
        )
44337
1d2b37def017 nodemap: double check the source docket when doing incremental update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44336
diff changeset
   728
1d2b37def017 nodemap: double check the source docket when doing incremental update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44336
diff changeset
   729
        self._nm_root = self._nm_max_idx = self._nm_docket = None
1d2b37def017 nodemap: double check the source docket when doing incremental update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44336
diff changeset
   730
        return docket, changed, data
44333
50ad851efd9b nodemap: introduce append-only incremental update of the persistent data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44320
diff changeset
   731
44335
e41a164db7a9 nodemap: track the maximum revision tracked in the nodemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44333
diff changeset
   732
    def update_nodemap_data(self, docket, nm_data):
e41a164db7a9 nodemap: track the maximum revision tracked in the nodemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44333
diff changeset
   733
        """provide full block of persisted binary data for a nodemap
44320
671f9479af0e nodemap: provide the on disk data to indexes who support it
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44314
diff changeset
   734
671f9479af0e nodemap: provide the on disk data to indexes who support it
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44314
diff changeset
   735
        The data are expected to come from disk. See `nodemap_data_all` for a
671f9479af0e nodemap: provide the on disk data to indexes who support it
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44314
diff changeset
   736
        produceur of such data."""
671f9479af0e nodemap: provide the on disk data to indexes who support it
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44314
diff changeset
   737
        if nm_data is not None:
44333
50ad851efd9b nodemap: introduce append-only incremental update of the persistent data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44320
diff changeset
   738
            self._nm_root, self._nm_max_idx = nodemaputil.parse_data(nm_data)
50ad851efd9b nodemap: introduce append-only incremental update of the persistent data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44320
diff changeset
   739
            if self._nm_root:
44337
1d2b37def017 nodemap: double check the source docket when doing incremental update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44336
diff changeset
   740
                self._nm_docket = docket
44333
50ad851efd9b nodemap: introduce append-only incremental update of the persistent data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44320
diff changeset
   741
            else:
44337
1d2b37def017 nodemap: double check the source docket when doing incremental update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44336
diff changeset
   742
                self._nm_root = self._nm_max_idx = self._nm_docket = None
44320
671f9479af0e nodemap: provide the on disk data to indexes who support it
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44314
diff changeset
   743
44313
6f9e8e142cea nodemap: add a (python) index class for persistent nodemap testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
   744
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   745
class InlinedIndexObject(BaseIndexObject):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   746
    def __init__(self, data, inline=0):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   747
        self._data = data
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   748
        self._lgt = self._inline_scan(None)
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   749
        self._inline_scan(self._lgt)
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   750
        self._extra = []
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   751
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   752
    def _inline_scan(self, lgt):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   753
        off = 0
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   754
        if lgt is not None:
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   755
            self._offsets = [0] * lgt
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   756
        count = 0
46974
3c9208702db3 revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46860
diff changeset
   757
        while off <= len(self._data) - self.entry_size:
46407
095fa99ae5f5 revlog: prepare pure parser for being overloaded
Raphaël Gomès <rgomes@octobus.net>
parents: 45942
diff changeset
   758
            start = off + self.big_int_size
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39217
diff changeset
   759
            (s,) = struct.unpack(
46407
095fa99ae5f5 revlog: prepare pure parser for being overloaded
Raphaël Gomès <rgomes@octobus.net>
parents: 45942
diff changeset
   760
                b'>i',
095fa99ae5f5 revlog: prepare pure parser for being overloaded
Raphaël Gomès <rgomes@octobus.net>
parents: 45942
diff changeset
   761
                self._data[start : start + self.int_size],
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39217
diff changeset
   762
            )
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   763
            if lgt is not None:
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   764
                self._offsets[count] = off
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   765
            count += 1
46974
3c9208702db3 revlog: replace revlog._io.size with a new revlog.index.entry_size
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46860
diff changeset
   766
            off += self.entry_size + s
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   767
        if off != len(self._data):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   768
            raise ValueError(b"corrupted data")
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   769
        return count
14421
639f26cab2f5 pure parsers: properly detect corrupt index files
Augie Fackler <durin42@gmail.com>
parents: 14064
diff changeset
   770
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   771
    def __delitem__(self, i):
34331
531332502568 style: always use `x is not None` instead of `not x is None`
Alex Gaynor <agaynor@mozilla.com>
parents: 32372
diff changeset
   772
        if not isinstance(i, slice) or not i.stop == -1 or i.step is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   773
            raise ValueError(b"deleting slices only supports a:-1 with step 1")
39217
5961517fd2a8 index: rename _fix_index() since it no longer fixes the index
Martin von Zweigbergk <martinvonz@google.com>
parents: 39216
diff changeset
   774
        i = i.start
5961517fd2a8 index: rename _fix_index() since it no longer fixes the index
Martin von Zweigbergk <martinvonz@google.com>
parents: 39216
diff changeset
   775
        self._check_index(i)
43533
642433629e20 revlog: deal with nodemap deletion within the index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43531
diff changeset
   776
        self._stripnodes(i)
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   777
        if i < self._lgt:
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   778
            self._offsets = self._offsets[:i]
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   779
            self._lgt = i
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   780
            self._extra = []
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   781
        else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39217
diff changeset
   782
            self._extra = self._extra[: i - self._lgt]
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   783
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   784
    def _calculate_index(self, i):
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   785
        return self._offsets[i]
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   786
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39217
diff changeset
   787
46704
913485776542 revlog: introduce v2 format
Raphaël Gomès <rgomes@octobus.net>
parents: 46635
diff changeset
   788
def parse_index2(data, inline, revlogv2=False):
29133
255274719dc1 pure: write a really lazy version of pure indexObject
Maciej Fijalkowski <fijall@gmail.com>
parents: 28861
diff changeset
   789
    if not inline:
46704
913485776542 revlog: introduce v2 format
Raphaël Gomès <rgomes@octobus.net>
parents: 46635
diff changeset
   790
        cls = IndexObject2 if revlogv2 else IndexObject
913485776542 revlog: introduce v2 format
Raphaël Gomès <rgomes@octobus.net>
parents: 46635
diff changeset
   791
        return cls(data), None
47262
468e451fc0de revlogv2: drop the code related to inlined revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47259
diff changeset
   792
    cls = InlinedIndexObject
46704
913485776542 revlog: introduce v2 format
Raphaël Gomès <rgomes@octobus.net>
parents: 46635
diff changeset
   793
    return cls(data, inline), (0, data)
913485776542 revlog: introduce v2 format
Raphaël Gomès <rgomes@octobus.net>
parents: 46635
diff changeset
   794
913485776542 revlog: introduce v2 format
Raphaël Gomès <rgomes@octobus.net>
parents: 46635
diff changeset
   795
47270
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   796
def parse_index_cl_v2(data):
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   797
    return IndexChangelogV2(data), None
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   798
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   799
47262
468e451fc0de revlogv2: drop the code related to inlined revlogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47259
diff changeset
   800
class IndexObject2(IndexObject):
46860
1dc86c2a43ce revlog: directly use the Struct object for related operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 46858
diff changeset
   801
    index_format = revlog_constants.INDEX_ENTRY_V2
46704
913485776542 revlog: introduce v2 format
Raphaël Gomès <rgomes@octobus.net>
parents: 46635
diff changeset
   802
47078
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Raphaël Gomès <rgomes@octobus.net>
parents: 47037
diff changeset
   803
    def replace_sidedata_info(
47259
07641bafa646 revlog: compress sidedata when doing "post-pull" sidedata update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47256
diff changeset
   804
        self,
07641bafa646 revlog: compress sidedata when doing "post-pull" sidedata update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47256
diff changeset
   805
        rev,
07641bafa646 revlog: compress sidedata when doing "post-pull" sidedata update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47256
diff changeset
   806
        sidedata_offset,
07641bafa646 revlog: compress sidedata when doing "post-pull" sidedata update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47256
diff changeset
   807
        sidedata_length,
07641bafa646 revlog: compress sidedata when doing "post-pull" sidedata update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47256
diff changeset
   808
        offset_flags,
07641bafa646 revlog: compress sidedata when doing "post-pull" sidedata update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47256
diff changeset
   809
        compression_mode,
47078
223b47235d1c sidedata: enable sidedata computers to optionally rewrite flags
Raphaël Gomès <rgomes@octobus.net>
parents: 47037
diff changeset
   810
    ):
46717
502e795b55ac revlog-index: add `replace_sidedata_info` method
Raphaël Gomès <rgomes@octobus.net>
parents: 46704
diff changeset
   811
        """
502e795b55ac revlog-index: add `replace_sidedata_info` method
Raphaël Gomès <rgomes@octobus.net>
parents: 46704
diff changeset
   812
        Replace an existing index entry's sidedata offset and length with new
502e795b55ac revlog-index: add `replace_sidedata_info` method
Raphaël Gomès <rgomes@octobus.net>
parents: 46704
diff changeset
   813
        ones.
502e795b55ac revlog-index: add `replace_sidedata_info` method
Raphaël Gomès <rgomes@octobus.net>
parents: 46704
diff changeset
   814
        This cannot be used outside of the context of sidedata rewriting,
47243
3b04cf976c67 revlog: use `rev` instead of `i` in replace_sidedata_info
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47235
diff changeset
   815
        inside the transaction that creates the revision `rev`.
46717
502e795b55ac revlog-index: add `replace_sidedata_info` method
Raphaël Gomès <rgomes@octobus.net>
parents: 46704
diff changeset
   816
        """
47243
3b04cf976c67 revlog: use `rev` instead of `i` in replace_sidedata_info
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47235
diff changeset
   817
        if rev < 0:
46717
502e795b55ac revlog-index: add `replace_sidedata_info` method
Raphaël Gomès <rgomes@octobus.net>
parents: 46704
diff changeset
   818
            raise KeyError
47243
3b04cf976c67 revlog: use `rev` instead of `i` in replace_sidedata_info
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47235
diff changeset
   819
        self._check_index(rev)
47244
78230d036e5d revlog: simplify the replace_sidedata_info code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47243
diff changeset
   820
        if rev < self._lgt:
46717
502e795b55ac revlog-index: add `replace_sidedata_info` method
Raphaël Gomès <rgomes@octobus.net>
parents: 46704
diff changeset
   821
            msg = b"cannot rewrite entries outside of this transaction"
502e795b55ac revlog-index: add `replace_sidedata_info` method
Raphaël Gomès <rgomes@octobus.net>
parents: 46704
diff changeset
   822
            raise KeyError(msg)
47244
78230d036e5d revlog: simplify the replace_sidedata_info code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47243
diff changeset
   823
        else:
78230d036e5d revlog: simplify the replace_sidedata_info code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47243
diff changeset
   824
            entry = list(self[rev])
78230d036e5d revlog: simplify the replace_sidedata_info code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47243
diff changeset
   825
            entry[0] = offset_flags
78230d036e5d revlog: simplify the replace_sidedata_info code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47243
diff changeset
   826
            entry[8] = sidedata_offset
78230d036e5d revlog: simplify the replace_sidedata_info code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47243
diff changeset
   827
            entry[9] = sidedata_length
47259
07641bafa646 revlog: compress sidedata when doing "post-pull" sidedata update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47256
diff changeset
   828
            entry[11] = compression_mode
47244
78230d036e5d revlog: simplify the replace_sidedata_info code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47243
diff changeset
   829
            entry = tuple(entry)
47267
55d280bc59fa revlog: pass around the `rev` we deal with when packing/unpacking entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47262
diff changeset
   830
            new = self._pack_entry(rev, entry)
47244
78230d036e5d revlog: simplify the replace_sidedata_info code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47243
diff changeset
   831
            self._extra[rev - self._lgt] = new
46717
502e795b55ac revlog-index: add `replace_sidedata_info` method
Raphaël Gomès <rgomes@octobus.net>
parents: 46704
diff changeset
   832
47267
55d280bc59fa revlog: pass around the `rev` we deal with when packing/unpacking entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47262
diff changeset
   833
    def _unpack_entry(self, rev, data):
47256
2b69555e4875 revlog: introduce a compression mode for sidedata in the revlog index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47251
diff changeset
   834
        data = self.index_format.unpack(data)
2b69555e4875 revlog: introduce a compression mode for sidedata in the revlog index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47251
diff changeset
   835
        entry = data[:10]
2b69555e4875 revlog: introduce a compression mode for sidedata in the revlog index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47251
diff changeset
   836
        data_comp = data[10] & 3
2b69555e4875 revlog: introduce a compression mode for sidedata in the revlog index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47251
diff changeset
   837
        sidedata_comp = (data[10] & (3 << 2)) >> 2
2b69555e4875 revlog: introduce a compression mode for sidedata in the revlog index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47251
diff changeset
   838
        return entry + (data_comp, sidedata_comp)
47142
4292bed8da7c revlog: make the index always return the same tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47078
diff changeset
   839
47267
55d280bc59fa revlog: pass around the `rev` we deal with when packing/unpacking entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47262
diff changeset
   840
    def _pack_entry(self, rev, entry):
47256
2b69555e4875 revlog: introduce a compression mode for sidedata in the revlog index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47251
diff changeset
   841
        data = entry[:10]
2b69555e4875 revlog: introduce a compression mode for sidedata in the revlog index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47251
diff changeset
   842
        data_comp = entry[10] & 3
2b69555e4875 revlog: introduce a compression mode for sidedata in the revlog index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47251
diff changeset
   843
        sidedata_comp = (entry[11] & 3) << 2
2b69555e4875 revlog: introduce a compression mode for sidedata in the revlog index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47251
diff changeset
   844
        data += (data_comp | sidedata_comp,)
2b69555e4875 revlog: introduce a compression mode for sidedata in the revlog index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47251
diff changeset
   845
2b69555e4875 revlog: introduce a compression mode for sidedata in the revlog index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47251
diff changeset
   846
        return self.index_format.pack(*data)
47143
47ffc754989a revlog: always "append" full size tuple
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47142
diff changeset
   847
47037
d57386e5c80e revlog: have an explicit "pack_header" method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47034
diff changeset
   848
    def entry_binary(self, rev):
47034
0d8ff1f4ab0c revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   849
        """return the raw binary string representing a revision"""
0d8ff1f4ab0c revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   850
        entry = self[rev]
47267
55d280bc59fa revlog: pass around the `rev` we deal with when packing/unpacking entry
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47262
diff changeset
   851
        return self._pack_entry(rev, entry)
47034
0d8ff1f4ab0c revlog: add a `entry_binary` method on index
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47012
diff changeset
   852
47235
6b1eae313b2f revlogv2: store version information in the docket only
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47143
diff changeset
   853
    def pack_header(self, header):
6b1eae313b2f revlogv2: store version information in the docket only
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47143
diff changeset
   854
        """pack header information as binary"""
6b1eae313b2f revlogv2: store version information in the docket only
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47143
diff changeset
   855
        msg = 'version header should go in the docket, not the index: %d'
6b1eae313b2f revlogv2: store version information in the docket only
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47143
diff changeset
   856
        msg %= header
6b1eae313b2f revlogv2: store version information in the docket only
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47143
diff changeset
   857
        raise error.ProgrammingError(msg)
6b1eae313b2f revlogv2: store version information in the docket only
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47143
diff changeset
   858
46704
913485776542 revlog: introduce v2 format
Raphaël Gomès <rgomes@octobus.net>
parents: 46635
diff changeset
   859
47270
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   860
class IndexChangelogV2(IndexObject2):
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   861
    index_format = revlog_constants.INDEX_ENTRY_CL_V2
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   862
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   863
    def _unpack_entry(self, rev, data, r=True):
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   864
        items = self.index_format.unpack(data)
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   865
        entry = items[:3] + (rev, rev) + items[3:8]
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   866
        data_comp = items[8] & 3
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   867
        sidedata_comp = (items[8] >> 2) & 3
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   868
        return entry + (data_comp, sidedata_comp)
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   869
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   870
    def _pack_entry(self, rev, entry):
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   871
        assert entry[3] == rev, entry[3]
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   872
        assert entry[4] == rev, entry[4]
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   873
        data = entry[:3] + entry[5:10]
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   874
        data_comp = entry[10] & 3
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   875
        sidedata_comp = (entry[11] & 3) << 2
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   876
        data += (data_comp | sidedata_comp,)
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   877
        return self.index_format.pack(*data)
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   878
25ce16bf724b changelogv2: use a dedicated on disk format for changelogv2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47268
diff changeset
   879
44313
6f9e8e142cea nodemap: add a (python) index class for persistent nodemap testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
   880
def parse_index_devel_nodemap(data, inline):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45936
diff changeset
   881
    """like parse_index2, but alway return a PersistentNodeMapIndexObject"""
44313
6f9e8e142cea nodemap: add a (python) index class for persistent nodemap testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
   882
    return PersistentNodeMapIndexObject(data), None
6f9e8e142cea nodemap: add a (python) index class for persistent nodemap testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
   883
6f9e8e142cea nodemap: add a (python) index class for persistent nodemap testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44034
diff changeset
   884
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   885
def parse_dirstate(dmap, copymap, st):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39217
diff changeset
   886
    parents = [st[:20], st[20:40]]
17425
e95ec38f86b0 fix wording and not-completely-trivial spelling errors and bad docstrings
Mads Kiilerich <mads@kiilerich.com>
parents: 14995
diff changeset
   887
    # dereference fields so they will be local in loop
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   888
    format = b">cllll"
7945
94d7e14cfa42 pure/parsers: fix circular imports, import mercurial modules properly
Matt Mackall <mpm@selenic.com>
parents: 7873
diff changeset
   889
    e_size = struct.calcsize(format)
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   890
    pos1 = 40
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   891
    l = len(st)
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   892
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   893
    # the inner loop
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   894
    while pos1 < l:
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   895
        pos2 = pos1 + e_size
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   896
        e = _unpack(b">cllll", st[pos1:pos2])  # a literal here is faster
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   897
        pos1 = pos2 + e[4]
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   898
        f = st[pos2:pos1]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   899
        if b'\0' in f:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   900
            f, c = f.split(b'\0')
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   901
            copymap[f] = c
47665
a4443f66be6a dirstate-item: add a `from_v1_data` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47664
diff changeset
   902
        dmap[f] = DirstateItem.from_v1_data(*e[:4])
7700
f410c552fa15 pure Python implementation of parsers.c
Martin Geisler <mg@daimi.au.dk>
parents:
diff changeset
   903
    return parents
18567
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   904
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39217
diff changeset
   905
18567
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   906
def pack_dirstate(dmap, copymap, pl, now):
28861
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 27339
diff changeset
   907
    cs = stringio()
18567
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   908
    write = cs.write
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   909
    write(b"".join(pl))
43106
d783f945a701 py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43077
diff changeset
   910
    for f, e in pycompat.iteritems(dmap):
47540
1a6302427eb9 dirstate-item: use need_delay when packing dirstate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
   911
        if e.need_delay(now):
18567
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   912
            # The file was last modified "simultaneously" with the current
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   913
            # write to dirstate (i.e. within the same second for file-
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   914
            # systems with a granularity of 1 sec). This commonly happens
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   915
            # for at least a couple of files on 'update'.
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   916
            # The user could change the file without changing its size
19652
187bf2dde7c1 pack_dirstate: only invalidate mtime for files written in the last second
Siddharth Agarwal <sid0@fb.com>
parents: 18567
diff changeset
   917
            # within the same second. Invalidate the file's mtime in
18567
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   918
            # dirstate, forcing future 'status' calls to compare the
19652
187bf2dde7c1 pack_dirstate: only invalidate mtime for files written in the last second
Siddharth Agarwal <sid0@fb.com>
parents: 18567
diff changeset
   919
            # contents of the file if the size is the same. This prevents
187bf2dde7c1 pack_dirstate: only invalidate mtime for files written in the last second
Siddharth Agarwal <sid0@fb.com>
parents: 18567
diff changeset
   920
            # mistakenly treating such files as clean.
47667
d06ced90c80f dirstate-item: use `set_possibly_dirty` in `pure.pack_dirstate`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47666
diff changeset
   921
            e.set_possibly_dirty()
18567
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   922
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   923
        if f in copymap:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   924
            f = b"%s\0%s" % (f, copymap[f])
47509
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   925
        e = _pack(
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   926
            b">cllll",
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   927
            e.v1_state(),
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   928
            e.v1_mode(),
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   929
            e.v1_size(),
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   930
            e.v1_mtime(),
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   931
            len(f),
80dc1d452993 dirstate-entry: introduce dedicated accessors for v1 serialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47508
diff changeset
   932
        )
18567
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   933
        write(e)
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   934
        write(f)
194e63c1ccb9 dirstate: move pure python dirstate packing to pure/parsers.py
Siddharth Agarwal <sid0@fb.com>
parents: 17425
diff changeset
   935
    return cs.getvalue()