]> git.mxchange.org Git - simgear.git/commitdiff
Optionally, use internal code for SVN syncs.
authorJames Turner <zakalawe@mac.com>
Sun, 9 Jun 2013 18:18:32 +0000 (19:18 +0100)
committerJames Turner <zakalawe@mac.com>
Sun, 9 Jun 2013 21:55:15 +0000 (22:55 +0100)
CMakeLists.txt
simgear/scene/tsync/terrasync.cxx
simgear/simgear_config_cmake.h.in

index 854db0c9e4552a186ab57b7696fe0ab6663c0b7d..838b027866616cef60396e8e473aad0b1922a070 100644 (file)
@@ -108,6 +108,7 @@ endif()
 
 option(SIMGEAR_HEADLESS "Set to ON to build SimGear without GUI/graphics support" OFF)
 option(JPEG_FACTORY     "Enable JPEG-factory support" OFF)
+option(SG_SVN_CLIENT    "Set to ON to build SimGear with built-in SVN support" OFF)
 option(ENABLE_LIBSVN    "Set to ON to build SimGear with libsvnclient support" ON)
 option(ENABLE_RTI       "Set to ON to build SimGear with RTI support" OFF)
 option(ENABLE_TESTS     "Set to OFF to disable building SimGear's test applications" ON)
@@ -193,7 +194,9 @@ else()
     message(STATUS "JPEG-factory: DISABLED")
 endif(JPEG_FACTORY)
 
-if(ENABLE_LIBSVN)
+if (SG_SVN_CLIENT)
+    message(STATUS "Using built-in subversion client code")
+elseif(ENABLE_LIBSVN)
     find_package(SvnClient)
 
     if(LIBSVN_FOUND)
@@ -208,7 +211,7 @@ if(ENABLE_LIBSVN)
     endif(LIBSVN_FOUND)
 else()
     message(STATUS "Subversion client support: DISABLED")
-endif(ENABLE_LIBSVN)
+endif(SG_SVN_CLIENT)
 
 find_package(ZLIB REQUIRED)
 find_package(Threads REQUIRED)
index d351fa3dde7172c06bedffed805a4fc7150c9318..1db363fc9d4c9c2968e3c1ecde62a9a1470bc074 100644 (file)
 #include <simgear/misc/sg_dir.hxx>
 #include <simgear/debug/BufferedLogCallback.hxx>
 
+#ifdef SG_SVN_CLIENT
+#  include <simgear/io/HTTPClient.hxx>
+#  include <simgear/io/SVNRepository.hxx>
+#endif
+
 #ifdef HAVE_SVN_CLIENT_H
 #  ifdef HAVE_LIBSVN_CLIENT_1
 #    include <svn_version.h>
@@ -80,6 +85,9 @@
         { "svn_client", svn_client_version },
         { NULL, NULL }
     };
+#endif
+    
+#if defined(HAVE_SVN_CLIENT_H) or defined(SG_SVN_CLIENT)
     static const bool svn_built_in_available = true;
 #else
     static const bool svn_built_in_available = false;
@@ -163,7 +171,7 @@ public:
    void   setUseSvn(bool use_svn)           { _use_svn = use_svn;}
    void   setAllowedErrorCount(int errors)  {_allowed_errors = errors;}
 
-#ifdef HAVE_SVN_CLIENT_H
+#if defined(HAVE_SVN_CLIENT_H) or defined(SG_SVN_CLIENT)
    void setUseBuiltin(bool built_in) { _use_built_in = built_in;}
 #endif
 
@@ -182,7 +190,13 @@ private:
    bool syncTree(const char* dir, bool& isNewDirectory);
    bool syncTreeExternal(const char* dir);
 
-#ifdef HAVE_SVN_CLIENT_H
+
+#if defined(SG_SVN_CLIENT)
+   bool syncTreeInternal(const char* dir);
+   bool _use_built_in;
+   HTTP::Client _http;
+   std::auto_ptr<SVNRepository> _repository;
+#elif defined(HAVE_SVN_CLIENT_H)
    static int svnClientSetup(void);
    bool syncTreeInternal(const char* dir);
 
@@ -224,7 +238,7 @@ SGTerraSync::SvnThread::SvnThread() :
     _success_count(0),
     _consecutive_errors(0),
     _allowed_errors(6),
-#ifdef HAVE_SVN_CLIENT_H
+#if defined(HAVE_SVN_CLIENT_H) or defined(SG_SVN_CLIENT)
     _use_built_in(true),
 #endif
     _is_dirty(false),
@@ -293,7 +307,7 @@ bool SGTerraSync::SvnThread::start()
         return false;
     }
 
-#ifdef HAVE_SVN_CLIENT_H
+#if defined(HAVE_SVN_CLIENT_H) or defined(SG_SVN_CLIENT)
     _use_svn |= _use_built_in;
 #endif
 
@@ -323,7 +337,7 @@ bool SGTerraSync::SvnThread::start()
     _running = true;
 
     string status;
-#ifdef HAVE_SVN_CLIENT_H
+#if defined(HAVE_SVN_CLIENT_H) or defined(SG_SVN_CLIENT)
     if (_use_svn && _use_built_in)
         status = "Using built-in SVN support. ";
     else
@@ -369,7 +383,7 @@ bool SGTerraSync::SvnThread::syncTree(const char* dir, bool& isNewDirectory)
         }
     }
 
-#ifdef HAVE_SVN_CLIENT_H
+#if defined(HAVE_SVN_CLIENT_H) or defined(SG_SVN_CLIENT)
     if (_use_built_in)
         return syncTreeInternal(dir);
     else
@@ -379,8 +393,44 @@ bool SGTerraSync::SvnThread::syncTree(const char* dir, bool& isNewDirectory)
     }
 }
 
+#if defined(SG_SVN_CLIENT)
+    
+bool SGTerraSync::SvnThread::syncTreeInternal(const char* dir)
+{
+    ostringstream command;
+    command << _svn_server << "/" << dir;
+
+    SGPath path(_local_dir);
+    path.append(dir);
+    _repository.reset(new SVNRepository(path, &_http));
+    _repository->setBaseUrl(command.str());
+    
+    SGTimeStamp st;
+    st.stamp();
+    SG_LOG(SG_IO, SG_DEBUG, "terrasync: will sync " << command.str());
+    _repository->update();
+    
+    bool result = true;
+    while (!_stop && _repository->isDoingSync()) {
+        _http.update(100);
+    }
+    
+    if (_repository->failure() == SVNRepository::ERROR_NOT_FOUND) {
+        // this is fine, but maybe we should use a different return code
+        // in the future to higher layers can distuinguish this case
+    } else if (_repository->failure() != SVNRepository::NO_ERROR) {
+        result = false;
+    } else {
+        SG_LOG(SG_IO, SG_DEBUG, "sync of " << command.str() << " finished ("
+            << st.elapsedMSec() << " msec");
+    }
+    
+    _repository.reset();
+    return result;
+}
+    
+#elif defined(HAVE_SVN_CLIENT_H)
 
-#ifdef HAVE_SVN_CLIENT_H
 bool SGTerraSync::SvnThread::syncTreeInternal(const char* dir)
 {
     SG_LOG(SG_TERRAIN,SG_DEBUG, "Synchronizing scenery directory " << dir);
@@ -455,7 +505,7 @@ bool SGTerraSync::SvnThread::syncTreeInternal(const char* dir)
     svn_pool_destroy(subpool);
     return ReturnValue;
 }
-#endif
+#endif // of HAVE_SVN_CLIENT_H
 
 bool SGTerraSync::SvnThread::syncTreeExternal(const char* dir)
 {
@@ -571,7 +621,7 @@ void SGTerraSync::SvnThread::run()
     _is_dirty = true;
 }
 
-#ifdef HAVE_SVN_CLIENT_H
+#if defined(HAVE_SVN_CLIENT_H)
 // Configure our subversion session
 int SGTerraSync::SvnThread::svnClientSetup(void)
 {
@@ -670,7 +720,7 @@ int SGTerraSync::SvnThread::svnClientSetup(void)
     _svn_pool = pool;
     return EXIT_SUCCESS;
 }
-#endif
+#endif // of defined(HAVE_SVN_CLIENT_H)
 
 ///////////////////////////////////////////////////////////////////////////////
 // SGTerraSync ////////////////////////////////////////////////////////////////
@@ -722,7 +772,7 @@ void SGTerraSync::reinit()
         _svnThread->setLocalDir(_terraRoot->getStringValue("scenery-dir",""));
         _svnThread->setAllowedErrorCount(_terraRoot->getIntValue("max-errors",5));
 
-    #ifdef HAVE_SVN_CLIENT_H
+    #if defined(HAVE_SVN_CLIENT_H) or defined(SG_SVN_CLIENT)
         _svnThread->setUseBuiltin(_terraRoot->getBoolValue("use-built-in-svn",true));
     #else
         _terraRoot->setBoolValue("use-built-in-svn",false);
index 135b7f44d00a9bf72f946e22333dac40800c5d9f..8399f698e7c46d99c69c00a7834ddecdb68f981b 100644 (file)
@@ -20,4 +20,6 @@
 #cmakedefine GCC_ATOMIC_BUILTINS_FOUND
 
 #cmakedefine SYSTEM_EXPAT
-#cmakedefine ENABLE_SOUND
\ No newline at end of file
+#cmakedefine ENABLE_SOUND
+
+#cmakedefine SG_SVN_CLIENT
\ No newline at end of file