aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/git.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-07 09:40:36 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-07 09:40:36 -0400
commitc036de086e2f06e6dee1c31e29e05a802f6ccf80 (patch)
treea3760ae3cec9cabbab39bd95bd2eaab8e2ce2bdf /src/libutil/git.cc
parentc863e5f338947ecff275a67725ecf50b2a47bdb5 (diff)
parent81dfc2b01231c65137017de092c8506838fadd94 (diff)
Merge remote-tracking branch 'upstream/master' into trustless-remote-builder-simple
Diffstat (limited to 'src/libutil/git.cc')
-rw-r--r--src/libutil/git.cc25
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] }
+ };
+}
+
+}
+}