From e7f7bff4f54f72bed6ca0dfac8a9989e8a44223c Mon Sep 17 00:00:00 2001 From: Alexander Neundorf Date: Thu, 2 Feb 2023 22:44:52 +0100 Subject: Kate: improve the way the VCS-specific files are searched Before, CMake only checked for the .svn etc. directory only in ${CMAKE_SOURCE_DIR}, now it also goes the directories up to check whether those VCS directories exist in one of the parent directories. --- Source/cmExtraKateGenerator.cxx | 46 ++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/Source/cmExtraKateGenerator.cxx b/Source/cmExtraKateGenerator.cxx index 5be8f26..0d0b513 100644 --- a/Source/cmExtraKateGenerator.cxx +++ b/Source/cmExtraKateGenerator.cxx @@ -8,6 +8,7 @@ #include #include +#include "cmCMakePath.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" @@ -241,31 +242,38 @@ std::string cmExtraKateGenerator::GenerateFilesString( return fossilString; } - std::string s; - // check for the VCS files except when "forced" to "FILES" mode: if (mode != "LIST") { - s = cmStrCat(lg.GetSourceDirectory(), "/.git"); - if (cmSystemTools::FileExists(s)) { - return gitString; - } + cmCMakePath startDir(lg.GetSourceDirectory(), cmCMakePath::auto_format); + // move the directories up to the root directory to see whether we are in + // a subdir of a svn, git, hg or fossil checkout + for (;;) { + std::string s = startDir.String() + "/.git"; + if (cmSystemTools::FileExists(s)) { + return gitString; + } - s = cmStrCat(lg.GetSourceDirectory(), "/.svn"); - if (cmSystemTools::FileExists(s)) { - return svnString; - } - s = cmStrCat(lg.GetSourceDirectory(), "/.hg"); - if (cmSystemTools::FileExists(s)) { - return hgString; - } - s = cmStrCat(lg.GetSourceDirectory(), "/.fslckout"); - if (cmSystemTools::FileExists(s)) { - return fossilString; + s = startDir.String() + "/.svn"; + if (cmSystemTools::FileExists(s)) { + return svnString; + } + + s = startDir.String() + "/.hg"; + if (cmSystemTools::FileExists(s)) { + return hgString; + } + s = startDir.String() + "/.fslckout"; + if (cmSystemTools::FileExists(s)) { + return fossilString; + } + + if (!startDir.HasRelativePath()) { // have we reached the root dir ? + break; + } + startDir = startDir.GetParentPath(); } } - s = cmStrCat(lg.GetSourceDirectory(), '/'); - std::set files; std::string tmp; const auto& lgs = this->GlobalGenerator->GetLocalGenerators(); -- cgit v0.12