annotate mercurial/dirstatemap.py @ 48139:ced8cf9c4905

dirstatemap: use a common implementation for `dirstatemap.set_untracked` We can now make sure they use the same code, and drop the older, out of sync, implementation of `set_untracked` for the rust wrapper. Differential Revision: https://phab.mercurial-scm.org/D11572
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 01 Oct 2021 19:14:09 +0200
parents a1a6569b9283
children a8ff00ad290b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47506
8b7e47802deb dirstate: split dirstatemap in its own file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47494
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,
32411
df448de7cf3b parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents: 32391
diff changeset
15 policy,
30317
ba2c04059317 py3: use pycompat.ossep at certain places
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30224
diff changeset
16 pycompat,
31070
206532700213 txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30639
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
43554
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43553
diff changeset
25 parsers = policy.importmod('parsers')
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43553
diff changeset
26 rustmod = policy.importrust('dirstate')
32411
df448de7cf3b parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents: 32391
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
48059
d5528ac9b4f2 dirstate: Use the Rust implementation of DirstateItem when Rust is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 48046
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: 48046
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: 48046
diff changeset
32 else:
d5528ac9b4f2 dirstate: Use the Rust implementation of DirstateItem when Rust is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 48046
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
47487
cb29484eaade dirstate: introduce a symbolic constant for the FROM_P2 marker
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47486
diff changeset
37
48131
aec5b0981c26 dirstatemap: introduce a common base for the dirstatemap class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48121
diff changeset
38 class _dirstatemapcommon(object):
aec5b0981c26 dirstatemap: introduce a common base for the dirstatemap class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48121
diff changeset
39 """
aec5b0981c26 dirstatemap: introduce a common base for the dirstatemap class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48121
diff changeset
40 Methods that are identical for both implementations of the dirstatemap
aec5b0981c26 dirstatemap: introduce a common base for the dirstatemap class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48121
diff changeset
41 class, with and without Rust extensions enabled.
aec5b0981c26 dirstatemap: introduce a common base for the dirstatemap class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48121
diff changeset
42 """
aec5b0981c26 dirstatemap: introduce a common base for the dirstatemap class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48121
diff changeset
43
48134
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
44 # please pytype
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
45
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
46 _map = None
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
47 copymap = None
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
48
48132
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
49 def __init__(self, ui, opener, root, nodeconstants, use_dirstate_v2):
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
50 self._use_dirstate_v2 = use_dirstate_v2
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
51 self._nodeconstants = nodeconstants
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
52 self._ui = ui
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
53 self._opener = opener
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
54 self._root = root
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
55 self._filename = b'dirstate'
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
56 self._nodelen = 20 # Also update Rust code when changing this!
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
57 self._parents = None
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
58 self._dirtyparents = False
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
59
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
60 # for consistent view between _pl() and _read() invocations
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
61 self._pendingmode = None
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
62
48134
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
63 def preload(self):
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
64 """Loads the underlying data, if it's not already loaded"""
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
65 self._map
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
66
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
67 def get(self, key, default=None):
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
68 return self._map.get(key, default)
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
69
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
70 def __len__(self):
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
71 return len(self._map)
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
72
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
73 def __iter__(self):
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
74 return iter(self._map)
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
75
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
76 def __contains__(self, key):
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
77 return key in self._map
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
78
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
79 def __getitem__(self, item):
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
80 return self._map[item]
bbd924a36a6e dirstatemap: move a multiple simple functions in the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48133
diff changeset
81
48137
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
82 ### sub-class utility method
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
83 #
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
84 # Use to allow for generic implementation of some method while still coping
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
85 # with minor difference between implementation.
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
86
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
87 def _dirs_incr(self, filename, old_entry=None):
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
88 """incremente the dirstate counter if applicable
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
89
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
90 This might be a no-op for some subclass who deal with directory
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
91 tracking in a different way.
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
92 """
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
93
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
94 def _dirs_decr(self, filename, old_entry=None, remove_variant=False):
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
95 """decremente the dirstate counter if applicable
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
96
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
97 This might be a no-op for some subclass who deal with directory
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
98 tracking in a different way.
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
99 """
de793f249852 dirstatemap: create `_dirs_incr/_dirs_decr` methods on the common class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48136
diff changeset
100
48138
a1a6569b9283 dirstatemap: add a common `_refresh_entry` method for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48137
diff changeset
101 def _refresh_entry(self, f, entry):
a1a6569b9283 dirstatemap: add a common `_refresh_entry` method for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48137
diff changeset
102 """record updated state of an entry"""
a1a6569b9283 dirstatemap: add a common `_refresh_entry` method for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48137
diff changeset
103
48139
ced8cf9c4905 dirstatemap: use a common implementation for `dirstatemap.set_untracked`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
104 ### method to manipulate the entries
ced8cf9c4905 dirstatemap: use a common implementation for `dirstatemap.set_untracked`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
105
ced8cf9c4905 dirstatemap: use a common implementation for `dirstatemap.set_untracked`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
106 def set_untracked(self, f):
ced8cf9c4905 dirstatemap: use a common implementation for `dirstatemap.set_untracked`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
107 """Mark a file as no longer tracked in the dirstate map"""
ced8cf9c4905 dirstatemap: use a common implementation for `dirstatemap.set_untracked`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
108 entry = self.get(f)
ced8cf9c4905 dirstatemap: use a common implementation for `dirstatemap.set_untracked`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
109 if entry is None:
ced8cf9c4905 dirstatemap: use a common implementation for `dirstatemap.set_untracked`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
110 return False
ced8cf9c4905 dirstatemap: use a common implementation for `dirstatemap.set_untracked`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
111 else:
ced8cf9c4905 dirstatemap: use a common implementation for `dirstatemap.set_untracked`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
112 self._dirs_decr(f, old_entry=entry, remove_variant=not entry.added)
ced8cf9c4905 dirstatemap: use a common implementation for `dirstatemap.set_untracked`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
113 if not entry.merged:
ced8cf9c4905 dirstatemap: use a common implementation for `dirstatemap.set_untracked`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
114 self.copymap.pop(f, None)
ced8cf9c4905 dirstatemap: use a common implementation for `dirstatemap.set_untracked`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
115 entry.set_untracked()
ced8cf9c4905 dirstatemap: use a common implementation for `dirstatemap.set_untracked`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
116 self._refresh_entry(f, entry)
ced8cf9c4905 dirstatemap: use a common implementation for `dirstatemap.set_untracked`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
117 return True
ced8cf9c4905 dirstatemap: use a common implementation for `dirstatemap.set_untracked`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48138
diff changeset
118
48131
aec5b0981c26 dirstatemap: introduce a common base for the dirstatemap class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48121
diff changeset
119
aec5b0981c26 dirstatemap: introduce a common base for the dirstatemap class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48121
diff changeset
120 class dirstatemap(_dirstatemapcommon):
35101
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
121 """Map encapsulating the dirstate's contents.
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
122
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
123 The dirstate contains the following state:
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
124
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
125 - `identity` is the identity of the dirstate file, which can be used to
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
126 detect when changes have occurred to the dirstate file.
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
127
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
128 - `parents` is a pair containing the parents of the working copy. The
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
129 parents are updated by calling `setparents`.
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
130
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
131 - the state map maps filenames to tuples of (state, mode, size, mtime),
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
132 where state is a single character representing 'normal', 'added',
35102
853b7c41d19c dirstate: add explicit methods for modifying dirstate
Mark Thomas <mbthomas@fb.com>
parents: 35101
diff changeset
133 'removed', or 'merged'. It is read by treating the dirstate as a
48020
aa442fde0ea5 dirstate: update the documentation of the dirstatemap API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48014
diff changeset
134 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: 48014
diff changeset
135 documentation for details):
aa442fde0ea5 dirstate: update the documentation of the dirstatemap API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48014
diff changeset
136
aa442fde0ea5 dirstate: update the documentation of the dirstatemap API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48014
diff changeset
137 - `reset_state`,
aa442fde0ea5 dirstate: update the documentation of the dirstatemap API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48014
diff changeset
138 - `set_tracked`
aa442fde0ea5 dirstate: update the documentation of the dirstatemap API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48014
diff changeset
139 - `set_untracked`
aa442fde0ea5 dirstate: update the documentation of the dirstatemap API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48014
diff changeset
140 - `set_clean`
aa442fde0ea5 dirstate: update the documentation of the dirstatemap API
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48014
diff changeset
141 - `set_possibly_dirty`
35101
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
142
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
143 - `copymap` maps destination filenames to their source filename.
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
144
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
145 The dirstate also provides the following views onto the state:
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
146
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
147 - `filefoldmap` is a dict mapping normalized filenames to the denormalized
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
148 form that they appear as in the dirstate.
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
149
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
150 - `dirfoldmap` is a dict mapping normalized directory names to the
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
151 denormalized form that they appear as in the dirstate.
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
152 """
a052022639cc dirstate: document dirstatemap interface
Mark Thomas <mbthomas@fb.com>
parents: 35055
diff changeset
153
47291
1766130fe9ba dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 47288
diff changeset
154 def __init__(self, ui, opener, root, nodeconstants, use_dirstate_v2):
48132
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
155 super(dirstatemap, self).__init__(
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
156 ui, opener, root, nodeconstants, use_dirstate_v2
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
157 )
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
158 if self._use_dirstate_v2:
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
159 msg = "Dirstate V2 not supportedi"
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
160 msg += "(should have detected unsupported requirement)"
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
161 raise error.ProgrammingError(msg)
34344
c36c3fa7d35b dirstate: move opendirstatefile to dirstatemap
Durham Goode <durham@fb.com>
parents: 34343
diff changeset
162
48135
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
163 ### Core data storage and access
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
164
34934
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
165 @propertycache
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
166 def _map(self):
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
167 self._map = {}
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
168 self.read()
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
169 return self._map
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
170
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
171 @propertycache
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
172 def copymap(self):
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
173 self.copymap = {}
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
174 self._map
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
175 return self.copymap
6e66033f91cc dirstate: avoid reading the map when possible (issue5713) (issue5717)
Durham Goode <durham@fb.com>
parents: 34933
diff changeset
176
34933
0217f75b6e59 dirstate: move clear onto dirstatemap class
Durham Goode <durham@fb.com>
parents: 34678
diff changeset
177 def clear(self):
34935
ffeea2406276 dirstate: remove excess attribute lookups for dirstate.status (issue5714)
Durham Goode <durham@fb.com>
parents: 34934
diff changeset
178 self._map.clear()
ffeea2406276 dirstate: remove excess attribute lookups for dirstate.status (issue5714)
Durham Goode <durham@fb.com>
parents: 34934
diff changeset
179 self.copymap.clear()
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
180 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
181 util.clearcachedproperty(self, b"_dirs")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
182 util.clearcachedproperty(self, b"_alldirs")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
183 util.clearcachedproperty(self, b"filefoldmap")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
184 util.clearcachedproperty(self, b"dirfoldmap")
34933
0217f75b6e59 dirstate: move clear onto dirstatemap class
Durham Goode <durham@fb.com>
parents: 34678
diff changeset
185
35918
6e7fae8f1c6c contrib: fix dirstatenonnormalcheck to work in Python 3
Augie Fackler <augie@google.com>
parents: 35875
diff changeset
186 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
187 return pycompat.iteritems(self._map)
34339
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34200
diff changeset
188
35918
6e7fae8f1c6c contrib: fix dirstatenonnormalcheck to work in Python 3
Augie Fackler <augie@google.com>
parents: 35875
diff changeset
189 # forward for python2,3 compat
6e7fae8f1c6c contrib: fix dirstatenonnormalcheck to work in Python 3
Augie Fackler <augie@google.com>
parents: 35875
diff changeset
190 iteritems = items
6e7fae8f1c6c contrib: fix dirstatenonnormalcheck to work in Python 3
Augie Fackler <augie@google.com>
parents: 35875
diff changeset
191
48045
357307feaf61 debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents: 48041
diff changeset
192 def debug_iter(self, all):
357307feaf61 debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents: 48041
diff changeset
193 """
48046
cedfe2606adf debugsate: Change debug_iter() to yield tuples instead of DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48045
diff changeset
194 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: 48045
diff changeset
195
48045
357307feaf61 debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents: 48041
diff changeset
196 `all` is unused when Rust is not enabled
357307feaf61 debugstate: Always call dirstatemap.debug_iter()
Simon Sapin <simon.sapin@octobus.net>
parents: 48041
diff changeset
197 """
48046
cedfe2606adf debugsate: Change debug_iter() to yield tuples instead of DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48045
diff changeset
198 for (filename, item) in self.items():
cedfe2606adf debugsate: Change debug_iter() to yield tuples instead of DirstateItem
Simon Sapin <simon.sapin@octobus.net>
parents: 48045
diff changeset
199 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
200
34339
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34200
diff changeset
201 def keys(self):
b36881c68569 dirstate: create new dirstatemap class
Durham Goode <durham@fb.com>
parents: 34200
diff changeset
202 return self._map.keys()
34340
4ac04418ce66 dirstate: move nonnormalentries to dirstatemap
Durham Goode <durham@fb.com>
parents: 34339
diff changeset
203
48135
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
204 ### reading/setting parents
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
205
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
206 def parents(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
207 if not self._parents:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
208 try:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
209 fp = self._opendirstatefile()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
210 st = fp.read(2 * self._nodelen)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
211 fp.close()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
212 except IOError as err:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
213 if err.errno != errno.ENOENT:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
214 raise
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
215 # File doesn't exist, so the current state is empty
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
216 st = b''
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
217
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
218 l = len(st)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
219 if l == self._nodelen * 2:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
220 self._parents = (
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
221 st[: self._nodelen],
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
222 st[self._nodelen : 2 * self._nodelen],
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
223 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
224 elif l == 0:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
225 self._parents = (
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
226 self._nodeconstants.nullid,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
227 self._nodeconstants.nullid,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
228 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
229 else:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
230 raise error.Abort(
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
231 _(b'working directory state appears damaged!')
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
232 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
233
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
234 return self._parents
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
235
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
236 def setparents(self, p1, p2, fold_p2=False):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
237 self._parents = (p1, p2)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
238 self._dirtyparents = True
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
239 copies = {}
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
240 if fold_p2:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
241 for f, s in pycompat.iteritems(self._map):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
242 # Discard "merged" markers when moving away from a merge state
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
243 if s.merged or s.from_p2:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
244 source = self.copymap.pop(f, None)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
245 if source:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
246 copies[f] = source
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
247 s.drop_merge_data()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
248 return copies
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
249
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
250 ### disk interaction
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
251
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
252 def read(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
253 # ignore HG_PENDING because identity is used only for writing
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
254 self.identity = util.filestat.frompath(
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
255 self._opener.join(self._filename)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
256 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
257
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
258 try:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
259 fp = self._opendirstatefile()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
260 try:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
261 st = fp.read()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
262 finally:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
263 fp.close()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
264 except IOError as err:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
265 if err.errno != errno.ENOENT:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
266 raise
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
267 return
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
268 if not st:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
269 return
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
270
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
271 if util.safehasattr(parsers, b'dict_new_presized'):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
272 # Make an estimate of the number of files in the dirstate based on
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
273 # its size. This trades wasting some memory for avoiding costly
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
274 # resizes. Each entry have a prefix of 17 bytes followed by one or
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
275 # two path names. Studies on various large-scale real-world repositories
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
276 # found 54 bytes a reasonable upper limit for the average path names.
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
277 # Copy entries are ignored for the sake of this estimate.
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
278 self._map = parsers.dict_new_presized(len(st) // 71)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
279
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
280 # Python's garbage collector triggers a GC each time a certain number
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
281 # of container objects (the number being defined by
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
282 # gc.get_threshold()) are allocated. parse_dirstate creates a tuple
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
283 # for each file in the dirstate. The C version then immediately marks
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
284 # them as not to be tracked by the collector. However, this has no
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
285 # effect on when GCs are triggered, only on what objects the GC looks
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
286 # into. This means that O(number of files) GCs are unavoidable.
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
287 # Depending on when in the process's lifetime the dirstate is parsed,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
288 # this can get very expensive. As a workaround, disable GC while
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
289 # parsing the dirstate.
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
290 #
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
291 # (we cannot decorate the function directly since it is in a C module)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
292 parse_dirstate = util.nogc(parsers.parse_dirstate)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
293 p = parse_dirstate(self._map, self.copymap, st)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
294 if not self._dirtyparents:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
295 self.setparents(*p)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
296
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
297 # Avoid excess attribute lookups by fast pathing certain checks
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
298 self.__contains__ = self._map.__contains__
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
299 self.__getitem__ = self._map.__getitem__
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
300 self.get = self._map.get
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
301
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
302 def write(self, _tr, st, now):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
303 d = parsers.pack_dirstate(self._map, self.copymap, self.parents(), now)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
304 st.write(d)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
305 st.close()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
306 self._dirtyparents = False
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
307
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
308 def _opendirstatefile(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
309 fp, mode = txnutil.trypending(self._root, self._opener, self._filename)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
310 if self._pendingmode is not None and self._pendingmode != mode:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
311 fp.close()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
312 raise error.Abort(
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
313 _(b'working directory state may be changed parallelly')
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
314 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
315 self._pendingmode = mode
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
316 return fp
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
317
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
318 @propertycache
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
319 def identity(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
320 self._map
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
321 return self.identity
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
322
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
323 ### code related to maintaining and accessing "extra" property
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
324 # (e.g. "has_dir")
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
325
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
326 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
327 """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
328 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
329 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
330 ) 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
331 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
332 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
333 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
334
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
335 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
336 """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
337 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
338 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
339 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
340 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
341 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
342 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
343 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
344 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
345 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
346 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
347
48135
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
348 @propertycache
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
349 def filefoldmap(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
350 """Returns a dictionary mapping normalized case paths to their
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
351 non-normalized versions.
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
352 """
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
353 try:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
354 makefilefoldmap = parsers.make_file_foldmap
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
355 except AttributeError:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
356 pass
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
357 else:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
358 return makefilefoldmap(
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
359 self._map, util.normcasespec, util.normcasefallback
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
360 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
361
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
362 f = {}
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
363 normcase = util.normcase
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
364 for name, s in pycompat.iteritems(self._map):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
365 if not s.removed:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
366 f[normcase(name)] = name
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
367 f[b'.'] = b'.' # prevents useless util.fspath() invocation
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
368 return f
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
369
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
370 @propertycache
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
371 def dirfoldmap(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
372 f = {}
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
373 normcase = util.normcase
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
374 for name in self._dirs:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
375 f[normcase(name)] = name
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
376 return f
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
377
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
378 def hastrackeddir(self, d):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
379 """
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
380 Returns True if the dirstate contains a tracked (not removed) file
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
381 in this directory.
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
382 """
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
383 return d in self._dirs
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
384
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
385 def hasdir(self, d):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
386 """
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
387 Returns True if the dirstate contains a file (tracked or removed)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
388 in this directory.
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
389 """
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
390 return d in self._alldirs
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
391
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
392 @propertycache
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
393 def _dirs(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
394 return pathutil.dirs(self._map, only_tracked=True)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
395
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
396 @propertycache
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
397 def _alldirs(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
398 return pathutil.dirs(self._map)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
399
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
400 ### code related to manipulation of entries and copy-sources
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
401
48138
a1a6569b9283 dirstatemap: add a common `_refresh_entry` method for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48137
diff changeset
402 def _refresh_entry(self, f, entry):
a1a6569b9283 dirstatemap: add a common `_refresh_entry` method for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48137
diff changeset
403 if not entry.any_tracked:
a1a6569b9283 dirstatemap: add a common `_refresh_entry` method for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48137
diff changeset
404 self._map.pop(f, None)
a1a6569b9283 dirstatemap: add a common `_refresh_entry` method for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48137
diff changeset
405
47720
b0314d8deee1 dirstate: add a `set_possibly_dirty` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47692
diff changeset
406 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
407 """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
408 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
409
48002
4e6f27230aee dirstate: introduce a `set_clean` method on dirstate's map and items
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48000
diff changeset
410 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: 48000
diff changeset
411 """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: 48000
diff changeset
412 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: 48000
diff changeset
413 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: 48000
diff changeset
414 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: 48000
diff changeset
415 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: 48000
diff changeset
416 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: 48000
diff changeset
417
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
418 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
419 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
420 filename,
48022
938a7769050c dirstate: support file tracked nowhere in `reset_state`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48021
diff changeset
421 wc_tracked=False,
938a7769050c dirstate: support file tracked nowhere in `reset_state`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48021
diff changeset
422 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
423 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
424 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
425 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
426 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
427 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
428 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
429 ):
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
430 """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
431
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
432 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
433 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
434
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
435 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
436 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
437 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
438 """
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
439 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
440 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
441 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
442 # 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
443 # (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
444 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
445
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
446 if not (p1_tracked or p2_tracked or wc_tracked):
48022
938a7769050c dirstate: support file tracked nowhere in `reset_state`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48021
diff changeset
447 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: 48021
diff changeset
448 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: 48021
diff changeset
449 self.copymap.pop(filename, None)
47927
d5b54917eb92 dirstatemap: temporarily return early in `reset_state`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47925
diff changeset
450 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
451 elif merged:
48121
2c2788ce0257 dirstate: remove a update_file's special case for `merged` file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48120
diff changeset
452 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
453 elif not (p1_tracked or p2_tracked) and wc_tracked:
47934
6816ae362ddd dirstatemap: use the default code to handle "added" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47933
diff changeset
454 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
455 elif (p1_tracked or p2_tracked) and not wc_tracked:
47933
4cade5e944c2 dirstatemap: use the default code to handle "removed" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47932
diff changeset
456 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
457 elif clean_p2 and wc_tracked:
48120
d4e715d2be0b dirstate: remove a update_file's special case for tracked file with p2 data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48083
diff changeset
458 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
459 elif not p1_tracked and p2_tracked and wc_tracked:
47931
40cf4b278f8f dirstatemap: use the default code to handle "p2-tracked" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47930
diff changeset
460 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
461 elif possibly_dirty:
47930
625b6ddb828c dirstatemap: use the default code to handle "possibly_dirty" case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47929
diff changeset
462 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
463 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
464 # 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
465 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
466 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
467 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
468 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
469 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
470 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
471
47928
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47927
diff changeset
472 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: 47927
diff changeset
473 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: 47927
diff changeset
474 entry = DirstateItem(
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47927
diff changeset
475 wc_tracked=wc_tracked,
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47927
diff changeset
476 p1_tracked=p1_tracked,
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47927
diff changeset
477 p2_tracked=p2_tracked,
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47927
diff changeset
478 merged=merged,
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47927
diff changeset
479 clean_p1=clean_p1,
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47927
diff changeset
480 clean_p2=clean_p2,
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47927
diff changeset
481 possibly_dirty=possibly_dirty,
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47927
diff changeset
482 parentfiledata=parentfiledata,
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47927
diff changeset
483 )
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47927
diff changeset
484 self._map[filename] = entry
4f0ebf83e4dc dirstatemap: conclude `reset_state` with logic using the new __init__
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47927
diff changeset
485
48014
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
486 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: 48007
diff changeset
487 new = False
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
488 entry = self.get(filename)
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
489 if entry is None:
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
490 self._dirs_incr(filename)
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
491 entry = DirstateItem(
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
492 p1_tracked=False,
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
493 p2_tracked=False,
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
494 wc_tracked=True,
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
495 merged=False,
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
496 clean_p1=False,
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
497 clean_p2=False,
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
498 possibly_dirty=False,
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
499 parentfiledata=None,
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
500 )
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
501 self._map[filename] = entry
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
502 new = True
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
503 elif not entry.tracked:
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
504 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: 48007
diff changeset
505 entry.set_tracked()
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
506 new = True
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
507 else:
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
508 # 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: 48007
diff changeset
509 # 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: 48007
diff changeset
510 # 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: 48007
diff changeset
511 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: 48007
diff changeset
512 return new
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
513
42771
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42763
diff changeset
514
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42763
diff changeset
515 if rustmod is not None:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42931
diff changeset
516
48131
aec5b0981c26 dirstatemap: introduce a common base for the dirstatemap class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48121
diff changeset
517 class dirstatemap(_dirstatemapcommon):
47291
1766130fe9ba dirstate-v2: Change the on-disk format when the requirement is enabled
Simon Sapin <simon.sapin@octobus.net>
parents: 47288
diff changeset
518 def __init__(self, ui, opener, root, nodeconstants, use_dirstate_v2):
48132
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
519 super(dirstatemap, self).__init__(
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
520 ui, opener, root, nodeconstants, use_dirstate_v2
fe6617715464 dirstatemap: use a common __init__ for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48131
diff changeset
521 )
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47672
diff changeset
522 self._docket = None
42771
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42763
diff changeset
523
48135
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
524 ### Core data storage and access
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
525
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
526 @property
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
527 def docket(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
528 if not self._docket:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
529 if not self._use_dirstate_v2:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
530 raise error.ProgrammingError(
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
531 b'dirstate only has a docket in v2 format'
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
532 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
533 self._docket = docketmod.DirstateDocket.parse(
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
534 self._readdirstatefile(), self._nodeconstants
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
535 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
536 return self._docket
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
537
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
538 @propertycache
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
539 def _map(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
540 """
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
541 Fills the Dirstatemap when called.
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
542 """
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
543 # ignore HG_PENDING because identity is used only for writing
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
544 self.identity = util.filestat.frompath(
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
545 self._opener.join(self._filename)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
546 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
547
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
548 if self._use_dirstate_v2:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
549 if self.docket.uuid:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
550 # TODO: use mmap when possible
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
551 data = self._opener.read(self.docket.data_filename())
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
552 else:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
553 data = b''
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
554 self._map = rustmod.DirstateMap.new_v2(
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
555 data, self.docket.data_size, self.docket.tree_metadata
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
556 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
557 parents = self.docket.parents
48066
98c0408324e6 dirstate: Pass the final DirstateItem to _rustmap.addfile()
Simon Sapin <simon.sapin@octobus.net>
parents: 48065
diff changeset
558 else:
48135
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
559 self._map, parents = rustmod.DirstateMap.new_v1(
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
560 self._readdirstatefile()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
561 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
562
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
563 if parents and not self._dirtyparents:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
564 self.setparents(*parents)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
565
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
566 self.__contains__ = self._map.__contains__
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
567 self.__getitem__ = self._map.__getitem__
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
568 self.get = self._map.get
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
569 return self._map
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
570
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
571 @property
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
572 def copymap(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
573 return self._map.copymap()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
574
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
575 def debug_iter(self, all):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
576 """
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
577 Return an iterator of (filename, state, mode, size, mtime) tuples
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
578
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
579 `all`: also include with `state == b' '` dirstate tree nodes that
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
580 don't have an associated `DirstateItem`.
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
581
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
582 """
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
583 return self._map.debug_iter(all)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
584
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
585 def clear(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
586 self._map.clear()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
587 self.setparents(
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
588 self._nodeconstants.nullid, self._nodeconstants.nullid
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
589 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
590 util.clearcachedproperty(self, b"_dirs")
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
591 util.clearcachedproperty(self, b"_alldirs")
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
592 util.clearcachedproperty(self, b"dirfoldmap")
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
593
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
594 def items(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
595 return self._map.items()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
596
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
597 # forward for python2,3 compat
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
598 iteritems = items
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
599
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
600 def keys(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
601 return iter(self._map)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
602
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
603 ### reading/setting parents
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
604
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
605 def setparents(self, p1, p2, fold_p2=False):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
606 self._parents = (p1, p2)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
607 self._dirtyparents = True
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
608 copies = {}
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
609 if fold_p2:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
610 # Collect into an intermediate list to avoid a `RuntimeError`
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
611 # exception due to mutation during iteration.
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
612 # TODO: move this the whole loop to Rust where `iter_mut`
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
613 # enables in-place mutation of elements of a collection while
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
614 # iterating it, without mutating the collection itself.
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
615 candidatefiles = [
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
616 (f, s)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
617 for f, s in self._map.items()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
618 if s.merged or s.from_p2
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
619 ]
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
620 for f, s in candidatefiles:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
621 # Discard "merged" markers when moving away from a merge state
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
622 if s.merged:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
623 source = self.copymap.get(f)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
624 if source:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
625 copies[f] = source
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
626 self.reset_state(
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
627 f,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
628 wc_tracked=True,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
629 p1_tracked=True,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
630 possibly_dirty=True,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
631 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
632 # Also fix up otherparent markers
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
633 elif s.from_p2:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
634 source = self.copymap.get(f)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
635 if source:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
636 copies[f] = source
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
637 self.reset_state(
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
638 f,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
639 p1_tracked=False,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
640 wc_tracked=True,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
641 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
642 return copies
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
643
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
644 def parents(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
645 if not self._parents:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
646 if self._use_dirstate_v2:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
647 self._parents = self.docket.parents
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
648 else:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
649 read_len = self._nodelen * 2
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
650 st = self._readdirstatefile(read_len)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
651 l = len(st)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
652 if l == read_len:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
653 self._parents = (
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
654 st[: self._nodelen],
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
655 st[self._nodelen : 2 * self._nodelen],
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
656 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
657 elif l == 0:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
658 self._parents = (
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
659 self._nodeconstants.nullid,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
660 self._nodeconstants.nullid,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
661 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
662 else:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
663 raise error.Abort(
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
664 _(b'working directory state appears damaged!')
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
665 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
666
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
667 return self._parents
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
668
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
669 ### disk interaction
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
670
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
671 @propertycache
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
672 def identity(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
673 self._map
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
674 return self.identity
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
675
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
676 def write(self, tr, st, now):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
677 if not self._use_dirstate_v2:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
678 p1, p2 = self.parents()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
679 packed = self._map.write_v1(p1, p2, now)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
680 st.write(packed)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
681 st.close()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
682 self._dirtyparents = False
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
683 return
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
684
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
685 # We can only append to an existing data file if there is one
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
686 can_append = self.docket.uuid is not None
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
687 packed, meta, append = self._map.write_v2(now, can_append)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
688 if append:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
689 docket = self.docket
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
690 data_filename = docket.data_filename()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
691 if tr:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
692 tr.add(data_filename, docket.data_size)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
693 with self._opener(data_filename, b'r+b') as fp:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
694 fp.seek(docket.data_size)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
695 assert fp.tell() == docket.data_size
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
696 written = fp.write(packed)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
697 if written is not None: # py2 may return None
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
698 assert written == len(packed), (written, len(packed))
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
699 docket.data_size += len(packed)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
700 docket.parents = self.parents()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
701 docket.tree_metadata = meta
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
702 st.write(docket.serialize())
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
703 st.close()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
704 else:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
705 old_docket = self.docket
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
706 new_docket = docketmod.DirstateDocket.with_new_uuid(
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
707 self.parents(), len(packed), meta
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
708 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
709 data_filename = new_docket.data_filename()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
710 if tr:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
711 tr.add(data_filename, 0)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
712 self._opener.write(data_filename, packed)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
713 # Write the new docket after the new data file has been
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
714 # written. Because `st` was opened with `atomictemp=True`,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
715 # the actual `.hg/dirstate` file is only affected on close.
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
716 st.write(new_docket.serialize())
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
717 st.close()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
718 # Remove the old data file after the new docket pointing to
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
719 # the new data file was written.
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
720 if old_docket.uuid:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
721 data_filename = old_docket.data_filename()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
722 unlink = lambda _tr=None: self._opener.unlink(data_filename)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
723 if tr:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
724 category = b"dirstate-v2-clean-" + old_docket.uuid
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
725 tr.addpostclose(category, unlink)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
726 else:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
727 unlink()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
728 self._docket = new_docket
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
729 # Reload from the newly-written file
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
730 util.clearcachedproperty(self, b"_map")
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
731 self._dirtyparents = False
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
732
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
733 def _opendirstatefile(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
734 fp, mode = txnutil.trypending(
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
735 self._root, self._opener, self._filename
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
736 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
737 if self._pendingmode is not None and self._pendingmode != mode:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
738 fp.close()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
739 raise error.Abort(
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
740 _(b'working directory state may be changed parallelly')
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
741 )
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
742 self._pendingmode = mode
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
743 return fp
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
744
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
745 def _readdirstatefile(self, size=-1):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
746 try:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
747 with self._opendirstatefile() as fp:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
748 return fp.read(size)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
749 except IOError as err:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
750 if err.errno != errno.ENOENT:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
751 raise
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
752 # File doesn't exist, so the current state is empty
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
753 return b''
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
754
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
755 ### code related to maintaining and accessing "extra" property
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
756 # (e.g. "has_dir")
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
757
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
758 @propertycache
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
759 def filefoldmap(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
760 """Returns a dictionary mapping normalized case paths to their
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
761 non-normalized versions.
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
762 """
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
763 return self._map.filefoldmapasdict()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
764
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
765 def hastrackeddir(self, d):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
766 return self._map.hastrackeddir(d)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
767
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
768 def hasdir(self, d):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
769 return self._map.hasdir(d)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
770
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
771 @propertycache
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
772 def dirfoldmap(self):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
773 f = {}
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
774 normcase = util.normcase
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
775 for name in self._map.tracked_dirs():
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
776 f[normcase(name)] = name
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
777 return f
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
778
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
779 ### code related to manipulation of entries and copy-sources
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
780
48138
a1a6569b9283 dirstatemap: add a common `_refresh_entry` method for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48137
diff changeset
781 def _refresh_entry(self, f, entry):
a1a6569b9283 dirstatemap: add a common `_refresh_entry` method for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48137
diff changeset
782 if not entry.any_tracked:
a1a6569b9283 dirstatemap: add a common `_refresh_entry` method for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48137
diff changeset
783 self._map.drop_item_and_copy_source(f)
a1a6569b9283 dirstatemap: add a common `_refresh_entry` method for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48137
diff changeset
784 else:
a1a6569b9283 dirstatemap: add a common `_refresh_entry` method for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48137
diff changeset
785 self._map.addfile(f, entry)
a1a6569b9283 dirstatemap: add a common `_refresh_entry` method for dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48137
diff changeset
786
48135
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
787 def set_possibly_dirty(self, filename):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
788 """record that the current state of the file on disk is unknown"""
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
789 entry = self[filename]
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
790 entry.set_possibly_dirty()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
791 self._map.set_dirstate_item(filename, entry)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
792
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
793 def set_clean(self, filename, mode, size, mtime):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
794 """mark a file as back to a clean state"""
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
795 entry = self[filename]
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
796 mtime = mtime & rangemask
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
797 size = size & rangemask
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
798 entry.set_clean(mode, size, mtime)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
799 self._map.set_dirstate_item(filename, entry)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
800 self._map.copymap().pop(filename, None)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
801
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
802 def __setitem__(self, key, value):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
803 assert isinstance(value, DirstateItem)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
804 self._map.set_dirstate_item(key, value)
42771
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42763
diff changeset
805
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
806 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
807 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
808 filename,
48022
938a7769050c dirstate: support file tracked nowhere in `reset_state`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48021
diff changeset
809 wc_tracked=False,
938a7769050c dirstate: support file tracked nowhere in `reset_state`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48021
diff changeset
810 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
811 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
812 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
813 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
814 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
815 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
816 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
817 ):
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
818 """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
819
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
820 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
821 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
822
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
823 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
824 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
825 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
826 """
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
827 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
828 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
829 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
830 )
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
831 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
832 # 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
833 # (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
834 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
835
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
836 if not (p1_tracked or p2_tracked or wc_tracked):
48133
5fc2dfb073d6 dirstatemap: rename `_rustmap` to `_map`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48132
diff changeset
837 self._map.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
838 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
839 # 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
840 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
841 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
842 # 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
843 # 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
844 # 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
845 # 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
846 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
847 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
848 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
849 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
850 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
851 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
852 )
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
853 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
854 # XXX might be merged and removed ?
47925
226c7dbeea11 rust-dirstatemap: temporarily use `from_v1_data` in `addfile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47924
diff changeset
855 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
856 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
857 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
858 # 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
859 # `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
860 # 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
861 #
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
862 # 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
863 # 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
864 # 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
865 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
866 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
867 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
868 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
869 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
870 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
871 )
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
872 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
873 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
874 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
875 # 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
876 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
877 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
878 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
879 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
880 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
881 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
882 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
883 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
884
48014
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
885 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: 48007
diff changeset
886 new = False
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
887 entry = self.get(filename)
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
888 if entry is None:
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
889 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: 48007
diff changeset
890 new = True
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
891 elif not entry.tracked:
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
892 entry.set_tracked()
48133
5fc2dfb073d6 dirstatemap: rename `_rustmap` to `_map`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48132
diff changeset
893 self._map.set_dirstate_item(filename, entry)
48014
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
894 new = True
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
895 else:
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
896 # 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: 48007
diff changeset
897 # 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: 48007
diff changeset
898 # 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: 48007
diff changeset
899 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: 48007
diff changeset
900 return new
0d2a404f1932 dirstate: introduce a set_tracked method on "map" and "item"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48007
diff changeset
901
48135
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
902 ### Legacy method we need to get rid of
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
903
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
904 def addfile(
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
905 self,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
906 f,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
907 mode=0,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
908 size=None,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
909 mtime=None,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
910 added=False,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
911 merged=False,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
912 from_p2=False,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
913 possibly_dirty=False,
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
914 ):
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
915 if added:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
916 assert not possibly_dirty
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
917 assert not from_p2
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
918 item = DirstateItem.new_added()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
919 elif merged:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
920 assert not possibly_dirty
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
921 assert not from_p2
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
922 item = DirstateItem.new_merged()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
923 elif from_p2:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
924 assert not possibly_dirty
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
925 item = DirstateItem.new_from_p2()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
926 elif possibly_dirty:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
927 item = DirstateItem.new_possibly_dirty()
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
928 else:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
929 assert size is not None
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
930 assert mtime is not None
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
931 size = size & rangemask
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
932 mtime = mtime & rangemask
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
933 item = DirstateItem.new_normal(mode, size, mtime)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
934 self._map.addfile(f, item)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
935 if added:
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
936 self.copymap.pop(f, None)
771c90807a2b dirstatemap: arrange methods by category
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48134
diff changeset
937
42771
749ef8c31187 rust-dirstate: call rust dirstatemap from Python
Raphaël Gomès <rgomes@octobus.net>
parents: 42763
diff changeset
938 def removefile(self, *args, **kwargs):
48133
5fc2dfb073d6 dirstatemap: rename `_rustmap` to `_map`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48132
diff changeset
939 return self._map.removefile(*args, **kwargs)