aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-02-22 17:35:20 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-02-22 17:35:20 +0300
commitf27e01c849a88803614f521f601efecca1da649c (patch)
treeb64d3b73646d0715837ef3db2ad6f031f258bb50
parent34dd55af8432455c25cfe659841273bcd2b8e76a (diff)
Add repository URL fragment to canonical name
-rw-r--r--libbpkg/manifest.cxx16
-rw-r--r--tests/repository-location/driver.cxx30
2 files changed, 27 insertions, 19 deletions
diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx
index d58b6d8..8683037 100644
--- a/libbpkg/manifest.cxx
+++ b/libbpkg/manifest.cxx
@@ -11,7 +11,7 @@
#include <cstring> // strncmp(), strcmp()
#include <utility> // move()
#include <cstdint> // uint16_t, UINT16_MAX
-#include <algorithm> // find(), find_if_not(), replace()
+#include <algorithm> // find(), find_if_not(), find_first_of(), replace()
#include <stdexcept> // invalid_argument
#include <libbutl/path.mxx>
@@ -2016,11 +2016,13 @@ namespace bpkg
url_ = move (u);
// Set canonical name to the base location canonical name 'bpkg:<host>'
- // part. The path part of the canonical name is calculated below.
+ // part. The '<path>[#<fragment>]' part of the canonical name is
+ // calculated below.
//
if (b.remote ())
canonical_name_ =
- b.canonical_name_.substr (0, b.canonical_name_.find ("/"));
+ b.canonical_name_.substr (0,
+ b.canonical_name_.find_first_of ("/#"));
}
}
@@ -2088,7 +2090,7 @@ namespace bpkg
string cp (sp.relative () ? sp.posix_string () : sp.string ());
- // Don't allow empty canonical names.
+ // Don't allow canonical names without both host and path parts.
//
if (canonical_name_.empty () && cp.empty ())
throw invalid_argument ("empty repository name");
@@ -2107,6 +2109,12 @@ namespace bpkg
}
canonical_name_ += cp;
+
+ if (url_.fragment)
+ {
+ canonical_name_ += '#';
+ canonical_name_ += *url_.fragment;
+ }
}
// git_reference
diff --git a/tests/repository-location/driver.cxx b/tests/repository-location/driver.cxx
index e4282fe..e078376 100644
--- a/tests/repository-location/driver.cxx
+++ b/tests/repository-location/driver.cxx
@@ -308,18 +308,18 @@ namespace bpkg
repository_location l (loc ("file:/git/repo#branch",
repository_type::git));
assert (l.string () == "file:/git/repo#branch");
- assert (l.canonical_name () == "git:/git/repo");
+ assert (l.canonical_name () == "git:/git/repo#branch");
}
{
repository_location l (loc ("/git/repo#branch", repository_type::git));
assert (l.string () == "file:/git/repo#branch");
- assert (l.canonical_name () == "git:/git/repo");
+ assert (l.canonical_name () == "git:/git/repo#branch");
}
{
repository_location l (loc ("file://localhost/#master",
repository_type::git));
assert (l.string () == "file:/#master");
- assert (l.canonical_name () == "git:/");
+ assert (l.canonical_name () == "git:/#master");
}
#else
{
@@ -374,19 +374,19 @@ namespace bpkg
repository_location l (loc ("file:/c:/git/repo#branch",
repository_type::git));
assert (l.string () == "file:/c:/git/repo#branch");
- assert (l.canonical_name () == "git:c:\\git\\repo");
+ assert (l.canonical_name () == "git:c:\\git\\repo#branch");
}
{
repository_location l (loc ("c:\\git\\repo#branch",
repository_type::git));
assert (l.string () == "file:/c:/git/repo#branch");
- assert (l.canonical_name () == "git:c:\\git\\repo");
+ assert (l.canonical_name () == "git:c:\\git\\repo#branch");
}
{
repository_location l (loc ("file://localhost/c:/#master",
repository_type::git));
assert (l.string () == "file:/c:#master");
- assert (l.canonical_name () == "git:c:");
+ assert (l.canonical_name () == "git:c:#master");
}
#endif
{
@@ -440,7 +440,7 @@ namespace bpkg
repository_location l (loc ("git://example.com/test#master",
repository_type::git));
assert (l.string () == "git://example.com/test#master");
- assert (l.canonical_name () == "git:example.com/test");
+ assert (l.canonical_name () == "git:example.com/test#master");
assert (l.proto () == proto::git);
assert (l.type () == repository_type::git);
}
@@ -448,7 +448,7 @@ namespace bpkg
repository_location l (loc ("http://example.com/test.git#master",
repository_type::git));
assert (l.string () == "http://example.com/test.git#master");
- assert (l.canonical_name () == "git:example.com/test");
+ assert (l.canonical_name () == "git:example.com/test#master");
assert (l.proto () == proto::http);
assert (l.type () == repository_type::git);
}
@@ -456,7 +456,7 @@ namespace bpkg
repository_location l (loc ("https://example.com/test.git#master",
repository_type::git));
assert (l.string () == "https://example.com/test.git#master");
- assert (l.canonical_name () == "git:example.com/test");
+ assert (l.canonical_name () == "git:example.com/test#master");
assert (l.proto () == proto::https);
assert (l.type () == repository_type::git);
}
@@ -464,7 +464,7 @@ namespace bpkg
repository_location l (loc ("http://git.example.com#master",
repository_type::git));
assert (l.string () == "http://git.example.com/#master");
- assert (l.canonical_name () == "git:example.com");
+ assert (l.canonical_name () == "git:example.com#master");
}
{
repository_url u ("http://git.example.com/a/#master");
@@ -472,7 +472,7 @@ namespace bpkg
repository_location l (u, repository_type::git);
assert (l.string () == "http://git.example.com/#master");
- assert (l.canonical_name () == "git:example.com");
+ assert (l.canonical_name () == "git:example.com#master");
}
{
repository_location l (loc ("http://a.com/a/b/../c/1/aa/../bb"));
@@ -518,19 +518,19 @@ namespace bpkg
repository_location l (loc ("https://git.example.com/test.git#master",
repository_type::git));
assert (l.string () == "https://git.example.com/test.git#master");
- assert (l.canonical_name () == "git:example.com/test");
+ assert (l.canonical_name () == "git:example.com/test#master");
}
{
repository_location l (loc ("https://scm.example.com/test.git#master",
repository_type::git));
assert (l.string () == "https://scm.example.com/test.git#master");
- assert (l.canonical_name () == "git:example.com/test");
+ assert (l.canonical_name () == "git:example.com/test#master");
}
{
repository_location l (loc ("https://www.example.com/test.git#master",
repository_type::git));
assert (l.string () == "https://www.example.com/test.git#master");
- assert (l.canonical_name () == "git:example.com/test");
+ assert (l.canonical_name () == "git:example.com/test#master");
}
{
repository_location l (loc ("http://cppget.org/qw//1/a//b/"));
@@ -607,7 +607,7 @@ namespace bpkg
l1,
repository_type::git));
assert (l2.string () == "https://example.com/test.git#master");
- assert (l2.canonical_name () == "git:example.com/test");
+ assert (l2.canonical_name () == "git:example.com/test#master");
assert (l2.proto () == proto::https);
}
#ifndef _WIN32