mercurial/interfaces/dirstate.py
author Matt Harbison <matt_harbison@yahoo.com>
Fri, 27 Sep 2024 12:30:37 -0400
changeset 51925 93d872a06132
parent 51924 3688a984134b
child 52431 2c8c46c3c401
permissions -rw-r--r--
typing: add type annotations to the dirstate classes The basic procedure here was to use `merge-pyi` to merge the `git/dirstate.pyi` file in (after renaming the interface class to match), cleaning up the import statement mess, and then repeating the procedure for `mercurial/dirstate.pyi`. Surprisingly, git's dirstate had more hints inferred in its *.pyi file. After that, it was a manual examination of each method in the interface, and how they were implemented in the core and git classes to verify what was inferred by pytype, and fill in the missing gaps. Since this involved jumping around between three different files, I applied the same type info to all three at the same time. Complex types I rolled up into type aliases in the interface module, and used that as needed. That way if it changes, there's one place to edit. There are some hints still missing, and some documentation that doesn't match the signatures. They should all be marked with TODOs. There are also a bunch of methods on the core class that aren't on the Protocol class that seem like maybe they should be (like `set_tracked()`). There are even more methods missing from the git class. But that's a project for another time.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
     4
import os
51919
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
     5
import typing
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
     6
51917
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
     7
from typing import (
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
     8
    Any,
51919
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
     9
    Callable,
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    10
    Dict,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    11
    Iterable,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    12
    Iterator,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    13
    List,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    14
    Optional,
51917
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
    15
    Protocol,
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    16
    Tuple,
51917
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
    17
)
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
    18
51919
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
    19
if typing.TYPE_CHECKING:
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
    20
    # 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: 51918
diff changeset
    21
    # to avoid circular imports
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
    22
    from .. import (
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
    23
        match as matchmod,
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    24
        scmutil,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    25
        transaction as txnmod,
51919
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
    26
    )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43008
diff changeset
    27
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    28
    # TODO: finish adding type hints
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    29
    AddParentChangeCallbackT = Callable[
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    30
        ["idirstate", Tuple[Any, Any], Tuple[Any, Any]], Any
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    31
    ]
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    32
    """The callback type for dirstate.addparentchangecallback()."""
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    33
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    34
    # 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: 51924
diff changeset
    35
    #  conditionalized with python or rust implementations.  Also,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    36
    #  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: 51924
diff changeset
    37
    DirstateItemT = Any  # dirstatemap.DirstateItem
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    38
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    39
    IgnoreFileAndLineT = Tuple[Optional[bytes], int, bytes]
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    40
    """The return type of dirstate._ignorefileandline(), which holds
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    41
    ``(file, lineno, originalline)``.
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    42
    """
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    43
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    44
    FlagFuncFallbackT = Callable[[], "FlagFuncReturnT"]
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    45
    """The type for the dirstate.flagfunc() fallback function."""
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    46
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    47
    FlagFuncReturnT = Callable[[bytes], bytes]
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    48
    """The return type of dirstate.flagfunc()."""
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    49
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    50
    # TODO: verify and complete this- it came from a pytype *.pyi file
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    51
    StatusReturnT = Tuple[Any, scmutil.status, Any]
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    52
    """The return type of dirstate.status()."""
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    53
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    54
    # TODO: probably doesn't belong here.
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    55
    TransactionT = txnmod.transaction
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    56
    """The type for a transaction used with dirstate.
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    57
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    58
    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: 51924
diff changeset
    59
    of the transaction module.
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    60
    """
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    61
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    62
    # 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: 51924
diff changeset
    63
    WalkReturnT = Dict[bytes, Optional[os.stat_result]]
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    64
    """The return type of dirstate.walk().
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    65
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    66
    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: 51924
diff changeset
    67
    if the file exists.
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    68
    """
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
    69
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
    70
51917
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
    71
class idirstate(Protocol):
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
    72
    # 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
    73
    # def __init__(
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
    74
    #     self,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
    75
    #     opener,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
    76
    #     ui,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
    77
    #     root,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
    78
    #     validate,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
    79
    #     sparsematchfn,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
    80
    #     nodeconstants,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
    81
    #     use_dirstate_v2,
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
    82
    #     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
    83
    # ):
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
    84
    #     """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
    85
    #
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
    86
    #     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
    87
    #     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
    88
    #     the dirstate.
382d9629cede interfaces: convert the dirstate zope interface to a Protocol class
Matt Harbison <matt_harbison@yahoo.com>
parents: 51859
diff changeset
    89
    #     """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
    90
42929
97b79354e9f0 idirstate: group private methods and attrs that are in the interface
Augie Fackler <augie@google.com>
parents: 42928
diff changeset
    91
    # 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
    92
    # public or removed from the interface.
51919
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
    93
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
    94
    # TODO: decorate with `@rootcache(b'.hgignore')` like dirstate class?
51924
3688a984134b interfaces: change a couple of dirstate fields to `@property`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51919
diff changeset
    95
    @property
3688a984134b interfaces: change a couple of dirstate fields to `@property`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51919
diff changeset
    96
    def _ignore(self) -> matchmod.basematcher:
3688a984134b interfaces: change a couple of dirstate fields to `@property`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51919
diff changeset
    97
        """Matcher for ignored files."""
51919
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
    98
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
    99
    @property
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
   100
    def is_changing_any(self) -> bool:
50023
e1cff85484e2 dirstate: introduce a `is_changing_any` property
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50022
diff changeset
   101
        """True if any changes in progress."""
51919
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
   102
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
   103
    @property
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
   104
    def is_changing_parents(self) -> bool:
50022
e333cc169c45 dirstate: rename `pendingparentchange` to `is_changing_parents`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49961
diff changeset
   105
        """True if parents changes in progress."""
51919
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
   106
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
   107
    @property
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
   108
    def is_changing_files(self) -> bool:
50026
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
   109
        """True if file tracking changes in progress."""
42929
97b79354e9f0 idirstate: group private methods and attrs that are in the interface
Augie Fackler <augie@google.com>
parents: 42928
diff changeset
   110
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   111
    def _ignorefiles(self) -> List[bytes]:
42929
97b79354e9f0 idirstate: group private methods and attrs that are in the interface
Augie Fackler <augie@google.com>
parents: 42928
diff changeset
   112
        """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
   113
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   114
    def _ignorefileandline(self, f: bytes) -> IgnoreFileAndLineT:
43787
be8552f25cab cleanup: fix docstring formatting
Matt Harbison <matt_harbison@yahoo.com>
parents: 43077
diff changeset
   115
        """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
   116
51919
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
   117
    # 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: 51918
diff changeset
   118
    #  (can't because circular import)
51924
3688a984134b interfaces: change a couple of dirstate fields to `@property`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51919
diff changeset
   119
    @property
3688a984134b interfaces: change a couple of dirstate fields to `@property`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51919
diff changeset
   120
    def _checklink(self) -> bool:
3688a984134b interfaces: change a couple of dirstate fields to `@property`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51919
diff changeset
   121
        """Callable for checking symlinks."""  # TODO: this comment looks stale
51919
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
   122
b455dfddfed0 interfaces: convert the zope `Attribute` attrs to regular fields
Matt Harbison <matt_harbison@yahoo.com>
parents: 51918
diff changeset
   123
    # 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: 51918
diff changeset
   124
    #  (can't because circular import)
51924
3688a984134b interfaces: change a couple of dirstate fields to `@property`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51919
diff changeset
   125
    @property
3688a984134b interfaces: change a couple of dirstate fields to `@property`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51919
diff changeset
   126
    def _checkexec(self) -> bool:
3688a984134b interfaces: change a couple of dirstate fields to `@property`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51919
diff changeset
   127
        """Callable for checking exec bits."""  # TODO: this comment looks stale
42929
97b79354e9f0 idirstate: group private methods and attrs that are in the interface
Augie Fackler <augie@google.com>
parents: 42928
diff changeset
   128
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   129
    @contextlib.contextmanager
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   130
    def changing_parents(self, repo) -> Iterator:  # TODO: typehint this
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
   131
        """Context manager for handling dirstate parents.
42927
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
        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
   134
        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
   135
        released.
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
   136
        """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   137
50026
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
   138
    @contextlib.contextmanager
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   139
    def changing_files(self, repo) -> Iterator:  # TODO: typehint this
50026
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
   140
        """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
   141
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
   142
        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
   143
        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
   144
        released.
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
   145
        """
3550e4a88ccd dirstate: add a context for tracking files change
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50023
diff changeset
   146
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   147
    def hasdir(self, d: bytes) -> bool:
42927
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
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   150
    def flagfunc(self, buildfallback: FlagFuncFallbackT) -> FlagFuncReturnT:
49880
9ea66d166ec7 dirstate: update docstrings in idirstate from the current dirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49076
diff changeset
   151
        """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
   152
9ea66d166ec7 dirstate: update docstrings in idirstate from the current dirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49076
diff changeset
   153
        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
   154
        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
   155
        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
   156
        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
   157
        """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   158
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   159
    def getcwd(self) -> bytes:
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
   160
        """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
   161
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   162
        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
   163
        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
   164
        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
   165
        """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   166
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   167
    def pathto(self, f: bytes, cwd: Optional[bytes] = None) -> bytes:
49881
b3ae17037b54 dirstate: swap pathto() and get_entry() in idirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49880
diff changeset
   168
        pass
b3ae17037b54 dirstate: swap pathto() and get_entry() in idirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49880
diff changeset
   169
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   170
    def get_entry(self, path: bytes) -> DirstateItemT:
49076
9c8d67a3af5e idirstate: add missing get_entry() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 48875
diff changeset
   171
        """return a DirstateItem for the associated path"""
9c8d67a3af5e idirstate: add missing get_entry() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 48875
diff changeset
   172
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   173
    def __contains__(self, key: Any) -> bool:
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   174
        """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
   175
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   176
    def __iter__(self) -> Iterator[bytes]:
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   177
        """Iterate the dirstate's contained filenames as bytestrings."""
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   178
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   179
    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: 47280
diff changeset
   180
        """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
   181
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   182
        As usual, filename is a bytestring.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   183
        """
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   184
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   185
    iteritems = items
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   186
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   187
    def parents(self) -> List[bytes]:
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   188
        pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   189
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   190
    def p1(self) -> bytes:
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   191
        pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   192
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   193
    def p2(self) -> bytes:
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   194
        pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   195
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   196
    def branch(self) -> bytes:
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   197
        pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   198
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   199
    # TODO: typehint the return.  It's a copies Map of some sort.
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   200
    def setparents(self, p1: bytes, p2: Optional[bytes] = None):
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   201
        """Set dirstate parents to p1 and p2.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   202
49880
9ea66d166ec7 dirstate: update docstrings in idirstate from the current dirstate
Anton Shestakov <av6@dwimlabs.net>
parents: 49076
diff changeset
   203
        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
   204
        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
   205
        returned by the call.
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
        See localrepo.setparents()
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   208
        """
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   209
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   210
    def setbranch(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   211
        self, branch: bytes, transaction: Optional[TransactionT]
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   212
    ) -> None:
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   213
        pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   214
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   215
    def invalidate(self) -> None:
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
   216
        """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
   217
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   218
        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
   219
        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
   220
        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
   221
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   222
    def copy(self, source: Optional[bytes], dest: bytes) -> None:
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   223
        """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
   224
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   225
    def copied(self, file: bytes) -> Optional[bytes]:
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   226
        pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   227
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   228
    def copies(self) -> Dict[bytes, bytes]:
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   229
        pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   230
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   231
    def normalize(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   232
        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: 51924
diff changeset
   233
    ) -> bytes:
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
   234
        """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   235
        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
   236
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   237
        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
   238
        disk, to avoid extra filesystem access.
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
        If ignoremissing is True, missing path are returned
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   241
        unchanged. Otherwise, we try harder to normalize possibly
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   242
        existing path components.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   243
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   244
        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
   245
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   246
        - version of name already stored in the dirstate
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   247
        - version of name stored on disk
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   248
        - version provided via command arguments
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
   249
        """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   250
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   251
    def clear(self) -> None:
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   252
        pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   253
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   254
    def rebuild(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   255
        self,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   256
        parent: bytes,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   257
        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: 51924
diff changeset
   258
        changedfiles: Optional[Iterable[bytes]] = None,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   259
    ) -> None:
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   260
        pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   261
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   262
    def write(self, tr: Optional[TransactionT]) -> None:
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   263
        pass
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   264
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   265
    def addparentchangecallback(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   266
        self, category: bytes, callback: AddParentChangeCallbackT
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   267
    ) -> None:
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   268
        """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
   269
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   270
        Callback will be called with the following arguments:
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   271
            dirstate, (oldp1, oldp2), (newp1, newp2)
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   272
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   273
        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
   274
        with a newer callback.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   275
        """
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   276
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   277
    def walk(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   278
        self,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   279
        match: matchmod.basematcher,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   280
        subrepos: Any,  # TODO: figure out what this is
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   281
        unknown: bool,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   282
        ignored: bool,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   283
        full: bool = True,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   284
    ) -> WalkReturnT:
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
   285
        """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   286
        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
   287
        matched by match.
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   288
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   289
        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
   290
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   291
        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
   292
        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
   293
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
   294
        """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   295
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   296
    def status(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   297
        self,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   298
        match: matchmod.basematcher,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   299
        subrepos: bool,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   300
        ignored: bool,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   301
        clean: bool,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   302
        unknown: bool,
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   303
    ) -> StatusReturnT:
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
   304
        """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
   305
        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
   306
        scmutil.status and:
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   307
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   308
          unsure:
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   309
            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
   310
            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
   311
            but mtime differs)
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   312
          status.modified:
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   313
            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
   314
            was written (different size or mode)
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   315
          status.clean:
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   316
            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
   317
            dirstate was written
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
   318
        """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   319
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   320
    # 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: 51924
diff changeset
   321
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   322
    def matches(self, match: matchmod.basematcher) -> Iterable[bytes]:
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43787
diff changeset
   323
        """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   324
        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
   325
        """
42927
d459cd8ea42d interfaces: introduce an interface for dirstate implementations
Augie Fackler <augie@google.com>
parents:
diff changeset
   326
51925
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   327
    # TODO: finish adding typehints here, and to subclasses
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   328
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   329
    def verify(
93d872a06132 typing: add type annotations to the dirstate classes
Matt Harbison <matt_harbison@yahoo.com>
parents: 51924
diff changeset
   330
        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: 51924
diff changeset
   331
    ) -> Iterator[bytes]:
49882
8c7895db8955 dirstate: add missing methods and kwargs to idirstate interface
Anton Shestakov <av6@dwimlabs.net>
parents: 49881
diff changeset
   332
        """
8c7895db8955 dirstate: add missing methods and kwargs to idirstate interface
Anton Shestakov <av6@dwimlabs.net>
parents: 49881
diff changeset
   333
        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
   334
        """