| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,7 @@ | |||
| 16 | 16 | # typing ------------------------------------------------------------------ | |
| 17 | 17 | ||
| 18 | 18 | from typing import Any, Iterator, List, Match, Optional, Tuple, Type, Union, TYPE_CHECKING | |
| 19 | - from git.types import TBD, Final, Literal | ||
| 19 | + from git.types import PathLike, TBD, Final, Literal | ||
| 20 | 20 | ||
| 21 | 21 | if TYPE_CHECKING: | |
| 22 | 22 | from .objects.tree import Tree | |
@@ -84,7 +84,7 @@ def _process_diff_args(self, args: List[Union[str, 'Diffable', object]]) -> List | |||
| 84 | 84 | return args | |
| 85 | 85 | ||
| 86 | 86 | def diff(self, other: Union[Type[Index], Type['Tree'], object, None, str] = Index, | |
| 87 | - paths: Union[str, List[str], Tuple[str, ...], None] = None, | ||
| 87 | + paths: Union[PathLike, List[PathLike], Tuple[PathLike, ...], None] = None, | ||
| 88 | 88 | create_patch: bool = False, **kwargs: Any) -> 'DiffIndex': | |
| 89 | 89 | """Creates diffs between two items being trees, trees and index or an | |
| 90 | 90 | index and the working tree. It will detect renames automatically. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | 12 | # typing ---------------------------------------------------- | |
| 13 | 13 | ||
| 14 | - from typing import List, Optional, Tuple, Union, TYPE_CHECKING | ||
| 14 | + from typing import List, Optional, Sequence, Tuple, Union, TYPE_CHECKING | ||
| 15 | 15 | from git.types import PathLike | |
| 16 | 16 | ||
| 17 | 17 | if TYPE_CHECKING: | |
@@ -113,7 +113,7 @@ class CheckoutError(GitError): | |||
| 113 | 113 | were checked out successfully and hence match the version stored in the | |
| 114 | 114 | index""" | |
| 115 | 115 | ||
| 116 | - def __init__(self, message: str, failed_files: List[PathLike], valid_files: List[PathLike], | ||
| 116 | + def __init__(self, message: str, failed_files: Sequence[PathLike], valid_files: List[PathLike], | ||
| 117 | 117 | failed_reasons: List[str]) -> None: | |
| 118 | 118 | ||
| 119 | 119 | Exception.__init__(self, message) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | # | |
| 4 | 4 | # This module is part of GitPython and is released under | |
| 5 | 5 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php | |
| 6 | + from git.refs.reference import Reference | ||
| 6 | 7 | import glob | |
| 7 | 8 | from io import BytesIO | |
| 8 | 9 | import os | |
@@ -65,16 +66,18 @@ | |||
| 65 | 66 | ||
| 66 | 67 | # typing ----------------------------------------------------------------------------- | |
| 67 | 68 | ||
| 68 | - from typing import Any, Callable, Dict, IO, Iterator, List, Sequence, TYPE_CHECKING, Tuple, Union | ||
| 69 | + from typing import (Any, Callable, Dict, IO, Iterable, Iterator, List, | ||
| 70 | + Sequence, TYPE_CHECKING, Tuple, Union) | ||
| 69 | 71 | ||
| 70 | 72 | from git.types import PathLike, TBD | |
| 71 | 73 | ||
| 72 | 74 | if TYPE_CHECKING: | |
| 73 | 75 | from subprocess import Popen | |
| 74 | 76 | from git.repo import Repo | |
| 75 | 77 | ||
| 78 | + | ||
| 76 | 79 | StageType = int | |
| 77 | - Treeish = Union[Tree, Commit, bytes] | ||
| 80 | + Treeish = Union[Tree, Commit, str, bytes] | ||
| 78 | 81 | ||
| 79 | 82 | ||
| 80 | 83 | __all__ = ('IndexFile', 'CheckoutError') | |
@@ -490,7 +493,7 @@ def unmerged_blobs(self) -> Dict[PathLike, List[Tuple[StageType, Blob]]]: | |||
| 490 | 493 | return path_map | |
| 491 | 494 | ||
| 492 | 495 | @classmethod | |
| 493 | - def entry_key(cls, *entry: Union[Tuple[BaseIndexEntry], Tuple[PathLike, StageType]]) -> Tuple[PathLike, StageType]: | ||
| 496 | + def entry_key(cls, *entry: Union[BaseIndexEntry, PathLike, StageType]) -> Tuple[PathLike, StageType]: | ||
| 494 | 497 | return entry_key(*entry) | |
| 495 | 498 | ||
| 496 | 499 | def resolve_blobs(self, iter_blobs: Iterator[Blob]) -> 'IndexFile': | |
@@ -513,7 +516,7 @@ def resolve_blobs(self, iter_blobs: Iterator[Blob]) -> 'IndexFile': | |||
| 513 | 516 | if stage_null_key in self.entries: | |
| 514 | 517 | raise ValueError("Path %r already exists at stage 0" % str(blob.path)) | |
| 515 | 518 | # END assert blob is not stage 0 already | |
| 516 | - | ||
| 519 | + | ||
| 517 | 520 | # delete all possible stages | |
| 518 | 521 | for stage in (1, 2, 3): | |
| 519 | 522 | try: | |
@@ -650,8 +653,9 @@ def _entries_for_paths(self, paths, path_rewriter, fprogress, entries): | |||
| 650 | 653 | # END path handling | |
| 651 | 654 | return entries_added | |
| 652 | 655 | ||
| 653 | - def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=None, | ||
| 654 | - write=True, write_extension_data=False): | ||
| 656 | + def add(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, Submodule]], force: bool = True, | ||
| 657 | + fprogress: Callable = lambda *args: None, path_rewriter: Callable = None, | ||
| 658 | + write: bool = True, write_extension_data: bool = False) -> List[BaseIndexEntry]: | ||
| 655 | 659 | """Add files from the working tree, specific blobs or BaseIndexEntries | |
| 656 | 660 | to the index. | |
| 657 | 661 | ||
@@ -838,7 +842,8 @@ def _items_to_rela_paths(self, items): | |||
| 838 | 842 | ||
| 839 | 843 | @post_clear_cache | |
| 840 | 844 | @default_index | |
| 841 | - def remove(self, items, working_tree=False, **kwargs): | ||
| 845 | + def remove(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, Submodule]], working_tree: bool = False, | ||
| 846 | + **kwargs: Any) -> List[str]: | ||
| 842 | 847 | """Remove the given items from the index and optionally from | |
| 843 | 848 | the working tree as well. | |
| 844 | 849 | ||
@@ -889,7 +894,8 @@ def remove(self, items, working_tree=False, **kwargs): | |||
| 889 | 894 | ||
| 890 | 895 | @post_clear_cache | |
| 891 | 896 | @default_index | |
| 892 | - def move(self, items, skip_errors=False, **kwargs): | ||
| 897 | + def move(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, Submodule]], skip_errors: bool = False, | ||
| 898 | + **kwargs: Any) -> List[Tuple[str, str]]: | ||
| 893 | 899 | """Rename/move the items, whereas the last item is considered the destination of | |
| 894 | 900 | the move operation. If the destination is a file, the first item ( of two ) | |
| 895 | 901 | must be a file as well. If the destination is a directory, it may be preceded | |
@@ -951,9 +957,9 @@ def move(self, items, skip_errors=False, **kwargs): | |||
| 951 | 957 | ||
| 952 | 958 | return out | |
| 953 | 959 | ||
| 954 | - def commit(self, message, parent_commits=None, head=True, author=None, | ||
| 955 | - committer=None, author_date=None, commit_date=None, | ||
| 956 | - skip_hooks=False): | ||
| 960 | + def commit(self, message: str, parent_commits=None, head: bool = True, author: str = None, | ||
| 961 | + committer: str = None, author_date: str = None, commit_date: str = None, | ||
| 962 | + skip_hooks: bool = False) -> Commit: | ||
| 957 | 963 | """Commit the current default index file, creating a commit object. | |
| 958 | 964 | For more information on the arguments, see tree.commit. | |
| 959 | 965 | ||
@@ -977,33 +983,39 @@ def commit(self, message, parent_commits=None, head=True, author=None, | |||
| 977 | 983 | run_commit_hook('post-commit', self) | |
| 978 | 984 | return rval | |
| 979 | 985 | ||
| 980 | - def _write_commit_editmsg(self, message): | ||
| 986 | + def _write_commit_editmsg(self, message: str) -> None: | ||
| 981 | 987 | with open(self._commit_editmsg_filepath(), "wb") as commit_editmsg_file: | |
| 982 | 988 | commit_editmsg_file.write(message.encode(defenc)) | |
| 983 | 989 | ||
| 984 | - def _remove_commit_editmsg(self): | ||
| 990 | + def _remove_commit_editmsg(self) -> None: | ||
| 985 | 991 | os.remove(self._commit_editmsg_filepath()) | |
| 986 | 992 | ||
| 987 | - def _read_commit_editmsg(self): | ||
| 993 | + def _read_commit_editmsg(self) -> str: | ||
| 988 | 994 | with open(self._commit_editmsg_filepath(), "rb") as commit_editmsg_file: | |
| 989 | 995 | return commit_editmsg_file.read().decode(defenc) | |
| 990 | 996 | ||
| 991 | - def _commit_editmsg_filepath(self): | ||
| 997 | + def _commit_editmsg_filepath(self) -> str: | ||
| 992 | 998 | return osp.join(self.repo.common_dir, "COMMIT_EDITMSG") | |
| 993 | 999 | ||
| 994 | - @classmethod | ||
| 995 | - def _flush_stdin_and_wait(cls, proc, ignore_stdout=False): | ||
| 996 | - proc.stdin.flush() | ||
| 997 | - proc.stdin.close() | ||
| 998 | - stdout = '' | ||
| 999 | - if not ignore_stdout: | ||
| 1000 | + def _flush_stdin_and_wait(cls, proc: 'Popen[bytes]', ignore_stdout: bool = False) -> bytes: | ||
| 1001 | + stdin_IO = proc.stdin | ||
| 1002 | + if stdin_IO: | ||
| 1003 | + stdin_IO.flush() | ||
| 1004 | + stdin_IO.close() | ||
| 1005 | + | ||
| 1006 | + stdout = b'' | ||
| 1007 | + if not ignore_stdout and proc.stdout: | ||
| 1000 | 1008 | stdout = proc.stdout.read() | |
| 1001 | - proc.stdout.close() | ||
| 1002 | - proc.wait() | ||
| 1009 | + | ||
| 1010 | + if proc.stdout: | ||
| 1011 | + proc.stdout.close() | ||
| 1012 | + proc.wait() | ||
| 1003 | 1013 | return stdout | |
| 1004 | 1014 | ||
| 1005 | 1015 | @default_index | |
| 1006 | - def checkout(self, paths=None, force=False, fprogress=lambda *args: None, **kwargs): | ||
| 1016 | + def checkout(self, paths: Union[None, Iterable[PathLike]] = None, force: bool = False, | ||
| 1017 | + fprogress: Callable = lambda *args: None, **kwargs: Any | ||
| 1018 | + ) -> Union[None, Iterator[PathLike], List[PathLike]]: | ||
| 1007 | 1019 | """Checkout the given paths or all files from the version known to the index into | |
| 1008 | 1020 | the working tree. | |
| 1009 | 1021 | ||
@@ -1054,12 +1066,15 @@ def checkout(self, paths=None, force=False, fprogress=lambda *args: None, **kwar | |||
| 1054 | 1066 | failed_reasons = [] | |
| 1055 | 1067 | unknown_lines = [] | |
| 1056 | 1068 | ||
| 1057 | - def handle_stderr(proc, iter_checked_out_files): | ||
| 1058 | - stderr = proc.stderr.read() | ||
| 1059 | - if not stderr: | ||
| 1060 | - return | ||
| 1069 | + def handle_stderr(proc: 'Popen[bytes]', iter_checked_out_files: Iterable[PathLike]) -> None: | ||
| 1070 | + | ||
| 1071 | + stderr_IO = proc.stderr | ||
| 1072 | + if not stderr_IO: | ||
| 1073 | + return None # return early if stderr empty | ||
| 1074 | + else: | ||
| 1075 | + stderr_bytes = stderr_IO.read() | ||
| 1061 | 1076 | # line contents: | |
| 1062 | - stderr = stderr.decode(defenc) | ||
| 1077 | + stderr = stderr_bytes.decode(defenc) | ||
| 1063 | 1078 | # git-checkout-index: this already exists | |
| 1064 | 1079 | endings = (' already exists', ' is not in the cache', ' does not exist at stage', ' is unmerged') | |
| 1065 | 1080 | for line in stderr.splitlines(): | |
@@ -1123,7 +1138,7 @@ def handle_stderr(proc, iter_checked_out_files): | |||
| 1123 | 1138 | proc = self.repo.git.checkout_index(args, **kwargs) | |
| 1124 | 1139 | # FIXME: Reading from GIL! | |
| 1125 | 1140 | make_exc = lambda: GitCommandError(("git-checkout-index",) + tuple(args), 128, proc.stderr.read()) | |
| 1126 | - checked_out_files = [] | ||
| 1141 | + checked_out_files = [] # type: List[PathLike] | ||
| 1127 | 1142 | ||
| 1128 | 1143 | for path in paths: | |
| 1129 | 1144 | co_path = to_native_path_linux(self._to_relative_path(path)) | |
@@ -1133,11 +1148,11 @@ def handle_stderr(proc, iter_checked_out_files): | |||
| 1133 | 1148 | try: | |
| 1134 | 1149 | self.entries[(co_path, 0)] | |
| 1135 | 1150 | except KeyError: | |
| 1136 | - folder = co_path | ||
| 1151 | + folder = str(co_path) | ||
| 1137 | 1152 | if not folder.endswith('/'): | |
| 1138 | 1153 | folder += '/' | |
| 1139 | 1154 | for entry in self.entries.values(): | |
| 1140 | - if entry.path.startswith(folder): | ||
| 1155 | + if str(entry.path).startswith(folder): | ||
| 1141 | 1156 | p = entry.path | |
| 1142 | 1157 | self._write_path_to_stdin(proc, p, p, make_exc, | |
| 1143 | 1158 | fprogress, read_from_stdout=False) | |
@@ -1167,7 +1182,9 @@ def handle_stderr(proc, iter_checked_out_files): | |||
| 1167 | 1182 | assert "Should not reach this point" | |
| 1168 | 1183 | ||
| 1169 | 1184 | @default_index | |
| 1170 | - def reset(self, commit='HEAD', working_tree=False, paths=None, head=False, **kwargs): | ||
| 1185 | + def reset(self, commit: Union[Commit, Reference, str] = 'HEAD', working_tree: bool = False, | ||
| 1186 | + paths: Union[None, Iterable[PathLike]] = None, | ||
| 1187 | + head: bool = False, **kwargs: Any) -> 'IndexFile': | ||
| 1171 | 1188 | """Reset the index to reflect the tree at the given commit. This will not | |
| 1172 | 1189 | adjust our HEAD reference as opposed to HEAD.reset by default. | |
| 1173 | 1190 | ||
@@ -1235,10 +1252,12 @@ def reset(self, commit='HEAD', working_tree=False, paths=None, head=False, **kwa | |||
| 1235 | 1252 | return self | |
| 1236 | 1253 | ||
| 1237 | 1254 | @default_index | |
| 1238 | - def diff(self, other=diff.Diffable.Index, paths=None, create_patch=False, **kwargs): | ||
| 1255 | + def diff(self, other: Union[diff.Diffable.Index, 'IndexFile.Index', Treeish, None, object] = diff.Diffable.Index, | ||
| 1256 | + paths: Union[str, List[PathLike], Tuple[PathLike, ...]] = None, create_patch: bool = False, **kwargs: Any | ||
| 1257 | + ) -> diff.DiffIndex: | ||
| 1239 | 1258 | """Diff this index against the working copy or a Tree or Commit object | |
| 1240 | 1259 | ||
| 1241 | - For a documentation of the parameters and return values, see | ||
| 1260 | + For a documentation of the parameters and return values, see, | ||
| 1242 | 1261 | Diffable.diff | |
| 1243 | 1262 | ||
| 1244 | 1263 | :note: | |
@@ -1256,7 +1275,7 @@ def diff(self, other=diff.Diffable.Index, paths=None, create_patch=False, **kwar | |||
| 1256 | 1275 | other = self.repo.rev_parse(other) | |
| 1257 | 1276 | # END object conversion | |
| 1258 | 1277 | ||
| 1259 | - if isinstance(other, Object): | ||
| 1278 | + if isinstance(other, Object): # for Tree or Commit | ||
| 1260 | 1279 | # invert the existing R flag | |
| 1261 | 1280 | cur_val = kwargs.get('R', False) | |
| 1262 | 1281 | kwargs['R'] = not cur_val | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,7 @@ | |||
| 13 | 13 | S_IFREG, | |
| 14 | 14 | ) | |
| 15 | 15 | import subprocess | |
| 16 | - from typing import List, Tuple, cast | ||
| 16 | + from typing import List, Tuple, Union, cast | ||
| 17 | 17 | ||
| 18 | 18 | from git.cmd import PROC_CREATIONFLAGS, handle_process_output | |
| 19 | 19 | from git.compat import ( | |
@@ -168,7 +168,7 @@ def read_header(stream): | |||
| 168 | 168 | return version, num_entries | |
| 169 | 169 | ||
| 170 | 170 | ||
| 171 | - def entry_key(*entry) -> Tuple[PathLike, int]: | ||
| 171 | + def entry_key(*entry: Union[BaseIndexEntry, PathLike, int]) -> Tuple[PathLike, int]: | ||
| 172 | 172 | """:return: Key suitable to be used for the index.entries dictionary | |
| 173 | 173 | :param entry: One instance of type BaseIndexEntry or the path and the stage""" | |
| 174 | 174 | if len(entry) == 1: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,8 @@ | |||
| 8 | 8 | ) | |
| 9 | 9 | from git.objects import Blob | |
| 10 | 10 | ||
| 11 | + from git.types import PathLike | ||
| 12 | + | ||
| 11 | 13 | ||
| 12 | 14 | __all__ = ('BlobFilter', 'BaseIndexEntry', 'IndexEntry') | |
| 13 | 15 | ||
@@ -79,7 +81,7 @@ def hexsha(self): | |||
| 79 | 81 | return b2a_hex(self[1]).decode('ascii') | |
| 80 | 82 | ||
| 81 | 83 | @property | |
| 82 | - def stage(self): | ||
| 84 | + def stage(self) -> int: | ||
| 83 | 85 | """Stage of the entry, either: | |
| 84 | 86 | ||
| 85 | 87 | * 0 = default stage | |
@@ -92,7 +94,7 @@ def stage(self): | |||
| 92 | 94 | return (self[2] & CE_STAGEMASK) >> CE_STAGESHIFT | |
| 93 | 95 | ||
| 94 | 96 | @property | |
| 95 | - def path(self): | ||
| 97 | + def path(self) -> PathLike: | ||
| 96 | 98 | """:return: our path relative to the repository working tree root""" | |
| 97 | 99 | return self[3] | |
| 98 | 100 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments