mercurial/dirstatemap.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Tue, 28 Sep 2021 20:05:37 +0200
changeset 48061 060cd909439f
parent 48060 a660d8a53267
child 48068 bf8837e3d7ce
permissions -rw-r--r--
dirstate: drop all logic around the "non-normal" sets The dirstate has a lot of code to compute a set of all "non-normal" and "from_other_parent" entries. This is all used in one, unique, location, when `setparent` is called and moved from a merge to a non merge. At that time, any "merge related" information has to be dropped. This is mostly useful for command like `graft` or `shelve` that move to a single-parent state -before- the commit. Otherwise the commit will already have removed all traces of the merge information in the dirstate (e.g. for a regular merges). The bookkeeping for these sets is quite invasive. And it seems simpler to just drop it and do the full computation in the single location where we actually use it (since we have to do the computation at least once anyway). This simplify the code a lot, and clarify why this kind of computation is needed. The possible drawback compared to the previous code are: - if the operation happens in a loop, we will end up doing it multiple time, - the C code to detect entry of interest have been dropped, for now. It will be re-introduced later, with a processing code directly in C for even faster operation. Differential Revision: https://phab.mercurial-scm.org/D11507
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47501
8b7e47802deb dirstate: split dirstatemap in its own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47489
diff changeset
     1
# dirstatemap.py
8226
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
     2
#
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
     3
# 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: 9678
diff changeset
     4
# GNU General Public License version 2 or any later version.
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     5
27503
0f4596622273 dirstate: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27399
diff changeset
     6
from __future__ import absolute_import
0f4596622273 dirstate: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27399
diff changeset
     7
0f4596622273 dirstate: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27399
diff changeset
     8
import errno
0f4596622273 dirstate: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27399
diff changeset
     9
0f4596622273 dirstate: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27399
diff changeset
    10
from .i18n import _
43239
6fcdcea2b03a dirstate: add some traces on listdir calls
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
    11
27503
0f4596622273 dirstate: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27399
diff changeset
    12
from . import (
0f4596622273 dirstate: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27399
diff changeset
    13
    error,
0f4596622273 dirstate: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27399
diff changeset
    14
    pathutil,
32372
df448de7cf3b parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents: 32352
diff changeset
    15
    policy,
30304
ba2c04059317 py3: use pycompat.ossep at certain places
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30224
diff changeset
    16
    pycompat,
31050
206532700213 txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30634
diff changeset
    17
    txnutil,
27503
0f4596622273 dirstate: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27399
diff changeset
    18
    util,
0f4596622273 dirstate: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27399
diff changeset
    19
)
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    20
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
    21
from .dirstateutils import (
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
    22
    docket as docketmod,
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
    23
)
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
    24
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43505
diff changeset
    25
parsers = policy.importmod('parsers')
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43505
diff changeset
    26
rustmod = policy.importrust('dirstate')
32372
df448de7cf3b parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents: 32352
diff changeset
    27
8261
0fe1f57ac2bd dirstate: use propertycache
Matt Mackall <mpm@selenic.com>
parents: 8226
diff changeset
    28
propertycache = util.propertycache
16201
fb7c4c14223f dirstate: filecacheify _branch
Idan Kamara <idankk86@gmail.com>
parents: 16200
diff changeset
    29
48044
d5528ac9b4f2 dirstate: Use the Rust implementation of DirstateItem when Rust is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 48024
diff changeset
    30
if rustmod is None:
d5528ac9b4f2 dirstate: Use the Rust implementation of DirstateItem when Rust is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 48024
diff changeset
    31
    DirstateItem = parsers.DirstateItem
d5528ac9b4f2 dirstate: Use the Rust implementation of DirstateItem when Rust is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 48024
diff changeset
    32
else:
d5528ac9b4f2 dirstate: Use the Rust implementation of DirstateItem when Rust is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 48024
diff changeset
    33
    DirstateItem = rustmod.DirstateItem
21808
7537e57f5dbd dirstate: add dirstatetuple to create dirstate values
Siddharth Agarwal <sid0@fb.com>
parents: 21116
diff changeset
    34
47521
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47514
diff changeset
    35
rangemask = 0x7FFFFFFF
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47514
diff changeset
    36
47482
cb29484eaade dirstate: introduce a symbolic constant for the FROM_P2 marker
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47481
diff changeset
    37
34332
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34188
diff changeset
    38
class dirstatemap(object):
35078
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    39
    """Map encapsulating the dirstate's contents.
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    40
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    41
    The dirstate contains the following state:
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    42
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    43
    - `identity` is the identity of the dirstate file, which can be used to
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    44
      detect when changes have occurred to the dirstate file.
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    45
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    46
    - `parents` is a pair containing the parents of the working copy. The
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    47
      parents are updated by calling `setparents`.
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    48
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    49
    - the state map maps filenames to tuples of (state, mode, size, mtime),
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    50
      where state is a single character representing 'normal', 'added',
35079
853b7c41d19c dirstate: add explicit methods for modifying dirstate
Mark Thomas <mbthomas@fb.com>
parents: 35078
diff changeset
    51
      'removed', or 'merged'. It is read by treating the dirstate as a
47996
aa442fde0ea5 dirstate: update the documentation of the dirstatemap API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47990
diff changeset
    52
      dict.  File state is updated by calling various methods (see each
aa442fde0ea5 dirstate: update the documentation of the dirstatemap API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47990
diff changeset
    53
      documentation for details):
aa442fde0ea5 dirstate: update the documentation of the dirstatemap API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47990
diff changeset
    54
aa442fde0ea5 dirstate: update the documentation of the dirstatemap API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47990
diff changeset
    55
      - `reset_state`,
aa442fde0ea5 dirstate: update the documentation of the dirstatemap API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47990
diff changeset
    56
      - `set_tracked`
aa442fde0ea5 dirstate: update the documentation of the dirstatemap API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47990
diff changeset
    57
      - `set_untracked`
aa442fde0ea5 dirstate: update the documentation of the dirstatemap API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47990
diff changeset
    58
      - `set_clean`
aa442fde0ea5 dirstate: update the documentation of the dirstatemap API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47990
diff changeset
    59
      - `set_possibly_dirty`
35078
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    60
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    61
    - `copymap` maps destination filenames to their source filename.
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    62
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    63
    The dirstate also provides the following views onto the state:
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    64
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    65
    - `filefoldmap` is a dict mapping normalized filenames to the denormalized
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    66
      form that they appear as in the dirstate.
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    67
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    68
    - `dirfoldmap` is a dict mapping normalized directory names to the
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    69
      denormalized form that they appear as in the dirstate.
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    70
    """
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35016
diff changeset
    71
47280
1766130fe9ba dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 47277
diff changeset
    72
    def __init__(self, ui, opener, root, nodeconstants, use_dirstate_v2):
34337
c36c3fa7d35b dirstate: move opendirstatefile to dirstatemap
Durham Goode <durham@fb.com>
parents: 34336
diff changeset
    73
        self._ui = ui
c36c3fa7d35b dirstate: move opendirstatefile to dirstatemap
Durham Goode <durham@fb.com>
parents: 34336
diff changeset
    74
        self._opener = opener
c36c3fa7d35b dirstate: move opendirstatefile to dirstatemap
Durham Goode <durham@fb.com>
parents: 34336
diff changeset
    75
        self._root = root
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    76
        self._filename = b'dirstate'
45219
4f0e03d980f3 dirstate: isolate node len dependency for the pure version
Joerg Sonnenberger <joerg@bec.de>
parents: 44852
diff changeset
    77
        self._nodelen = 20
46780
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
    78
        self._nodeconstants = nodeconstants
47280
1766130fe9ba dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 47277
diff changeset
    79
        assert (
1766130fe9ba dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 47277
diff changeset
    80
            not use_dirstate_v2
1766130fe9ba dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 47277
diff changeset
    81
        ), "should have detected unsupported requirement"
34337
c36c3fa7d35b dirstate: move opendirstatefile to dirstatemap
Durham Goode <durham@fb.com>
parents: 34336
diff changeset
    82
34339
ec769bba34d3 dirstate: move parents source of truth to dirstatemap
Durham Goode <durham@fb.com>
parents: 34338
diff changeset
    83
        self._parents = None
ec769bba34d3 dirstate: move parents source of truth to dirstatemap
Durham Goode <durham@fb.com>
parents: 34338
diff changeset
    84
        self._dirtyparents = False
34332
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34188
diff changeset
    85
34337
c36c3fa7d35b dirstate: move opendirstatefile to dirstatemap
Durham Goode <durham@fb.com>
parents: 34336
diff changeset
    86
        # for consistent view between _pl() and _read() invocations
c36c3fa7d35b dirstate: move opendirstatefile to dirstatemap
Durham Goode <durham@fb.com>
parents: 34336
diff changeset
    87
        self._pendingmode = None
c36c3fa7d35b dirstate: move opendirstatefile to dirstatemap
Durham Goode <durham@fb.com>
parents: 34336
diff changeset
    88
34934
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
    89
    @propertycache
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
    90
    def _map(self):
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
    91
        self._map = {}
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
    92
        self.read()
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
    93
        return self._map
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
    94
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
    95
    @propertycache
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
    96
    def copymap(self):
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
    97
        self.copymap = {}
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
    98
        self._map
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
    99
        return self.copymap
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
   100
34933
0217f75b6e59 dirstate: move clear onto dirstatemap class
Durham Goode <durham@fb.com>
parents: 34678
diff changeset
   101
    def clear(self):
34935
ffeea2406276 dirstate: remove excess attribute lookups for dirstate.status (issue5714)
Durham Goode <durham@fb.com>
parents: 34934
diff changeset
   102
        self._map.clear()
ffeea2406276 dirstate: remove excess attribute lookups for dirstate.status (issue5714)
Durham Goode <durham@fb.com>
parents: 34934
diff changeset
   103
        self.copymap.clear()
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
   104
        self.setparents(self._nodeconstants.nullid, self._nodeconstants.nullid)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   105
        util.clearcachedproperty(self, b"_dirs")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   106
        util.clearcachedproperty(self, b"_alldirs")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   107
        util.clearcachedproperty(self, b"filefoldmap")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   108
        util.clearcachedproperty(self, b"dirfoldmap")
34933
0217f75b6e59 dirstate: move clear onto dirstatemap class
Durham Goode <durham@fb.com>
parents: 34678
diff changeset
   109
35878
6e7fae8f1c6c contrib: fix dirstatenonnormalcheck to work in Python 3
Augie Fackler <augie@google.com>
parents: 35835
diff changeset
   110
    def items(self):
43106
d783f945a701 py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43090
diff changeset
   111
        return pycompat.iteritems(self._map)
34332
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34188
diff changeset
   112
35878
6e7fae8f1c6c contrib: fix dirstatenonnormalcheck to work in Python 3
Augie Fackler <augie@google.com>
parents: 35835
diff changeset
   113
    # forward for python2,3 compat
6e7fae8f1c6c contrib: fix dirstatenonnormalcheck to work in Python 3
Augie Fackler <augie@google.com>
parents: 35835
diff changeset
   114
    iteritems = items
6e7fae8f1c6c contrib: fix dirstatenonnormalcheck to work in Python 3
Augie Fackler <augie@google.com>
parents: 35835
diff changeset
   115
48023
357307feaf61 debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents: 48019
diff changeset
   116
    def debug_iter(self, all):
357307feaf61 debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents: 48019
diff changeset
   117
        """
48024
cedfe2606adf debugsate: Change debug_iter() to yield tuples instead of DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48023
diff changeset
   118
        Return an iterator of (filename, state, mode, size, mtime) tuples
cedfe2606adf debugsate: Change debug_iter() to yield tuples instead of DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48023
diff changeset
   119
48023
357307feaf61 debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents: 48019
diff changeset
   120
        `all` is unused when Rust is not enabled
357307feaf61 debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents: 48019
diff changeset
   121
        """
48024
cedfe2606adf debugsate: Change debug_iter() to yield tuples instead of DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48023
diff changeset
   122
        for (filename, item) in self.items():
cedfe2606adf debugsate: Change debug_iter() to yield tuples instead of DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48023
diff changeset
   123
            yield (filename, item.state, item.mode, item.size, item.mtime)
47683
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   124
34408
7d2f71b7bc31 dirstate: implement __len__ on dirstatemap (issue5695)
Simon Whitaker <swhitaker@fb.com>
parents: 34339
diff changeset
   125
    def __len__(self):
7d2f71b7bc31 dirstate: implement __len__ on dirstatemap (issue5695)
Simon Whitaker <swhitaker@fb.com>
parents: 34339
diff changeset
   126
        return len(self._map)
7d2f71b7bc31 dirstate: implement __len__ on dirstatemap (issue5695)
Simon Whitaker <swhitaker@fb.com>
parents: 34339
diff changeset
   127
34332
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34188
diff changeset
   128
    def __iter__(self):
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34188
diff changeset
   129
        return iter(self._map)
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34188
diff changeset
   130
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34188
diff changeset
   131
    def get(self, key, default=None):
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34188
diff changeset
   132
        return self._map.get(key, default)
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34188
diff changeset
   133
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34188
diff changeset
   134
    def __contains__(self, key):
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34188
diff changeset
   135
        return key in self._map
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34188
diff changeset
   136
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34188
diff changeset
   137
    def __getitem__(self, key):
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34188
diff changeset
   138
        return self._map[key]
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34188
diff changeset
   139
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34188
diff changeset
   140
    def keys(self):
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34188
diff changeset
   141
        return self._map.keys()
34333
4ac04418ce66 dirstate: move nonnormalentries to dirstatemap
Durham Goode <durham@fb.com>
parents: 34332
diff changeset
   142
34935
ffeea2406276 dirstate: remove excess attribute lookups for dirstate.status (issue5714)
Durham Goode <durham@fb.com>
parents: 34934
diff changeset
   143
    def preload(self):
ffeea2406276 dirstate: remove excess attribute lookups for dirstate.status (issue5714)
Durham Goode <durham@fb.com>
parents: 34934
diff changeset
   144
        """Loads the underlying data, if it's not already loaded"""
ffeea2406276 dirstate: remove excess attribute lookups for dirstate.status (issue5714)
Durham Goode <durham@fb.com>
parents: 34934
diff changeset
   145
        self._map
ffeea2406276 dirstate: remove excess attribute lookups for dirstate.status (issue5714)
Durham Goode <durham@fb.com>
parents: 34934
diff changeset
   146
47687
e59bd6723f2f dirstate-map: factor out the change to _dirs and _alldirs on adding
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47686
diff changeset
   147
    def _dirs_incr(self, filename, old_entry=None):
e59bd6723f2f dirstate-map: factor out the change to _dirs and _alldirs on adding
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47686
diff changeset
   148
        """incremente the dirstate counter if applicable"""
e59bd6723f2f dirstate-map: factor out the change to _dirs and _alldirs on adding
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47686
diff changeset
   149
        if (
e59bd6723f2f dirstate-map: factor out the change to _dirs and _alldirs on adding
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47686
diff changeset
   150
            old_entry is None or old_entry.removed
e59bd6723f2f dirstate-map: factor out the change to _dirs and _alldirs on adding
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47686
diff changeset
   151
        ) and "_dirs" in self.__dict__:
e59bd6723f2f dirstate-map: factor out the change to _dirs and _alldirs on adding
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47686
diff changeset
   152
            self._dirs.addpath(filename)
e59bd6723f2f dirstate-map: factor out the change to _dirs and _alldirs on adding
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47686
diff changeset
   153
        if old_entry is None and "_alldirs" in self.__dict__:
e59bd6723f2f dirstate-map: factor out the change to _dirs and _alldirs on adding
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47686
diff changeset
   154
            self._alldirs.addpath(filename)
e59bd6723f2f dirstate-map: factor out the change to _dirs and _alldirs on adding
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47686
diff changeset
   155
47689
f2aef39abc14 dirstate-map: factor out the change to _dirs and _alldirs on removing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47688
diff changeset
   156
    def _dirs_decr(self, filename, old_entry=None, remove_variant=False):
47688
b37ab6b5c438 dirstate-map: factor out the change to _dirs and _alldirs on dropping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47687
diff changeset
   157
        """decremente the dirstate counter if applicable"""
b37ab6b5c438 dirstate-map: factor out the change to _dirs and _alldirs on dropping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47687
diff changeset
   158
        if old_entry is not None:
b37ab6b5c438 dirstate-map: factor out the change to _dirs and _alldirs on dropping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47687
diff changeset
   159
            if "_dirs" in self.__dict__ and not old_entry.removed:
b37ab6b5c438 dirstate-map: factor out the change to _dirs and _alldirs on dropping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47687
diff changeset
   160
                self._dirs.delpath(filename)
47689
f2aef39abc14 dirstate-map: factor out the change to _dirs and _alldirs on removing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47688
diff changeset
   161
            if "_alldirs" in self.__dict__ and not remove_variant:
47688
b37ab6b5c438 dirstate-map: factor out the change to _dirs and _alldirs on dropping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47687
diff changeset
   162
                self._alldirs.delpath(filename)
47689
f2aef39abc14 dirstate-map: factor out the change to _dirs and _alldirs on removing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47688
diff changeset
   163
        elif remove_variant and "_alldirs" in self.__dict__:
f2aef39abc14 dirstate-map: factor out the change to _dirs and _alldirs on removing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47688
diff changeset
   164
            self._alldirs.addpath(filename)
47688
b37ab6b5c438 dirstate-map: factor out the change to _dirs and _alldirs on dropping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47687
diff changeset
   165
        if "filefoldmap" in self.__dict__:
b37ab6b5c438 dirstate-map: factor out the change to _dirs and _alldirs on dropping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47687
diff changeset
   166
            normed = util.normcase(filename)
b37ab6b5c438 dirstate-map: factor out the change to _dirs and _alldirs on dropping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47687
diff changeset
   167
            self.filefoldmap.pop(normed, None)
b37ab6b5c438 dirstate-map: factor out the change to _dirs and _alldirs on dropping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47687
diff changeset
   168
47720
b0314d8deee1 dirstate: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47692
diff changeset
   169
    def set_possibly_dirty(self, filename):
b0314d8deee1 dirstate: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47692
diff changeset
   170
        """record that the current state of the file on disk is unknown"""
b0314d8deee1 dirstate: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47692
diff changeset
   171
        self[filename].set_possibly_dirty()
b0314d8deee1 dirstate: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47692
diff changeset
   172
47974
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47972
diff changeset
   173
    def set_clean(self, filename, 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: 47972
diff changeset
   174
        """mark a file as back to a clean state"""
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47972
diff changeset
   175
        entry = self[filename]
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47972
diff changeset
   176
        mtime = mtime & rangemask
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47972
diff changeset
   177
        size = size & rangemask
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47972
diff changeset
   178
        entry.set_clean(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: 47972
diff changeset
   179
        self.copymap.pop(filename, None)
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47972
diff changeset
   180
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   181
    def reset_state(
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   182
        self,
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   183
        filename,
47998
938a7769050c dirstate: support file tracked nowhere in `reset_state`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47997
diff changeset
   184
        wc_tracked=False,
938a7769050c dirstate: support file tracked nowhere in `reset_state`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47997
diff changeset
   185
        p1_tracked=False,
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   186
        p2_tracked=False,
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   187
        merged=False,
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   188
        clean_p1=False,
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   189
        clean_p2=False,
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   190
        possibly_dirty=False,
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   191
        parentfiledata=None,
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   192
    ):
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   193
        """Set a entry to a given state, diregarding all previous state
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   194
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   195
        This is to be used by the part of the dirstate API dedicated to
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   196
        adjusting the dirstate after a update/merge.
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   197
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   198
        note: calling this might result to no entry existing at all if the
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   199
        dirstate map does not see any point at having one for this file
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   200
        anymore.
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   201
        """
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   202
        if merged and (clean_p1 or clean_p2):
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   203
            msg = b'`merged` argument incompatible with `clean_p1`/`clean_p2`'
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   204
            raise error.ProgrammingError(msg)
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   205
        # copy information are now outdated
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   206
        # (maybe new information should be in directly passed to this function)
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   207
        self.copymap.pop(filename, None)
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   208
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   209
        if not (p1_tracked or p2_tracked or wc_tracked):
47998
938a7769050c dirstate: support file tracked nowhere in `reset_state`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47997
diff changeset
   210
            old_entry = self._map.pop(filename, None)
938a7769050c dirstate: support file tracked nowhere in `reset_state`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47997
diff changeset
   211
            self._dirs_decr(filename, old_entry=old_entry)
938a7769050c dirstate: support file tracked nowhere in `reset_state`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47997
diff changeset
   212
            self.copymap.pop(filename, None)
47896
d5b54917eb92 dirstatemap: temporarily return early in `reset_state`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47894
diff changeset
   213
            return
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   214
        elif merged:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   215
            # XXX might be merged and removed ?
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   216
            entry = self.get(filename)
47904
822c67420c77 dirstatemap: use the default code to handle "merged" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47903
diff changeset
   217
            if entry is None or not entry.tracked:
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   218
                # XXX mostly replicate dirstate.other parent.  We should get
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   219
                # the higher layer to pass us more reliable data where `merged`
47904
822c67420c77 dirstatemap: use the default code to handle "merged" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47903
diff changeset
   220
                # actually mean merged. Dropping this clause will show failure
822c67420c77 dirstatemap: use the default code to handle "merged" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47903
diff changeset
   221
                # in `test-graft.t`
822c67420c77 dirstatemap: use the default code to handle "merged" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47903
diff changeset
   222
                merged = False
822c67420c77 dirstatemap: use the default code to handle "merged" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47903
diff changeset
   223
                clean_p2 = True
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   224
        elif not (p1_tracked or p2_tracked) and wc_tracked:
47903
6816ae362ddd dirstatemap: use the default code to handle "added" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47902
diff changeset
   225
            pass  # file is added, nothing special to adjust
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   226
        elif (p1_tracked or p2_tracked) and not wc_tracked:
47902
4cade5e944c2 dirstatemap: use the default code to handle "removed" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47901
diff changeset
   227
            pass
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   228
        elif clean_p2 and wc_tracked:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   229
            if p1_tracked or self.get(filename) is not None:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   230
                # XXX the `self.get` call is catching some case in
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   231
                # `test-merge-remove.t` where the file is tracked in p1, the
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   232
                # p1_tracked argument is False.
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   233
                #
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   234
                # In addition, this seems to be a case where the file is marked
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   235
                # as merged without actually being the result of a merge
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   236
                # action. So thing are not ideal here.
47901
3429f48d486d dirstatemap: use the default code to handle "clean-p2" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47900
diff changeset
   237
                merged = True
3429f48d486d dirstatemap: use the default code to handle "clean-p2" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47900
diff changeset
   238
                clean_p2 = False
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   239
        elif not p1_tracked and p2_tracked and wc_tracked:
47900
40cf4b278f8f dirstatemap: use the default code to handle "p2-tracked" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47899
diff changeset
   240
            clean_p2 = True
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   241
        elif possibly_dirty:
47899
625b6ddb828c dirstatemap: use the default code to handle "possibly_dirty" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47898
diff changeset
   242
            pass
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   243
        elif wc_tracked:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   244
            # this is a "normal" file
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   245
            if parentfiledata is None:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   246
                msg = b'failed to pass parentfiledata for a normal file: %s'
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   247
                msg %= filename
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   248
                raise error.ProgrammingError(msg)
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   249
        else:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   250
            assert False, 'unreachable'
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   251
47897
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47896
diff changeset
   252
        old_entry = self._map.get(filename)
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47896
diff changeset
   253
        self._dirs_incr(filename, old_entry)
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47896
diff changeset
   254
        entry = DirstateItem(
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47896
diff changeset
   255
            wc_tracked=wc_tracked,
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47896
diff changeset
   256
            p1_tracked=p1_tracked,
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47896
diff changeset
   257
            p2_tracked=p2_tracked,
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47896
diff changeset
   258
            merged=merged,
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47896
diff changeset
   259
            clean_p1=clean_p1,
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47896
diff changeset
   260
            clean_p2=clean_p2,
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47896
diff changeset
   261
            possibly_dirty=possibly_dirty,
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47896
diff changeset
   262
            parentfiledata=parentfiledata,
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47896
diff changeset
   263
        )
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47896
diff changeset
   264
        self._map[filename] = entry
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47896
diff changeset
   265
47990
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   266
    def set_tracked(self, filename):
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   267
        new = False
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   268
        entry = self.get(filename)
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   269
        if entry is None:
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   270
            self._dirs_incr(filename)
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   271
            entry = DirstateItem(
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   272
                p1_tracked=False,
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   273
                p2_tracked=False,
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   274
                wc_tracked=True,
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   275
                merged=False,
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   276
                clean_p1=False,
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   277
                clean_p2=False,
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   278
                possibly_dirty=False,
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   279
                parentfiledata=None,
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   280
            )
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   281
            self._map[filename] = entry
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   282
            new = True
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   283
        elif not entry.tracked:
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   284
            self._dirs_incr(filename, entry)
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   285
            entry.set_tracked()
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   286
            new = True
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   287
        else:
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   288
            # XXX This is probably overkill for more case, but we need this to
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   289
            # fully replace the `normallookup` call with `set_tracked` one.
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   290
            # Consider smoothing this in the future.
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   291
            self.set_possibly_dirty(filename)
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   292
        return new
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   293
47890
3853e6ee160d dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47770
diff changeset
   294
    def set_untracked(self, f):
3853e6ee160d dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47770
diff changeset
   295
        """Mark a file as no longer tracked in the dirstate map"""
47972
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   296
        entry = self.get(f)
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   297
        if entry is None:
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   298
            return False
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   299
        else:
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   300
            self._dirs_decr(f, old_entry=entry, remove_variant=not entry.added)
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   301
            if not entry.merged:
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   302
                self.copymap.pop(f, None)
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   303
            if entry.added:
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   304
                self._map.pop(f, None)
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   305
            else:
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   306
                entry.set_untracked()
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   307
            return True
35079
853b7c41d19c dirstate: add explicit methods for modifying dirstate
Mark Thomas <mbthomas@fb.com>
parents: 35078
diff changeset
   308
34676
bfddc3d678ae dirstate: remove _filefoldmap property cache
Durham Goode <durham@fb.com>
parents: 34675
diff changeset
   309
    @propertycache
34334
d8b35920b7b1 dirstate: move filefoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34333
diff changeset
   310
    def filefoldmap(self):
d8b35920b7b1 dirstate: move filefoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34333
diff changeset
   311
        """Returns a dictionary mapping normalized case paths to their
d8b35920b7b1 dirstate: move filefoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34333
diff changeset
   312
        non-normalized versions.
d8b35920b7b1 dirstate: move filefoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34333
diff changeset
   313
        """
d8b35920b7b1 dirstate: move filefoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34333
diff changeset
   314
        try:
d8b35920b7b1 dirstate: move filefoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34333
diff changeset
   315
            makefilefoldmap = parsers.make_file_foldmap
d8b35920b7b1 dirstate: move filefoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34333
diff changeset
   316
        except AttributeError:
d8b35920b7b1 dirstate: move filefoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34333
diff changeset
   317
            pass
d8b35920b7b1 dirstate: move filefoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34333
diff changeset
   318
        else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   319
            return makefilefoldmap(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   320
                self._map, util.normcasespec, util.normcasefallback
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   321
            )
34334
d8b35920b7b1 dirstate: move filefoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34333
diff changeset
   322
d8b35920b7b1 dirstate: move filefoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34333
diff changeset
   323
        f = {}
d8b35920b7b1 dirstate: move filefoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34333
diff changeset
   324
        normcase = util.normcase
43106
d783f945a701 py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43090
diff changeset
   325
        for name, s in pycompat.iteritems(self._map):
47542
b8013cb71ef3 dirstate-item: use the properties in dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47539
diff changeset
   326
            if not s.removed:
34334
d8b35920b7b1 dirstate: move filefoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34333
diff changeset
   327
                f[normcase(name)] = name
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   328
        f[b'.'] = b'.'  # prevents useless util.fspath() invocation
34334
d8b35920b7b1 dirstate: move filefoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34333
diff changeset
   329
        return f
34335
af9722412ac3 dirstate: move _dirs to dirstatemap
Durham Goode <durham@fb.com>
parents: 34334
diff changeset
   330
35084
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   331
    def hastrackeddir(self, d):
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   332
        """
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   333
        Returns True if the dirstate contains a tracked (not removed) file
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   334
        in this directory.
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   335
        """
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   336
        return d in self._dirs
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   337
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   338
    def hasdir(self, d):
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   339
        """
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   340
        Returns True if the dirstate contains a file (tracked or removed)
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   341
        in this directory.
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   342
        """
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   343
        return d in self._alldirs
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   344
34677
014bd2a555c8 dirstate: remove _dirs property cache
Durham Goode <durham@fb.com>
parents: 34676
diff changeset
   345
    @propertycache
35084
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   346
    def _dirs(self):
47944
e02f9af7aed1 pathutil: replace the `skip` argument of `dirs` with a boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47907
diff changeset
   347
        return pathutil.dirs(self._map, only_tracked=True)
34337
c36c3fa7d35b dirstate: move opendirstatefile to dirstatemap
Durham Goode <durham@fb.com>
parents: 34336
diff changeset
   348
35084
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   349
    @propertycache
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   350
    def _alldirs(self):
43523
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43506
diff changeset
   351
        return pathutil.dirs(self._map)
35084
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   352
34337
c36c3fa7d35b dirstate: move opendirstatefile to dirstatemap
Durham Goode <durham@fb.com>
parents: 34336
diff changeset
   353
    def _opendirstatefile(self):
c36c3fa7d35b dirstate: move opendirstatefile to dirstatemap
Durham Goode <durham@fb.com>
parents: 34336
diff changeset
   354
        fp, mode = txnutil.trypending(self._root, self._opener, self._filename)
c36c3fa7d35b dirstate: move opendirstatefile to dirstatemap
Durham Goode <durham@fb.com>
parents: 34336
diff changeset
   355
        if self._pendingmode is not None and self._pendingmode != mode:
c36c3fa7d35b dirstate: move opendirstatefile to dirstatemap
Durham Goode <durham@fb.com>
parents: 34336
diff changeset
   356
            fp.close()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   357
            raise error.Abort(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
   358
                _(b'working directory state may be changed parallelly')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   359
            )
34337
c36c3fa7d35b dirstate: move opendirstatefile to dirstatemap
Durham Goode <durham@fb.com>
parents: 34336
diff changeset
   360
        self._pendingmode = mode
c36c3fa7d35b dirstate: move opendirstatefile to dirstatemap
Durham Goode <durham@fb.com>
parents: 34336
diff changeset
   361
        return fp
c36c3fa7d35b dirstate: move opendirstatefile to dirstatemap
Durham Goode <durham@fb.com>
parents: 34336
diff changeset
   362
34338
0c3e3810cdb6 dirstate: move parent reading to the dirstatemap class
Durham Goode <durham@fb.com>
parents: 34337
diff changeset
   363
    def parents(self):
34339
ec769bba34d3 dirstate: move parents source of truth to dirstatemap
Durham Goode <durham@fb.com>
parents: 34338
diff changeset
   364
        if not self._parents:
ec769bba34d3 dirstate: move parents source of truth to dirstatemap
Durham Goode <durham@fb.com>
parents: 34338
diff changeset
   365
            try:
ec769bba34d3 dirstate: move parents source of truth to dirstatemap
Durham Goode <durham@fb.com>
parents: 34338
diff changeset
   366
                fp = self._opendirstatefile()
45219
4f0e03d980f3 dirstate: isolate node len dependency for the pure version
Joerg Sonnenberger <joerg@bec.de>
parents: 44852
diff changeset
   367
                st = fp.read(2 * self._nodelen)
34339
ec769bba34d3 dirstate: move parents source of truth to dirstatemap
Durham Goode <durham@fb.com>
parents: 34338
diff changeset
   368
                fp.close()
ec769bba34d3 dirstate: move parents source of truth to dirstatemap
Durham Goode <durham@fb.com>
parents: 34338
diff changeset
   369
            except IOError as err:
ec769bba34d3 dirstate: move parents source of truth to dirstatemap
Durham Goode <durham@fb.com>
parents: 34338
diff changeset
   370
                if err.errno != errno.ENOENT:
ec769bba34d3 dirstate: move parents source of truth to dirstatemap
Durham Goode <durham@fb.com>
parents: 34338
diff changeset
   371
                    raise
ec769bba34d3 dirstate: move parents source of truth to dirstatemap
Durham Goode <durham@fb.com>
parents: 34338
diff changeset
   372
                # File doesn't exist, so the current state is empty
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   373
                st = b''
34339
ec769bba34d3 dirstate: move parents source of truth to dirstatemap
Durham Goode <durham@fb.com>
parents: 34338
diff changeset
   374
34338
0c3e3810cdb6 dirstate: move parent reading to the dirstatemap class
Durham Goode <durham@fb.com>
parents: 34337
diff changeset
   375
            l = len(st)
45219
4f0e03d980f3 dirstate: isolate node len dependency for the pure version
Joerg Sonnenberger <joerg@bec.de>
parents: 44852
diff changeset
   376
            if l == self._nodelen * 2:
4f0e03d980f3 dirstate: isolate node len dependency for the pure version
Joerg Sonnenberger <joerg@bec.de>
parents: 44852
diff changeset
   377
                self._parents = (
4f0e03d980f3 dirstate: isolate node len dependency for the pure version
Joerg Sonnenberger <joerg@bec.de>
parents: 44852
diff changeset
   378
                    st[: self._nodelen],
4f0e03d980f3 dirstate: isolate node len dependency for the pure version
Joerg Sonnenberger <joerg@bec.de>
parents: 44852
diff changeset
   379
                    st[self._nodelen : 2 * self._nodelen],
4f0e03d980f3 dirstate: isolate node len dependency for the pure version
Joerg Sonnenberger <joerg@bec.de>
parents: 44852
diff changeset
   380
                )
34339
ec769bba34d3 dirstate: move parents source of truth to dirstatemap
Durham Goode <durham@fb.com>
parents: 34338
diff changeset
   381
            elif l == 0:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
   382
                self._parents = (
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
   383
                    self._nodeconstants.nullid,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
   384
                    self._nodeconstants.nullid,
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
   385
                )
34339
ec769bba34d3 dirstate: move parents source of truth to dirstatemap
Durham Goode <durham@fb.com>
parents: 34338
diff changeset
   386
            else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   387
                raise error.Abort(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
   388
                    _(b'working directory state appears damaged!')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   389
                )
34339
ec769bba34d3 dirstate: move parents source of truth to dirstatemap
Durham Goode <durham@fb.com>
parents: 34338
diff changeset
   390
ec769bba34d3 dirstate: move parents source of truth to dirstatemap
Durham Goode <durham@fb.com>
parents: 34338
diff changeset
   391
        return self._parents
ec769bba34d3 dirstate: move parents source of truth to dirstatemap
Durham Goode <durham@fb.com>
parents: 34338
diff changeset
   392
48059
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   393
    def setparents(self, p1, p2, fold_p2=False):
34339
ec769bba34d3 dirstate: move parents source of truth to dirstatemap
Durham Goode <durham@fb.com>
parents: 34338
diff changeset
   394
        self._parents = (p1, p2)
ec769bba34d3 dirstate: move parents source of truth to dirstatemap
Durham Goode <durham@fb.com>
parents: 34338
diff changeset
   395
        self._dirtyparents = True
48059
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   396
        copies = {}
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   397
        if fold_p2:
48061
060cd909439f dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48060
diff changeset
   398
            for f, s in pycompat.iteritems(self._map):
48059
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   399
                # Discard "merged" markers when moving away from a merge state
48060
a660d8a53267 dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48059
diff changeset
   400
                if s.merged or s.from_p2:
a660d8a53267 dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48059
diff changeset
   401
                    source = self.copymap.pop(f, None)
48059
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   402
                    if source:
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   403
                        copies[f] = source
48060
a660d8a53267 dirstate: use a new `drop_merge_data` in `setparent`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48059
diff changeset
   404
                    s.drop_merge_data()
48059
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   405
        return copies
34672
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   406
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   407
    def read(self):
34675
c6ef9a2498a5 dirstate: move identity to dirstatemap
Durham Goode <durham@fb.com>
parents: 34674
diff changeset
   408
        # ignore HG_PENDING because identity is used only for writing
c6ef9a2498a5 dirstate: move identity to dirstatemap
Durham Goode <durham@fb.com>
parents: 34674
diff changeset
   409
        self.identity = util.filestat.frompath(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   410
            self._opener.join(self._filename)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   411
        )
34675
c6ef9a2498a5 dirstate: move identity to dirstatemap
Durham Goode <durham@fb.com>
parents: 34674
diff changeset
   412
34672
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   413
        try:
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   414
            fp = self._opendirstatefile()
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   415
            try:
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   416
                st = fp.read()
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   417
            finally:
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   418
                fp.close()
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   419
        except IOError as err:
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   420
            if err.errno != errno.ENOENT:
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   421
                raise
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   422
            return
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   423
        if not st:
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   424
            return
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   425
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   426
        if util.safehasattr(parsers, b'dict_new_presized'):
34672
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   427
            # Make an estimate of the number of files in the dirstate based on
45243
ad7006830106 dirstate: restore original estimation and update comment
Joerg Sonnenberger <joerg@bec.de>
parents: 45241
diff changeset
   428
            # its size. This trades wasting some memory for avoiding costly
ad7006830106 dirstate: restore original estimation and update comment
Joerg Sonnenberger <joerg@bec.de>
parents: 45241
diff changeset
   429
            # resizes. Each entry have a prefix of 17 bytes followed by one or
ad7006830106 dirstate: restore original estimation and update comment
Joerg Sonnenberger <joerg@bec.de>
parents: 45241
diff changeset
   430
            # two path names. Studies on various large-scale real-world repositories
ad7006830106 dirstate: restore original estimation and update comment
Joerg Sonnenberger <joerg@bec.de>
parents: 45241
diff changeset
   431
            # found 54 bytes a reasonable upper limit for the average path names.
ad7006830106 dirstate: restore original estimation and update comment
Joerg Sonnenberger <joerg@bec.de>
parents: 45241
diff changeset
   432
            # Copy entries are ignored for the sake of this estimate.
ad7006830106 dirstate: restore original estimation and update comment
Joerg Sonnenberger <joerg@bec.de>
parents: 45241
diff changeset
   433
            self._map = parsers.dict_new_presized(len(st) // 71)
34672
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   434
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   435
        # Python's garbage collector triggers a GC each time a certain number
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   436
        # of container objects (the number being defined by
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   437
        # gc.get_threshold()) are allocated. parse_dirstate creates a tuple
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   438
        # for each file in the dirstate. The C version then immediately marks
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   439
        # them as not to be tracked by the collector. However, this has no
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   440
        # effect on when GCs are triggered, only on what objects the GC looks
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   441
        # into. This means that O(number of files) GCs are unavoidable.
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   442
        # Depending on when in the process's lifetime the dirstate is parsed,
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   443
        # this can get very expensive. As a workaround, disable GC while
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   444
        # parsing the dirstate.
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   445
        #
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   446
        # (we cannot decorate the function directly since it is in a C module)
42747
760a7851e9ba rust-parsers: move parser bindings to their own file and Python module
Raphaël Gomès <rgomes@octobus.net>
parents: 42456
diff changeset
   447
        parse_dirstate = util.nogc(parsers.parse_dirstate)
34672
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   448
        p = parse_dirstate(self._map, self.copymap, st)
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   449
        if not self._dirtyparents:
e159f217230e dirstate: move _read into dirstatemap
Durham Goode <durham@fb.com>
parents: 34480
diff changeset
   450
            self.setparents(*p)
34673
e2214632c3a2 dirstate: move write into dirstatemap
Durham Goode <durham@fb.com>
parents: 34672
diff changeset
   451
34935
ffeea2406276 dirstate: remove excess attribute lookups for dirstate.status (issue5714)
Durham Goode <durham@fb.com>
parents: 34934
diff changeset
   452
        # Avoid excess attribute lookups by fast pathing certain checks
ffeea2406276 dirstate: remove excess attribute lookups for dirstate.status (issue5714)
Durham Goode <durham@fb.com>
parents: 34934
diff changeset
   453
        self.__contains__ = self._map.__contains__
ffeea2406276 dirstate: remove excess attribute lookups for dirstate.status (issue5714)
Durham Goode <durham@fb.com>
parents: 34934
diff changeset
   454
        self.__getitem__ = self._map.__getitem__
ffeea2406276 dirstate: remove excess attribute lookups for dirstate.status (issue5714)
Durham Goode <durham@fb.com>
parents: 34934
diff changeset
   455
        self.get = self._map.get
ffeea2406276 dirstate: remove excess attribute lookups for dirstate.status (issue5714)
Durham Goode <durham@fb.com>
parents: 34934
diff changeset
   456
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   457
    def write(self, _tr, st, now):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   458
        st.write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   459
            parsers.pack_dirstate(self._map, self.copymap, self.parents(), now)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   460
        )
34673
e2214632c3a2 dirstate: move write into dirstatemap
Durham Goode <durham@fb.com>
parents: 34672
diff changeset
   461
        st.close()
e2214632c3a2 dirstate: move write into dirstatemap
Durham Goode <durham@fb.com>
parents: 34672
diff changeset
   462
        self._dirtyparents = False
47094
e061a1df32a8 dirstate-tree: Abstract "non-normal" and "other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47012
diff changeset
   463
34675
c6ef9a2498a5 dirstate: move identity to dirstatemap
Durham Goode <durham@fb.com>
parents: 34674
diff changeset
   464
    @propertycache
c6ef9a2498a5 dirstate: move identity to dirstatemap
Durham Goode <durham@fb.com>
parents: 34674
diff changeset
   465
    def identity(self):
34934
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
   466
        self._map
34675
c6ef9a2498a5 dirstate: move identity to dirstatemap
Durham Goode <durham@fb.com>
parents: 34674
diff changeset
   467
        return self.identity
c6ef9a2498a5 dirstate: move identity to dirstatemap
Durham Goode <durham@fb.com>
parents: 34674
diff changeset
   468
34678
e8a89ed7ce96 dirstate: move the _dirfoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34677
diff changeset
   469
    @propertycache
e8a89ed7ce96 dirstate: move the _dirfoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34677
diff changeset
   470
    def dirfoldmap(self):
e8a89ed7ce96 dirstate: move the _dirfoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34677
diff changeset
   471
        f = {}
e8a89ed7ce96 dirstate: move the _dirfoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34677
diff changeset
   472
        normcase = util.normcase
35084
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 35083
diff changeset
   473
        for name in self._dirs:
34678
e8a89ed7ce96 dirstate: move the _dirfoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34677
diff changeset
   474
            f[normcase(name)] = name
e8a89ed7ce96 dirstate: move the _dirfoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34677
diff changeset
   475
        return f
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   476
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   477
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   478
if rustmod is not None:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   479
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   480
    class dirstatemap(object):
47280
1766130fe9ba dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 47277
diff changeset
   481
        def __init__(self, ui, opener, root, nodeconstants, use_dirstate_v2):
1766130fe9ba dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 47277
diff changeset
   482
            self._use_dirstate_v2 = use_dirstate_v2
46780
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
   483
            self._nodeconstants = nodeconstants
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   484
            self._ui = ui
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   485
            self._opener = opener
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   486
            self._root = root
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   487
            self._filename = b'dirstate'
47280
1766130fe9ba dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 47277
diff changeset
   488
            self._nodelen = 20  # Also update Rust code when changing this!
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   489
            self._parents = None
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   490
            self._dirtyparents = False
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   491
            self._docket = None
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   492
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   493
            # for consistent view between _pl() and _read() invocations
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   494
            self._pendingmode = None
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   495
47320
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47280
diff changeset
   496
            self._use_dirstate_tree = self._ui.configbool(
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47280
diff changeset
   497
                b"experimental",
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47280
diff changeset
   498
                b"dirstate-tree.in-memory",
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47280
diff changeset
   499
                False,
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47280
diff changeset
   500
            )
a43d256c041a dirstate-v2: Add `hg debugupgraderepo` command support
Simon Sapin <simon.sapin@octobus.net>
parents: 47280
diff changeset
   501
47521
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47514
diff changeset
   502
        def addfile(
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47514
diff changeset
   503
            self,
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47514
diff changeset
   504
            f,
47525
fe4641cf9b72 dirstate: use a `added` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47524
diff changeset
   505
            mode=0,
47521
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47514
diff changeset
   506
            size=None,
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47514
diff changeset
   507
            mtime=None,
47525
fe4641cf9b72 dirstate: use a `added` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47524
diff changeset
   508
            added=False,
47527
c6b91a9c242a dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47525
diff changeset
   509
            merged=False,
47521
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47514
diff changeset
   510
            from_p2=False,
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47514
diff changeset
   511
            possibly_dirty=False,
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47514
diff changeset
   512
        ):
48051
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48050
diff changeset
   513
            if added:
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48050
diff changeset
   514
                assert not possibly_dirty
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48050
diff changeset
   515
                assert not from_p2
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48050
diff changeset
   516
                item = DirstateItem.new_added()
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48050
diff changeset
   517
            elif merged:
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48050
diff changeset
   518
                assert not possibly_dirty
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48050
diff changeset
   519
                assert not from_p2
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48050
diff changeset
   520
                item = DirstateItem.new_merged()
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48050
diff changeset
   521
            elif from_p2:
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48050
diff changeset
   522
                assert not possibly_dirty
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48050
diff changeset
   523
                item = DirstateItem.new_from_p2()
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48050
diff changeset
   524
            elif possibly_dirty:
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48050
diff changeset
   525
                item = DirstateItem.new_possibly_dirty()
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48050
diff changeset
   526
            else:
48052
d07d38ef6362 dirstate: Appease pytype
Simon Sapin <simon.sapin@octobus.net>
parents: 48051
diff changeset
   527
                assert size is not None
d07d38ef6362 dirstate: Appease pytype
Simon Sapin <simon.sapin@octobus.net>
parents: 48051
diff changeset
   528
                assert mtime is not None
48051
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48050
diff changeset
   529
                size = size & rangemask
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48050
diff changeset
   530
                mtime = mtime & rangemask
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48050
diff changeset
   531
                item = DirstateItem.new_normal(mode, size, mtime)
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48050
diff changeset
   532
            self._rustmap.addfile(f, item)
47983
ffde999a3ea9 dirstate: same logic as what we did for `_drop`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47974
diff changeset
   533
            if added:
ffde999a3ea9 dirstate: same logic as what we did for `_drop`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47974
diff changeset
   534
                self.copymap.pop(f, None)
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   535
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   536
        def reset_state(
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   537
            self,
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   538
            filename,
47998
938a7769050c dirstate: support file tracked nowhere in `reset_state`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47997
diff changeset
   539
            wc_tracked=False,
938a7769050c dirstate: support file tracked nowhere in `reset_state`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47997
diff changeset
   540
            p1_tracked=False,
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   541
            p2_tracked=False,
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   542
            merged=False,
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   543
            clean_p1=False,
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   544
            clean_p2=False,
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   545
            possibly_dirty=False,
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   546
            parentfiledata=None,
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   547
        ):
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   548
            """Set a entry to a given state, disregarding all previous state
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   549
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   550
            This is to be used by the part of the dirstate API dedicated to
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   551
            adjusting the dirstate after a update/merge.
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   552
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   553
            note: calling this might result to no entry existing at all if the
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   554
            dirstate map does not see any point at having one for this file
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   555
            anymore.
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   556
            """
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   557
            if merged and (clean_p1 or clean_p2):
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   558
                msg = (
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   559
                    b'`merged` argument incompatible with `clean_p1`/`clean_p2`'
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   560
                )
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   561
                raise error.ProgrammingError(msg)
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   562
            # copy information are now outdated
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   563
            # (maybe new information should be in directly passed to this function)
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   564
            self.copymap.pop(filename, None)
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   565
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   566
            if not (p1_tracked or p2_tracked or wc_tracked):
48050
2ac0e6b23222 dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents: 48048
diff changeset
   567
                self._rustmap.drop_item_and_copy_source(filename)
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   568
            elif merged:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   569
                # XXX might be merged and removed ?
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   570
                entry = self.get(filename)
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   571
                if entry is not None and entry.tracked:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   572
                    # XXX mostly replicate dirstate.other parent.  We should get
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   573
                    # the higher layer to pass us more reliable data where `merged`
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   574
                    # actually mean merged. Dropping the else clause will show
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   575
                    # failure in `test-graft.t`
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   576
                    self.addfile(filename, merged=True)
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   577
                else:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   578
                    self.addfile(filename, from_p2=True)
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   579
            elif not (p1_tracked or p2_tracked) and wc_tracked:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   580
                self.addfile(
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   581
                    filename, added=True, possibly_dirty=possibly_dirty
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   582
                )
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   583
            elif (p1_tracked or p2_tracked) and not wc_tracked:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   584
                # XXX might be merged and removed ?
47894
226c7dbeea11 rust-dirstatemap: temporarily use `from_v1_data` in `addfile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47893
diff changeset
   585
                self[filename] = DirstateItem.from_v1_data(b'r', 0, 0, 0)
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   586
            elif clean_p2 and wc_tracked:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   587
                if p1_tracked or self.get(filename) is not None:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   588
                    # XXX the `self.get` call is catching some case in
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   589
                    # `test-merge-remove.t` where the file is tracked in p1, the
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   590
                    # p1_tracked argument is False.
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   591
                    #
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   592
                    # In addition, this seems to be a case where the file is marked
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   593
                    # as merged without actually being the result of a merge
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   594
                    # action. So thing are not ideal here.
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   595
                    self.addfile(filename, merged=True)
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   596
                else:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   597
                    self.addfile(filename, from_p2=True)
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   598
            elif not p1_tracked and p2_tracked and wc_tracked:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   599
                self.addfile(
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   600
                    filename, from_p2=True, possibly_dirty=possibly_dirty
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   601
                )
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   602
            elif possibly_dirty:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   603
                self.addfile(filename, possibly_dirty=possibly_dirty)
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   604
            elif wc_tracked:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   605
                # this is a "normal" file
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   606
                if parentfiledata is None:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   607
                    msg = b'failed to pass parentfiledata for a normal file: %s'
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   608
                    msg %= filename
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   609
                    raise error.ProgrammingError(msg)
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   610
                mode, size, mtime = parentfiledata
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   611
                self.addfile(filename, mode=mode, size=size, mtime=mtime)
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   612
            else:
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   613
                assert False, 'unreachable'
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   614
47990
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   615
        def set_tracked(self, filename):
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   616
            new = False
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   617
            entry = self.get(filename)
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   618
            if entry is None:
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   619
                self.addfile(filename, added=True)
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   620
                new = True
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   621
            elif not entry.tracked:
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   622
                entry.set_tracked()
48045
32ef647821b2 dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Simon Sapin <simon.sapin@octobus.net>
parents: 48044
diff changeset
   623
                self._rustmap.set_dirstate_item(filename, entry)
47990
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   624
                new = True
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   625
            else:
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   626
                # XXX This is probably overkill for more case, but we need this to
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   627
                # fully replace the `normallookup` call with `set_tracked` one.
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   628
                # Consider smoothing this in the future.
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   629
                self.set_possibly_dirty(filename)
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   630
            return new
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47983
diff changeset
   631
47890
3853e6ee160d dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47770
diff changeset
   632
        def set_untracked(self, f):
3853e6ee160d dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47770
diff changeset
   633
            """Mark a file as no longer tracked in the dirstate map"""
3853e6ee160d dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47770
diff changeset
   634
            # in merge is only trigger more logic, so it "fine" to pass it.
3853e6ee160d dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47770
diff changeset
   635
            #
3853e6ee160d dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47770
diff changeset
   636
            # the inner rust dirstate map code need to be adjusted once the API
3853e6ee160d dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47770
diff changeset
   637
            # for dirstate/dirstatemap/DirstateItem is a bit more settled
47972
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   638
            entry = self.get(f)
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   639
            if entry is None:
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   640
                return False
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   641
            else:
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   642
                if entry.added:
48050
2ac0e6b23222 dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents: 48048
diff changeset
   643
                    self._rustmap.drop_item_and_copy_source(f)
47972
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   644
                else:
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   645
                    self._rustmap.removefile(f, in_merge=True)
5a6c1ef4bcac dirstate: make dirstatemap.set_untracked deal with added file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47970
diff changeset
   646
                return True
47890
3853e6ee160d dirstatemap: replace `removefile` by an explicit `entry.set_untracked()`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47770
diff changeset
   647
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   648
        def removefile(self, *args, **kwargs):
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   649
            return self._rustmap.removefile(*args, **kwargs)
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   650
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   651
        def get(self, *args, **kwargs):
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   652
            return self._rustmap.get(*args, **kwargs)
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   653
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   654
        @property
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   655
        def copymap(self):
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   656
            return self._rustmap.copymap()
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   657
48023
357307feaf61 debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents: 48019
diff changeset
   658
        def debug_iter(self, all):
48024
cedfe2606adf debugsate: Change debug_iter() to yield tuples instead of DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48023
diff changeset
   659
            """
cedfe2606adf debugsate: Change debug_iter() to yield tuples instead of DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48023
diff changeset
   660
            Return an iterator of (filename, state, mode, size, mtime) tuples
cedfe2606adf debugsate: Change debug_iter() to yield tuples instead of DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48023
diff changeset
   661
cedfe2606adf debugsate: Change debug_iter() to yield tuples instead of DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48023
diff changeset
   662
            `all`: also include with `state == b' '` dirstate tree nodes that
cedfe2606adf debugsate: Change debug_iter() to yield tuples instead of DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48023
diff changeset
   663
            don't have an associated `DirstateItem`.
cedfe2606adf debugsate: Change debug_iter() to yield tuples instead of DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48023
diff changeset
   664
cedfe2606adf debugsate: Change debug_iter() to yield tuples instead of DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48023
diff changeset
   665
            """
48023
357307feaf61 debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents: 48019
diff changeset
   666
            return self._rustmap.debug_iter(all)
47683
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   667
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   668
        def preload(self):
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   669
            self._rustmap
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   670
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   671
        def clear(self):
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   672
            self._rustmap.clear()
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
   673
            self.setparents(
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
   674
                self._nodeconstants.nullid, self._nodeconstants.nullid
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
   675
            )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   676
            util.clearcachedproperty(self, b"_dirs")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   677
            util.clearcachedproperty(self, b"_alldirs")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   678
            util.clearcachedproperty(self, b"dirfoldmap")
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   679
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   680
        def items(self):
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   681
            return self._rustmap.items()
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   682
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   683
        def keys(self):
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   684
            return iter(self._rustmap)
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   685
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   686
        def __contains__(self, key):
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   687
            return key in self._rustmap
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   688
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   689
        def __getitem__(self, item):
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   690
            return self._rustmap[item]
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   691
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   692
        def __len__(self):
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   693
            return len(self._rustmap)
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   694
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   695
        def __iter__(self):
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   696
            return iter(self._rustmap)
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   697
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   698
        # forward for python2,3 compat
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   699
        iteritems = items
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   700
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   701
        def _opendirstatefile(self):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   702
            fp, mode = txnutil.trypending(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   703
                self._root, self._opener, self._filename
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   704
            )
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   705
            if self._pendingmode is not None and self._pendingmode != mode:
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   706
                fp.close()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   707
                raise error.Abort(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
   708
                    _(b'working directory state may be changed parallelly')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   709
                )
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   710
            self._pendingmode = mode
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   711
            return fp
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   712
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   713
        def _readdirstatefile(self, size=-1):
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   714
            try:
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   715
                with self._opendirstatefile() as fp:
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   716
                    return fp.read(size)
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   717
            except IOError as err:
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   718
                if err.errno != errno.ENOENT:
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   719
                    raise
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   720
                # File doesn't exist, so the current state is empty
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   721
                return b''
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   722
48059
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   723
        def setparents(self, p1, p2, fold_p2=False):
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   724
            self._parents = (p1, p2)
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   725
            self._dirtyparents = True
48059
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   726
            copies = {}
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   727
            if fold_p2:
48061
060cd909439f dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48060
diff changeset
   728
                # Collect into an intermediate list to avoid a `RuntimeError`
060cd909439f dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48060
diff changeset
   729
                # exception due to mutation during iteration.
060cd909439f dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48060
diff changeset
   730
                # TODO: move this the whole loop to Rust where `iter_mut`
060cd909439f dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48060
diff changeset
   731
                # enables in-place mutation of elements of a collection while
060cd909439f dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48060
diff changeset
   732
                # iterating it, without mutating the collection itself.
060cd909439f dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48060
diff changeset
   733
                candidatefiles = [
060cd909439f dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48060
diff changeset
   734
                    (f, s)
060cd909439f dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48060
diff changeset
   735
                    for f, s in self._rustmap.items()
060cd909439f dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48060
diff changeset
   736
                    if s.merged or s.from_p2
060cd909439f dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48060
diff changeset
   737
                ]
060cd909439f dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48060
diff changeset
   738
                for f, s in candidatefiles:
48059
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   739
                    # Discard "merged" markers when moving away from a merge state
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   740
                    if s.merged:
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   741
                        source = self.copymap.get(f)
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   742
                        if source:
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   743
                            copies[f] = source
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   744
                        self.reset_state(
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   745
                            f,
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   746
                            wc_tracked=True,
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   747
                            p1_tracked=True,
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   748
                            possibly_dirty=True,
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   749
                        )
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   750
                    # Also fix up otherparent markers
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   751
                    elif s.from_p2:
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   752
                        source = self.copymap.get(f)
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   753
                        if source:
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   754
                            copies[f] = source
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   755
                        self.reset_state(
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   756
                            f,
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   757
                            p1_tracked=False,
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   758
                            wc_tracked=True,
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   759
                        )
5d68c4eedd66 dirstate: move parent state handling in the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   760
            return copies
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   761
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   762
        def parents(self):
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   763
            if not self._parents:
47280
1766130fe9ba dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 47277
diff changeset
   764
                if self._use_dirstate_v2:
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   765
                    self._parents = self.docket.parents
47280
1766130fe9ba dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 47277
diff changeset
   766
                else:
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   767
                    read_len = self._nodelen * 2
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   768
                    st = self._readdirstatefile(read_len)
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   769
                    l = len(st)
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   770
                    if l == read_len:
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   771
                        self._parents = (
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   772
                            st[: self._nodelen],
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   773
                            st[self._nodelen : 2 * self._nodelen],
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   774
                        )
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   775
                    elif l == 0:
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   776
                        self._parents = (
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   777
                            self._nodeconstants.nullid,
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   778
                            self._nodeconstants.nullid,
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   779
                        )
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   780
                    else:
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   781
                        raise error.Abort(
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   782
                            _(b'working directory state appears damaged!')
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   783
                        )
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   784
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   785
            return self._parents
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   786
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   787
        @property
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   788
        def docket(self):
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   789
            if not self._docket:
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   790
                if not self._use_dirstate_v2:
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   791
                    raise error.ProgrammingError(
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   792
                        b'dirstate only has a docket in v2 format'
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   793
                    )
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   794
                self._docket = docketmod.DirstateDocket.parse(
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   795
                    self._readdirstatefile(), self._nodeconstants
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   796
                )
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   797
            return self._docket
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   798
47122
9aba0cde0ed9 rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   799
        @propertycache
9aba0cde0ed9 rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   800
        def _rustmap(self):
9aba0cde0ed9 rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   801
            """
9aba0cde0ed9 rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   802
            Fills the Dirstatemap when called.
9aba0cde0ed9 rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   803
            """
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   804
            # ignore HG_PENDING because identity is used only for writing
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   805
            self.identity = util.filestat.frompath(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   806
                self._opener.join(self._filename)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42927
diff changeset
   807
            )
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   808
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   809
            if self._use_dirstate_v2:
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   810
                if self.docket.uuid:
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   811
                    # TODO: use mmap when possible
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   812
                    data = self._opener.read(self.docket.data_filename())
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   813
                else:
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   814
                    data = b''
47675
48aec076b8fb dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47674
diff changeset
   815
                self._rustmap = rustmod.DirstateMap.new_v2(
47682
78f7f0d490ee dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47678
diff changeset
   816
                    data, self.docket.data_size, self.docket.tree_metadata
47675
48aec076b8fb dirstate-v2: Enforce data size read from the docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47674
diff changeset
   817
                )
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   818
                parents = self.docket.parents
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   819
            else:
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   820
                self._rustmap, parents = rustmod.DirstateMap.new_v1(
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   821
                    self._use_dirstate_tree, self._readdirstatefile()
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   822
                )
47122
9aba0cde0ed9 rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   823
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   824
            if parents and not self._dirtyparents:
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   825
                self.setparents(*parents)
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   826
43280
5d4046594d6f rust-dirstatemap: remove additional lookups in dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents: 43274
diff changeset
   827
            self.__contains__ = self._rustmap.__contains__
5d4046594d6f rust-dirstatemap: remove additional lookups in dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents: 43274
diff changeset
   828
            self.__getitem__ = self._rustmap.__getitem__
5d4046594d6f rust-dirstatemap: remove additional lookups in dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents: 43274
diff changeset
   829
            self.get = self._rustmap.get
47122
9aba0cde0ed9 rust: Read dirstate from disk in DirstateMap constructor
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   830
            return self._rustmap
43280
5d4046594d6f rust-dirstatemap: remove additional lookups in dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents: 43274
diff changeset
   831
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   832
        def write(self, tr, st, now):
47678
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   833
            if not self._use_dirstate_v2:
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   834
                p1, p2 = self.parents()
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   835
                packed = self._rustmap.write_v1(p1, p2, now)
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   836
                st.write(packed)
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   837
                st.close()
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   838
                self._dirtyparents = False
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   839
                return
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   840
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   841
            # We can only append to an existing data file if there is one
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   842
            can_append = self.docket.uuid is not None
47682
78f7f0d490ee dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47678
diff changeset
   843
            packed, meta, append = self._rustmap.write_v2(now, can_append)
47678
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   844
            if append:
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   845
                docket = self.docket
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   846
                data_filename = docket.data_filename()
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   847
                if tr:
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   848
                    tr.add(data_filename, docket.data_size)
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   849
                with self._opener(data_filename, b'r+b') as fp:
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   850
                    fp.seek(docket.data_size)
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   851
                    assert fp.tell() == docket.data_size
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   852
                    written = fp.write(packed)
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   853
                    if written is not None:  # py2 may return None
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   854
                        assert written == len(packed), (written, len(packed))
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   855
                docket.data_size += len(packed)
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   856
                docket.parents = self.parents()
47682
78f7f0d490ee dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47678
diff changeset
   857
                docket.tree_metadata = meta
47678
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   858
                st.write(docket.serialize())
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   859
                st.close()
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   860
            else:
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   861
                old_docket = self.docket
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   862
                new_docket = docketmod.DirstateDocket.with_new_uuid(
47682
78f7f0d490ee dirstate-v2: Move fixed-size tree metadata into the docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47678
diff changeset
   863
                    self.parents(), len(packed), meta
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   864
                )
47678
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   865
                data_filename = new_docket.data_filename()
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   866
                if tr:
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   867
                    tr.add(data_filename, 0)
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   868
                self._opener.write(data_filename, packed)
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   869
                # Write the new docket after the new data file has been
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   870
                # written. Because `st` was opened with `atomictemp=True`,
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   871
                # the actual `.hg/dirstate` file is only affected on close.
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   872
                st.write(new_docket.serialize())
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   873
                st.close()
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   874
                # Remove the old data file after the new docket pointing to
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   875
                # the new data file was written.
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   876
                if old_docket.uuid:
47678
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   877
                    data_filename = old_docket.data_filename()
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   878
                    unlink = lambda _tr=None: self._opener.unlink(data_filename)
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   879
                    if tr:
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   880
                        category = b"dirstate-v2-clean-" + old_docket.uuid
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   881
                        tr.addpostclose(category, unlink)
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   882
                    else:
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   883
                        unlink()
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
   884
                self._docket = new_docket
47678
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   885
            # Reload from the newly-written file
065e61628980 dirstate-v2: Support appending to the same data file
Simon Sapin <simon.sapin@octobus.net>
parents: 47675
diff changeset
   886
            util.clearcachedproperty(self, b"_rustmap")
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   887
            self._dirtyparents = False
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   888
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   889
        @propertycache
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   890
        def filefoldmap(self):
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   891
            """Returns a dictionary mapping normalized case paths to their
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   892
            non-normalized versions.
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   893
            """
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   894
            return self._rustmap.filefoldmapasdict()
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   895
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   896
        def hastrackeddir(self, d):
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   897
            return self._rustmap.hastrackeddir(d)
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   898
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   899
        def hasdir(self, d):
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   900
            return self._rustmap.hasdir(d)
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   901
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   902
        @propertycache
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   903
        def identity(self):
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   904
            self._rustmap
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   905
            return self.identity
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   906
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   907
        @propertycache
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   908
        def dirfoldmap(self):
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   909
            f = {}
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   910
            normcase = util.normcase
47683
284a20269a97 dirstate-v2: Separate iterators for dirfoldmap and debugdirstate
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
   911
            for name in self._rustmap.tracked_dirs():
42755
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   912
                f[normcase(name)] = name
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42747
diff changeset
   913
            return f
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   914
47720
b0314d8deee1 dirstate: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47692
diff changeset
   915
        def set_possibly_dirty(self, filename):
b0314d8deee1 dirstate: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47692
diff changeset
   916
            """record that the current state of the file on disk is unknown"""
b0314d8deee1 dirstate: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47692
diff changeset
   917
            entry = self[filename]
b0314d8deee1 dirstate: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47692
diff changeset
   918
            entry.set_possibly_dirty()
48045
32ef647821b2 dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Simon Sapin <simon.sapin@octobus.net>
parents: 48044
diff changeset
   919
            self._rustmap.set_dirstate_item(filename, entry)
47720
b0314d8deee1 dirstate: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47692
diff changeset
   920
47974
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47972
diff changeset
   921
        def set_clean(self, filename, 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: 47972
diff changeset
   922
            """mark a file as back to a clean state"""
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47972
diff changeset
   923
            entry = self[filename]
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47972
diff changeset
   924
            mtime = mtime & rangemask
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47972
diff changeset
   925
            size = size & rangemask
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47972
diff changeset
   926
            entry.set_clean(mode, size, mtime)
48045
32ef647821b2 dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Simon Sapin <simon.sapin@octobus.net>
parents: 48044
diff changeset
   927
            self._rustmap.set_dirstate_item(filename, entry)
47974
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47972
diff changeset
   928
            self._rustmap.copymap().pop(filename, None)
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47972
diff changeset
   929
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   930
        def __setitem__(self, key, value):
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47689
diff changeset
   931
            assert isinstance(value, DirstateItem)
48045
32ef647821b2 dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Simon Sapin <simon.sapin@octobus.net>
parents: 48044
diff changeset
   932
            self._rustmap.set_dirstate_item(key, value)