Skip to content

Commit

Permalink
Merge pull request #17586 from JuliaLang/kf/libgit2usability
Browse files Browse the repository at this point in the history
Libgit2 usability issues
  • Loading branch information
Keno authored Jul 28, 2016
2 parents bcc2121 + 7ba3ebd commit e717ded
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions base/libgit2/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ function credentials_callback(cred::Ptr{Ptr{Void}}, url_ptr::Cstring,
# parse url for schema and host
urlparts = match(urlmatcher, url)
schema = urlparts.captures[1]
urlusername = urlparts.captures[4]
urlusername = urlusername === nothing ? "" : String(urlusername)
host = urlparts.captures[5]
schema = schema === nothing ? "" : schema*"://"

Expand Down Expand Up @@ -114,15 +116,23 @@ function credentials_callback(cred::Ptr{Ptr{Void}}, url_ptr::Cstring,
ENV["SSH_KEY_PATH"]
else
keydefpath = creds[:prvkey, credid] # check if credentials were already used
if keydefpath !== nothing && !isusedcreds
keydefpath === nothing && (keydefpath = "")
if !isempty(keydefpath) && !isusedcreds
keydefpath # use cached value
else
if keydefpath === nothing || isempty(keydefpath)
keydefpath = joinpath(homedir(),".ssh","id_rsa")
defaultkeydefpath = joinpath(homedir(),".ssh","id_rsa")
if isempty(keydefpath) && isfile(defaultkeydefpath)
keydefpath = defaultkeydefpath
else
keydefpath =
prompt("Private key location for '$schema$username@$host'", default=keydefpath)
end
prompt("Private key location for '$schema$username@$host'", default=keydefpath)
end
end

# If the private key changed, invalidate the cached public key
(privatekey != creds[:prvkey, credid]) &&
(creds[:pubkey, credid] = "")
creds[:prvkey, credid] = privatekey # save credentials

# For SSH we need a public key location, look for environment vars SSH_* as well
Expand All @@ -145,11 +155,22 @@ function credentials_callback(cred::Ptr{Ptr{Void}}, url_ptr::Cstring,
end
creds[:pubkey, credid] = publickey # save credentials

passphrase = if haskey(ENV,"SSH_KEY_PASS")
ENV["SSH_KEY_PASS"]
passphrase_required = true
if !isfile(privatekey)
warn("Private key not found")
else
# In encrypted private keys, the second line is "Proc-Type: 4,ENCRYPTED"
open(privatekey) do f
passphrase_required = (readline(f); chomp(readline(f)) == "Proc-Type: 4,ENCRYPTED")
end
end

passphrase = if haskey(ENV,"SSH_KEY_PASS")
ENV["SSH_KEY_PASS"]
else
passdef = creds[:pass, credid] # check if credentials were already used
if passdef === nothing || isusedcreds
passdef === nothing && (passdef = "")
if passphrase_required && (isempty(passdef) || isusedcreds)
if is_windows()
passdef = Base.winprompt(
"Your SSH Key requires a password, please enter it now:",
Expand All @@ -160,8 +181,9 @@ function credentials_callback(cred::Ptr{Ptr{Void}}, url_ptr::Cstring,
passdef = prompt("Passphrase for $privatekey", password=true)
end
end
passdef
end
creds[:pass, credid] = passphrase # save credentials
creds[:pass, credid] = passphrase

isempty(username) && return Cint(Error.EAUTH)

Expand All @@ -180,13 +202,14 @@ function credentials_callback(cred::Ptr{Ptr{Void}}, url_ptr::Cstring,
if is_windows()
if username === nothing || userpass === nothing || isusedcreds
res = Base.winprompt("Please enter your credentials for '$schema$host'", "Credentials required",
username === nothing ? "" : username; prompt_username = true)
username === nothing || isempty(username) ?
urlusername : username; prompt_username = true)
isnull(res) && return Cint(Error.EAUTH)
username, userpass = Base.get(res)
end
else
if username === nothing || isusedcreds
username = prompt("Username for '$schema$host'")
username = prompt("Username for '$schema$host'", default = urlusername)
end

if userpass === nothing || isusedcreds
Expand Down

6 comments on commit e717ded

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@tkelman
Copy link
Contributor

Choose a reason for hiding this comment

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

@jrevels nanosoldier problems?

@jrevels
Copy link
Member

Choose a reason for hiding this comment

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

Looks like GitHub blocked nanosoldier's push via a pre-receive hook:

remote: Unexpected system error after push was received.
remote: These changes may not be reflected on github.com!
To [email protected]:JuliaCI/BaseBenchmarkReports.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to '[email protected]:JuliaCI/BaseBenchmarkReports.git'

I'll look into it.

@jrevels
Copy link
Member

Choose a reason for hiding this comment

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

As nanosoldier, from the same node, I just manually pushed the commit nanosoldier made that GitHub rejected. I didn't encounter any errors - maybe it was a fluke on GitHub's end?

Here's the daily report.

@jrevels
Copy link
Member

Choose a reason for hiding this comment

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

@tkelman
Copy link
Contributor

Choose a reason for hiding this comment

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

oh right, it didn't last long but was at about the right time

Please sign in to comment.