From db4a9915b25ab682762eb73d65aab44e6bddcc1f Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 11 Jan 2023 21:39:15 +0300 Subject: Add --git-capabilities common option --- bpkg/types-parsers.cxx | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'bpkg/types-parsers.cxx') diff --git a/bpkg/types-parsers.cxx b/bpkg/types-parsers.cxx index e27f050..f23751d 100644 --- a/bpkg/types-parsers.cxx +++ b/bpkg/types-parsers.cxx @@ -3,6 +3,8 @@ #include +#include + namespace bpkg { namespace cli @@ -141,6 +143,83 @@ namespace bpkg throw invalid_value (o, v); } + void parser:: + parse (git_protocol_capabilities& x, bool& xs, scanner& s) + { + xs = true; + const char* o (s.next ()); + + if (!s.more ()) + throw missing_value (o); + + const string v (s.next ()); + if (v == "dumb") + x = git_protocol_capabilities::dumb; + else if (v == "smart") + x = git_protocol_capabilities::smart; + else if (v == "unadv") + x = git_protocol_capabilities::unadv; + else + throw invalid_value (o, v); + } + + void parser:: + parse (git_capabilities_map& x, bool& xs, scanner& s) + { + xs = true; + const char* o (s.next ()); + + if (!s.more ()) + throw missing_value (o); + + string v (s.next ()); + size_t p (v.rfind ('=')); + + if (p == string::npos) + throw invalid_value (o, v); + + string k (v, 0, p); + + // Verify that the key is a valid remote git repository URL prefix. + // + try + { + repository_url u (k); + + if (u.scheme == repository_protocol::file) + throw invalid_value (o, k, "local repository location"); + } + catch (const invalid_argument& e) + { + throw invalid_value (o, k, e.what ()); + } + + // Parse the protocol capabilities value. + // + int ac (2); + char* av[] = {const_cast (o), + const_cast (v.c_str () + p + 1)}; + + argv_scanner vs (0, ac, av); + + bool dummy; + parser::parse (x[k], dummy, vs); + } + + void parser:: + merge (git_capabilities_map& b, const git_capabilities_map& a) + { + for (const auto& o: a) + { + auto i (b.find (o.first)); + + if (i != b.end ()) + i->second = o.second; + else + b.emplace (o.first, o.second); + } + } + void parser:: parse (stdout_format& x, bool& xs, scanner& s) { -- cgit v1.1