Skip to content
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

Merged
merged 4 commits into from
Aug 8, 2017
Merged

Make utility for generating git url string #23040

merged 4 commits into from
Aug 8, 2017

Conversation

omus
Copy link
Member

@omus omus commented Jul 30, 2017

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.

@omus omus added the libgit2 The libgit2 library or the LibGit2 stdlib module label Jul 30, 2017
@@ -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"
Copy link
Member Author

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".

Copy link
Contributor

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

Copy link
Member Author

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)

Copy link
Member Author

@omus omus Jul 30, 2017

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.

Copy link
Contributor

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 ?

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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

@yuyichao
Copy link
Contributor

Just want to make sure this happens after alias resolution in .gitconfig right?

@omus
Copy link
Member Author

omus commented Jul 30, 2017

Just want to make sure this happens after alias resolution in .gitconfig right?

I believe so. What is your concern?

@yuyichao
Copy link
Contributor

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
Copy link
Contributor

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?)://)?+
Copy link
Contributor

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

Copy link
Member Author

@omus omus Jul 31, 2017

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

Copy link
Contributor

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

omus added 2 commits July 31, 2017 22:37
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.
@omus
Copy link
Member Author

omus commented Aug 2, 2017

Added some documentation. Ready to merge.

* `path::AbstractString=""`: the path to specify to use in the output if provided.

# Examples

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no blank line here

Copy link
Member Author

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?

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.
Copy link
Contributor

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

Copy link
Member Author

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.

@omus
Copy link
Member Author

omus commented Aug 5, 2017

I think this is ready to go. Will merge on Tuesday.

@omus omus merged commit edbcb91 into master Aug 8, 2017
@omus omus deleted the cv/git-url branch August 8, 2017 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libgit2 The libgit2 library or the LibGit2 stdlib module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants