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

use LibGit2_jll for LibGit2 library #51294

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkgimage.mk
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ $(eval $(call pkgimg_builder,GMP_jll,Artifacts Libdl))
$(eval $(call pkgimg_builder,LLVMLibUnwind_jll,Artifacts Libdl))
$(eval $(call pkgimg_builder,LibUV_jll,Artifacts Libdl))
$(eval $(call pkgimg_builder,LibUnwind_jll,Artifacts Libdl))
$(eval $(call pkgimg_builder,MbedTLS_jll,Artifacts Libdl))
$(eval $(call sysimg_builder,MbedTLS_jll,Artifacts Libdl))
$(eval $(call pkgimg_builder,nghttp2_jll,Artifacts Libdl))
$(eval $(call pkgimg_builder,OpenLibm_jll,Artifacts Libdl))
$(eval $(call pkgimg_builder,PCRE2_jll,Artifacts Libdl))
Expand All @@ -100,25 +100,25 @@ $(eval $(call pkgimg_builder,DelimitedFiles,Mmap))

# 2-depth packages
$(eval $(call pkgimg_builder,LLD_jll,Zlib_jll libLLVM_jll Artifacts Libdl))
$(eval $(call pkgimg_builder,LibSSH2_jll,Artifacts Libdl MbedTLS_jll))
$(eval $(call sysimg_builder,LibSSH2_jll,Artifacts Libdl MbedTLS_jll))
$(eval $(call pkgimg_builder,MPFR_jll,Artifacts Libdl GMP_jll))
$(eval $(call sysimg_builder,LinearAlgebra,Libdl libblastrampoline_jll OpenBLAS_jll))
$(eval $(call sysimg_builder,Dates,Printf))
$(eval $(call pkgimg_builder,Distributed,Random Serialization Sockets))
$(eval $(call sysimg_builder,Future,Random))
$(eval $(call sysimg_builder,InteractiveUtils,Markdown))
$(eval $(call sysimg_builder,LibGit2,NetworkOptions Printf SHA Base64))
$(eval $(call sysimg_builder,UUIDs,Random SHA))

# 3-depth packages
# LibGit2_jll
$(eval $(call sysimg_builder,LibGit2_jll,MbedTLS_jll LibSSH2_jll Artifacts Libdl))
$(eval $(call pkgimg_builder,LibCURL_jll,LibSSH2_jll nghttp2_jll MbedTLS_jll Zlib_jll Artifacts Libdl))
$(eval $(call sysimg_builder,REPL,InteractiveUtils Markdown Sockets Unicode))
$(eval $(call pkgimg_builder,SharedArrays,Distributed Mmap Random Serialization))
$(eval $(call sysimg_builder,TOML,Dates))
$(eval $(call pkgimg_builder,Test,Logging Random Serialization InteractiveUtils))

# 4-depth packages
$(eval $(call sysimg_builder,LibGit2,LibGit2_jll NetworkOptions Printf SHA Base64))
$(eval $(call sysimg_builder,LibCURL,LibCURL_jll MozillaCACerts_jll))

# 5-depth packages
Expand Down
1 change: 1 addition & 0 deletions stdlib/LibGit2/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
LibGit2_jll = "e37daf67-58a4-590a-8e99-b0245dd2ffc5"
NetworkOptions = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Expand Down
10 changes: 6 additions & 4 deletions stdlib/LibGit2/src/LibGit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ using SHA: sha1, sha256

export with, GitRepo, GitConfig

using LibGit2_jll

const GITHUB_REGEX =
r"^(?:(?:ssh://)?git@|git://|https://(?:[\w\.\+\-]+@)?)github.com[:/](([^/].+)/(.+?))(?:\.git)?$"i

Expand Down Expand Up @@ -983,15 +985,15 @@ function ensure_initialized()
end

@noinline function initialize()
@check ccall((:git_libgit2_init, :libgit2), Cint, ())
@check ccall((:git_libgit2_init, libgit2), Cint, ())

cert_loc = NetworkOptions.ca_roots()
cert_loc !== nothing && set_ssl_cert_locations(cert_loc)

atexit() do
# refcount zero, no objects to be finalized
if Threads.atomic_sub!(REFCOUNT, 1) == 1
ccall((:git_libgit2_shutdown, :libgit2), Cint, ())
ccall((:git_libgit2_shutdown, libgit2), Cint, ())
end
end
end
Expand All @@ -1003,7 +1005,7 @@ function set_ssl_cert_locations(cert_loc)
else # files, /dev/null, non-existent paths, etc.
cert_file = cert_loc
end
ret = @ccall "libgit2".git_libgit2_opts(
ret = @ccall libgit2.git_libgit2_opts(
Consts.SET_SSL_CERT_LOCATIONS::Cint;
cert_file::Cstring,
cert_dir::Cstring)::Cint
Expand All @@ -1029,7 +1031,7 @@ end
Sets the system tracing configuration to the specified level.
"""
function trace_set(level::Union{Integer,Consts.GIT_TRACE_LEVEL}, cb=trace_cb())
@check @ccall "libgit2".git_trace_set(level::Cint, cb::Ptr{Cvoid})::Cint
@check @ccall libgit2.git_trace_set(level::Cint, cb::Ptr{Cvoid})::Cint
end

end # module
6 changes: 3 additions & 3 deletions stdlib/LibGit2/src/blame.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ which commits to probe - see [`BlameOptions`](@ref) for more information.
function GitBlame(repo::GitRepo, path::AbstractString; options::BlameOptions=BlameOptions())
ensure_initialized()
blame_ptr_ptr = Ref{Ptr{Cvoid}}(C_NULL)
@check ccall((:git_blame_file, :libgit2), Cint,
@check ccall((:git_blame_file, libgit2), Cint,
(Ptr{Ptr{Cvoid}}, Ptr{Cvoid}, Cstring, Ptr{BlameOptions}),
blame_ptr_ptr, repo.ptr, path, Ref(options))
return GitBlame(repo, blame_ptr_ptr[])
Expand All @@ -27,7 +27,7 @@ that function later.
"""
function counthunks(blame::GitBlame)
ensure_initialized()
return ccall((:git_blame_get_hunk_count, :libgit2), Int32, (Ptr{Cvoid},), blame.ptr)
return ccall((:git_blame_get_hunk_count, libgit2), Int32, (Ptr{Cvoid},), blame.ptr)
end

function Base.getindex(blame::GitBlame, i::Integer)
Expand All @@ -36,7 +36,7 @@ function Base.getindex(blame::GitBlame, i::Integer)
end
ensure_initialized()
GC.@preserve blame begin
hunk_ptr = ccall((:git_blame_get_hunk_byindex, :libgit2),
hunk_ptr = ccall((:git_blame_get_hunk_byindex, libgit2),
Ptr{BlameHunk},
(Ptr{Cvoid}, Csize_t), blame.ptr, i-1)
elem = unsafe_load(hunk_ptr)
Expand Down
8 changes: 4 additions & 4 deletions stdlib/LibGit2/src/blob.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function Base.length(blob::GitBlob)
ensure_initialized()
return ccall((:git_blob_rawsize, :libgit2), Int64, (Ptr{Cvoid},), blob.ptr)
return ccall((:git_blob_rawsize, libgit2), Int64, (Ptr{Cvoid},), blob.ptr)
end

"""
Expand All @@ -20,7 +20,7 @@ is binary and not valid Unicode.
"""
function rawcontent(blob::GitBlob)
ensure_initialized()
ptr = ccall((:git_blob_rawcontent, :libgit2), Ptr{UInt8}, (Ptr{Cvoid},), blob.ptr)
ptr = ccall((:git_blob_rawcontent, libgit2), Ptr{UInt8}, (Ptr{Cvoid},), blob.ptr)
copy(unsafe_wrap(Array, ptr, (length(blob),), own = false))
end

Expand All @@ -47,7 +47,7 @@ the first 8000 bytes.
"""
function isbinary(blob::GitBlob)
ensure_initialized()
bin_flag = ccall((:git_blob_is_binary, :libgit2), Cint, (Ptr{Cvoid},), blob.ptr)
bin_flag = ccall((:git_blob_is_binary, libgit2), Cint, (Ptr{Cvoid},), blob.ptr)
return bin_flag == 1
end

Expand All @@ -67,7 +67,7 @@ id = LibGit2.addblob!(repo, blob_file)
function addblob!(repo::GitRepo, path::AbstractString)
ensure_initialized()
id_ref = Ref{GitHash}()
@check ccall((:git_blob_create_from_disk, :libgit2), Cint,
@check ccall((:git_blob_create_from_disk, libgit2), Cint,
(Ptr{GitHash}, Ptr{Cvoid}, Cstring),
id_ref, repo.ptr, path)
return id_ref[]
Expand Down
16 changes: 8 additions & 8 deletions stdlib/LibGit2/src/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function mirror_callback(remote::Ptr{Ptr{Cvoid}}, repo_ptr::Ptr{Cvoid},
ensure_initialized()
# Create the remote with a mirroring url
fetch_spec = "+refs/*:refs/*"
err = ccall((:git_remote_create_with_fetchspec, :libgit2), Cint,
err = ccall((:git_remote_create_with_fetchspec, libgit2), Cint,
(Ptr{Ptr{Cvoid}}, Ptr{Cvoid}, Cstring, Cstring, Cstring),
remote, repo_ptr, name, url, fetch_spec)
err != 0 && return Cint(err)
Expand Down Expand Up @@ -43,23 +43,23 @@ end
function user_abort()
ensure_initialized()
# Note: Potentially it could be better to just throw a Julia error.
ccall((:giterr_set_str, :libgit2), Cvoid,
ccall((:giterr_set_str, libgit2), Cvoid,
(Cint, Cstring), Cint(Error.Callback),
"Aborting, user cancelled credential request.")
return Cint(Error.EUSER)
end

function prompt_limit()
ensure_initialized()
ccall((:giterr_set_str, :libgit2), Cvoid,
ccall((:giterr_set_str, libgit2), Cvoid,
(Cint, Cstring), Cint(Error.Callback),
"Aborting, maximum number of prompts reached.")
return Cint(Error.EAUTH)
end

function exhausted_abort()
ensure_initialized()
ccall((:giterr_set_str, :libgit2), Cvoid,
ccall((:giterr_set_str, libgit2), Cvoid,
(Cint, Cstring), Cint(Error.Callback),
"All authentication methods have failed.")
return Cint(Error.EAUTH)
Expand All @@ -79,7 +79,7 @@ function authenticate_ssh(libgit2credptr::Ptr{Ptr{Cvoid}}, p::CredentialPayload,

# first try ssh-agent if credentials support its usage
if p.use_ssh_agent && username_ptr != Cstring(C_NULL) && (!revised || !isfilled(cred))
err = ccall((:git_cred_ssh_key_from_agent, :libgit2), Cint,
err = ccall((:git_cred_ssh_key_from_agent, libgit2), Cint,
(Ptr{Ptr{Cvoid}}, Cstring), libgit2credptr, username_ptr)

p.use_ssh_agent = false # use ssh-agent only one time
Expand Down Expand Up @@ -175,7 +175,7 @@ function authenticate_ssh(libgit2credptr::Ptr{Ptr{Cvoid}}, p::CredentialPayload,
if !revised
return exhausted_abort()
end
return ccall((:git_cred_ssh_key_new, :libgit2), Cint,
return ccall((:git_cred_ssh_key_new, libgit2), Cint,
(Ptr{Ptr{Cvoid}}, Cstring, Cstring, Cstring, Cstring),
libgit2credptr, cred.user, cred.pubkey, cred.prvkey, cred.pass)
end
Expand Down Expand Up @@ -235,7 +235,7 @@ function authenticate_userpass(libgit2credptr::Ptr{Ptr{Cvoid}}, p::CredentialPay
return exhausted_abort()
end

return ccall((:git_cred_userpass_plaintext_new, :libgit2), Cint,
return ccall((:git_cred_userpass_plaintext_new, libgit2), Cint,
(Ptr{Ptr{Cvoid}}, Cstring, Cstring),
libgit2credptr, cred.user, cred.pass)
end
Expand Down Expand Up @@ -339,7 +339,7 @@ function credentials_callback(libgit2credptr::Ptr{Ptr{Cvoid}}, url_ptr::Cstring,
if err == 0
if p.explicit !== nothing
ensure_initialized()
ccall((:giterr_set_str, :libgit2), Cvoid, (Cint, Cstring), Cint(Error.Callback),
ccall((:giterr_set_str, libgit2), Cvoid, (Cint, Cstring), Cint(Error.Callback),
"The explicitly provided credential is incompatible with the requested " *
"authentication methods.")
end
Expand Down
10 changes: 5 additions & 5 deletions stdlib/LibGit2/src/commit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ function message(c::GitCommit, raw::Bool=false)
ensure_initialized()
GC.@preserve c begin
local msg_ptr::Cstring
msg_ptr = raw ? ccall((:git_commit_message_raw, :libgit2), Cstring, (Ptr{Cvoid},), c.ptr) :
ccall((:git_commit_message, :libgit2), Cstring, (Ptr{Cvoid},), c.ptr)
msg_ptr = raw ? ccall((:git_commit_message_raw, libgit2), Cstring, (Ptr{Cvoid},), c.ptr) :
ccall((:git_commit_message, libgit2), Cstring, (Ptr{Cvoid},), c.ptr)
if msg_ptr == C_NULL
return nothing
end
Expand All @@ -33,7 +33,7 @@ the person who made changes to the relevant file(s). See also [`committer`](@ref
function author(c::GitCommit)
ensure_initialized()
GC.@preserve c begin
ptr = ccall((:git_commit_author, :libgit2), Ptr{SignatureStruct}, (Ptr{Cvoid},), c.ptr)
ptr = ccall((:git_commit_author, libgit2), Ptr{SignatureStruct}, (Ptr{Cvoid},), c.ptr)
@assert ptr != C_NULL
sig = Signature(ptr)
end
Expand All @@ -51,7 +51,7 @@ a `committer` who committed it.
function committer(c::GitCommit)
ensure_initialized()
GC.@preserve c begin
ptr = ccall((:git_commit_committer, :libgit2), Ptr{SignatureStruct}, (Ptr{Cvoid},), c.ptr)
ptr = ccall((:git_commit_committer, libgit2), Ptr{SignatureStruct}, (Ptr{Cvoid},), c.ptr)
sig = Signature(ptr)
end
return sig
Expand All @@ -74,7 +74,7 @@ function commit(repo::GitRepo,
commit_id_ptr = Ref(GitHash())
nparents = length(parents)
parentptrs = Ptr{Cvoid}[c.ptr for c in parents]
@check ccall((:git_commit_create, :libgit2), Cint,
@check ccall((:git_commit_create, libgit2), Cint,
(Ptr{GitHash}, Ptr{Cvoid}, Ptr{UInt8},
Ptr{SignatureStruct}, Ptr{SignatureStruct},
Ptr{UInt8}, Ptr{UInt8}, Ptr{Cvoid},
Expand Down
Loading