2023-11-04 21:35:38 +02:00
|
|
|
#include <cerrno>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <regex>
|
|
|
|
#include <strings.h> // for strcasecmp
|
|
|
|
|
2022-05-04 15:32:21 +03:00
|
|
|
#include "git.hh"
|
|
|
|
|
2023-11-04 21:35:38 +02:00
|
|
|
namespace nix::git {
|
|
|
|
|
|
|
|
using namespace nix;
|
|
|
|
using namespace std::string_literals;
|
|
|
|
|
2022-05-04 15:32:21 +03:00
|
|
|
std::optional<LsRemoteRefLine> parseLsRemoteLine(std::string_view line)
|
|
|
|
{
|
|
|
|
const static std::regex line_regex("^(ref: *)?([^\\s]+)(?:\\t+(.*))?$");
|
|
|
|
std::match_results<std::string_view::const_iterator> match;
|
|
|
|
if (!std::regex_match(line.cbegin(), line.cend(), match, line_regex))
|
|
|
|
return std::nullopt;
|
|
|
|
|
|
|
|
return LsRemoteRefLine {
|
|
|
|
.kind = match[1].length() == 0
|
|
|
|
? LsRemoteRefLine::Kind::Object
|
|
|
|
: LsRemoteRefLine::Kind::Symbolic,
|
|
|
|
.target = match[2],
|
|
|
|
.reference = match[3].length() == 0 ? std::nullopt : std::optional<std::string>{ match[3] }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|