aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-04-19 22:43:08 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-04-19 22:43:08 +0300
commitbba520774fd6185f62a6bf52c61b98104a826f5f (patch)
tree4be19b347486932c7858349bb7a7c476e88dd5a4
parent7cf0854121525747b438b7f94bf2d050f61fb615 (diff)
Add support for comma-separated list of git reference filter
-rw-r--r--libbpkg/manifest.cxx15
-rw-r--r--libbpkg/manifest.hxx10
-rw-r--r--tests/repository-location/driver.cxx30
3 files changed, 46 insertions, 9 deletions
diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx
index e1dfb52..2374b77 100644
--- a/libbpkg/manifest.cxx
+++ b/libbpkg/manifest.cxx
@@ -2093,7 +2093,7 @@ namespace bpkg
// Verify the URL fragment.
//
if (url_.fragment)
- git_ref_filter r (*url_.fragment);
+ parse_git_ref_filters (*url_.fragment);
break;
}
@@ -2327,6 +2327,19 @@ namespace bpkg
"git repository commit id must be 40 characters long");
}
+ git_ref_filters
+ parse_git_ref_filters (const string& s)
+ {
+ git_ref_filters r;
+ for (size_t p (0); p != string::npos; )
+ {
+ size_t e (s.find (',', p));
+ r.emplace_back (string (s, p, e != string::npos ? e - p : e));
+ p = e != string::npos ? e + 1 : e;
+ }
+ return r;
+ }
+
// repository_manifest
//
repository_role repository_manifest::
diff --git a/libbpkg/manifest.hxx b/libbpkg/manifest.hxx
index fdec69e..f3223b6 100644
--- a/libbpkg/manifest.hxx
+++ b/libbpkg/manifest.hxx
@@ -849,6 +849,8 @@ namespace bpkg
public:
// Parse the [<name>][@<commit>] repository URL fragment representation.
+ // Throw std::invalid_argument if the filter representation format is
+ // invalid.
//
explicit
git_ref_filter (const std::string&);
@@ -859,6 +861,14 @@ namespace bpkg
commit (std::move (c)) {}
};
+ using git_ref_filters = std::vector<git_ref_filter>;
+
+ // Parse a comma-separated list of git reference filters. Throw
+ // std::invalid_argument if the filter list format is invalid.
+ //
+ LIBBPKG_EXPORT git_ref_filters
+ parse_git_ref_filters (const std::string&);
+
enum class repository_role
{
base,
diff --git a/tests/repository-location/driver.cxx b/tests/repository-location/driver.cxx
index 2e39c26..ee8fba1 100644
--- a/tests/repository-location/driver.cxx
+++ b/tests/repository-location/driver.cxx
@@ -19,6 +19,7 @@ using namespace butl;
namespace bpkg
{
using butl::optional;
+ using butl::nullopt;
inline static repository_location
loc ()
@@ -99,6 +100,12 @@ namespace bpkg
return true;
}
+ inline static bool
+ operator== (const git_ref_filter& x, const git_ref_filter& y)
+ {
+ return x.commit == y.commit && x.name == y.name;
+ }
+
int
main (int argc, char* argv[])
{
@@ -159,6 +166,9 @@ namespace bpkg
assert (bad_loc ("https://www.example.com/test.git#",
repository_type::git));
+ assert (bad_loc ("https://www.example.com/test.git#,",
+ repository_type::git));
+
assert (bad_loc ("https://www.example.com/test.git#@",
repository_type::git));
@@ -812,16 +822,20 @@ namespace bpkg
// Repository URL fragments.
//
{
- string branch ("master");
- string commit ("0a53e9ddeaddad63ad106860237bbf53411d11a7");
+ string n ("master");
+ string c ("0a53e9ddeaddad63ad106860237bbf53411d11a7");
+
+ assert (git_ref_filter (n) == git_ref_filter (n, nullopt));
+ assert (git_ref_filter (c + "@") == git_ref_filter (c, nullopt));
+ assert (git_ref_filter (c) == git_ref_filter (nullopt, c));
+ assert (git_ref_filter ("@" + c) == git_ref_filter (nullopt, c));
+ assert (git_ref_filter (n + "@" + c) == git_ref_filter (n, c));
- assert (*git_ref_filter (branch).name == branch);
- assert (*git_ref_filter (commit + "@").name == commit);
- assert (*git_ref_filter (commit).commit == commit);
- assert (*git_ref_filter ("@" + commit).commit == commit);
+ assert (parse_git_ref_filters ("tag") ==
+ git_ref_filters ({git_ref_filter ("tag")}));
- git_ref_filter r (branch + "@" + commit);
- assert (*r.name == branch && *r.commit == commit);
+ assert (parse_git_ref_filters ("a,b") ==
+ git_ref_filters ({git_ref_filter ("a"), git_ref_filter ("b")}));
}
// repository_url