Gracefully handle ‘svn info’ failure

This command would e.g. fail if the repository format is of a newer date (in which case the code expecting a result would do “out of bounds” access).

Rather than split on newline, split third element on colon, and then take second element of that result, we now parse the output into a map and look for the ‘URL’ key.
This commit is contained in:
Allan Odgaard
2012-08-25 15:15:00 +02:00
parent 895dd9a1bd
commit 8d13174001

View File

@@ -2,6 +2,7 @@
#include <oak/oak.h>
#include <text/parse.h>
#include <text/trim.h>
#include <text/tokenize.h>
#include <io/io.h>
#include <oak/debug.h>
@@ -54,6 +55,18 @@ static void parse_status_output (scm::status_map_t& entries, std::string const&
}
}
static std::map<std::string, std::string> parse_info_output (std::string const& str)
{
std::map<std::string, std::string> res;
citerate(line, text::tokenize(str.begin(), str.end(), '\n'))
{
std::string::size_type n = (*line).find(':');
if(n != std::string::npos)
res.insert(std::make_pair((*line).substr(0, n), (*line).substr(n+2)));
}
return res;
}
static void collect_all_paths (std::string const& svn, scm::status_map_t& entries, std::string const& dir)
{
ASSERT_NE(svn, NULL_STR);
@@ -79,10 +92,9 @@ namespace scm
std::map<std::string, std::string> env = oak::basic_environment();
env["PWD"] = wcPath;
std::string info_output = io::exec(env, executable(), "info", NULL);
std::vector<std::string> v = text::split(info_output, "\n");
return text::split(v[2], ": ")[1];
auto info = parse_info_output(io::exec(env, executable(), "info", NULL));
auto urlInfo = info.find("URL");
return urlInfo != info.end() ? urlInfo->second : NULL_STR;
}
status_map_t status (std::string const& wcPath) const