From 556fd265538e6d7a801beb1a0fdc65d87dc25b86 Mon Sep 17 00:00:00 2001
From: Xavier Besseron <xavier.besseron@uni.lu>
Date: Fri, 24 Aug 2012 11:25:41 +0200
Subject: [PATCH 6/7] Add a LoadExternal() function and an ExternalParser
 class

This call 'svn status' and parse the result to get the list of externals repositories.
The external repositories found are added to the Repositories list.
---
 Source/CTest/cmCTestSVN.cxx |   49 +++++++++++++++++++++++++++++++++++++++++++
 Source/CTest/cmCTestSVN.h   |    3 +++
 2 files changed, 52 insertions(+)

diff --git a/Source/CTest/cmCTestSVN.cxx b/Source/CTest/cmCTestSVN.cxx
index d2c8d10..7f348da 100644
--- a/Source/CTest/cmCTestSVN.cxx
+++ b/Source/CTest/cmCTestSVN.cxx
@@ -460,6 +460,55 @@ void cmCTestSVN::WriteXMLGlobal(std::ostream& xml)
 }
 
 //----------------------------------------------------------------------------
+class cmCTestSVN::ExternalParser: public cmCTestVC::LineParser
+{
+public:
+  ExternalParser(cmCTestSVN* svn, const char* prefix): SVN(svn)
+    {
+    this->SetLog(&svn->Log, prefix);
+    this->RegexExternal.compile("^X..... +(.+)$");
+    }
+private:
+  cmCTestSVN* SVN;
+  cmsys::RegularExpression RegexExternal;
+  bool ProcessLine()
+    {
+    if(this->RegexExternal.find(this->Line))
+      {
+      this->DoPath(this->RegexExternal.match(1));
+      }
+    return true;
+    }
+
+  void DoPath(std::string const& path)
+    {
+      // Get local path relative to the source directory
+      std::string local_path;
+      if(path.size() > this->SVN->SourceDirectory.size() &&
+         strncmp(path.c_str(), this->SVN->SourceDirectory.c_str(), this->SVN->SourceDirectory.size()) == 0)
+        {
+        local_path = path.c_str() + this->SVN->SourceDirectory.size() + 1;
+        }
+      else
+        {
+        local_path = path;
+        }
+      this->SVN->Repositories.push_back( SVNInfo(local_path.c_str()) );
+    }
+};
+
+//----------------------------------------------------------------------------
+void cmCTestSVN::LoadExternals()
+{
+  // Run "svn status" to get the list of external repositories
+  const char* svn = this->CommandLineTool.c_str();
+  const char* svn_status[] = {svn, "status", 0};
+  ExternalParser out(this, "external-out> ");
+  OutputLogger err(this->Log, "external-err> ");
+  this->RunChild(svn_status, &out, &err);
+}
+
+//----------------------------------------------------------------------------
 std::string cmCTestSVN::SVNInfo::BuildLocalPath(std::string const& path) const
 {
   std::string local_path;
diff --git a/Source/CTest/cmCTestSVN.h b/Source/CTest/cmCTestSVN.h
index 79be9b7..571af8c 100644
--- a/Source/CTest/cmCTestSVN.h
+++ b/Source/CTest/cmCTestSVN.h
@@ -71,6 +71,7 @@ private:
   SVNInfo* RootInfo;
 
   std::string LoadInfo(SVNInfo& svninfo);
+  void LoadExternals();
   void LoadModifications();
   void LoadRevisions();
   void LoadRevisions(SVNInfo& svninfo);
@@ -87,10 +88,12 @@ private:
   class LogParser;
   class StatusParser;
   class UpdateParser;
+  class ExternalParser;
   friend class InfoParser;
   friend class LogParser;
   friend class StatusParser;
   friend class UpdateParser;
+  friend class ExternalParser;
 };
 
 #endif
-- 
1.7.9.5

