| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 91d4cc5 commit 0414bf7
14 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -578,7 +578,7 @@ def _included_paths(self) -> List[Tuple[str, str]]: | |||
| 578 | 578 | value, | |
| 579 | 579 | ) | |
| 580 | 580 | if self._repo.git_dir: | |
| 581 | - if fnmatch.fnmatchcase(str(self._repo.git_dir), value): | ||
| 581 | + if fnmatch.fnmatchcase(os.fspath(self._repo.git_dir), value): | ||
| 582 | 582 | paths += self.items(section) | |
| 583 | 583 | ||
| 584 | 584 | elif keyword == "onbranch": | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -404,10 +404,10 @@ def _iter_expand_paths(self: "IndexFile", paths: Sequence[PathLike]) -> Iterator | |||
| 404 | 404 | def raise_exc(e: Exception) -> NoReturn: | |
| 405 | 405 | raise e | |
| 406 | 406 | ||
| 407 | - r = str(self.repo.working_tree_dir) | ||
| 407 | + r = os.fspath(self.repo.working_tree_dir) | ||
| 408 | 408 | rs = r + os.sep | |
| 409 | 409 | for path in paths: | |
| 410 | - abs_path = str(path) | ||
| 410 | + abs_path = os.fspath(path) | ||
| 411 | 411 | if not osp.isabs(abs_path): | |
| 412 | 412 | abs_path = osp.join(r, path) | |
| 413 | 413 | # END make absolute path | |
@@ -434,7 +434,7 @@ def raise_exc(e: Exception) -> NoReturn: | |||
| 434 | 434 | # characters. | |
| 435 | 435 | if abs_path not in resolved_paths: | |
| 436 | 436 | for f in self._iter_expand_paths(glob.glob(abs_path)): | |
| 437 | - yield str(f).replace(rs, "") | ||
| 437 | + yield os.fspath(f).replace(rs, "") | ||
| 438 | 438 | continue | |
| 439 | 439 | # END glob handling | |
| 440 | 440 | try: | |
@@ -569,7 +569,7 @@ def resolve_blobs(self, iter_blobs: Iterator[Blob]) -> "IndexFile": | |||
| 569 | 569 | for blob in iter_blobs: | |
| 570 | 570 | stage_null_key = (blob.path, 0) | |
| 571 | 571 | if stage_null_key in self.entries: | |
| 572 | - raise ValueError("Path %r already exists at stage 0" % str(blob.path)) | ||
| 572 | + raise ValueError("Path %r already exists at stage 0" % os.fspath(blob.path)) | ||
| 573 | 573 | # END assert blob is not stage 0 already | |
| 574 | 574 | ||
| 575 | 575 | # Delete all possible stages. | |
@@ -656,10 +656,10 @@ def _to_relative_path(self, path: PathLike) -> PathLike: | |||
| 656 | 656 | return path | |
| 657 | 657 | if self.repo.bare: | |
| 658 | 658 | raise InvalidGitRepositoryError("require non-bare repository") | |
| 659 | - if not osp.normpath(str(path)).startswith(str(self.repo.working_tree_dir)): | ||
| 659 | + if not osp.normpath(os.fspath(path)).startswith(os.fspath(self.repo.working_tree_dir)): | ||
| 660 | 660 | raise ValueError("Absolute path %r is not in git repository at %r" % (path, self.repo.working_tree_dir)) | |
| 661 | 661 | result = os.path.relpath(path, self.repo.working_tree_dir) | |
| 662 | - if str(path).endswith(os.sep) and not result.endswith(os.sep): | ||
| 662 | + if os.fspath(path).endswith(os.sep) and not result.endswith(os.sep): | ||
| 663 | 663 | result += os.sep | |
| 664 | 664 | return result | |
| 665 | 665 | ||
@@ -731,7 +731,7 @@ def _entries_for_paths( | |||
| 731 | 731 | for path in paths: | |
| 732 | 732 | if osp.isabs(path): | |
| 733 | 733 | abspath = path | |
| 734 | - gitrelative_path = path[len(str(self.repo.working_tree_dir)) + 1 :] | ||
| 734 | + gitrelative_path = path[len(os.fspath(self.repo.working_tree_dir)) + 1 :] | ||
| 735 | 735 | else: | |
| 736 | 736 | gitrelative_path = path | |
| 737 | 737 | if self.repo.working_tree_dir: | |
@@ -1359,11 +1359,11 @@ def make_exc() -> GitCommandError: | |||
| 1359 | 1359 | try: | |
| 1360 | 1360 | self.entries[(co_path, 0)] | |
| 1361 | 1361 | except KeyError: | |
| 1362 | - folder = str(co_path) | ||
| 1362 | + folder = os.fspath(co_path) | ||
| 1363 | 1363 | if not folder.endswith("/"): | |
| 1364 | 1364 | folder += "/" | |
| 1365 | 1365 | for entry in self.entries.values(): | |
| 1366 | - if str(entry.path).startswith(folder): | ||
| 1366 | + if os.fspath(entry.path).startswith(folder): | ||
| 1367 | 1367 | p = entry.path | |
| 1368 | 1368 | self._write_path_to_stdin(proc, p, p, make_exc, fprogress, read_from_stdout=False) | |
| 1369 | 1369 | checked_out_files.append(p) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -87,7 +87,7 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None: | |||
| 87 | 87 | return | |
| 88 | 88 | ||
| 89 | 89 | env = os.environ.copy() | |
| 90 | - env["GIT_INDEX_FILE"] = safe_decode(str(index.path)) | ||
| 90 | + env["GIT_INDEX_FILE"] = safe_decode(os.fspath(index.path)) | ||
| 91 | 91 | env["GIT_EDITOR"] = ":" | |
| 92 | 92 | cmd = [hp] | |
| 93 | 93 | try: | |
@@ -167,7 +167,7 @@ def write_cache( | |||
| 167 | 167 | beginoffset = tell() | |
| 168 | 168 | write(entry.ctime_bytes) # ctime | |
| 169 | 169 | write(entry.mtime_bytes) # mtime | |
| 170 | - path_str = str(entry.path) | ||
| 170 | + path_str = os.fspath(entry.path) | ||
| 171 | 171 | path: bytes = force_bytes(path_str, encoding=defenc) | |
| 172 | 172 | plen = len(path) & CE_NAMEMASK # Path length | |
| 173 | 173 | assert plen == len(path), "Path %s too long to fit into index" % entry.path | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -106,7 +106,7 @@ def git_working_dir(func: Callable[..., _T]) -> Callable[..., _T]: | |||
| 106 | 106 | @wraps(func) | |
| 107 | 107 | def set_git_working_dir(self: "IndexFile", *args: Any, **kwargs: Any) -> _T: | |
| 108 | 108 | cur_wd = os.getcwd() | |
| 109 | - os.chdir(str(self.repo.working_tree_dir)) | ||
| 109 | + os.chdir(os.fspath(self.repo.working_tree_dir)) | ||
| 110 | 110 | try: | |
| 111 | 111 | return func(self, *args, **kwargs) | |
| 112 | 112 | finally: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ | |||
| 6 | 6 | __all__ = ["Blob"] | |
| 7 | 7 | ||
| 8 | 8 | from mimetypes import guess_type | |
| 9 | + import os | ||
| 9 | 10 | import sys | |
| 10 | 11 | ||
| 11 | 12 | if sys.version_info >= (3, 8): | |
@@ -44,5 +45,5 @@ def mime_type(self) -> str: | |||
| 44 | 45 | """ | |
| 45 | 46 | guesses = None | |
| 46 | 47 | if self.path: | |
| 47 | - guesses = guess_type(str(self.path)) | ||
| 48 | + guesses = guess_type(os.fspath(self.path)) | ||
| 48 | 49 | return guesses and guesses[0] or self.DEFAULT_MIME_TYPE | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -352,7 +352,7 @@ def _clone_repo( | |||
| 352 | 352 | module_abspath_dir = osp.dirname(module_abspath) | |
| 353 | 353 | if not osp.isdir(module_abspath_dir): | |
| 354 | 354 | os.makedirs(module_abspath_dir) | |
| 355 | - module_checkout_path = osp.join(str(repo.working_tree_dir), path) | ||
| 355 | + module_checkout_path = osp.join(os.fspath(repo.working_tree_dir), path) | ||
| 356 | 356 | ||
| 357 | 357 | if url.startswith("../"): | |
| 358 | 358 | remote_name = repo.active_branch.tracking_branch().remote_name | |
@@ -541,7 +541,7 @@ def add( | |||
| 541 | 541 | if sm.exists(): | |
| 542 | 542 | # Reretrieve submodule from tree. | |
| 543 | 543 | try: | |
| 544 | - sm = repo.head.commit.tree[str(path)] | ||
| 544 | + sm = repo.head.commit.tree[os.fspath(path)] | ||
| 545 | 545 | sm._name = name | |
| 546 | 546 | return sm | |
| 547 | 547 | except KeyError: | |
@@ -1016,7 +1016,7 @@ def move(self, module_path: PathLike, configuration: bool = True, module: bool = | |||
| 1016 | 1016 | return self | |
| 1017 | 1017 | # END handle no change | |
| 1018 | 1018 | ||
| 1019 | - module_checkout_abspath = join_path_native(str(self.repo.working_tree_dir), module_checkout_path) | ||
| 1019 | + module_checkout_abspath = join_path_native(os.fspath(self.repo.working_tree_dir), module_checkout_path) | ||
| 1020 | 1020 | if osp.isfile(module_checkout_abspath): | |
| 1021 | 1021 | raise ValueError("Cannot move repository onto a file: %s" % module_checkout_abspath) | |
| 1022 | 1022 | # END handle target files | |
@@ -1313,7 +1313,7 @@ def set_parent_commit(self, commit: Union[Commit_ish, str, None], check: bool = | |||
| 1313 | 1313 | # If check is False, we might see a parent-commit that doesn't even contain the | |
| 1314 | 1314 | # submodule anymore. in that case, mark our sha as being NULL. | |
| 1315 | 1315 | try: | |
| 1316 | - self.binsha = pctree[str(self.path)].binsha | ||
| 1316 | + self.binsha = pctree[os.fspath(self.path)].binsha | ||
| 1317 | 1317 | except KeyError: | |
| 1318 | 1318 | self.binsha = self.NULL_BIN_SHA | |
| 1319 | 1319 | ||
@@ -1395,7 +1395,7 @@ def rename(self, new_name: str) -> "Submodule": | |||
| 1395 | 1395 | destination_module_abspath = self._module_abspath(self.repo, self.path, new_name) | |
| 1396 | 1396 | source_dir = mod.git_dir | |
| 1397 | 1397 | # Let's be sure the submodule name is not so obviously tied to a directory. | |
| 1398 | - if str(destination_module_abspath).startswith(str(mod.git_dir)): | ||
| 1398 | + if os.fspath(destination_module_abspath).startswith(os.fspath(mod.git_dir)): | ||
| 1399 | 1399 | tmp_dir = self._module_abspath(self.repo, self.path, str(uuid.uuid4())) | |
| 1400 | 1400 | os.renames(source_dir, tmp_dir) | |
| 1401 | 1401 | source_dir = tmp_dir | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | 4 | __all__ = ["Reference"] | |
| 5 | 5 | ||
| 6 | + import os | ||
| 6 | 7 | from git.util import IterableObj, LazyMixin | |
| 7 | 8 | ||
| 8 | 9 | from .symbolic import SymbolicReference, T_References | |
@@ -65,7 +66,7 @@ def __init__(self, repo: "Repo", path: PathLike, check_path: bool = True) -> Non | |||
| 65 | 66 | If ``False``, you can provide any path. | |
| 66 | 67 | Otherwise the path must start with the default path prefix of this type. | |
| 67 | 68 | """ | |
| 68 | - if check_path and not str(path).startswith(self._common_path_default + "/"): | ||
| 69 | + if check_path and not os.fspath(path).startswith(self._common_path_default + "/"): | ||
| 69 | 70 | raise ValueError(f"Cannot instantiate {self.__class__.__name__!r} from path {path}") | |
| 70 | 71 | self.path: str # SymbolicReference converts to string at the moment. | |
| 71 | 72 | super().__init__(repo, path) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -79,7 +79,7 @@ def __init__(self, repo: "Repo", path: PathLike, check_path: bool = False) -> No | |||
| 79 | 79 | self.path = path | |
| 80 | 80 | ||
| 81 | 81 | def __str__(self) -> str: | |
| 82 | - return str(self.path) | ||
| 82 | + return os.fspath(self.path) | ||
| 83 | 83 | ||
| 84 | 84 | def __repr__(self) -> str: | |
| 85 | 85 | return '<git.%s "%s">' % (self.__class__.__name__, self.path) | |
@@ -103,7 +103,7 @@ def name(self) -> str: | |||
| 103 | 103 | In case of symbolic references, the shortest assumable name is the path | |
| 104 | 104 | itself. | |
| 105 | 105 | """ | |
| 106 | - return str(self.path) | ||
| 106 | + return os.fspath(self.path) | ||
| 107 | 107 | ||
| 108 | 108 | @property | |
| 109 | 109 | def abspath(self) -> PathLike: | |
@@ -178,7 +178,7 @@ def _check_ref_name_valid(ref_path: PathLike) -> None: | |||
| 178 | 178 | """ | |
| 179 | 179 | previous: Union[str, None] = None | |
| 180 | 180 | one_before_previous: Union[str, None] = None | |
| 181 | - for c in str(ref_path): | ||
| 181 | + for c in os.fspath(ref_path): | ||
| 182 | 182 | if c in " ~^:?*[\\": | |
| 183 | 183 | raise ValueError( | |
| 184 | 184 | f"Invalid reference '{ref_path}': references cannot contain spaces, tildes (~), carets (^)," | |
@@ -212,7 +212,7 @@ def _check_ref_name_valid(ref_path: PathLike) -> None: | |||
| 212 | 212 | raise ValueError(f"Invalid reference '{ref_path}': references cannot end with a forward slash (/)") | |
| 213 | 213 | elif previous == "@" and one_before_previous is None: | |
| 214 | 214 | raise ValueError(f"Invalid reference '{ref_path}': references cannot be '@'") | |
| 215 | - elif any(component.endswith(".lock") for component in str(ref_path).split("/")): | ||
| 215 | + elif any(component.endswith(".lock") for component in os.fspath(ref_path).split("/")): | ||
| 216 | 216 | raise ValueError( | |
| 217 | 217 | f"Invalid reference '{ref_path}': references cannot have slash-separated components that end with" | |
| 218 | 218 | " '.lock'" | |
@@ -235,7 +235,7 @@ def _get_ref_info_helper( | |||
| 235 | 235 | tokens: Union[None, List[str], Tuple[str, str]] = None | |
| 236 | 236 | repodir = _git_dir(repo, ref_path) | |
| 237 | 237 | try: | |
| 238 | - with open(os.path.join(repodir, str(ref_path)), "rt", encoding="UTF-8") as fp: | ||
| 238 | + with open(os.path.join(repodir, os.fspath(ref_path)), "rt", encoding="UTF-8") as fp: | ||
| 239 | 239 | value = fp.read().rstrip() | |
| 240 | 240 | # Don't only split on spaces, but on whitespace, which allows to parse lines like: | |
| 241 | 241 | # 60b64ef992065e2600bfef6187a97f92398a9144 branch 'master' of git-server:/path/to/repo | |
@@ -614,7 +614,7 @@ def to_full_path(cls, path: Union[PathLike, "SymbolicReference"]) -> PathLike: | |||
| 614 | 614 | full_ref_path = path | |
| 615 | 615 | if not cls._common_path_default: | |
| 616 | 616 | return full_ref_path | |
| 617 | - if not str(path).startswith(cls._common_path_default + "/"): | ||
| 617 | + if not os.fspath(path).startswith(cls._common_path_default + "/"): | ||
| 618 | 618 | full_ref_path = "%s/%s" % (cls._common_path_default, path) | |
| 619 | 619 | return full_ref_path | |
| 620 | 620 | ||
@@ -706,7 +706,7 @@ def _create( | |||
| 706 | 706 | if not force and os.path.isfile(abs_ref_path): | |
| 707 | 707 | target_data = str(target) | |
| 708 | 708 | if isinstance(target, SymbolicReference): | |
| 709 | - target_data = str(target.path) | ||
| 709 | + target_data = os.fspath(target.path) | ||
| 710 | 710 | if not resolve: | |
| 711 | 711 | target_data = "ref: " + target_data | |
| 712 | 712 | with open(abs_ref_path, "rb") as fd: | |
@@ -842,7 +842,7 @@ def _iter_items( | |||
| 842 | 842 | ||
| 843 | 843 | # Read packed refs. | |
| 844 | 844 | for _sha, rela_path in cls._iter_packed_refs(repo): | |
| 845 | - if rela_path.startswith(str(common_path)): | ||
| 845 | + if rela_path.startswith(os.fspath(common_path)): | ||
| 846 | 846 | rela_paths.add(rela_path) | |
| 847 | 847 | # END relative path matches common path | |
| 848 | 848 | # END packed refs reading | |
@@ -931,4 +931,4 @@ def from_path(cls: Type[T_References], repo: "Repo", path: PathLike) -> T_Refere | |||
| 931 | 931 | ||
| 932 | 932 | def is_remote(self) -> bool: | |
| 933 | 933 | """:return: True if this symbolic reference points to a remote branch""" | |
| 934 | - return str(self.path).startswith(self._remote_common_path_default + "/") | ||
| 934 | + return os.fspath(self.path).startswith(self._remote_common_path_default + "/") | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -554,7 +554,7 @@ def tag(self, path: PathLike) -> TagReference: | |||
| 554 | 554 | ||
| 555 | 555 | @staticmethod | |
| 556 | 556 | def _to_full_tag_path(path: PathLike) -> str: | |
| 557 | - path_str = str(path) | ||
| 557 | + path_str = os.fspath(path) | ||
| 558 | 558 | if path_str.startswith(TagReference._common_path_default + "/"): | |
| 559 | 559 | return path_str | |
| 560 | 560 | if path_str.startswith(TagReference._common_default + "/"): | |
@@ -959,7 +959,7 @@ def is_dirty( | |||
| 959 | 959 | if not submodules: | |
| 960 | 960 | default_args.append("--ignore-submodules") | |
| 961 | 961 | if path: | |
| 962 | - default_args.extend(["--", str(path)]) | ||
| 962 | + default_args.extend(["--", os.fspath(path)]) | ||
| 963 | 963 | if index: | |
| 964 | 964 | # diff index against HEAD. | |
| 965 | 965 | if osp.isfile(self.index.path) and len(self.git.diff("--cached", *default_args)): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -272,9 +272,9 @@ def stream_copy(source: BinaryIO, destination: BinaryIO, chunk_size: int = 512 * | |||
| 272 | 272 | def join_path(a: PathLike, *p: PathLike) -> PathLike: | |
| 273 | 273 | R"""Join path tokens together similar to osp.join, but always use ``/`` instead of | |
| 274 | 274 | possibly ``\`` on Windows.""" | |
| 275 | - path = str(a) | ||
| 275 | + path = os.fspath(a) | ||
| 276 | 276 | for b in p: | |
| 277 | - b = str(b) | ||
| 277 | + b = os.fspath(b) | ||
| 278 | 278 | if not b: | |
| 279 | 279 | continue | |
| 280 | 280 | if b.startswith("/"): | |
@@ -290,18 +290,18 @@ def join_path(a: PathLike, *p: PathLike) -> PathLike: | |||
| 290 | 290 | if sys.platform == "win32": | |
| 291 | 291 | ||
| 292 | 292 | def to_native_path_windows(path: PathLike) -> PathLike: | |
| 293 | - path = str(path) | ||
| 293 | + path = os.fspath(path) | ||
| 294 | 294 | return path.replace("/", "\\") | |
| 295 | 295 | ||
| 296 | 296 | def to_native_path_linux(path: PathLike) -> str: | |
| 297 | - path = str(path) | ||
| 297 | + path = os.fspath(path) | ||
| 298 | 298 | return path.replace("\\", "/") | |
| 299 | 299 | ||
| 300 | 300 | to_native_path = to_native_path_windows | |
| 301 | 301 | else: | |
| 302 | 302 | # No need for any work on Linux. | |
| 303 | 303 | def to_native_path_linux(path: PathLike) -> str: | |
| 304 | - return str(path) | ||
| 304 | + return os.fspath(path) | ||
| 305 | 305 | ||
| 306 | 306 | to_native_path = to_native_path_linux | |
| 307 | 307 | ||
@@ -372,7 +372,7 @@ def is_exec(fpath: str) -> bool: | |||
| 372 | 372 | progs = [] | |
| 373 | 373 | if not path: | |
| 374 | 374 | path = os.environ["PATH"] | |
| 375 | - for folder in str(path).split(os.pathsep): | ||
| 375 | + for folder in os.fspath(path).split(os.pathsep): | ||
| 376 | 376 | folder = folder.strip('"') | |
| 377 | 377 | if folder: | |
| 378 | 378 | exe_path = osp.join(folder, program) | |
@@ -397,7 +397,7 @@ def _cygexpath(drive: Optional[str], path: str) -> str: | |||
| 397 | 397 | p = cygpath(p) | |
| 398 | 398 | elif drive: | |
| 399 | 399 | p = "/proc/cygdrive/%s/%s" % (drive.lower(), p) | |
| 400 | - p_str = str(p) # ensure it is a str and not AnyPath | ||
| 400 | + p_str = os.fspath(p) # ensure it is a str and not AnyPath | ||
| 401 | 401 | return p_str.replace("\\", "/") | |
| 402 | 402 | ||
| 403 | 403 | ||
@@ -418,7 +418,7 @@ def _cygexpath(drive: Optional[str], path: str) -> str: | |||
| 418 | 418 | ||
| 419 | 419 | def cygpath(path: str) -> str: | |
| 420 | 420 | """Use :meth:`git.cmd.Git.polish_url` instead, that works on any environment.""" | |
| 421 | - path = str(path) # Ensure is str and not AnyPath. | ||
| 421 | + path = os.fspath(path) # Ensure is str and not AnyPath. | ||
| 422 | 422 | # Fix to use Paths when 3.5 dropped. Or to be just str if only for URLs? | |
| 423 | 423 | if not path.startswith(("/cygdrive", "//", "/proc/cygdrive")): | |
| 424 | 424 | for regex, parser, recurse in _cygpath_parsers: | |
@@ -438,7 +438,7 @@ def cygpath(path: str) -> str: | |||
| 438 | 438 | ||
| 439 | 439 | ||
| 440 | 440 | def decygpath(path: PathLike) -> str: | |
| 441 | - path = str(path) | ||
| 441 | + path = os.fspath(path) | ||
| 442 | 442 | m = _decygpath_regex.match(path) | |
| 443 | 443 | if m: | |
| 444 | 444 | drive, rest_path = m.groups() | |
@@ -497,7 +497,7 @@ def is_cygwin_git(git_executable: Union[None, PathLike]) -> bool: | |||
| 497 | 497 | elif git_executable is None: | |
| 498 | 498 | return False | |
| 499 | 499 | else: | |
| 500 | - return _is_cygwin_git(str(git_executable)) | ||
| 500 | + return _is_cygwin_git(os.fspath(git_executable)) | ||
| 501 | 501 | ||
| 502 | 502 | ||
| 503 | 503 | def get_user_id() -> str: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments