From 761aff4493aacfb0fab1c2ad747d009279e7824d Mon Sep 17 00:00:00 2001 From: Martijn Pieters Date: Mon, 21 Jun 2021 13:41:49 +0100 Subject: [PATCH 1/2] Use a pipe to pass filenames to git check-ignore The number of files in a project could be larger than the limit on command-line arguments. Using a pipe avoids running into this issue. --- isort/settings.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/isort/settings.py b/isort/settings.py index d04dd8386..1dec20467 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -2,7 +2,6 @@ Defines how the default settings for isort should be loaded """ -import codecs import configparser import fnmatch import glob @@ -544,16 +543,12 @@ def _check_folder_gitignore(self, folder: str) -> Optional[Path]: git_folder = Path(topfolder_result.decode("utf-8").split("\n")[0]) files = glob.glob(str(git_folder) + "/**/*", recursive=True) - files_result = ( - codecs.escape_decode( # type: ignore - subprocess.check_output( # nosec # skipcq: PYL-W1510 - ["git", "-C", str(git_folder), "check-ignore", *files] - ) - )[0] - .decode("utf-8") - .split("\n") - ) - files_result = files_result[:-1] if files_result else files_result + files_result = subprocess.check_output( # nosec # skipcq: PYL-W1510 + ["git", "-C", str(git_folder), "check-ignore", "--stdin"], + encoding="utf-8", + env={"LANG": "C.UTF-8"}, + input="\n".join(files), + ).splitlines() self.git_ignore[git_folder] = {Path(f.strip('"')) for f in files_result} From 84664a6820dc62488c46a0500376da1f12bccaa0 Mon Sep 17 00:00:00 2001 From: Timothy Edmund Crosley Date: Mon, 21 Jun 2021 06:09:34 -0700 Subject: [PATCH 2/2] Use escape_decode to address windows based usage --- isort/settings.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/isort/settings.py b/isort/settings.py index 1dec20467..93ec08ba1 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -2,6 +2,7 @@ Defines how the default settings for isort should be loaded """ +import codecs import configparser import fnmatch import glob @@ -543,12 +544,16 @@ def _check_folder_gitignore(self, folder: str) -> Optional[Path]: git_folder = Path(topfolder_result.decode("utf-8").split("\n")[0]) files = glob.glob(str(git_folder) + "/**/*", recursive=True) - files_result = subprocess.check_output( # nosec # skipcq: PYL-W1510 - ["git", "-C", str(git_folder), "check-ignore", "--stdin"], - encoding="utf-8", - env={"LANG": "C.UTF-8"}, - input="\n".join(files), - ).splitlines() + files_result = ( + codecs.escape_decode( # type: ignore + subprocess.check_output( # nosec # skipcq: PYL-W1510 + ["git", "-C", str(git_folder), "check-ignore", "--stdin"], + input="\n".join(files).encode(), + ) + )[0] + .decode("utf-8") + .splitlines() + ) self.git_ignore[git_folder] = {Path(f.strip('"')) for f in files_result}