Skip to content

Commit

Permalink
Merge pull request #1244 from Yobmod/main
Browse files Browse the repository at this point in the history
Added types to Index submodule
  • Loading branch information
Byron authored May 18, 2021
2 parents 33346b2 + c30bf3b commit b11bcfa
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 179 deletions.
8 changes: 4 additions & 4 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ def _set_cache_(self, attr: str) -> None:
# END handle version info

@property
def working_dir(self) -> Union[None, str]:
def working_dir(self) -> Union[None, PathLike]:
""":return: Git directory we are working on"""
return self._working_dir

Expand Down Expand Up @@ -1187,7 +1187,7 @@ def __get_object_header(self, cmd, ref: AnyStr) -> Tuple[str, str, int]:
cmd.stdin.flush()
return self._parse_object_header(cmd.stdout.readline())

def get_object_header(self, ref: AnyStr) -> Tuple[str, str, int]:
def get_object_header(self, ref: str) -> Tuple[str, str, int]:
""" Use this method to quickly examine the type and size of the object behind
the given ref.
Expand All @@ -1198,7 +1198,7 @@ def get_object_header(self, ref: AnyStr) -> Tuple[str, str, int]:
cmd = self._get_persistent_cmd("cat_file_header", "cat_file", batch_check=True)
return self.__get_object_header(cmd, ref)

def get_object_data(self, ref: AnyStr) -> Tuple[str, str, int, bytes]:
def get_object_data(self, ref: str) -> Tuple[str, str, int, bytes]:
""" As get_object_header, but returns object data as well
:return: (hexsha, type_string, size_as_int,data_string)
:note: not threadsafe"""
Expand All @@ -1207,7 +1207,7 @@ def get_object_data(self, ref: AnyStr) -> Tuple[str, str, int, bytes]:
del(stream)
return (hexsha, typename, size, data)

def stream_object_data(self, ref: AnyStr) -> Tuple[str, str, int, 'Git.CatFileContentStream']:
def stream_object_data(self, ref: str) -> Tuple[str, str, int, 'Git.CatFileContentStream']:
""" As get_object_header, but returns the data as a stream
:return: (hexsha, type_string, size_as_int, stream)
Expand Down
12 changes: 6 additions & 6 deletions git/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# typing-------------------------------------------------

from typing import TYPE_CHECKING, AnyStr
from typing import TYPE_CHECKING
from git.types import PathLike

if TYPE_CHECKING:
Expand All @@ -39,18 +39,18 @@ def __init__(self, root_path: PathLike, git: 'Git') -> None:
super(GitCmdObjectDB, self).__init__(root_path)
self._git = git

def info(self, sha: bytes) -> OInfo:
hexsha, typename, size = self._git.get_object_header(bin_to_hex(sha))
def info(self, binsha: bytes) -> OInfo:
hexsha, typename, size = self._git.get_object_header(bin_to_hex(binsha))
return OInfo(hex_to_bin(hexsha), typename, size)

def stream(self, sha: bytes) -> OStream:
def stream(self, binsha: bytes) -> OStream:
"""For now, all lookup is done by git itself"""
hexsha, typename, size, stream = self._git.stream_object_data(bin_to_hex(sha))
hexsha, typename, size, stream = self._git.stream_object_data(bin_to_hex(binsha))
return OStream(hex_to_bin(hexsha), typename, size, stream)

# { Interface

def partial_to_complete_sha_hex(self, partial_hexsha: AnyStr) -> bytes:
def partial_to_complete_sha_hex(self, partial_hexsha: str) -> bytes:
""":return: Full binary 20 byte sha from the given partial hexsha
:raise AmbiguousObjectName:
:raise BadObject:
Expand Down
4 changes: 2 additions & 2 deletions git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# typing ------------------------------------------------------------------

from typing import Any, Iterator, List, Match, Optional, Tuple, Type, Union, TYPE_CHECKING
from git.types import TBD, Final, Literal
from git.types import PathLike, TBD, Final, Literal

if TYPE_CHECKING:
from .objects.tree import Tree
Expand Down Expand Up @@ -84,7 +84,7 @@ def _process_diff_args(self, args: List[Union[str, 'Diffable', object]]) -> List
return args

def diff(self, other: Union[Type[Index], Type['Tree'], object, None, str] = Index,
paths: Union[str, List[str], Tuple[str, ...], None] = None,
paths: Union[PathLike, List[PathLike], Tuple[PathLike, ...], None] = None,
create_patch: bool = False, **kwargs: Any) -> 'DiffIndex':
"""Creates diffs between two items being trees, trees and index or an
index and the working tree. It will detect renames automatically.
Expand Down
11 changes: 7 additions & 4 deletions git/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# typing ----------------------------------------------------

from typing import List, Optional, Tuple, Union, TYPE_CHECKING
from typing import List, Sequence, Tuple, Union, TYPE_CHECKING
from git.types import PathLike

if TYPE_CHECKING:
Expand Down Expand Up @@ -113,7 +113,7 @@ class CheckoutError(GitError):
were checked out successfully and hence match the version stored in the
index"""

def __init__(self, message: str, failed_files: List[PathLike], valid_files: List[PathLike],
def __init__(self, message: str, failed_files: Sequence[PathLike], valid_files: Sequence[PathLike],
failed_reasons: List[str]) -> None:

Exception.__init__(self, message)
Expand All @@ -139,8 +139,11 @@ class HookExecutionError(CommandError):
"""Thrown if a hook exits with a non-zero exit code. It provides access to the exit code and the string returned
via standard output"""

def __init__(self, command: Union[List[str], Tuple[str, ...], str], status: Optional[str],
stderr: Optional[str] = None, stdout: Optional[str] = None) -> None:
def __init__(self, command: Union[List[str], Tuple[str, ...], str],
status: Union[str, int, None, Exception],
stderr: Union[bytes, str, None] = None,
stdout: Union[bytes, str, None] = None) -> None:

super(HookExecutionError, self).__init__(command, status, stderr, stdout)
self._msg = "Hook('%s') failed%s"

Expand Down
Loading

0 comments on commit b11bcfa

Please sign in to comment.