Show More
@@ -4,6 +4,11 b'' | |||
|
4 | 4 | # GNU General Public License version 2 or any later version. |
|
5 | 5 | |
|
6 | 6 | |
|
7 | from typing import ( | |
|
8 | Optional, | |
|
9 | TYPE_CHECKING, | |
|
10 | ) | |
|
11 | ||
|
7 | 12 | from .i18n import _ |
|
8 | 13 | |
|
9 | 14 | from . import ( |
@@ -12,6 +17,7 b' from . import (' | |||
|
12 | 17 | policy, |
|
13 | 18 | testing, |
|
14 | 19 | txnutil, |
|
20 | typelib, | |
|
15 | 21 | util, |
|
16 | 22 | ) |
|
17 | 23 | |
@@ -20,6 +26,11 b' from .dirstateutils import (' | |||
|
20 | 26 | v2, |
|
21 | 27 | ) |
|
22 | 28 | |
|
29 | if TYPE_CHECKING: | |
|
30 | from . import ( | |
|
31 | ui as uimod, | |
|
32 | ) | |
|
33 | ||
|
23 | 34 | parsers = policy.importmod('parsers') |
|
24 | 35 | rustmod = policy.importrust('dirstate') |
|
25 | 36 | |
@@ -46,12 +57,31 b' class _dirstatemapcommon:' | |||
|
46 | 57 | class, with and without Rust extensions enabled. |
|
47 | 58 | """ |
|
48 | 59 | |
|
60 | _use_dirstate_v2: bool | |
|
61 | _nodeconstants: typelib.NodeConstants | |
|
62 | _ui: "uimod.ui" | |
|
63 | _root: bytes | |
|
64 | _filename: bytes | |
|
65 | _nodelen: int | |
|
66 | _dirtyparents: bool | |
|
67 | _docket: Optional["docketmod.DirstateDocket"] | |
|
68 | _write_mode: int | |
|
69 | _pendingmode: Optional[bool] | |
|
70 | identity: Optional[typelib.CacheStat] | |
|
71 | ||
|
49 | 72 | # please pytype |
|
50 | 73 | |
|
51 | 74 | _map = None |
|
52 | 75 | copymap = None |
|
53 | 76 | |
|
54 | def __init__(self, ui, opener, root, nodeconstants, use_dirstate_v2): | |
|
77 | def __init__( | |
|
78 | self, | |
|
79 | ui: "uimod.ui", | |
|
80 | opener, | |
|
81 | root: bytes, | |
|
82 | nodeconstants: typelib.NodeConstants, | |
|
83 | use_dirstate_v2: bool, | |
|
84 | ) -> None: | |
|
55 | 85 | self._use_dirstate_v2 = use_dirstate_v2 |
|
56 | 86 | self._nodeconstants = nodeconstants |
|
57 | 87 | self._ui = ui |
@@ -76,16 +106,16 b' class _dirstatemapcommon:' | |||
|
76 | 106 | # for consistent view between _pl() and _read() invocations |
|
77 | 107 | self._pendingmode = None |
|
78 | 108 | |
|
79 | def _set_identity(self): | |
|
109 | def _set_identity(self) -> None: | |
|
80 | 110 | self.identity = self._get_current_identity() |
|
81 | 111 | |
|
82 | def _get_current_identity(self): | |
|
112 | def _get_current_identity(self) -> Optional[typelib.CacheStat]: | |
|
83 | 113 | try: |
|
84 | 114 | return util.cachestat(self._opener.join(self._filename)) |
|
85 | 115 | except FileNotFoundError: |
|
86 | 116 | return None |
|
87 | 117 | |
|
88 | def may_need_refresh(self): | |
|
118 | def may_need_refresh(self) -> bool: | |
|
89 | 119 | if 'identity' not in vars(self): |
|
90 | 120 | # no existing identity, we need a refresh |
|
91 | 121 | return True |
@@ -104,7 +134,7 b' class _dirstatemapcommon:' | |||
|
104 | 134 | return True |
|
105 | 135 | return current_identity != self.identity |
|
106 | 136 | |
|
107 | def preload(self): | |
|
137 | def preload(self) -> None: | |
|
108 | 138 | """Loads the underlying data, if it's not already loaded""" |
|
109 | 139 | self._map |
|
110 | 140 | |
@@ -135,7 +165,7 b' class _dirstatemapcommon:' | |||
|
135 | 165 | self._pendingmode = mode |
|
136 | 166 | return fp |
|
137 | 167 | |
|
138 | def _readdirstatefile(self, size=-1): | |
|
168 | def _readdirstatefile(self, size: int = -1) -> bytes: | |
|
139 | 169 | try: |
|
140 | 170 | with self._opendirstatefile() as fp: |
|
141 | 171 | return fp.read(size) |
@@ -144,7 +174,7 b' class _dirstatemapcommon:' | |||
|
144 | 174 | return b'' |
|
145 | 175 | |
|
146 | 176 | @property |
|
147 | def docket(self): | |
|
177 | def docket(self) -> "docketmod.DirstateDocket": | |
|
148 | 178 | if not self._docket: |
|
149 | 179 | if not self._use_dirstate_v2: |
|
150 | 180 | raise error.ProgrammingError( |
@@ -707,6 +707,8 b' def hidewindow() -> None:' | |||
|
707 | 707 | |
|
708 | 708 | |
|
709 | 709 | class cachestat: |
|
710 | stat: os.stat_result | |
|
711 | ||
|
710 | 712 | def __init__(self, path: bytes) -> None: |
|
711 | 713 | self.stat = os.stat(path) |
|
712 | 714 |
@@ -21,8 +21,21 b' TYPE_CHECKING = typing.TYPE_CHECKING' | |||
|
21 | 21 | if TYPE_CHECKING: |
|
22 | 22 | from typing import ( |
|
23 | 23 | BinaryIO, |
|
24 | Union, | |
|
25 | ) | |
|
26 | ||
|
27 | from . import ( | |
|
28 | node, | |
|
29 | posix, | |
|
30 | windows, | |
|
24 | 31 | ) |
|
25 | 32 | |
|
26 | 33 | BinaryIO_Proxy = BinaryIO |
|
34 | CacheStat = Union[posix.cachestat, windows.cachestat] | |
|
35 | NodeConstants = node.sha1nodeconstants | |
|
27 | 36 | else: |
|
37 | from typing import Any | |
|
38 | ||
|
28 | 39 | BinaryIO_Proxy = object |
|
40 | CacheStat = Any | |
|
41 | NodeConstants = Any |
General Comments 0
You need to be logged in to leave comments.
Login now