Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82124 - trunk/tools/inspect
From: dnljms_at_[hidden]
Date: 2012-12-20 15:33:55


Author: danieljames
Date: 2012-12-20 15:33:54 EST (Thu, 20 Dec 2012)
New Revision: 82124
URL: http://svn.boost.org/trac/boost/changeset/82124

Log:
Swallow program execution manager exceptions when running subversion.

In case inspect isn't run in a subversion checkout.
Text files modified:
   trunk/tools/inspect/inspect.cpp | 88 +++++++++++++++++++++++++++++++--------
   1 files changed, 70 insertions(+), 18 deletions(-)

Modified: trunk/tools/inspect/inspect.cpp
==============================================================================
--- trunk/tools/inspect/inspect.cpp (original)
+++ trunk/tools/inspect/inspect.cpp 2012-12-20 15:33:54 EST (Thu, 20 Dec 2012)
@@ -124,30 +124,82 @@
   typedef std::vector< lib_error_count > lib_error_count_vector;
   lib_error_count_vector libs;
 
+// run subversion to get revisions info ------------------------------------//
+//
+// implemented as function object that can be passed to boost::execution_monitor
+// in order to swallow any errors from 'svn info'.
+
+ struct svn_check
+ {
+ explicit svn_check(const fs::path & inspect_root) :
+ inspect_root(inspect_root), fp(0) {}
+
+ int operator()() {
+ string rev("unknown");
+ string repos("unknown");
+ string command("cd ");
+ command += inspect_root.string() + " && svn info";
+
+ fp = (POPEN(command.c_str(), "r"));
+ if (fp)
+ {
+ static const int line_max = 128;
+ char line[line_max];
+ while (fgets(line, line_max, fp) != NULL)
+ {
+ string ln(line);
+ string::size_type pos;
+ if ((pos = ln.find("Revision: ")) != string::npos)
+ rev = ln.substr(pos + 10);
+ else if ((pos = ln.find("URL: ")) != string::npos)
+ repos = ln.substr(pos + 5);
+ }
+ }
+
+ result = repos + " at revision " + rev;
+ return 0;
+ }
+
+ ~svn_check() { if (fp) PCLOSE(fp); }
+
+ const fs::path & inspect_root;
+ std::string result;
+ FILE* fp;
+ private:
+ svn_check(svn_check const&);
+ svn_check const& operator=(svn_check const&);
+ };
+
+ // Small helper class because svn_check can't be passed by copy.
+ template <typename F, typename R>
+ struct nullary_function_ref
+ {
+ explicit nullary_function_ref(F& f) : f(f) {}
+ R operator()() const { return f(); }
+ F& f;
+ };
+
 // get info (as a string) if inspect_root is svn working copy --------------//
 
   string info( const fs::path & inspect_root )
   {
- string rev("unknown");
- string repos("unknown");
- string command("cd ");
- command += inspect_root.string() + " && svn info";
- FILE* fp = POPEN(command.c_str(), "r");
- if (fp)
- {
- static const int line_max = 128;
- char line[line_max];
- while (fgets(line, line_max, fp) != NULL)
- {
- string ln(line);
- string::size_type pos;
- if ((pos = ln.find("Revision: ")) != string::npos)
- rev = ln.substr(pos + 10);
- else if ((pos = ln.find("URL: ")) != string::npos)
- repos = ln.substr(pos + 5);
+ try {
+ boost::execution_monitor e;
+ svn_check check(inspect_root);
+
+ e.execute(nullary_function_ref<svn_check, int>(check));
+ return check.result;
+ }
+ catch(boost::execution_exception const& e) {
+ if (e.code() == boost::execution_exception::system_error) {
+ // There was an error running 'svn info' - it probably
+ // wasn't run in a subversion repo.
+ return string("unknown");
+ }
+ else {
+ throw;
       }
     }
- return repos + " at revision " + rev;
   }
 
 // visit_predicate (determines which directories are visited) --------------//


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk