Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc936e40

Browse files
committed
fixup! [Finder] Add recursive .gitignore files support
1 parenta2b5e91 commitc936e40

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

‎src/Symfony/Component/Finder/Iterator/VcsIgnoredFilterIterator.php‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class VcsIgnoredFilterIterator extends \FilterIterator
2121
*/
2222
private$baseDir;
2323

24+
/** @var array<string, string|null> */
25+
private$gitignoreFilesCache = [];
26+
2427
publicfunction__construct(Iterator$iterator,string$baseDir)
2528
{
2629
$this->baseDir =$baseDir;
@@ -41,24 +44,32 @@ public function accept(): bool
4144

4245
do {
4346
$parentDirectory =\dirname($parentDirectory);
44-
$gitignoreFilePath ="{$parentDirectory}/.gitignore";
45-
46-
if (!file_exists($gitignoreFilePath)) {
47-
continue;
48-
}
49-
50-
if (!is_file($gitignoreFilePath) || !is_readable($gitignoreFilePath)) {
51-
thrownew \RuntimeException("The\"ignoreVCSIgnored\" option cannot be used by the Finder as the\"{$gitignoreFilePath}\" file is not readable.");
52-
}
53-
5447
$relativeFilePath =substr($fileRealPath,\strlen($parentDirectory) +1);
5548

56-
$regex = Gitignore::toRegex(file_get_contents($gitignoreFilePath));
57-
if (preg_match($regex,$relativeFilePath)) {
49+
$regex =$this->readGitignoreFile("{$parentDirectory}/.gitignore");
50+
51+
if (null !==$regex &&preg_match($regex,$relativeFilePath)) {
5852
returnfalse;
5953
}
6054
}while ($parentDirectory !==$this->baseDir);
6155

6256
returntrue;
6357
}
58+
59+
privatefunctionreadGitignoreFile(string$path): ?string
60+
{
61+
if (array_key_exists($path,$this->gitignoreFilesCache)) {
62+
return$this->gitignoreFilesCache[$path];
63+
}
64+
65+
if (!file_exists($path)) {
66+
returnnull;
67+
}
68+
69+
if (!is_file($path) || !is_readable($path)) {
70+
thrownew \RuntimeException("The\"ignoreVCSIgnored\" option cannot be used by the Finder as the\"{$path}\" file is not readable.");
71+
}
72+
73+
return$this->gitignoreFilesCache[$path] = Gitignore::toRegex(file_get_contents($path));
74+
}
6475
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp