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