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