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