Everywhere: Rename "excludePath" to "ignorePattern"

This commit is contained in:
Riyyi
2022-03-06 17:21:16 +01:00
parent b37a8087e9
commit 6f1f1c3fe7
6 changed files with 47 additions and 44 deletions
+3 -3
View File
@@ -75,15 +75,15 @@ void Config::parseConfigFile()
void to_json(nlohmann::json& object, const Settings& settings)
{
object = nlohmann::json {
{ "excludePaths", settings.excludePaths },
{ "ignorePatterns", settings.ignorePatterns },
{ "systemDirectories", settings.systemDirectories }
};
}
void from_json(const nlohmann::json& object, Settings& settings)
{
if (object.find("excludePaths") != object.end()) {
object.at("excludePaths").get_to(settings.excludePaths);
if (object.find("ignorePatterns") != object.end()) {
object.at("ignorePatterns").get_to(settings.ignorePatterns);
}
if (object.find("systemDirectories") != object.end()) {
+3 -3
View File
@@ -17,7 +17,7 @@
#include "util/singleton.h"
struct Settings {
std::vector<std::string> excludePaths {
std::vector<std::string> ignorePatterns {
".git/",
"*.md",
"manafiles.json",
@@ -38,10 +38,10 @@ public:
virtual ~Config();
void setSystemDirectories(const std::vector<std::filesystem::path>& systemDirectories) { m_settings.systemDirectories = systemDirectories; }
void setExcludePaths(const std::vector<std::string>& excludePaths) { m_settings.excludePaths = excludePaths; }
void setIgnorePatterns(const std::vector<std::string>& ignorePatterns) { m_settings.ignorePatterns = ignorePatterns; }
void setVerbose(bool verbose) { m_verbose = verbose; }
const std::vector<std::string>& excludePaths() const { return m_settings.excludePaths; }
const std::vector<std::string>& ignorePatterns() const { return m_settings.ignorePatterns; }
const std::vector<std::filesystem::path>& systemDirectories() const { return m_settings.systemDirectories; }
const std::filesystem::path& workingDirectory() const { return m_workingDirectory; }
+26 -26
View File
@@ -115,21 +115,21 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path)
size_t cutFrom = pathString.find(Config::the().workingDirectory()) == 0 ? Config::the().workingDirectorySize() : 0;
pathString = pathString.substr(cutFrom);
for (const auto& excludePath : Config::the().excludePaths()) {
for (const auto& ignorePattern : Config::the().ignorePatterns()) {
if (pathString == excludePath) {
if (pathString == ignorePattern) {
return true;
}
// If starts with '/', only match in the working directory root
bool onlyMatchInRoot = false;
if (excludePath.front() == '/') {
if (ignorePattern.front() == '/') {
onlyMatchInRoot = true;
}
// If ends with '/', only match directories
bool onlyMatchDirectories = false;
if (excludePath.back() == '/') {
if (ignorePattern.back() == '/') {
onlyMatchDirectories = true;
}
@@ -138,7 +138,7 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path)
bool tryPatternState = true;
size_t pathIterator = 0;
size_t excludeIterator = 0;
size_t ignoreIterator = 0;
if (!onlyMatchInRoot) {
pathIterator++;
@@ -148,13 +148,13 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path)
// Example, iterator at []: [.]log/output.txt
// [*].log
if (pathIterator < pathString.length()
&& excludeIterator < excludePath.length() - 1
&& excludePath.at(excludeIterator) == '*'
&& pathString.at(pathIterator) == excludePath.at(excludeIterator + 1)) {
excludeIterator++;
&& ignoreIterator < ignorePattern.length() - 1
&& ignorePattern.at(ignoreIterator) == '*'
&& pathString.at(pathIterator) == ignorePattern.at(ignoreIterator + 1)) {
ignoreIterator++;
}
for (; pathIterator < pathString.length() && excludeIterator < excludePath.length();) {
for (; pathIterator < pathString.length() && ignoreIterator < ignorePattern.length();) {
char character = pathString.at(pathIterator);
pathIterator++;
@@ -167,11 +167,11 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path)
continue;
}
if (character == excludePath.at(excludeIterator)) {
if (character == ignorePattern.at(ignoreIterator)) {
// Fail if the final match hasn't reached the end of the ignore pattern
// Example, iterator at []: doc/buil[d]
// buil[d]/
if (pathIterator == pathString.length() && excludeIterator < excludePath.length() - 1) {
if (pathIterator == pathString.length() && ignoreIterator < ignorePattern.length() - 1) {
break;
}
@@ -179,17 +179,17 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path)
// Example, iterator at []: /includ[e]/header.h
// /includ[e]*/
if (pathIterator < pathString.length()
&& excludeIterator < excludePath.length() - 2
&& excludePath.at(excludeIterator + 1) == '*'
&& pathString.at(pathIterator) == excludePath.at(excludeIterator + 2)) {
excludeIterator++;
&& ignoreIterator < ignorePattern.length() - 2
&& ignorePattern.at(ignoreIterator + 1) == '*'
&& pathString.at(pathIterator) == ignorePattern.at(ignoreIterator + 2)) {
ignoreIterator++;
}
excludeIterator++;
ignoreIterator++;
continue;
}
if (excludePath.at(excludeIterator) == '*') {
if (ignorePattern.at(ignoreIterator) == '*') {
// Fail if we're entering a subdirectory and we should only match in the root
// Example, iterator at []: /src[/]include/header.h
// /[*]include/
@@ -199,9 +199,9 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path)
// Next path character == next ignore pattern character
if (pathIterator < pathString.length()
&& excludeIterator + 1 < excludePath.length()
&& pathString.at(pathIterator) == excludePath.at(excludeIterator + 1)) {
excludeIterator++;
&& ignoreIterator + 1 < ignorePattern.length()
&& pathString.at(pathIterator) == ignorePattern.at(ignoreIterator + 1)) {
ignoreIterator++;
}
continue;
@@ -210,20 +210,20 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path)
// Reset filter pattern if it hasnt been completed at this point
// Example, iterator at []: /[s]rc/include/header.h
// /[i]nclude*/
if (excludeIterator < excludePath.length() - 1) {
excludeIterator = 0;
if (ignoreIterator < ignorePattern.length() - 1) {
ignoreIterator = 0;
}
tryPatternState = false;
}
if (excludeIterator == excludePath.length()) {
if (ignoreIterator == ignorePattern.length()) {
return true;
}
if (excludePath.back() == '*' && excludeIterator == excludePath.length() - 1) {
if (ignorePattern.back() == '*' && ignoreIterator == ignorePattern.length() - 1) {
return true;
}
if (onlyMatchDirectories && excludeIterator == excludePath.length() - 1) {
if (onlyMatchDirectories && ignoreIterator == ignorePattern.length() - 1) {
return true;
}
}