Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 753e2da

Browse files
committed
completely remove 'is_cygwin_git' and use sys.platform instead
1 parent aa6b7e9 commit 753e2da

File tree

2 files changed

+1
-86
lines changed

2 files changed

+1
-86
lines changed

git/cmd.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
from git.util import (
3333
cygpath,
3434
expand_path,
35-
is_cygwin_git,
3635
patch_env,
3736
remove_password_if_present,
3837
stream_copy,
@@ -661,7 +660,7 @@ def refresh(cls, path: Union[None, PathLike] = None) -> bool:
661660

662661
@classmethod
663662
def is_cygwin(cls) -> bool:
664-
return is_cygwin_git(cls.GIT_PYTHON_GIT_EXECUTABLE)
663+
return cls.GIT_PYTHON_GIT_EXECUTABLE is not None and sys.platform == "cygwin"
665664

666665
@overload
667666
@classmethod

git/util.py

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
Files_TD,
9797
Has_id_attribute,
9898
HSH_TD,
99-
Literal,
10099
PathLike,
101100
Protocol,
102101
SupportsIndex,
@@ -344,44 +343,6 @@ def _get_exe_extensions() -> Sequence[str]:
344343
return ()
345344

346345

347-
def py_where(program: str, path: Optional[PathLike] = None) -> List[str]:
348-
"""Perform a path search to assist :func:`is_cygwin_git`.
349-
350-
This is not robust for general use. It is an implementation detail of
351-
:func:`is_cygwin_git`. When a search following all shell rules is needed,
352-
:func:`shutil.which` can be used instead.
353-
354-
:note:
355-
Neither this function nor :func:`shutil.which` will predict the effect of an
356-
executable search on a native Windows system due to a :class:`subprocess.Popen`
357-
call without ``shell=True``, because shell and non-shell executable search on
358-
Windows differ considerably.
359-
"""
360-
# From: http://stackoverflow.com/a/377028/548792
361-
winprog_exts = _get_exe_extensions()
362-
363-
def is_exec(fpath: str) -> bool:
364-
return (
365-
osp.isfile(fpath)
366-
and os.access(fpath, os.X_OK)
367-
and (
368-
sys.platform != "win32" or not winprog_exts or any(fpath.upper().endswith(ext) for ext in winprog_exts)
369-
)
370-
)
371-
372-
progs = []
373-
if not path:
374-
path = os.environ["PATH"]
375-
for folder in str(path).split(os.pathsep):
376-
folder = folder.strip('"')
377-
if folder:
378-
exe_path = osp.join(folder, program)
379-
for f in [exe_path] + ["%s%s" % (exe_path, e) for e in winprog_exts]:
380-
if is_exec(f):
381-
progs.append(f)
382-
return progs
383-
384-
385346
def _cygexpath(drive: Optional[str], path: str) -> str:
386347
if osp.isabs(path) and not drive:
387348
# Invoked from `cygpath()` directly with `D:Apps\123`?
@@ -447,51 +408,6 @@ def decygpath(path: PathLike) -> str:
447408
return path.replace("/", "\\")
448409

449410

450-
#: Store boolean flags denoting if a specific Git executable
451-
#: is from a Cygwin installation (since `cache_lru()` unsupported on PY2).
452-
_is_cygwin_cache: Dict[str, Optional[bool]] = {}
453-
454-
455-
def _is_cygwin_git(git_executable: str) -> bool:
456-
is_cygwin = _is_cygwin_cache.get(git_executable) # type: Optional[bool]
457-
if is_cygwin is None:
458-
is_cygwin = False
459-
try:
460-
git_dir = osp.dirname(git_executable)
461-
if not git_dir:
462-
res = py_where(git_executable)
463-
git_dir = osp.dirname(res[0]) if res else ""
464-
465-
# Just a name given, not a real path.
466-
uname_cmd = osp.join(git_dir, "uname")
467-
process = subprocess.Popen([uname_cmd], stdout=subprocess.PIPE, universal_newlines=True)
468-
uname_out, _ = process.communicate()
469-
# retcode = process.poll()
470-
is_cygwin = "CYGWIN" in uname_out
471-
except Exception as ex:
472-
_logger.debug("Failed checking if running in CYGWIN due to: %r", ex)
473-
_is_cygwin_cache[git_executable] = is_cygwin
474-
475-
return is_cygwin
476-
477-
478-
@overload
479-
def is_cygwin_git(git_executable: None) -> Literal[False]: ...
480-
481-
482-
@overload
483-
def is_cygwin_git(git_executable: PathLike) -> bool: ...
484-
485-
486-
def is_cygwin_git(git_executable: Union[None, PathLike]) -> bool:
487-
if sys.platform == "win32": # TODO: See if we can use `sys.platform != "cygwin"`.
488-
return False
489-
elif git_executable is None:
490-
return False
491-
else:
492-
return _is_cygwin_git(str(git_executable))
493-
494-
495411
def get_user_id() -> str:
496412
""":return: String identifying the currently active system user as ``name@node``"""
497413
return "%s@%s" % (getpass.getuser(), platform.node())

0 commit comments

Comments
 (0)