diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2022-11-03 17:43:40 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2022-11-03 17:43:40 +0100 |
commit | b95faccf03e5213b6087626ab8d46e0704aad6b5 (patch) | |
tree | f9d560f2004f951d8efbf1024292a88366d8efd7 /src/libutil/git.cc | |
parent | 47dec825c5daeeb9d615eb4d1eead3dbaa06c7c9 (diff) | |
parent | dd1970c233a82328445b69e903574e14115ee933 (diff) |
Merge remote-tracking branch 'origin/master' into auto-uid-allocation
Diffstat (limited to 'src/libutil/git.cc')
-rw-r--r-- | src/libutil/git.cc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/libutil/git.cc b/src/libutil/git.cc new file mode 100644 index 000000000..f35c2fdb7 --- /dev/null +++ b/src/libutil/git.cc @@ -0,0 +1,25 @@ +#include "git.hh" + +#include <regex> + +namespace nix { +namespace git { + +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] } + }; +} + +} +} |