|
|
@ -116,21 +116,21 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path, |
|
|
|
size_t cutFrom = pathString.find(Config::the().workingDirectory()) == 0 ? Config::the().workingDirectorySize() : 0; |
|
|
|
size_t cutFrom = pathString.find(Config::the().workingDirectory()) == 0 ? Config::the().workingDirectorySize() : 0; |
|
|
|
pathString = pathString.substr(cutFrom); |
|
|
|
pathString = pathString.substr(cutFrom); |
|
|
|
|
|
|
|
|
|
|
|
for (const auto& ignorePattern : patterns) { |
|
|
|
for (const auto& pattern : patterns) { |
|
|
|
|
|
|
|
|
|
|
|
if (pathString == ignorePattern) { |
|
|
|
if (pathString == pattern) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If starts with '/', only match in the working directory root
|
|
|
|
// If starts with '/', only match in the working directory root
|
|
|
|
bool onlyMatchInRoot = false; |
|
|
|
bool onlyMatchInRoot = false; |
|
|
|
if (ignorePattern.front() == '/') { |
|
|
|
if (pattern.front() == '/') { |
|
|
|
onlyMatchInRoot = true; |
|
|
|
onlyMatchInRoot = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If ends with '/', only match directories
|
|
|
|
// If ends with '/', only match directories
|
|
|
|
bool onlyMatchDirectories = false; |
|
|
|
bool onlyMatchDirectories = false; |
|
|
|
if (ignorePattern.back() == '/') { |
|
|
|
if (pattern.back() == '/') { |
|
|
|
onlyMatchDirectories = true; |
|
|
|
onlyMatchDirectories = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -139,7 +139,7 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path, |
|
|
|
bool tryPatternState = true; |
|
|
|
bool tryPatternState = true; |
|
|
|
|
|
|
|
|
|
|
|
size_t pathIterator = 0; |
|
|
|
size_t pathIterator = 0; |
|
|
|
size_t ignoreIterator = 0; |
|
|
|
size_t patternIterator = 0; |
|
|
|
|
|
|
|
|
|
|
|
if (!onlyMatchInRoot) { |
|
|
|
if (!onlyMatchInRoot) { |
|
|
|
pathIterator++; |
|
|
|
pathIterator++; |
|
|
@ -149,13 +149,13 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path, |
|
|
|
// Example, iterator at []: [.]log/output.txt
|
|
|
|
// Example, iterator at []: [.]log/output.txt
|
|
|
|
// [*].log
|
|
|
|
// [*].log
|
|
|
|
if (pathIterator < pathString.length() |
|
|
|
if (pathIterator < pathString.length() |
|
|
|
&& ignoreIterator < ignorePattern.length() - 1 |
|
|
|
&& patternIterator < pattern.length() - 1 |
|
|
|
&& ignorePattern.at(ignoreIterator) == '*' |
|
|
|
&& pattern.at(patternIterator) == '*' |
|
|
|
&& pathString.at(pathIterator) == ignorePattern.at(ignoreIterator + 1)) { |
|
|
|
&& pathString.at(pathIterator) == pattern.at(patternIterator + 1)) { |
|
|
|
ignoreIterator++; |
|
|
|
patternIterator++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (; pathIterator < pathString.length() && ignoreIterator < ignorePattern.length();) { |
|
|
|
for (; pathIterator < pathString.length() && patternIterator < pattern.length();) { |
|
|
|
char character = pathString.at(pathIterator); |
|
|
|
char character = pathString.at(pathIterator); |
|
|
|
pathIterator++; |
|
|
|
pathIterator++; |
|
|
|
|
|
|
|
|
|
|
@ -168,11 +168,11 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path, |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (character == ignorePattern.at(ignoreIterator)) { |
|
|
|
if (character == pattern.at(patternIterator)) { |
|
|
|
// Fail if the final match hasn't reached the end of the ignore pattern
|
|
|
|
// Fail if the final match hasn't reached the end of the ignore pattern
|
|
|
|
// Example, iterator at []: doc/buil[d]
|
|
|
|
// Example, iterator at []: doc/buil[d]
|
|
|
|
// buil[d]/
|
|
|
|
// buil[d]/
|
|
|
|
if (pathIterator == pathString.length() && ignoreIterator < ignorePattern.length() - 1) { |
|
|
|
if (pathIterator == pathString.length() && patternIterator < pattern.length() - 1) { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -180,17 +180,17 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path, |
|
|
|
// Example, iterator at []: /includ[e]/header.h
|
|
|
|
// Example, iterator at []: /includ[e]/header.h
|
|
|
|
// /includ[e]*/
|
|
|
|
// /includ[e]*/
|
|
|
|
if (pathIterator < pathString.length() |
|
|
|
if (pathIterator < pathString.length() |
|
|
|
&& ignoreIterator < ignorePattern.length() - 2 |
|
|
|
&& patternIterator < pattern.length() - 2 |
|
|
|
&& ignorePattern.at(ignoreIterator + 1) == '*' |
|
|
|
&& pattern.at(patternIterator + 1) == '*' |
|
|
|
&& pathString.at(pathIterator) == ignorePattern.at(ignoreIterator + 2)) { |
|
|
|
&& pathString.at(pathIterator) == pattern.at(patternIterator + 2)) { |
|
|
|
ignoreIterator++; |
|
|
|
patternIterator++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ignoreIterator++; |
|
|
|
patternIterator++; |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (ignorePattern.at(ignoreIterator) == '*') { |
|
|
|
if (pattern.at(patternIterator) == '*') { |
|
|
|
// Fail if we're entering a subdirectory and we should only match in the root
|
|
|
|
// Fail if we're entering a subdirectory and we should only match in the root
|
|
|
|
// Example, iterator at []: /src[/]include/header.h
|
|
|
|
// Example, iterator at []: /src[/]include/header.h
|
|
|
|
// /[*]include/
|
|
|
|
// /[*]include/
|
|
|
@ -200,9 +200,9 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path, |
|
|
|
|
|
|
|
|
|
|
|
// Next path character == next ignore pattern character
|
|
|
|
// Next path character == next ignore pattern character
|
|
|
|
if (pathIterator < pathString.length() |
|
|
|
if (pathIterator < pathString.length() |
|
|
|
&& ignoreIterator + 1 < ignorePattern.length() |
|
|
|
&& patternIterator + 1 < pattern.length() |
|
|
|
&& pathString.at(pathIterator) == ignorePattern.at(ignoreIterator + 1)) { |
|
|
|
&& pathString.at(pathIterator) == pattern.at(patternIterator + 1)) { |
|
|
|
ignoreIterator++; |
|
|
|
patternIterator++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
continue; |
|
|
|
continue; |
|
|
@ -211,20 +211,20 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path, |
|
|
|
// Reset filter pattern if it hasnt been completed at this point
|
|
|
|
// Reset filter pattern if it hasnt been completed at this point
|
|
|
|
// Example, iterator at []: /[s]rc/include/header.h
|
|
|
|
// Example, iterator at []: /[s]rc/include/header.h
|
|
|
|
// /[i]nclude*/
|
|
|
|
// /[i]nclude*/
|
|
|
|
if (ignoreIterator < ignorePattern.length() - 1) { |
|
|
|
if (patternIterator < pattern.length() - 1) { |
|
|
|
ignoreIterator = 0; |
|
|
|
patternIterator = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
tryPatternState = false; |
|
|
|
tryPatternState = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (ignoreIterator == ignorePattern.length()) { |
|
|
|
if (patternIterator == pattern.length()) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
if (ignorePattern.back() == '*' && ignoreIterator == ignorePattern.length() - 1) { |
|
|
|
if (pattern.back() == '*' && patternIterator == pattern.length() - 1) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
if (onlyMatchDirectories && ignoreIterator == ignorePattern.length() - 1) { |
|
|
|
if (onlyMatchDirectories && patternIterator == pattern.length() - 1) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|