From f65fa338a50fbb0f8d6a6b2555499f5981869c2f Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Thu, 3 Feb 2011 08:56:28 +0200 Subject: [PATCH] Tighten the directory name mathing with -i. Only match full directory names as parts of whole paths. So -isrc matches src/file.cpp and proj/src/file.cpp. But does not match mysrc/file.cpp or proj/srcfiles/file.cpp. --- cli/pathmatch.cpp | 9 ++++++++- test/testpathmatch.cpp | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/cli/pathmatch.cpp b/cli/pathmatch.cpp index 25ed6cd71..270f5c1da 100644 --- a/cli/pathmatch.cpp +++ b/cli/pathmatch.cpp @@ -35,7 +35,14 @@ bool PathMatch::Match(const std::string &path) if (findpath[findpath.length() - 1] != '/') findpath = RemoveFilename(findpath); - if (findpath.find(*iterMask) != std::string::npos) + // Match relative paths starting with mask + // -isrc matches src/foo.cpp + if (findpath.compare(0, (*iterMask).size(), *iterMask) == 0) + return true; + // Match only full directory name in middle or end of the path + // -isrc matches myproject/src/ but does not match + // myproject/srcfiles/ or myproject/mysrc/ + if (findpath.find("/" + *iterMask) != std::string::npos) return true; } return false; diff --git a/test/testpathmatch.cpp b/test/testpathmatch.cpp index dadeef311..f929308e7 100644 --- a/test/testpathmatch.cpp +++ b/test/testpathmatch.cpp @@ -38,6 +38,10 @@ private: TEST_CASE(onemaskemptypath); TEST_CASE(onemasksamepath); TEST_CASE(onemasksamepathwithfile); + TEST_CASE(onemaskdifferentdir1); + TEST_CASE(onemaskdifferentdir2); + TEST_CASE(onemaskdifferentdir3); + TEST_CASE(onemaskdifferentdir4); TEST_CASE(onemasklongerpath1); TEST_CASE(onemasklongerpath2); TEST_CASE(onemasklongerpath3); @@ -95,6 +99,38 @@ private: ASSERT(match.Match("src/file.txt")); } + void onemaskdifferentdir1() + { + std::vector masks; + masks.push_back("src/"); + PathMatch match(masks); + ASSERT(!match.Match("srcfiles/file.txt")); + } + + void onemaskdifferentdir2() + { + std::vector masks; + masks.push_back("src/"); + PathMatch match(masks); + ASSERT(!match.Match("proj/srcfiles/file.txt")); + } + + void onemaskdifferentdir3() + { + std::vector masks; + masks.push_back("src/"); + PathMatch match(masks); + ASSERT(!match.Match("proj/mysrc/file.txt")); + } + + void onemaskdifferentdir4() + { + std::vector masks; + masks.push_back("src/"); + PathMatch match(masks); + ASSERT(!match.Match("proj/mysrcfiles/file.txt")); + } + void onemasklongerpath1() { std::vector masks;