From c279a6a20ade252d221853a89733e734ccb01fb2 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Sat, 16 May 2015 21:10:44 -0700 Subject: [PATCH] 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. --- commands.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/commands.cpp b/commands.cpp index f984132..f8e9f23 100644 --- a/commands.cpp +++ b/commands.cpp @@ -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 command; command.push_back("git"); @@ -77,6 +77,31 @@ static std::string git_version () return word; } +static std::vector parse_version (const std::string& str) +{ + std::istringstream in(str); + std::vector version; + std::string component; + while (std::getline(in, component, '.')) { + version.push_back(std::atoi(component.c_str())); + } + return version; +} + +static std::vector git_version () +{ + return parse_version(git_version_string()); +} + +static std::vector make_version (int a, int b, int c) +{ + std::vector 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 command;