Add helpers to faciliate Git version comparison

This will be useful as we start to gate code on the version of Git that's installed.
This commit is contained in:
Andrew Ayer
2015-05-16 21:10:44 -07:00
parent 439bcd852d
commit c279a6a20a

View File

@@ -60,7 +60,7 @@ static std::string attribute_name (const char* key_name)
}
}
static std::string git_version ()
static std::string git_version_string ()
{
std::vector<std::string> command;
command.push_back("git");
@@ -77,6 +77,31 @@ static std::string git_version ()
return word;
}
static std::vector<int> parse_version (const std::string& str)
{
std::istringstream in(str);
std::vector<int> version;
std::string component;
while (std::getline(in, component, '.')) {
version.push_back(std::atoi(component.c_str()));
}
return version;
}
static std::vector<int> git_version ()
{
return parse_version(git_version_string());
}
static std::vector<int> make_version (int a, int b, int c)
{
std::vector<int> version;
version.push_back(a);
version.push_back(b);
version.push_back(c);
return version;
}
static void git_config (const std::string& name, const std::string& value)
{
std::vector<std::string> command;