annotate mercurial/interfaces/dirstate.py @ 52535:2ac368d0a5b6

interfaces: make `dirstate` Protocol class methods abstract Now all known Protocol methods that should be implemented by the subclass are abstract. See cdd4bc69bfc1 for details. Note that this will break the `git` extension more, because there are a bunch of methods that aren't implemented that should be, in favor of some very old methods that won't be called (like `add()` and `drop()`). It's already broken, so I'm not taking the time to figure out how to modernize it right now. It's not detected by pytype because the only instantiation of `gitdirstate` is in `git/__init__.py`, which was already excluded from pytype checking for some other reason. AT least with this, it 1) doesn't get forgotten about, and 2) will require changing the interface if/when the core dirstate class evolves.
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 11 Dec 2024 21:09:15 -0500
parents 8820c991aee4
children 5c48fd4c0e68
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51901
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51293
diff changeset
1 from __future__ import annotations
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51293
diff changeset
2
52462
2c8c46c3c401 interfaces: mark a few dirstate methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 51965
diff changeset
3 import abc
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
4 import contextlib
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
5 import os
51959
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
6 import typing
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
7
51957
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
8 from typing import (
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
9 Any,
51959
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
10 Callable,
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
11 Dict,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
12 Iterable,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
13 Iterator,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
14 List,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
15 Optional,
51957
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
16 Protocol,
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
17 Tuple,
51957
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
18 )
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
19
51959
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
20 if typing.TYPE_CHECKING:
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
21 # Almost all mercurial modules are only imported in the type checking phase
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
22 # to avoid circular imports
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
23 from .. import (
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
24 match as matchmod,
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
25 transaction as txnmod,
51959
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
26 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43010
diff changeset
27
52481
9d79ffeed7c0 typing: use the `Status` protocol wherever `scmutil.status` was being used
Matt Harbison <matt_harbison@yahoo.com>
parents: 52462
diff changeset
28 from . import status as istatus
9d79ffeed7c0 typing: use the `Status` protocol wherever `scmutil.status` was being used
Matt Harbison <matt_harbison@yahoo.com>
parents: 52462
diff changeset
29
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
30 # TODO: finish adding type hints
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
31 AddParentChangeCallbackT = Callable[
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
32 ["idirstate", Tuple[Any, Any], Tuple[Any, Any]], Any
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
33 ]
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
34 """The callback type for dirstate.addparentchangecallback()."""
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
35
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
36 # TODO: add a Protocol for dirstatemap.DirStateItem? (It is
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
37 # conditionalized with python or rust implementations. Also,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
38 # git.dirstate needs to yield non-None from ``items()``.)
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
39 DirstateItemT = Any # dirstatemap.DirstateItem
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
40
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
41 IgnoreFileAndLineT = Tuple[Optional[bytes], int, bytes]
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
42 """The return type of dirstate._ignorefileandline(), which holds
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
43 ``(file, lineno, originalline)``.
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
44 """
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
45
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
46 FlagFuncFallbackT = Callable[[], "FlagFuncReturnT"]
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
47 """The type for the dirstate.flagfunc() fallback function."""
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
48
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
49 FlagFuncReturnT = Callable[[bytes], bytes]
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
50 """The return type of dirstate.flagfunc()."""
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
51
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
52 # TODO: verify and complete this- it came from a pytype *.pyi file
52481
9d79ffeed7c0 typing: use the `Status` protocol wherever `scmutil.status` was being used
Matt Harbison <matt_harbison@yahoo.com>
parents: 52462
diff changeset
53 StatusReturnT = Tuple[Any, istatus.Status, Any]
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
54 """The return type of dirstate.status()."""
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
55
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
56 # TODO: probably doesn't belong here.
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
57 TransactionT = txnmod.transaction
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
58 """The type for a transaction used with dirstate.
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
59
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
60 This is meant to help callers avoid having to remember to delay the import
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
61 of the transaction module.
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
62 """
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
63
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
64 # TODO: The value can also be mercurial.osutil.stat
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
65 WalkReturnT = Dict[bytes, Optional[os.stat_result]]
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
66 """The return type of dirstate.walk().
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
67
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
68 The matched files are keyed in the dictionary, mapped to a stat-like object
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
69 if the file exists.
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
70 """
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
71
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
72
51957
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
73 class idirstate(Protocol):
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
74 # 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: 51901
diff changeset
75 # def __init__(
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
76 # self,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
77 # opener,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
78 # ui,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
79 # root,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
80 # validate,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
81 # sparsematchfn,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
82 # nodeconstants,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
83 # use_dirstate_v2,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
84 # use_tracked_hint=False,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
85 # ):
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
86 # """Create a new dirstate object.
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
87 #
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
88 # 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: 51901
diff changeset
89 # 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: 51901
diff changeset
90 # the dirstate.
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51901
diff changeset
91 # """
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
92
42933
97b79354e9f0 idirstate: group private methods and attrs that are in the interface
Augie Fackler <augie@google.com>
parents: 42932
diff changeset
93 # 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: 42932
diff changeset
94 # public or removed from the interface.
51959
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
95
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
96 # TODO: decorate with `@rootcache(b'.hgignore')` like dirstate class?
51964
3688a984134b interfaces: change a couple of dirstate fields to `@property`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51959
diff changeset
97 @property
3688a984134b interfaces: change a couple of dirstate fields to `@property`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51959
diff changeset
98 def _ignore(self) -> matchmod.basematcher:
3688a984134b interfaces: change a couple of dirstate fields to `@property`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51959
diff changeset
99 """Matcher for ignored files."""
51959
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
100
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
101 @property
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
102 @abc.abstractmethod
51959
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
103 def is_changing_any(self) -> bool:
50079
e1cff85484e2 dirstate: introduce a `is_changing_any` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50078
diff changeset
104 """True if any changes in progress."""
51959
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
105
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
106 @property
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
107 @abc.abstractmethod
51959
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
108 def is_changing_parents(self) -> bool:
50078
e333cc169c45 dirstate: rename `pendingparentchange` to `is_changing_parents`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
109 """True if parents changes in progress."""
51959
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
110
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
111 @property
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
112 @abc.abstractmethod
51959
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
113 def is_changing_files(self) -> bool:
50082
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50079
diff changeset
114 """True if file tracking changes in progress."""
42933
97b79354e9f0 idirstate: group private methods and attrs that are in the interface
Augie Fackler <augie@google.com>
parents: 42932
diff changeset
115
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
116 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
117 def _ignorefileandline(self, f: bytes) -> IgnoreFileAndLineT:
43807
be8552f25cab cleanup: fix docstring formatting
Matt Harbison <matt_harbison@yahoo.com>
parents: 43077
diff changeset
118 """Given a file `f`, return the ignore file and line that ignores it."""
42933
97b79354e9f0 idirstate: group private methods and attrs that are in the interface
Augie Fackler <augie@google.com>
parents: 42932
diff changeset
119
51959
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
120 # TODO: decorate with `@util.propertycache` like dirstate class?
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
121 # (can't because circular import)
51964
3688a984134b interfaces: change a couple of dirstate fields to `@property`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51959
diff changeset
122 @property
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
123 @abc.abstractmethod
51964
3688a984134b interfaces: change a couple of dirstate fields to `@property`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51959
diff changeset
124 def _checklink(self) -> bool:
3688a984134b interfaces: change a couple of dirstate fields to `@property`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51959
diff changeset
125 """Callable for checking symlinks.""" # TODO: this comment looks stale
51959
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
126
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
127 # TODO: decorate with `@util.propertycache` like dirstate class?
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51958
diff changeset
128 # (can't because circular import)
51964
3688a984134b interfaces: change a couple of dirstate fields to `@property`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51959
diff changeset
129 @property
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
130 @abc.abstractmethod
51964
3688a984134b interfaces: change a couple of dirstate fields to `@property`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51959
diff changeset
131 def _checkexec(self) -> bool:
3688a984134b interfaces: change a couple of dirstate fields to `@property`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51959
diff changeset
132 """Callable for checking exec bits.""" # TODO: this comment looks stale
42933
97b79354e9f0 idirstate: group private methods and attrs that are in the interface
Augie Fackler <augie@google.com>
parents: 42932
diff changeset
133
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
134 @contextlib.contextmanager
52462
2c8c46c3c401 interfaces: mark a few dirstate methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 51965
diff changeset
135 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
136 def changing_parents(self, repo) -> Iterator: # TODO: typehint this
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43807
diff changeset
137 """Context manager for handling dirstate parents.
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
138
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
139 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
140 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
141 released.
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43807
diff changeset
142 """
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
143
50082
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50079
diff changeset
144 @contextlib.contextmanager
52462
2c8c46c3c401 interfaces: mark a few dirstate methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 51965
diff changeset
145 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
146 def changing_files(self, repo) -> Iterator: # TODO: typehint this
50082
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50079
diff changeset
147 """Context manager for handling dirstate files.
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50079
diff changeset
148
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50079
diff changeset
149 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: 50079
diff changeset
150 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: 50079
diff changeset
151 released.
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50079
diff changeset
152 """
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50079
diff changeset
153
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
154 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
155 def hasdir(self, d: bytes) -> bool:
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
156 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
157
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
158 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
159 def flagfunc(self, buildfallback: FlagFuncFallbackT) -> FlagFuncReturnT:
49959
9ea66d166ec7 dirstate: update docstrings in idirstate from the current dirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49131
diff changeset
160 """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: 49131
diff changeset
161
9ea66d166ec7 dirstate: update docstrings in idirstate from the current dirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49131
diff changeset
162 The information is extracted from three possible layers:
9ea66d166ec7 dirstate: update docstrings in idirstate from the current dirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49131
diff changeset
163 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: 49131
diff changeset
164 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: 49131
diff changeset
165 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: 49131
diff changeset
166 """
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
167
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
168 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
169 def getcwd(self) -> bytes:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43807
diff changeset
170 """Return the path from which a canonical path is calculated.
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
171
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
172 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
173 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
174 used to get real file paths. Use vfs functions instead.
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43807
diff changeset
175 """
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
176
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
177 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
178 def pathto(self, f: bytes, cwd: Optional[bytes] = None) -> bytes:
49960
b3ae17037b54 dirstate: swap pathto() and get_entry() in idirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49959
diff changeset
179 pass
b3ae17037b54 dirstate: swap pathto() and get_entry() in idirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49959
diff changeset
180
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
181 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
182 def get_entry(self, path: bytes) -> DirstateItemT:
49131
9c8d67a3af5e idirstate: add missing get_entry() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 48966
diff changeset
183 """return a DirstateItem for the associated path"""
9c8d67a3af5e idirstate: add missing get_entry() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 48966
diff changeset
184
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
185 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
186 def __contains__(self, key: Any) -> bool:
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
187 """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
188
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
189 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
190 def __iter__(self) -> Iterator[bytes]:
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
191 """Iterate the dirstate's contained filenames as bytestrings."""
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
192
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
193 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
194 def items(self) -> Iterator[Tuple[bytes, DirstateItemT]]:
47539
84391ddf4c78 dirstate-item: rename the class to DirstateItem
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47291
diff changeset
195 """Iterate the dirstate's entries as (filename, DirstateItem.
42931
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 As usual, filename is a bytestring.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
198 """
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
199
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
200 iteritems = items
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
201
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
202 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
203 def parents(self) -> List[bytes]:
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
204 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
205
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
206 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
207 def p1(self) -> bytes:
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
208 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
209
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
210 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
211 def p2(self) -> bytes:
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
212 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
213
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
214 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
215 def branch(self) -> bytes:
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
216 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
217
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
218 # TODO: typehint the return. It's a copies Map of some sort.
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
219 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
220 def setparents(self, p1: bytes, p2: Optional[bytes] = None):
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
221 """Set dirstate parents to p1 and p2.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
222
49959
9ea66d166ec7 dirstate: update docstrings in idirstate from the current dirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49131
diff changeset
223 When moving from two parents to one, "merged" entries a
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
224 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
225 returned by the call.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
226
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
227 See localrepo.setparents()
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
228 """
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
229
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
230 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
231 def setbranch(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
232 self, branch: bytes, transaction: Optional[TransactionT]
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
233 ) -> None:
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
234 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
235
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
236 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
237 def invalidate(self) -> None:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43807
diff changeset
238 """Causes the next access to reread the dirstate.
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
239
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
240 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
241 rereads the dirstate. Use localrepo.invalidatedirstate() if you want to
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43807
diff changeset
242 check whether the dirstate has changed before rereading it."""
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
243
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
244 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
245 def copy(self, source: Optional[bytes], dest: bytes) -> None:
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
246 """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
247
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
248 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
249 def copied(self, file: bytes) -> Optional[bytes]:
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
250 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
251
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
252 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
253 def copies(self) -> Dict[bytes, bytes]:
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
254 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
255
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
256 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
257 def normalize(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
258 self, path: bytes, isknown: bool = False, ignoremissing: bool = False
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
259 ) -> bytes:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43807
diff changeset
260 """
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
261 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
262
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
263 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
264 disk, to avoid extra filesystem access.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
265
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
266 If ignoremissing is True, missing path are returned
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
267 unchanged. Otherwise, we try harder to normalize possibly
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
268 existing path components.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
269
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
270 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
271
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
272 - version of name already stored in the dirstate
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
273 - version of name stored on disk
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
274 - version provided via command arguments
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43807
diff changeset
275 """
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
276
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
277 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
278 def clear(self) -> None:
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
279 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
280
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
281 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
282 def rebuild(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
283 self,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
284 parent: bytes,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
285 allfiles: Iterable[bytes], # TODO: more than iterable? (uses len())
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
286 changedfiles: Optional[Iterable[bytes]] = None,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
287 ) -> None:
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
288 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
289
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
290 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
291 def write(self, tr: Optional[TransactionT]) -> None:
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
292 pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
293
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
294 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
295 def addparentchangecallback(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
296 self, category: bytes, callback: AddParentChangeCallbackT
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
297 ) -> None:
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
298 """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
299
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
300 Callback will be called with the following arguments:
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
301 dirstate, (oldp1, oldp2), (newp1, newp2)
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
302
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
303 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
304 with a newer callback.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
305 """
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
306
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
307 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
308 def walk(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
309 self,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
310 match: matchmod.basematcher,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
311 subrepos: Any, # TODO: figure out what this is
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
312 unknown: bool,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
313 ignored: bool,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
314 full: bool = True,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
315 ) -> WalkReturnT:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43807
diff changeset
316 """
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
317 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
318 matched by match.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
319
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
320 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
321
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
322 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
323 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
324
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43807
diff changeset
325 """
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
326
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
327 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
328 def status(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
329 self,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
330 match: matchmod.basematcher,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
331 subrepos: bool,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
332 ignored: bool,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
333 clean: bool,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
334 unknown: bool,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
335 ) -> StatusReturnT:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43807
diff changeset
336 """Determine the status of the working copy relative to the
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
337 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
338 scmutil.status and:
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
339
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
340 unsure:
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
341 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
342 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
343 but mtime differs)
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
344 status.modified:
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
345 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
346 was written (different size or mode)
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
347 status.clean:
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
348 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
349 dirstate was written
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43807
diff changeset
350 """
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
351
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
352 # TODO: could return a list, except git.dirstate is a generator
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
353
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
354 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
355 def matches(self, match: matchmod.basematcher) -> Iterable[bytes]:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43807
diff changeset
356 """
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
357 return files in the dirstate (in whatever state) filtered by match
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43807
diff changeset
358 """
42931
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
359
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
360 # TODO: finish adding typehints here, and to subclasses
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
361
52535
2ac368d0a5b6 interfaces: make `dirstate` Protocol class methods abstract
Matt Harbison <matt_harbison@yahoo.com>
parents: 52534
diff changeset
362 @abc.abstractmethod
51965
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
363 def verify(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
364 self, m1, m2, p1: bytes, narrow_matcher: Optional[Any] = None
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51964
diff changeset
365 ) -> Iterator[bytes]:
49961
8c7895db8955 dirstate: add missing methods and kwargs to idirstate interface
Anton Shestakov <av6@dwimlabs.net>
parents: 49960
diff changeset
366 """
8c7895db8955 dirstate: add missing methods and kwargs to idirstate interface
Anton Shestakov <av6@dwimlabs.net>
parents: 49960
diff changeset
367 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: 49960
diff changeset
368 """