##// END OF EJS Templates
interfaces: introduce an interface for dirstate implementations...
Augie Fackler -
r43197:d459cd8e default
parent child Browse files
Show More
@@ -0,0 +1,257 b''
1 from __future__ import absolute_import, print_function
2
3 import contextlib
4
5 from .. import (
6 node as nodemod,
7 )
8
9 from . import (
10 util as interfaceutil,
11 )
12
13 class idirstate(interfaceutil.Interface):
14
15 def __init__(opener, ui, root, validate, sparsematchfn):
16 '''Create a new dirstate object.
17
18 opener is an open()-like callable that can be used to open the
19 dirstate file; root is the root of the directory tracked by
20 the dirstate.
21 '''
22
23 @contextlib.contextmanager
24 def parentchange():
25 '''Context manager for handling dirstate parents.
26
27 If an exception occurs in the scope of the context manager,
28 the incoherent dirstate won't be written when wlock is
29 released.
30 '''
31
32 def pendingparentchange():
33 '''Returns true if the dirstate is in the middle of a set of changes
34 that modify the dirstate parent.
35 '''
36
37 _map = interfaceutil.Attribute(
38 """Return the dirstate contents (see documentation for dirstatemap).
39
40 TODO this should not be exposed.
41 """
42 )
43
44 def hasdir(d):
45 pass
46
47 _ignore = interfaceutil.Attribute('Matcher for ignored files.')
48
49 _checklink = interfaceutil.Attribute('Callable for checking symlinks.')
50 _checkexec = interfaceutil.Attribute('Callable for checking exec bits.')
51
52 def flagfunc(buildfallback):
53 pass
54
55 def getcwd():
56 '''Return the path from which a canonical path is calculated.
57
58 This path should be used to resolve file patterns or to convert
59 canonical paths back to file paths for display. It shouldn't be
60 used to get real file paths. Use vfs functions instead.
61 '''
62
63 def pathto(f, cwd=None):
64 pass
65
66 def __getitem__(key):
67 '''Return the current state of key (a filename) in the dirstate.
68
69 States are:
70 n normal
71 m needs merging
72 r marked for removal
73 a marked for addition
74 ? not tracked
75 '''
76
77 def __contains__(key):
78 """Check if bytestring `key` is known to the dirstate."""
79
80 def __iter__():
81 """Iterate the dirstate's contained filenames as bytestrings."""
82
83 def items():
84 """Iterate the dirstate's entries as (filename, dirstatetuple).
85
86 As usual, filename is a bytestring.
87 """
88
89 iteritems = items
90
91 def parents():
92 pass
93
94 def p1():
95 pass
96
97 def p2():
98 pass
99
100 def branch():
101 pass
102
103 def setparents(p1, p2=nodemod.nullid):
104 """Set dirstate parents to p1 and p2.
105
106 When moving from two parents to one, 'm' merged entries a
107 adjusted to normal and previous copy records discarded and
108 returned by the call.
109
110 See localrepo.setparents()
111 """
112
113 def setbranch(branch):
114 pass
115
116 def invalidate():
117 '''Causes the next access to reread the dirstate.
118
119 This is different from localrepo.invalidatedirstate() because it always
120 rereads the dirstate. Use localrepo.invalidatedirstate() if you want to
121 check whether the dirstate has changed before rereading it.'''
122
123 def copy(source, dest):
124 """Mark dest as a copy of source. Unmark dest if source is None."""
125
126 def copied(file):
127 pass
128
129 def copies():
130 pass
131
132 def normal(f, parentfiledata=None):
133 '''Mark a file normal and clean.
134
135 parentfiledata: (mode, size, mtime) of the clean file
136
137 parentfiledata should be computed from memory (for mode,
138 size), as or close as possible from the point where we
139 determined the file was clean, to limit the risk of the
140 file having been changed by an external process between the
141 moment where the file was determined to be clean and now.'''
142 pass
143
144 def normallookup(f):
145 '''Mark a file normal, but possibly dirty.'''
146
147 def otherparent(f):
148 '''Mark as coming from the other parent, always dirty.'''
149
150 def add(f):
151 '''Mark a file added.'''
152
153 def remove(f):
154 '''Mark a file removed.'''
155
156 def merge(f):
157 '''Mark a file merged.'''
158
159 def drop(f):
160 '''Drop a file from the dirstate'''
161
162 def normalize(path, isknown=False, ignoremissing=False):
163 '''
164 normalize the case of a pathname when on a casefolding filesystem
165
166 isknown specifies whether the filename came from walking the
167 disk, to avoid extra filesystem access.
168
169 If ignoremissing is True, missing path are returned
170 unchanged. Otherwise, we try harder to normalize possibly
171 existing path components.
172
173 The normalized case is determined based on the following precedence:
174
175 - version of name already stored in the dirstate
176 - version of name stored on disk
177 - version provided via command arguments
178 '''
179
180 def clear():
181 pass
182
183 def rebuild(parent, allfiles, changedfiles=None):
184 pass
185
186 def identity():
187 '''Return identity of dirstate it to detect changing in storage
188
189 If identity of previous dirstate is equal to this, writing
190 changes based on the former dirstate out can keep consistency.
191 '''
192
193 def write(tr):
194 pass
195
196 def addparentchangecallback(category, callback):
197 """add a callback to be called when the wd parents are changed
198
199 Callback will be called with the following arguments:
200 dirstate, (oldp1, oldp2), (newp1, newp2)
201
202 Category is a unique identifier to allow overwriting an old callback
203 with a newer callback.
204 """
205
206 def _ignorefiles():
207 """Return a list of files containing patterns to ignore.
208
209 TODO this should not be exposed."""
210
211 def _ignorefileandline(f):
212 """Given a file `f`, return the ignore file and line that ignores it.
213
214 TODO this should not be exposed."""
215
216 def walk(match, subrepos, unknown, ignored, full=True):
217 '''
218 Walk recursively through the directory tree, finding all files
219 matched by match.
220
221 If full is False, maybe skip some known-clean files.
222
223 Return a dict mapping filename to stat-like object (either
224 mercurial.osutil.stat instance or return value of os.stat()).
225
226 '''
227
228 def status(match, subrepos, ignored, clean, unknown):
229 '''Determine the status of the working copy relative to the
230 dirstate and return a pair of (unsure, status), where status is of type
231 scmutil.status and:
232
233 unsure:
234 files that might have been modified since the dirstate was
235 written, but need to be read to be sure (size is the same
236 but mtime differs)
237 status.modified:
238 files that have definitely been modified since the dirstate
239 was written (different size or mode)
240 status.clean:
241 files that have definitely not been modified since the
242 dirstate was written
243 '''
244
245 def matches(match):
246 '''
247 return files in the dirstate (in whatever state) filtered by match
248 '''
249
250 def savebackup(tr, backupname):
251 '''Save current dirstate into backup file'''
252
253 def restorebackup(tr, backupname):
254 '''Restore dirstate by backup file'''
255
256 def clearbackup(tr, backupname):
257 '''Clear backup file'''
@@ -27,6 +27,11 b' from . import ('
27 27 util,
28 28 )
29 29
30 from .interfaces import (
31 dirstate as intdirstate,
32 util as interfaceutil,
33 )
34
30 35 parsers = policy.importmod(r'parsers')
31 36 rustmod = policy.importrust(r'dirstate')
32 37
@@ -55,6 +60,7 b' def _getfsnow(vfs):'
55 60 os.close(tmpfd)
56 61 vfs.unlink(tmpname)
57 62
63 @interfaceutil.implementer(intdirstate.idirstate)
58 64 class dirstate(object):
59 65
60 66 def __init__(self, opener, ui, root, validate, sparsematchfn):
@@ -15,6 +15,7 b" if subprocess.call(['python', '%s/hghave"
15 15 sys.exit(80)
16 16
17 17 from mercurial.interfaces import (
18 dirstate as intdirstate,
18 19 repository,
19 20 )
20 21 from mercurial.thirdparty.zope import (
@@ -25,6 +26,7 b' from mercurial.thirdparty.zope.interface'
25 26 )
26 27 from mercurial import (
27 28 bundlerepo,
29 dirstate,
28 30 filelog,
29 31 httppeer,
30 32 localrepo,
@@ -189,6 +191,8 b' def main():'
189 191 ziverify.verifyClass(repository.iverifyproblem,
190 192 simplestorerepo.simplefilestoreproblem)
191 193
194 ziverify.verifyClass(intdirstate.idirstate, dirstate.dirstate)
195
192 196 vfs = vfsmod.vfs(b'.')
193 197 fl = filelog.filelog(vfs, b'dummy.i')
194 198 checkzobject(fl, allowextra=True)
General Comments 0
You need to be logged in to leave comments. Login now