Browse Source

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.
Alexander Neundorf 2 years ago
parent
commit
e7f7bff4f5
1 changed files with 27 additions and 19 deletions
  1. 27 19
      Source/cmExtraKateGenerator.cxx

+ 27 - 19
Source/cmExtraKateGenerator.cxx

@@ -8,6 +8,7 @@
 #include <set>
 #include <vector>
 
+#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<std::string> files;
   std::string tmp;
   const auto& lgs = this->GlobalGenerator->GetLocalGenerators();