Manager: Add new pattern logic to pulling/pushing targets
This commit is contained in:
+10
-15
@@ -106,7 +106,8 @@ void Dotfile::push(const std::vector<std::string>& targets)
|
|||||||
pullOrPush(SyncType::Push, targets);
|
pullOrPush(SyncType::Push, targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Dotfile::filter(const std::filesystem::directory_entry& path)
|
bool Dotfile::filter(const std::filesystem::directory_entry& path,
|
||||||
|
const std::vector<std::string>& patterns)
|
||||||
{
|
{
|
||||||
std::string pathString = path.path().string();
|
std::string pathString = path.path().string();
|
||||||
assert(pathString.front() == '/');
|
assert(pathString.front() == '/');
|
||||||
@@ -115,7 +116,7 @@ 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 : Config::the().ignorePatterns()) {
|
for (const auto& ignorePattern : patterns) {
|
||||||
|
|
||||||
if (pathString == ignorePattern) {
|
if (pathString == ignorePattern) {
|
||||||
return true;
|
return true;
|
||||||
@@ -485,27 +486,21 @@ void Dotfile::forEachDotfile(const std::vector<std::string>& targets, const std:
|
|||||||
{
|
{
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
for (const auto& path : std::filesystem::recursive_directory_iterator { Config::the().workingDirectory() }) {
|
for (const auto& path : std::filesystem::recursive_directory_iterator { Config::the().workingDirectory() }) {
|
||||||
if (path.is_directory() || filter(path)) {
|
if (path.is_directory()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!targets.empty() && !include(path.path(), targets)) {
|
// Ignore pattern check
|
||||||
|
if (filter(path, Config::the().ignorePatterns())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Include check
|
||||||
|
if (!targets.empty() && !filter(path, targets)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
callback(path, index++);
|
callback(path, index++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Dotfile::include(const std::filesystem::path& path, const std::vector<std::string>& targets)
|
|
||||||
{
|
|
||||||
for (const auto& target : targets) {
|
|
||||||
if (path.string().find(Config::the().workingDirectory() / target) == 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Dotfile::isSystemTarget(const std::string& target)
|
bool Dotfile::isSystemTarget(const std::string& target)
|
||||||
{
|
{
|
||||||
for (const auto& systemDirectory : Config::the().systemDirectories()) {
|
for (const auto& systemDirectory : Config::the().systemDirectories()) {
|
||||||
|
|||||||
+2
-2
@@ -30,7 +30,8 @@ public:
|
|||||||
void pull(const std::vector<std::string>& targets = {});
|
void pull(const std::vector<std::string>& targets = {});
|
||||||
void push(const std::vector<std::string>& targets = {});
|
void push(const std::vector<std::string>& targets = {});
|
||||||
|
|
||||||
bool filter(const std::filesystem::directory_entry& path);
|
bool filter(const std::filesystem::directory_entry& path,
|
||||||
|
const std::vector<std::string>& patterns);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void pullOrPush(SyncType type, const std::vector<std::string>& targets = {});
|
void pullOrPush(SyncType type, const std::vector<std::string>& targets = {});
|
||||||
@@ -41,7 +42,6 @@ private:
|
|||||||
void selectivelyCommentOrUncomment(const std::string& path);
|
void selectivelyCommentOrUncomment(const std::string& path);
|
||||||
|
|
||||||
void forEachDotfile(const std::vector<std::string>& targets, const std::function<void(const std::filesystem::directory_entry&, size_t)>& callback);
|
void forEachDotfile(const std::vector<std::string>& targets, const std::function<void(const std::filesystem::directory_entry&, size_t)>& callback);
|
||||||
bool include(const std::filesystem::path& path, const std::vector<std::string>& targets);
|
|
||||||
bool isSystemTarget(const std::string& target);
|
bool isSystemTarget(const std::string& target);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -93,16 +93,11 @@ void testDotfileFilters(const std::unordered_map<std::string, bool>& tests,
|
|||||||
|
|
||||||
createTestDotfiles(fileNames, fileContents);
|
createTestDotfiles(fileNames, fileContents);
|
||||||
|
|
||||||
auto ignorePatterns = Config::the().ignorePatterns();
|
|
||||||
Config::the().setIgnorePatterns(testIgnorePatterns);
|
|
||||||
|
|
||||||
for (const auto& path : fileNames) {
|
for (const auto& path : fileNames) {
|
||||||
bool result = Dotfile::the().filter(std::filesystem::directory_entry { "/" + path });
|
bool result = Dotfile::the().filter(std::filesystem::directory_entry { "/" + path }, testIgnorePatterns);
|
||||||
EXPECT_EQ(result, tests.at(path), printf(" path = '%s'\n", path.c_str()));
|
EXPECT_EQ(result, tests.at(path), printf(" path = '%s'\n", path.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Config::the().setIgnorePatterns(ignorePatterns);
|
|
||||||
|
|
||||||
removeTestDotfiles(fileNames, false);
|
removeTestDotfiles(fileNames, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user