From 5d69b98c5d62b05d1d6d6fd24aeac468af509365 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 14 Nov 2018 16:12:25 +0300 Subject: Add support for repository typed URLs (git+https://..., etc) --- bpkg/manifest-utility.cxx | 27 ++++++++++++++++++++------- bpkg/rep-add.cli | 6 +++--- bpkg/rep-fetch.cxx | 4 ++-- bpkg/repository-types.cli | 11 +++++++++++ 4 files changed, 36 insertions(+), 12 deletions(-) (limited to 'bpkg') diff --git a/bpkg/manifest-utility.cxx b/bpkg/manifest-utility.cxx index c329108..79c131b 100644 --- a/bpkg/manifest-utility.cxx +++ b/bpkg/manifest-utility.cxx @@ -92,7 +92,9 @@ namespace bpkg parse_location (const string& s, optional ot) try { - repository_url u (s); + typed_repository_url tu (s); + + repository_url& u (tu.url); assert (u.path); // Make the relative path absolute using the current directory. @@ -102,13 +104,24 @@ namespace bpkg // Guess the repository type to construct the repository location: // - // 1. If type is specified as an option use that (but validate - // incompatible scheme/type e.g., git/pkg). + // 1. If the type is specified in the URL scheme, then use that (but + // validate that it matches the --type option, if present). + // + // 2. If the type is specified as an option, then use that. // - // 2. See guess_type() function description in libbpkg/manifest.hxx for - // the algorithm details. + // Validate the protocol/type compatibility (e.g. git:// vs pkg) for both + // cases. // - repository_type t (ot ? *ot : guess_type (u, true)); + // 3. See the guess_type() function description in + // for the algorithm details. + // + if (tu.type && ot && tu.type != ot) + fail << to_string (*ot) << " repository type mismatch for location '" + << s << "'"; + + repository_type t (tu.type ? *tu.type : + ot ? *ot : + guess_type (tu.url, true /* local */)); try { @@ -125,7 +138,7 @@ namespace bpkg // If the pkg repository type was guessed, then suggest the user to // specify the type explicitly. // - if (!ot && t == repository_type::pkg) + if (!tu.type && !ot && t == repository_type::pkg) dr << info << "consider using --type to specify repository type"; dr << endf; diff --git a/bpkg/rep-add.cli b/bpkg/rep-add.cli index 481b30a..9605ac7 100644 --- a/bpkg/rep-add.cli +++ b/bpkg/rep-add.cli @@ -40,9 +40,9 @@ namespace bpkg case of a local repository, its content (for example, the presence of the \cb{.git/} subdirectory). Without any identifying information the \cb{pkg} type is assumed unless explicitly specified with the \cb{--type} - option. Note, however, that the \cb{dir} repository type is never guessed - since it is not easily distinguishable from local \cb{pkg} and \cb{git} - repositories. + option or in the URL scheme. Note, however, that the \cb{dir} repository + type is never guessed since it is not easily distinguishable from local + \cb{pkg} and \cb{git} repositories. " } diff --git a/bpkg/rep-fetch.cxx b/bpkg/rep-fetch.cxx index 77ffc10..ef42b03 100644 --- a/bpkg/rep-fetch.cxx +++ b/bpkg/rep-fetch.cxx @@ -537,8 +537,8 @@ namespace bpkg } catch (const invalid_argument& e) { - fail << "invalid relative repository location '" << l - << "': " << e << + fail << "invalid relative repository location '" << l << "': " + << e << info << "base repository location is " << rl; } diff --git a/bpkg/repository-types.cli b/bpkg/repository-types.cli index 79c50f8..1471ecf 100644 --- a/bpkg/repository-types.cli +++ b/bpkg/repository-types.cli @@ -16,6 +16,17 @@ structure, and the format of their URLs. Currently three types of repositories are supported: archive-based \cb{pkg}, directory-based \cb{dir}, and version control-based \cb{git}. +The repository location may specify the repository type as part of the URL +scheme component in the \c{\i{type}\b{+}\i{protocol}} form. For example: + +\ +git+https://example.com/foo +dir+file:///tmp/repo +\ + +Note that the explicit specification is only needed when the correct type +cannot be guessed from the URL. See \l{bpkg-rep-add(1)} for details. + \h|PKG REPOSITORIES| -- cgit v1.1