diff options
author | Yobmod <yobmod@gmail.com> | 2021-05-16 18:22:53 +0100 |
---|---|---|
committer | Yobmod <yobmod@gmail.com> | 2021-05-16 18:22:53 +0100 |
commit | 7c6c8dcc01b08748c552228e00070b0c94affa94 (patch) | |
tree | f580dc52722fb0ff02a1d02009f06c5bed6fb7c9 | |
parent | 11d91e245194cd9a2e44b81b2b3c62514596c578 (diff) | |
download | gitpython-7c6c8dcc01b08748c552228e00070b0c94affa94.tar.gz |
Add remaining types to IndexFile ._store_items() ._entries_for_paths()
-rw-r--r-- | git/index/base.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/git/index/base.py b/git/index/base.py index cf7fafef..d939e1af 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -66,7 +66,7 @@ from .util import ( # typing ----------------------------------------------------------------------------- -from typing import (Any, Callable, Dict, IO, Iterable, Iterator, List, +from typing import (Any, BinaryIO, Callable, Dict, IO, Iterable, Iterator, List, Sequence, TYPE_CHECKING, Tuple, Union) from git.types import PathLike, TBD @@ -567,7 +567,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): root_tree._cache = tree_items return root_tree - def _process_diff_args(self, args: Any) -> List[Any]: + def _process_diff_args(self, args: List[Union[str, diff.Diffable, object]] + ) -> List[Union[str, diff.Diffable, object]]: try: args.pop(args.index(self)) except IndexError: @@ -607,13 +608,14 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): # END for each item return paths, entries - def _store_path(self, filepath, fprogress): + def _store_path(self, filepath: PathLike, fprogress: Callable) -> BaseIndexEntry: """Store file at filepath in the database and return the base index entry Needs the git_working_dir decorator active ! This must be assured in the calling code""" st = os.lstat(filepath) # handles non-symlinks as well if S_ISLNK(st.st_mode): # in PY3, readlink is string, but we need bytes. In PY2, it's just OS encoded bytes, we assume UTF-8 - open_stream = lambda: BytesIO(force_bytes(os.readlink(filepath), encoding=defenc)) + open_stream = lambda: BytesIO(force_bytes(os.readlink(filepath), + encoding=defenc)) # type: Callable[[], BinaryIO] else: open_stream = lambda: open(filepath, 'rb') with open_stream() as stream: @@ -625,16 +627,18 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): @unbare_repo @git_working_dir - def _entries_for_paths(self, paths, path_rewriter, fprogress, entries): - entries_added = [] + def _entries_for_paths(self, paths: List[str], path_rewriter: Callable, fprogress: Callable, + entries: List[BaseIndexEntry]) -> List[BaseIndexEntry]: + entries_added = [] # type: List[BaseIndexEntry] if path_rewriter: for path in paths: if osp.isabs(path): abspath = path - gitrelative_path = path[len(self.repo.working_tree_dir) + 1:] + gitrelative_path = path[len(str(self.repo.working_tree_dir)) + 1:] else: gitrelative_path = path - abspath = osp.join(self.repo.working_tree_dir, gitrelative_path) + if self.repo.working_tree_dir: + abspath = osp.join(self.repo.working_tree_dir, gitrelative_path) # end obtain relative and absolute paths blob = Blob(self.repo, Blob.NULL_BIN_SHA, |