##// END OF EJS Templates
interfaces: convert the zope `Attribute` attrs to regular fields...
Matt Harbison -
r53201:b455dfdd default
parent child Browse files
Show More
@@ -1,227 +1,251
1 1 from __future__ import annotations
2 2
3 3 import contextlib
4 import typing
4 5
5 6 from typing import (
7 Callable,
6 8 Protocol,
7 9 )
8 10
9 from . import util as interfaceutil
11 if typing.TYPE_CHECKING:
12 # Almost all mercurial modules are only imported in the type checking phase
13 # to avoid circular imports
14 from .. import (
15 match as matchmod,
16 )
10 17
11 18
12 19 class idirstate(Protocol):
13 20 # TODO: convert these constructor args to fields?
14 21 # def __init__(
15 22 # self,
16 23 # opener,
17 24 # ui,
18 25 # root,
19 26 # validate,
20 27 # sparsematchfn,
21 28 # nodeconstants,
22 29 # use_dirstate_v2,
23 30 # use_tracked_hint=False,
24 31 # ):
25 32 # """Create a new dirstate object.
26 33 #
27 34 # opener is an open()-like callable that can be used to open the
28 35 # dirstate file; root is the root of the directory tracked by
29 36 # the dirstate.
30 37 # """
31 38
32 39 # TODO: all these private methods and attributes should be made
33 40 # public or removed from the interface.
34 _ignore = interfaceutil.Attribute("""Matcher for ignored files.""")
35 is_changing_any = interfaceutil.Attribute(
41
42 # TODO: decorate with `@rootcache(b'.hgignore')` like dirstate class?
43 _ignore: matchmod.basematcher
44 """Matcher for ignored files."""
45
46 @property
47 def is_changing_any(self) -> bool:
36 48 """True if any changes in progress."""
37 )
38 is_changing_parents = interfaceutil.Attribute(
49
50 @property
51 def is_changing_parents(self) -> bool:
39 52 """True if parents changes in progress."""
40 )
41 is_changing_files = interfaceutil.Attribute(
53
54 @property
55 def is_changing_files(self) -> bool:
42 56 """True if file tracking changes in progress."""
43 )
44 57
45 58 def _ignorefiles(self):
46 59 """Return a list of files containing patterns to ignore."""
47 60
48 61 def _ignorefileandline(self, f):
49 62 """Given a file `f`, return the ignore file and line that ignores it."""
50 63
51 _checklink = interfaceutil.Attribute("""Callable for checking symlinks.""")
52 _checkexec = interfaceutil.Attribute("""Callable for checking exec bits.""")
64 # TODO: decorate with `@util.propertycache` like dirstate class?
65 # (can't because circular import)
66 # TODO: The doc looks wrong- the core class has this as a @property, not a
67 # callable.
68 _checklink: Callable
69 """Callable for checking symlinks."""
70
71 # TODO: decorate with `@util.propertycache` like dirstate class?
72 # (can't because circular import)
73 # TODO: The doc looks wrong- the core class has this as a @property, not a
74 # callable.
75 _checkexec: Callable
76 """Callable for checking exec bits."""
53 77
54 78 @contextlib.contextmanager
55 79 def changing_parents(self, repo):
56 80 """Context manager for handling dirstate parents.
57 81
58 82 If an exception occurs in the scope of the context manager,
59 83 the incoherent dirstate won't be written when wlock is
60 84 released.
61 85 """
62 86
63 87 @contextlib.contextmanager
64 88 def changing_files(self, repo):
65 89 """Context manager for handling dirstate files.
66 90
67 91 If an exception occurs in the scope of the context manager,
68 92 the incoherent dirstate won't be written when wlock is
69 93 released.
70 94 """
71 95
72 96 def hasdir(self, d):
73 97 pass
74 98
75 99 def flagfunc(self, buildfallback):
76 100 """build a callable that returns flags associated with a filename
77 101
78 102 The information is extracted from three possible layers:
79 103 1. the file system if it supports the information
80 104 2. the "fallback" information stored in the dirstate if any
81 105 3. a more expensive mechanism inferring the flags from the parents.
82 106 """
83 107
84 108 def getcwd(self):
85 109 """Return the path from which a canonical path is calculated.
86 110
87 111 This path should be used to resolve file patterns or to convert
88 112 canonical paths back to file paths for display. It shouldn't be
89 113 used to get real file paths. Use vfs functions instead.
90 114 """
91 115
92 116 def pathto(self, f, cwd=None):
93 117 pass
94 118
95 119 def get_entry(self, path):
96 120 """return a DirstateItem for the associated path"""
97 121
98 122 def __contains__(self, key):
99 123 """Check if bytestring `key` is known to the dirstate."""
100 124
101 125 def __iter__(self):
102 126 """Iterate the dirstate's contained filenames as bytestrings."""
103 127
104 128 def items(self):
105 129 """Iterate the dirstate's entries as (filename, DirstateItem.
106 130
107 131 As usual, filename is a bytestring.
108 132 """
109 133
110 134 iteritems = items
111 135
112 136 def parents(self):
113 137 pass
114 138
115 139 def p1(self):
116 140 pass
117 141
118 142 def p2(self):
119 143 pass
120 144
121 145 def branch(self):
122 146 pass
123 147
124 148 def setparents(self, p1, p2=None):
125 149 """Set dirstate parents to p1 and p2.
126 150
127 151 When moving from two parents to one, "merged" entries a
128 152 adjusted to normal and previous copy records discarded and
129 153 returned by the call.
130 154
131 155 See localrepo.setparents()
132 156 """
133 157
134 158 def setbranch(self, branch, transaction):
135 159 pass
136 160
137 161 def invalidate(self):
138 162 """Causes the next access to reread the dirstate.
139 163
140 164 This is different from localrepo.invalidatedirstate() because it always
141 165 rereads the dirstate. Use localrepo.invalidatedirstate() if you want to
142 166 check whether the dirstate has changed before rereading it."""
143 167
144 168 def copy(self, source, dest):
145 169 """Mark dest as a copy of source. Unmark dest if source is None."""
146 170
147 171 def copied(self, file):
148 172 pass
149 173
150 174 def copies(self):
151 175 pass
152 176
153 177 def normalize(self, path, isknown=False, ignoremissing=False):
154 178 """
155 179 normalize the case of a pathname when on a casefolding filesystem
156 180
157 181 isknown specifies whether the filename came from walking the
158 182 disk, to avoid extra filesystem access.
159 183
160 184 If ignoremissing is True, missing path are returned
161 185 unchanged. Otherwise, we try harder to normalize possibly
162 186 existing path components.
163 187
164 188 The normalized case is determined based on the following precedence:
165 189
166 190 - version of name already stored in the dirstate
167 191 - version of name stored on disk
168 192 - version provided via command arguments
169 193 """
170 194
171 195 def clear(self):
172 196 pass
173 197
174 198 def rebuild(self, parent, allfiles, changedfiles=None):
175 199 pass
176 200
177 201 def write(self, tr):
178 202 pass
179 203
180 204 def addparentchangecallback(self, category, callback):
181 205 """add a callback to be called when the wd parents are changed
182 206
183 207 Callback will be called with the following arguments:
184 208 dirstate, (oldp1, oldp2), (newp1, newp2)
185 209
186 210 Category is a unique identifier to allow overwriting an old callback
187 211 with a newer callback.
188 212 """
189 213
190 214 def walk(self, match, subrepos, unknown, ignored, full=True):
191 215 """
192 216 Walk recursively through the directory tree, finding all files
193 217 matched by match.
194 218
195 219 If full is False, maybe skip some known-clean files.
196 220
197 221 Return a dict mapping filename to stat-like object (either
198 222 mercurial.osutil.stat instance or return value of os.stat()).
199 223
200 224 """
201 225
202 226 def status(self, match, subrepos, ignored, clean, unknown):
203 227 """Determine the status of the working copy relative to the
204 228 dirstate and return a pair of (unsure, status), where status is of type
205 229 scmutil.status and:
206 230
207 231 unsure:
208 232 files that might have been modified since the dirstate was
209 233 written, but need to be read to be sure (size is the same
210 234 but mtime differs)
211 235 status.modified:
212 236 files that have definitely been modified since the dirstate
213 237 was written (different size or mode)
214 238 status.clean:
215 239 files that have definitely not been modified since the
216 240 dirstate was written
217 241 """
218 242
219 243 def matches(self, match):
220 244 """
221 245 return files in the dirstate (in whatever state) filtered by match
222 246 """
223 247
224 248 def verify(self, m1, m2, p1, narrow_matcher=None):
225 249 """
226 250 check the dirstate contents against the parent manifest and yield errors
227 251 """
General Comments 0
You need to be logged in to leave comments. Login now