aboutsummaryrefslogtreecommitdiff
path: root/bpkg
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-21 14:14:08 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-21 14:14:08 +0200
commit26a42f71564fb97d5dba924f681e70fedcf6af46 (patch)
treec7433690a90824a80ac92c1706cdb6edae2bf2d4 /bpkg
parent450702a232bf07a82c6ac74fe28dc7bc9cffe67c (diff)
Expand and clarify empty repository_location
Diffstat (limited to 'bpkg')
-rw-r--r--bpkg/manifest21
-rw-r--r--bpkg/manifest.cxx19
2 files changed, 26 insertions, 14 deletions
diff --git a/bpkg/manifest b/bpkg/manifest
index 35ff650..47b8d76 100644
--- a/bpkg/manifest
+++ b/bpkg/manifest
@@ -321,20 +321,24 @@ namespace bpkg
//
repository_location () = default;
- // Creates remote/absolute repository location. Throws invalid_argument
- // if the location is a relative path.
+ // If the argument is not empty, creates remote/absolute repository
+ // location. Throws invalid_argument if the location is a relative
+ // path. If the argument is empty, then creates the special empty
+ // location.
//
explicit
repository_location (const std::string&);
// Creates a potentially relative repository location. If base is not
// empty, use it to complete the relative location to remote/absolute.
- // Throws invalid_argument if base itself is relative or the resulting
- // completed location is invalid.
+ // Throws invalid_argument if base is not empty but the location is
+ // empty, base itself is relative, or the resulting completed location
+ // is invalid.
//
repository_location (const std::string&, const repository_location& base);
- // Note that relative locations have no canonical name.
+ // Note that relative locations have no canonical name. Canonical
+ // name of an empty location is the empty name.
//
const std::string&
canonical_name () const noexcept {return canonical_name_;}
@@ -409,9 +413,10 @@ namespace bpkg
return port_;
}
- // Note that this is not necessarily syntactically the same
- // string as what was used to initialize this location. But
- // it should be semantically equivalent.
+ // Note that this is not necessarily syntactically the same string
+ // as what was used to initialize this location. But it should be
+ // semantically equivalent. String representation of an empty
+ // location is the empty string.
//
std::string
string () const;
diff --git a/bpkg/manifest.cxx b/bpkg/manifest.cxx
index b66d5d4..1034fe3 100644
--- a/bpkg/manifest.cxx
+++ b/bpkg/manifest.cxx
@@ -832,7 +832,7 @@ namespace bpkg
repository_location (const std::string& l)
: repository_location (l, repository_location ()) // Delegate.
{
- if (relative ())
+ if (!empty () && relative ())
throw invalid_argument ("relative filesystem path");
}
@@ -843,6 +843,14 @@ namespace bpkg
//
using std::string;
+ if (l.empty ())
+ {
+ if (!b.empty ())
+ throw invalid_argument ("empty location");
+
+ return;
+ }
+
// Base repository location can not be a relative path.
//
if (!b.empty () && b.relative ())
@@ -971,9 +979,6 @@ namespace bpkg
{
path_ = dir_path (l);
- if (path_.empty ())
- throw invalid_argument ("empty location");
-
// Complete if we are relative and have base.
//
if (!b.empty () && path_.relative ())
@@ -1052,13 +1057,15 @@ namespace bpkg
string repository_location::
string () const
{
+ using std::string; // Also function name.
+
if (empty ())
- return "";
+ return string ();
if (local ())
return path_.string ();
- std::string p ("http://" + host_);
+ string p ("http://" + host_);
if (port_ != 0)
p += ":" + to_string (port_);