annotate mercurial/interfaces/dirstate.py @ 51917:382d9629cede

interfaces: convert the dirstate zope interface to a Protocol class This is a small trial run for converting the repository interfaces enmasse, in the same series of steps. I'm not sure that this current code is valid (it has zope attribute fields, and it's missing all of the `self` args on its functions, but that was the previous state of things, and made PyCharm really unhappy). But it will be easier to review the repository interface changes if this change is separate from adding `self` and dropping the zope attributes all over. Having an empty constructor in a protocol is weird. I'm not sure if these args should be converted to fields that all subclasses would have, and comments around existing attributes say some should be going away. Comment it out for now so that it's not in the way, but also not forgotten.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 26 Sep 2024 18:04:31 -0400
parents f4733654f144
children 13aa17512583
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51859
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51270
diff changeset
1 from __future__ import annotations
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51270
diff changeset
2
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
3 import contextlib
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
4
51917
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
5 from typing import (
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
6 Protocol,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
7 )
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
8
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43008
diff changeset
9 from . import util as interfaceutil
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43008
diff changeset
10
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
11
51917
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
12 class idirstate(Protocol):
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
13 # TODO: convert these constructor args to fields?
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
14 # def __init__(
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
15 # self,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
16 # opener,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
17 # ui,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
18 # root,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
19 # validate,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
20 # sparsematchfn,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
21 # nodeconstants,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
22 # use_dirstate_v2,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
23 # use_tracked_hint=False,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
24 # ):
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
25 # """Create a new dirstate object.
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
26 #
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
27 # opener is an open()-like callable that can be used to open the
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
28 # dirstate file; root is the root of the directory tracked by
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
29 # the dirstate.
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
30 # """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
31
42929
97b79354e9f0 idirstate: group private methods and attrs that are in the interface
Augie Fackler <augie@google.com>
parents: 42928
diff changeset
32 # TODO: all these private methods and attributes should be made
97b79354e9f0 idirstate: group private methods and attrs that are in the interface
Augie Fackler <augie@google.com>
parents: 42928
diff changeset
33 # public or removed from the interface.
43008
5f8b6617e962 interfaces: use triple quotes for Attribute value
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42929
diff changeset
34 _ignore = interfaceutil.Attribute("""Matcher for ignored files.""")
50023
e1cff85484e2 dirstate: introduce a `is_changing_any` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50022
diff changeset
35 is_changing_any = interfaceutil.Attribute(
e1cff85484e2 dirstate: introduce a `is_changing_any` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50022
diff changeset
36 """True if any changes in progress."""
e1cff85484e2 dirstate: introduce a `is_changing_any` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50022
diff changeset
37 )
50022
e333cc169c45 dirstate: rename `pendingparentchange` to `is_changing_parents`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49961
diff changeset
38 is_changing_parents = interfaceutil.Attribute(
e333cc169c45 dirstate: rename `pendingparentchange` to `is_changing_parents`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49961
diff changeset
39 """True if parents changes in progress."""
e333cc169c45 dirstate: rename `pendingparentchange` to `is_changing_parents`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49961
diff changeset
40 )
50026
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
41 is_changing_files = interfaceutil.Attribute(
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
42 """True if file tracking changes in progress."""
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
43 )
42929
97b79354e9f0 idirstate: group private methods and attrs that are in the interface
Augie Fackler <augie@google.com>
parents: 42928
diff changeset
44
97b79354e9f0 idirstate: group private methods and attrs that are in the interface
Augie Fackler <augie@google.com>
parents: 42928
diff changeset
45 def _ignorefiles():
97b79354e9f0 idirstate: group private methods and attrs that are in the interface
Augie Fackler <augie@google.com>
parents: 42928
diff changeset
46 """Return a list of files containing patterns to ignore."""
97b79354e9f0 idirstate: group private methods and attrs that are in the interface
Augie Fackler <augie@google.com>
parents: 42928
diff changeset
47
97b79354e9f0 idirstate: group private methods and attrs that are in the interface
Augie Fackler <augie@google.com>
parents: 42928
diff changeset
48 def _ignorefileandline(f):
43787
be8552f25cab cleanup: fix docstring formatting
Matt Harbison <matt_harbison@yahoo.com>
parents: 43077
diff changeset
49 """Given a file `f`, return the ignore file and line that ignores it."""
42929
97b79354e9f0 idirstate: group private methods and attrs that are in the interface
Augie Fackler <augie@google.com>
parents: 42928
diff changeset
50
43008
5f8b6617e962 interfaces: use triple quotes for Attribute value
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42929
diff changeset
51 _checklink = interfaceutil.Attribute("""Callable for checking symlinks.""")
5f8b6617e962 interfaces: use triple quotes for Attribute value
Gregory Szorc <gregory.szorc@gmail.com>
parents: 42929
diff changeset
52 _checkexec = interfaceutil.Attribute("""Callable for checking exec bits.""")
42929
97b79354e9f0 idirstate: group private methods and attrs that are in the interface
Augie Fackler <augie@google.com>
parents: 42928
diff changeset
53
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
54 @contextlib.contextmanager
49961
7a8bfc05b691 dirstate: rename parentchange to changing_parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49960
diff changeset
55 def changing_parents(repo):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
56 """Context manager for handling dirstate parents.
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
57
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
58 If an exception occurs in the scope of the context manager,
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
59 the incoherent dirstate won't be written when wlock is
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
60 released.
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
61 """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
62
50026
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
63 @contextlib.contextmanager
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
64 def changing_files(repo):
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
65 """Context manager for handling dirstate files.
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
66
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
67 If an exception occurs in the scope of the context manager,
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
68 the incoherent dirstate won't be written when wlock is
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
69 released.
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
70 """
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
71
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
72 def hasdir(d):
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
73 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
74
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
75 def flagfunc(buildfallback):
49880
9ea66d166ec7 dirstate: update docstrings in idirstate from the current dirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49076
diff changeset
76 """build a callable that returns flags associated with a filename
9ea66d166ec7 dirstate: update docstrings in idirstate from the current dirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49076
diff changeset
77
9ea66d166ec7 dirstate: update docstrings in idirstate from the current dirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49076
diff changeset
78 The information is extracted from three possible layers:
9ea66d166ec7 dirstate: update docstrings in idirstate from the current dirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49076
diff changeset
79 1. the file system if it supports the information
9ea66d166ec7 dirstate: update docstrings in idirstate from the current dirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49076
diff changeset
80 2. the "fallback" information stored in the dirstate if any
9ea66d166ec7 dirstate: update docstrings in idirstate from the current dirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49076
diff changeset
81 3. a more expensive mechanism inferring the flags from the parents.
9ea66d166ec7 dirstate: update docstrings in idirstate from the current dirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49076
diff changeset
82 """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
83
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
84 def getcwd():
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
85 """Return the path from which a canonical path is calculated.
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
86
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
87 This path should be used to resolve file patterns or to convert
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
88 canonical paths back to file paths for display. It shouldn't be
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
89 used to get real file paths. Use vfs functions instead.
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
90 """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
91
49881
b3ae17037b54 dirstate: swap pathto() and get_entry() in idirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49880
diff changeset
92 def pathto(f, cwd=None):
b3ae17037b54 dirstate: swap pathto() and get_entry() in idirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49880
diff changeset
93 pass
b3ae17037b54 dirstate: swap pathto() and get_entry() in idirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49880
diff changeset
94
49076
9c8d67a3af5e idirstate: add missing get_entry() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 48875
diff changeset
95 def get_entry(path):
9c8d67a3af5e idirstate: add missing get_entry() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 48875
diff changeset
96 """return a DirstateItem for the associated path"""
9c8d67a3af5e idirstate: add missing get_entry() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 48875
diff changeset
97
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
98 def __contains__(key):
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
99 """Check if bytestring `key` is known to the dirstate."""
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
100
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
101 def __iter__():
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
102 """Iterate the dirstate's contained filenames as bytestrings."""
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
103
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
104 def items():
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47280
diff changeset
105 """Iterate the dirstate's entries as (filename, DirstateItem.
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
106
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
107 As usual, filename is a bytestring.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
108 """
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
109
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
110 iteritems = items
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
111
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
112 def parents():
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
113 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
114
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
115 def p1():
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
116 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
117
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
118 def p2():
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
119 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
120
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
121 def branch():
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
122 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
123
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46780
diff changeset
124 def setparents(p1, p2=None):
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
125 """Set dirstate parents to p1 and p2.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
126
49880
9ea66d166ec7 dirstate: update docstrings in idirstate from the current dirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49076
diff changeset
127 When moving from two parents to one, "merged" entries a
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
128 adjusted to normal and previous copy records discarded and
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
129 returned by the call.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
130
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
131 See localrepo.setparents()
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
132 """
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
133
51270
79cd29d598af dirstate: make the `transaction` argument of `setbranch` mandatory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50256
diff changeset
134 def setbranch(branch, transaction):
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
135 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
136
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
137 def invalidate():
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
138 """Causes the next access to reread the dirstate.
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
139
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
140 This is different from localrepo.invalidatedirstate() because it always
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
141 rereads the dirstate. Use localrepo.invalidatedirstate() if you want to
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
142 check whether the dirstate has changed before rereading it."""
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
143
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
144 def copy(source, dest):
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
145 """Mark dest as a copy of source. Unmark dest if source is None."""
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
146
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
147 def copied(file):
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
148 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
149
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
150 def copies():
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
151 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
152
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
153 def normalize(path, isknown=False, ignoremissing=False):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
154 """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
155 normalize the case of a pathname when on a casefolding filesystem
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
156
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
157 isknown specifies whether the filename came from walking the
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
158 disk, to avoid extra filesystem access.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
159
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
160 If ignoremissing is True, missing path are returned
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
161 unchanged. Otherwise, we try harder to normalize possibly
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
162 existing path components.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
163
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
164 The normalized case is determined based on the following precedence:
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
165
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
166 - version of name already stored in the dirstate
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
167 - version of name stored on disk
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
168 - version provided via command arguments
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
169 """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
170
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
171 def clear():
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
172 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
173
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
174 def rebuild(parent, allfiles, changedfiles=None):
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
175 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
176
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
177 def write(tr):
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
178 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
179
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
180 def addparentchangecallback(category, callback):
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
181 """add a callback to be called when the wd parents are changed
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
182
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
183 Callback will be called with the following arguments:
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
184 dirstate, (oldp1, oldp2), (newp1, newp2)
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
185
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
186 Category is a unique identifier to allow overwriting an old callback
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
187 with a newer callback.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
188 """
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
189
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
190 def walk(match, subrepos, unknown, ignored, full=True):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
191 """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
192 Walk recursively through the directory tree, finding all files
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
193 matched by match.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
194
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
195 If full is False, maybe skip some known-clean files.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
196
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
197 Return a dict mapping filename to stat-like object (either
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
198 mercurial.osutil.stat instance or return value of os.stat()).
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
199
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
200 """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
201
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
202 def status(match, subrepos, ignored, clean, unknown):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
203 """Determine the status of the working copy relative to the
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
204 dirstate and return a pair of (unsure, status), where status is of type
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
205 scmutil.status and:
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
206
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
207 unsure:
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
208 files that might have been modified since the dirstate was
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
209 written, but need to be read to be sure (size is the same
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
210 but mtime differs)
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
211 status.modified:
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
212 files that have definitely been modified since the dirstate
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
213 was written (different size or mode)
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
214 status.clean:
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
215 files that have definitely not been modified since the
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
216 dirstate was written
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
217 """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
218
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
219 def matches(match):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
220 """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
221 return files in the dirstate (in whatever state) filtered by match
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
222 """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
223
49882
8c7895db8955 dirstate: add missing methods and kwargs to idirstate interface
Anton Shestakov <av6@dwimlabs.net>
parents: 49881
diff changeset
224 def verify(m1, m2, p1, narrow_matcher=None):
8c7895db8955 dirstate: add missing methods and kwargs to idirstate interface
Anton Shestakov <av6@dwimlabs.net>
parents: 49881
diff changeset
225 """
8c7895db8955 dirstate: add missing methods and kwargs to idirstate interface
Anton Shestakov <av6@dwimlabs.net>
parents: 49881
diff changeset
226 check the dirstate contents against the parent manifest and yield errors
8c7895db8955 dirstate: add missing methods and kwargs to idirstate interface
Anton Shestakov <av6@dwimlabs.net>
parents: 49881
diff changeset
227 """