mirror of
https://github.com/NixOS/nix
synced 2025-06-30 03:23:16 +02:00
Fix indent
This commit is contained in:
parent
9d9d9ff0de
commit
d77a39a314
2 changed files with 24 additions and 23 deletions
|
@ -13,35 +13,36 @@ static const std::regex gitProviderRegex("github|gitlab|sourcehut");
|
||||||
static const std::regex gitSchemeRegex("git($|\\+.*)");
|
static const std::regex gitSchemeRegex("git($|\\+.*)");
|
||||||
static const std::regex defaultOutputRegex(".*\\.default($|\\^.*)");
|
static const std::regex defaultOutputRegex(".*\\.default($|\\^.*)");
|
||||||
|
|
||||||
std::optional<std::string> getNameFromURL(ParsedURL url) {
|
std::optional<std::string> getNameFromURL(const ParsedURL & url)
|
||||||
std::smatch match;
|
{
|
||||||
|
std::smatch match;
|
||||||
|
|
||||||
/* If there is a dir= argument, use its value */
|
/* If there is a dir= argument, use its value */
|
||||||
if (url.query.count("dir") > 0)
|
if (url.query.count("dir") > 0)
|
||||||
return url.query.at("dir");
|
return url.query.at("dir");
|
||||||
|
|
||||||
/* If the fragment isn't a "default" and contains two attribute elements, use the last one */
|
/* If the fragment isn't a "default" and contains two attribute elements, use the last one */
|
||||||
if (std::regex_match(url.fragment, match, lastAttributeRegex))
|
if (std::regex_match(url.fragment, match, lastAttributeRegex))
|
||||||
return match.str(1);
|
return match.str(1);
|
||||||
|
|
||||||
/* If this is a github/gitlab/sourcehut flake, use the repo name */
|
/* If this is a github/gitlab/sourcehut flake, use the repo name */
|
||||||
if (std::regex_match(url.scheme, gitProviderRegex) && std::regex_match(url.path, match, secondPathSegmentRegex))
|
if (std::regex_match(url.scheme, gitProviderRegex) && std::regex_match(url.path, match, secondPathSegmentRegex))
|
||||||
return match.str(1);
|
return match.str(1);
|
||||||
|
|
||||||
/* If it is a regular git flake, use the directory name */
|
/* If it is a regular git flake, use the directory name */
|
||||||
if (std::regex_match(url.scheme, gitSchemeRegex) && std::regex_match(url.path, match, lastPathSegmentRegex))
|
if (std::regex_match(url.scheme, gitSchemeRegex) && std::regex_match(url.path, match, lastPathSegmentRegex))
|
||||||
return match.str(1);
|
return match.str(1);
|
||||||
|
|
||||||
/* If everything failed but there is a non-default fragment, use it in full */
|
/* If everything failed but there is a non-default fragment, use it in full */
|
||||||
if (!url.fragment.empty() && !std::regex_match(url.fragment, defaultOutputRegex))
|
if (!url.fragment.empty() && !std::regex_match(url.fragment, defaultOutputRegex))
|
||||||
return url.fragment;
|
return url.fragment;
|
||||||
|
|
||||||
/* If there is no fragment, take the last element of the path */
|
/* If there is no fragment, take the last element of the path */
|
||||||
if (std::regex_match(url.path, match, lastPathSegmentRegex))
|
if (std::regex_match(url.path, match, lastPathSegmentRegex))
|
||||||
return match.str(1);
|
return match.str(1);
|
||||||
|
|
||||||
/* If even that didn't work, the URL does not contain enough info to determine a useful name */
|
/* If even that didn't work, the URL does not contain enough info to determine a useful name */
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,6 @@ namespace nix {
|
||||||
* flake output, for example because it is empty or "default".
|
* flake output, for example because it is empty or "default".
|
||||||
* Otherwise returns the extracted name.
|
* Otherwise returns the extracted name.
|
||||||
*/
|
*/
|
||||||
std::optional<std::string> getNameFromURL(ParsedURL url);
|
std::optional<std::string> getNameFromURL(const ParsedURL & url);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue