Show More
@@ -45,6 +45,8 from typing import ( | |||||
45 | List, |
|
45 | List, | |
46 | Optional, |
|
46 | Optional, | |
47 | Tuple, |
|
47 | Tuple, | |
|
48 | Type, | |||
|
49 | TypeVar, | |||
48 | ) |
|
50 | ) | |
49 |
|
51 | |||
50 | from .node import hex |
|
52 | from .node import hex | |
@@ -159,6 +161,10 unlink = platform.unlink | |||||
159 | username = platform.username |
|
161 | username = platform.username | |
160 |
|
162 | |||
161 |
|
163 | |||
|
164 | if typing.TYPE_CHECKING: | |||
|
165 | _Tfilestat = TypeVar('_Tfilestat', bound='filestat') | |||
|
166 | ||||
|
167 | ||||
162 | def setumask(val: int) -> None: |
|
168 | def setumask(val: int) -> None: | |
163 | '''updates the umask. used by chg server''' |
|
169 | '''updates the umask. used by chg server''' | |
164 | if pycompat.iswindows: |
|
170 | if pycompat.iswindows: | |
@@ -2491,11 +2497,11 class filestat: | |||||
2491 | 'exists()' examination on client side of this class. |
|
2497 | 'exists()' examination on client side of this class. | |
2492 | """ |
|
2498 | """ | |
2493 |
|
2499 | |||
2494 | def __init__(self, stat): |
|
2500 | def __init__(self, stat: Optional[os.stat_result]) -> None: | |
2495 | self.stat = stat |
|
2501 | self.stat = stat | |
2496 |
|
2502 | |||
2497 | @classmethod |
|
2503 | @classmethod | |
2498 | def frompath(cls, path): |
|
2504 | def frompath(cls: Type[_Tfilestat], path: bytes) -> _Tfilestat: | |
2499 | try: |
|
2505 | try: | |
2500 | stat = os.stat(path) |
|
2506 | stat = os.stat(path) | |
2501 | except FileNotFoundError: |
|
2507 | except FileNotFoundError: | |
@@ -2503,13 +2509,13 class filestat: | |||||
2503 | return cls(stat) |
|
2509 | return cls(stat) | |
2504 |
|
2510 | |||
2505 | @classmethod |
|
2511 | @classmethod | |
2506 | def fromfp(cls, fp): |
|
2512 | def fromfp(cls: Type[_Tfilestat], fp: BinaryIO) -> _Tfilestat: | |
2507 | stat = os.fstat(fp.fileno()) |
|
2513 | stat = os.fstat(fp.fileno()) | |
2508 | return cls(stat) |
|
2514 | return cls(stat) | |
2509 |
|
2515 | |||
2510 | __hash__ = object.__hash__ |
|
2516 | __hash__ = object.__hash__ | |
2511 |
|
2517 | |||
2512 | def __eq__(self, old): |
|
2518 | def __eq__(self, old) -> bool: | |
2513 | try: |
|
2519 | try: | |
2514 | # if ambiguity between stat of new and old file is |
|
2520 | # if ambiguity between stat of new and old file is | |
2515 | # avoided, comparison of size, ctime and mtime is enough |
|
2521 | # avoided, comparison of size, ctime and mtime is enough | |
@@ -2526,7 +2532,7 class filestat: | |||||
2526 | except AttributeError: |
|
2532 | except AttributeError: | |
2527 | return False |
|
2533 | return False | |
2528 |
|
2534 | |||
2529 | def isambig(self, old): |
|
2535 | def isambig(self, old: _Tfilestat) -> bool: | |
2530 | """Examine whether new (= self) stat is ambiguous against old one |
|
2536 | """Examine whether new (= self) stat is ambiguous against old one | |
2531 |
|
2537 | |||
2532 | "S[N]" below means stat of a file at N-th change: |
|
2538 | "S[N]" below means stat of a file at N-th change: | |
@@ -2561,7 +2567,7 class filestat: | |||||
2561 | except AttributeError: |
|
2567 | except AttributeError: | |
2562 | return False |
|
2568 | return False | |
2563 |
|
2569 | |||
2564 | def avoidambig(self, path, old): |
|
2570 | def avoidambig(self, path: bytes, old: _Tfilestat) -> bool: | |
2565 | """Change file stat of specified path to avoid ambiguity |
|
2571 | """Change file stat of specified path to avoid ambiguity | |
2566 |
|
2572 | |||
2567 | 'old' should be previous filestat of 'path'. |
|
2573 | 'old' should be previous filestat of 'path'. | |
@@ -2581,7 +2587,7 class filestat: | |||||
2581 | return False |
|
2587 | return False | |
2582 | return True |
|
2588 | return True | |
2583 |
|
2589 | |||
2584 | def __ne__(self, other): |
|
2590 | def __ne__(self, other) -> bool: | |
2585 | return not self == other |
|
2591 | return not self == other | |
2586 |
|
2592 | |||
2587 |
|
2593 |
General Comments 0
You need to be logged in to leave comments.
Login now