Skip to content

Commit 2f3bc6c

Browse files
authored
Merge pull request #12149 from DeterminateSystems/remove-url-field
ParsedURL: Remove 'url' and 'base' fields
2 parents a0901e5 + 4077aa4 commit 2f3bc6c

File tree

10 files changed

+26
-62
lines changed

10 files changed

+26
-62
lines changed

src/libfetchers/fetchers.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Input Input::fromURL(
6666
}
6767
}
6868

69-
throw Error("input '%s' is unsupported", url.url);
69+
throw Error("input '%s' is unsupported", url);
7070
}
7171

7272
Input Input::fromAttrs(const Settings & settings, Attrs && attrs)

src/libfetchers/git.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ struct GitInputScheme : InputScheme
426426
auto url = parseURL(getStrAttr(input.attrs, "url"));
427427
bool isBareRepository = url.scheme == "file" && !pathExists(url.path + "/.git");
428428
repoInfo.isLocal = url.scheme == "file" && !forceHttp && !isBareRepository;
429-
repoInfo.url = repoInfo.isLocal ? url.path : url.base;
429+
repoInfo.url = repoInfo.isLocal ? url.path : url.to_string();
430430

431431
// If this is a local directory and no ref or revision is
432432
// given, then allow the use of an unclean working tree.

src/libfetchers/github.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct GitArchiveInputScheme : InputScheme
5050
else if (std::regex_match(path[2], refRegex))
5151
ref = path[2];
5252
else
53-
throw BadURL("in URL '%s', '%s' is not a commit hash or branch/tag name", url.url, path[2]);
53+
throw BadURL("in URL '%s', '%s' is not a commit hash or branch/tag name", url, path[2]);
5454
} else if (size > 3) {
5555
std::string rs;
5656
for (auto i = std::next(path.begin(), 2); i != path.end(); i++) {
@@ -63,34 +63,34 @@ struct GitArchiveInputScheme : InputScheme
6363
if (std::regex_match(rs, refRegex)) {
6464
ref = rs;
6565
} else {
66-
throw BadURL("in URL '%s', '%s' is not a branch/tag name", url.url, rs);
66+
throw BadURL("in URL '%s', '%s' is not a branch/tag name", url, rs);
6767
}
6868
} else if (size < 2)
69-
throw BadURL("URL '%s' is invalid", url.url);
69+
throw BadURL("URL '%s' is invalid", url);
7070

7171
for (auto &[name, value] : url.query) {
7272
if (name == "rev") {
7373
if (rev)
74-
throw BadURL("URL '%s' contains multiple commit hashes", url.url);
74+
throw BadURL("URL '%s' contains multiple commit hashes", url);
7575
rev = Hash::parseAny(value, HashAlgorithm::SHA1);
7676
}
7777
else if (name == "ref") {
7878
if (!std::regex_match(value, refRegex))
79-
throw BadURL("URL '%s' contains an invalid branch/tag name", url.url);
79+
throw BadURL("URL '%s' contains an invalid branch/tag name", url);
8080
if (ref)
81-
throw BadURL("URL '%s' contains multiple branch/tag names", url.url);
81+
throw BadURL("URL '%s' contains multiple branch/tag names", url);
8282
ref = value;
8383
}
8484
else if (name == "host") {
8585
if (!std::regex_match(value, hostRegex))
86-
throw BadURL("URL '%s' contains an invalid instance host", url.url);
86+
throw BadURL("URL '%s' contains an invalid instance host", url);
8787
host_url = value;
8888
}
8989
// FIXME: barf on unsupported attributes
9090
}
9191

9292
if (ref && rev)
93-
throw BadURL("URL '%s' contains both a commit hash and a branch/tag name %s %s", url.url, *ref, rev->gitRev());
93+
throw BadURL("URL '%s' contains both a commit hash and a branch/tag name %s %s", url, *ref, rev->gitRev());
9494

9595
Input input{settings};
9696
input.attrs.insert_or_assign("type", std::string { schemeName() });

src/libfetchers/indirect.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ struct IndirectInputScheme : InputScheme
2626
else if (std::regex_match(path[1], refRegex))
2727
ref = path[1];
2828
else
29-
throw BadURL("in flake URL '%s', '%s' is not a commit hash or branch/tag name", url.url, path[1]);
29+
throw BadURL("in flake URL '%s', '%s' is not a commit hash or branch/tag name", url, path[1]);
3030
} else if (path.size() == 3) {
3131
if (!std::regex_match(path[1], refRegex))
32-
throw BadURL("in flake URL '%s', '%s' is not a branch/tag name", url.url, path[1]);
32+
throw BadURL("in flake URL '%s', '%s' is not a branch/tag name", url, path[1]);
3333
ref = path[1];
3434
if (!std::regex_match(path[2], revRegex))
35-
throw BadURL("in flake URL '%s', '%s' is not a commit hash", url.url, path[2]);
35+
throw BadURL("in flake URL '%s', '%s' is not a commit hash", url, path[2]);
3636
rev = Hash::parseAny(path[2], HashAlgorithm::SHA1);
3737
} else
38-
throw BadURL("GitHub URL '%s' is invalid", url.url);
38+
throw BadURL("GitHub URL '%s' is invalid", url);
3939

4040
std::string id = path[0];
4141
if (!std::regex_match(id, flakeRegex))

src/libfetchers/mercurial.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ struct MercurialInputScheme : InputScheme
161161
{
162162
auto url = parseURL(getStrAttr(input.attrs, "url"));
163163
bool isLocal = url.scheme == "file";
164-
return {isLocal, isLocal ? url.path : url.base};
164+
return {isLocal, isLocal ? url.path : url.to_string()};
165165
}
166166

167167
StorePath fetchToStore(ref<Store> store, Input & input) const

src/libfetchers/path.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct PathInputScheme : InputScheme
1414
if (url.scheme != "path") return {};
1515

1616
if (url.authority && *url.authority != "")
17-
throw Error("path URL '%s' should not have an authority ('%s')", url.url, *url.authority);
17+
throw Error("path URL '%s' should not have an authority ('%s')", url, *url.authority);
1818

1919
Input input{settings};
2020
input.attrs.insert_or_assign("type", "path");
@@ -27,10 +27,10 @@ struct PathInputScheme : InputScheme
2727
if (auto n = string2Int<uint64_t>(value))
2828
input.attrs.insert_or_assign(name, *n);
2929
else
30-
throw Error("path URL '%s' has invalid parameter '%s'", url.to_string(), name);
30+
throw Error("path URL '%s' has invalid parameter '%s'", url, name);
3131
}
3232
else
33-
throw Error("path URL '%s' has unsupported parameter '%s'", url.to_string(), name);
33+
throw Error("path URL '%s' has unsupported parameter '%s'", url, name);
3434

3535
return input;
3636
}

src/libflake/flake/flakeref.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,7 @@ std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
159159

160160
while (flakeRoot != "/") {
161161
if (pathExists(flakeRoot + "/.git")) {
162-
auto base = std::string("git+file://") + flakeRoot;
163-
164162
auto parsedURL = ParsedURL{
165-
.url = base, // FIXME
166-
.base = base,
167163
.scheme = "git+file",
168164
.authority = "",
169165
.path = flakeRoot,
@@ -220,8 +216,6 @@ static std::optional<std::pair<FlakeRef, std::string>> parseFlakeIdRef(
220216

221217
if (std::regex_match(url, match, flakeRegex)) {
222218
auto parsedURL = ParsedURL{
223-
.url = url,
224-
.base = "flake:" + match.str(1),
225219
.scheme = "flake",
226220
.authority = "",
227221
.path = match[1],

src/libutil-tests/url.cc

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,11 @@ namespace nix {
2020
}
2121

2222

23-
std::ostream& operator<<(std::ostream& os, const ParsedURL& p) {
24-
return os << "\n"
25-
<< "url: " << p.url << "\n"
26-
<< "base: " << p.base << "\n"
27-
<< "scheme: " << p.scheme << "\n"
28-
<< "authority: " << p.authority.value() << "\n"
29-
<< "path: " << p.path << "\n"
30-
<< "query: " << print_map(p.query) << "\n"
31-
<< "fragment: " << p.fragment << "\n";
32-
}
33-
3423
TEST(parseURL, parsesSimpleHttpUrl) {
3524
auto s = "http://www.example.org/file.tar.gz";
3625
auto parsed = parseURL(s);
3726

3827
ParsedURL expected {
39-
.url = "http://www.example.org/file.tar.gz",
40-
.base = "http://www.example.org/file.tar.gz",
4128
.scheme = "http",
4229
.authority = "www.example.org",
4330
.path = "/file.tar.gz",
@@ -53,8 +40,6 @@ namespace nix {
5340
auto parsed = parseURL(s);
5441

5542
ParsedURL expected {
56-
.url = "https://www.example.org/file.tar.gz",
57-
.base = "https://www.example.org/file.tar.gz",
5843
.scheme = "https",
5944
.authority = "www.example.org",
6045
.path = "/file.tar.gz",
@@ -70,8 +55,6 @@ namespace nix {
7055
auto parsed = parseURL(s);
7156

7257
ParsedURL expected {
73-
.url = "https://www.example.org/file.tar.gz",
74-
.base = "https://www.example.org/file.tar.gz",
7558
.scheme = "https",
7659
.authority = "www.example.org",
7760
.path = "/file.tar.gz",
@@ -87,8 +70,6 @@ namespace nix {
8770
auto parsed = parseURL(s);
8871

8972
ParsedURL expected {
90-
.url = "http://www.example.org/file.tar.gz",
91-
.base = "http://www.example.org/file.tar.gz",
9273
.scheme = "http",
9374
.authority = "www.example.org",
9475
.path = "/file.tar.gz",
@@ -104,8 +85,6 @@ namespace nix {
10485
auto parsed = parseURL(s);
10586

10687
ParsedURL expected {
107-
.url = "file+https://www.example.org/video.mp4",
108-
.base = "https://www.example.org/video.mp4",
10988
.scheme = "file+https",
11089
.authority = "www.example.org",
11190
.path = "/video.mp4",
@@ -126,8 +105,6 @@ namespace nix {
126105
auto parsed = parseURL(s);
127106

128107
ParsedURL expected {
129-
.url = "http://127.0.0.1:8080/file.tar.gz",
130-
.base = "https://127.0.0.1:8080/file.tar.gz",
131108
.scheme = "http",
132109
.authority = "127.0.0.1:8080",
133110
.path = "/file.tar.gz",
@@ -143,8 +120,6 @@ namespace nix {
143120
auto parsed = parseURL(s);
144121

145122
ParsedURL expected {
146-
.url = "http://[fe80::818c:da4d:8975:415c\%enp0s25]:8080",
147-
.base = "http://[fe80::818c:da4d:8975:415c\%enp0s25]:8080",
148123
.scheme = "http",
149124
.authority = "[fe80::818c:da4d:8975:415c\%enp0s25]:8080",
150125
.path = "",
@@ -161,8 +136,6 @@ namespace nix {
161136
auto parsed = parseURL(s);
162137

163138
ParsedURL expected {
164-
.url = "http://[2a02:8071:8192:c100:311d:192d:81ac:11ea]:8080",
165-
.base = "http://[2a02:8071:8192:c100:311d:192d:81ac:11ea]:8080",
166139
.scheme = "http",
167140
.authority = "[2a02:8071:8192:c100:311d:192d:81ac:11ea]:8080",
168141
.path = "",
@@ -185,8 +158,6 @@ namespace nix {
185158
auto parsed = parseURL(s);
186159

187160
ParsedURL expected {
188-
.url = "http://user:[email protected]/file.tar.gz",
189-
.base = "http://user:[email protected]/file.tar.gz",
190161
.scheme = "http",
191162
.authority = "user:[email protected]:8080",
192163
.path = "/file.tar.gz",
@@ -203,8 +174,6 @@ namespace nix {
203174
auto parsed = parseURL(s);
204175

205176
ParsedURL expected {
206-
.url = "",
207-
.base = "",
208177
.scheme = "file",
209178
.authority = "",
210179
.path = "/none/of//your/business",
@@ -228,8 +197,6 @@ namespace nix {
228197
auto parsed = parseURL(s);
229198

230199
ParsedURL expected {
231-
.url = "ftp://ftp.nixos.org/downloads/nixos.iso",
232-
.base = "ftp://ftp.nixos.org/downloads/nixos.iso",
233200
.scheme = "ftp",
234201
.authority = "ftp.nixos.org",
235202
.path = "/downloads/nixos.iso",

src/libutil/url.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ ParsedURL parseURL(const std::string & url)
4040
path = "/";
4141

4242
return ParsedURL{
43-
.url = url,
44-
.base = base,
4543
.scheme = scheme,
4644
.authority = authority,
4745
.path = percentDecode(path),
@@ -136,6 +134,12 @@ std::string ParsedURL::to_string() const
136134
+ (fragment.empty() ? "" : "#" + percentEncode(fragment));
137135
}
138136

137+
std::ostream & operator << (std::ostream & os, const ParsedURL & url)
138+
{
139+
os << url.to_string();
140+
return os;
141+
}
142+
139143
bool ParsedURL::operator ==(const ParsedURL & other) const noexcept
140144
{
141145
return

src/libutil/url.hh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ namespace nix {
77

88
struct ParsedURL
99
{
10-
std::string url;
11-
/// URL without query/fragment
12-
std::string base;
1310
std::string scheme;
1411
std::optional<std::string> authority;
1512
std::string path;
@@ -26,6 +23,8 @@ struct ParsedURL
2623
ParsedURL canonicalise();
2724
};
2825

26+
std::ostream & operator << (std::ostream & os, const ParsedURL & url);
27+
2928
MakeError(BadURL, Error);
3029

3130
std::string percentDecode(std::string_view in);

0 commit comments

Comments
 (0)