diff --git a/src/tools/ecode/ignorematcher.cpp b/src/tools/ecode/ignorematcher.cpp index 81fb013d2..c08e6144f 100644 --- a/src/tools/ecode/ignorematcher.cpp +++ b/src/tools/ecode/ignorematcher.cpp @@ -11,12 +11,16 @@ IgnoreMatcher::IgnoreMatcher( const std::string& rootPath ) : mPath( rootPath ) IgnoreMatcher::~IgnoreMatcher() {} -GitIgnoreMatcher::GitIgnoreMatcher( const std::string& rootPath, - const std::string& ignoreFileName ) : +GitIgnoreMatcher::GitIgnoreMatcher( const std::string& rootPath, const std::string& ignoreFileName, + bool addGitFolderFilter ) : IgnoreMatcher( rootPath ), mIgnoreFileName( ignoreFileName ), mIgnoreFilePath( mPath + mIgnoreFileName ) { if ( canMatch() ) { + if ( addGitFolderFilter ) { + if ( FileSystem::fileExists( mPath + ".git" ) ) // Also ignore the .git folder + mPatterns.emplace_back( std::make_pair( ".git/**", false ) ); + } if ( parse() ) { mMatcherReady = true; } @@ -34,8 +38,6 @@ const std::string& GitIgnoreMatcher::getIgnoreFilePath() const { bool GitIgnoreMatcher::parse() { std::string patternFile; FileSystem::fileGet( mPath + mIgnoreFileName, patternFile ); - if ( FileSystem::fileExists( mPath + ".git" ) ) // Also ignore the .git folder - mPatterns.emplace_back( std::make_pair( "**/.git/**", false ) ); std::vector patterns = String::split( patternFile ); for ( auto& pattern : patterns ) { bool negates = false; diff --git a/src/tools/ecode/ignorematcher.hpp b/src/tools/ecode/ignorematcher.hpp index 8de5c3df2..ee598cbd1 100644 --- a/src/tools/ecode/ignorematcher.hpp +++ b/src/tools/ecode/ignorematcher.hpp @@ -38,7 +38,8 @@ class IgnoreMatcher { class GitIgnoreMatcher : public IgnoreMatcher { public: GitIgnoreMatcher( const std::string& rootPath, - const std::string& ignoreFileName = ".gitignore" ); + const std::string& ignoreFileName = ".gitignore", + bool addGitFolderFilter = true ); bool canMatch() override; diff --git a/src/tools/ecode/projectdirectorytree.cpp b/src/tools/ecode/projectdirectorytree.cpp index c8aec3356..cbdde6013 100644 --- a/src/tools/ecode/projectdirectorytree.cpp +++ b/src/tools/ecode/projectdirectorytree.cpp @@ -39,7 +39,7 @@ void ProjectDirectoryTree::scan( const ProjectDirectoryTree::ScanCompleteEvent& const bool& ignoreHidden ) { #if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN || defined( __EMSCRIPTEN_PTHREADS__ ) mPool->run( - [this, acceptedPatterns, ignoreHidden] { + [this, acceptedPatterns = std::move( acceptedPatterns ), ignoreHidden] { #endif Lock l( mFilesMutex ); mRunning = true; @@ -47,15 +47,15 @@ void ProjectDirectoryTree::scan( const ProjectDirectoryTree::ScanCompleteEvent& mDirectories.push_back( mPath ); if ( !mAllowedMatcher && FileSystem::fileExists( mPath + PRJ_ALLOWED_PATH ) ) - mAllowedMatcher = std::make_unique( mPath, PRJ_ALLOWED_PATH ); + mAllowedMatcher = std::make_unique( mPath, PRJ_ALLOWED_PATH, false ); if ( !acceptedPatterns.empty() ) { std::vector files; std::vector names; - std::vector patterns; + mAcceptedPatterns.clear(); + mAcceptedPatterns.reserve( acceptedPatterns.size() ); for ( const auto& strPattern : acceptedPatterns ) - patterns.emplace_back( LuaPatternStorage( strPattern ) ); - mAcceptedPatterns = std::move( patterns ); + mAcceptedPatterns.emplace_back( std::string{ strPattern } ); std::set info; getDirectoryFiles( files, names, mPath, info, false, mIgnoreMatcher, mAllowedMatcher.get() ); @@ -63,7 +63,7 @@ void ProjectDirectoryTree::scan( const ProjectDirectoryTree::ScanCompleteEvent& bool found; for ( size_t i = 0; i < namesCount; i++ ) { found = false; - for ( auto& pattern : mAcceptedPatterns ) { + for ( const auto& pattern : mAcceptedPatterns ) { if ( pattern.matches( names[i] ) ) { found = true; break;