-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make utility for generating git url string #23040
Conversation
@@ -224,7 +229,7 @@ function credentials_callback(libgit2credptr::Ptr{Ptr{Void}}, url_ptr::Cstring, | |||
|
|||
if isset(allowed_types, Cuint(Consts.CREDTYPE_USERPASS_PLAINTEXT)) | |||
defaultcreds = reset!(UserPasswordCredentials(true), -1) | |||
credid = "$schema$host" | |||
credid = "$(isempty(schema) ? "ssh" : schema)://$host" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slight change to behaviour here. It used to be that when the schema
was not defined in the URL the credential ID would be "$host"
now it will be "ssh://$host"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure defaulting to ssh is any better than requiring setting a schema
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that using the scp-like syntax [email protected]:JuliaLang/julia.git
or ssh://[email protected]/JuliaLang/julia.git
both refer to the same git repo using the SSH protocol.
The advantage of defaulting to using SSH here is that both of these syntaxes will refer to the same credid
.
See https://git-scm.com/book/id/v2/Git-on-the-Server-The-Protocols (under "The SSH Protocol" section)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could just assign "ssh" to be the schema when one is missing but this would then modify the git_url
output from [email protected]:repo.git
to ssh://[email protected]/repo.git
which would no longer resemble the URL passed in by the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what would happen on [email protected]/JuliaLang/julia.git
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based upon the behavour of git clone
that URL should be invalid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right but if it gets passed here will you be prepending ssh
to it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently yes. I'll update the URL_REGEX to fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URL_REGEX no longer allows [email protected]/JuliaLang/julia.git
Just want to make sure this happens after alias resolution in |
I believe so. What is your concern? |
Just to make sure it's not broken. |
test/libgit2.jl
Outdated
@@ -183,15 +183,21 @@ end | |||
|
|||
@testset "HTTPS URL, no path" begin | |||
m = match(LibGit2.URL_REGEX, "https://user:[email protected]:80") | |||
@test m[:path] == "" | |||
@test m[:path] == nothing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
===
@@ -3,7 +3,7 @@ | |||
# Parse "GIT URLs" syntax (URLs and a scp-like syntax). For details see: | |||
# https://git-scm.com/docs/git-clone#_git_urls_a_id_urls_a | |||
const URL_REGEX = r""" | |||
^(?:(?<scheme>ssh|git|https?)://)? | |||
^(?:(?<scheme>ssh|git|https?)://)?+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the difference with this? regex101.com tells me it's greedy vs possessive, whether or not it "gives back" but I'm not familiar with the consequences of that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically when https://
is matched the regular expression will stop any backtracking where this string could be repurposed elsewhere in the regular expression:
julia> match(possessive_regex, "https://git@server:repo")
julia> match(original_regex, "https://git@server:repo")
RegexMatch("https://git@server:repo", scheme=nothing, user="https", password="//git", host="server", port=nothing, path="repo")
Details on possessive quantifiers: http://perldoc.perl.org/perlretut.html#Possessive-quantifiers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh ick. that's subtle, good catch and thanks for the explanation
Git URLs like `[email protected]:repo` are valid while URLs like `[email protected]/repo` are now treated as wrong.
Previously URLs like `http://[email protected]:repo` were being parsed incorrectly.
Added some documentation. Ready to merge. |
base/libgit2/utils.jl
Outdated
* `path::AbstractString=""`: the path to specify to use in the output if provided. | ||
|
||
# Examples | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no blank line here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I remove the blank line after # Keywords
as well?
base/libgit2/utils.jl
Outdated
be specified. | ||
* `port::Union{AbstractString,Integer}=""`: the port number to use in the output if | ||
provided. Cannot be specified when using the scp-like syntax. | ||
* `path::AbstractString=""`: the path to specify to use in the output if provided. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"to specify to use" sounds a bit redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird. I don't remember writing it like that. Will fix.
I think this is ready to go. Will merge on Tuesday. |
Part of #20725.
Various parts of the callback code create URLs for displaying information to the user. The
git_url
function allows us to consistently create these URL strings and allows us to test behaviour.