-
-
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
Improvements to libgit2 #16861
Improvements to libgit2 #16861
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
# This file is a part of Julia. License is MIT: http://julialang.org/license | ||
|
||
function GitBlob(path::AbstractString) | ||
blob_ptr_ptr = Ref{Ptr{Void}}(C_NULL) | ||
apath = abspath(path) | ||
ccall((:git_blob_create_fromdisk, :libgit2), Ptr{Void}, | ||
(Ptr{Ptr{Void}}, Ptr{UInt8}), blob_ptr_ptr, apath) | ||
blob_ptr_ptr == C_NULL && throw(Error.GitError(Error.ERROR)) | ||
return GitBlob(blob_ptr_ptr[]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this check for null before dereferencing or trying to create a GitBlob? edit: I guess there's an assertion in the auto-generated constructor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If error is returned, the exception will be raised. |
||
end | ||
|
||
function owner(blob::GitBlob) | ||
repo_ptr = @check ccall((:git_blob_owner, :libgit2), Ptr{Void}, (Ptr{Void},), blob.ptr) | ||
return GitRepo(repo_ptr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong, do not use |
||
end | ||
|
||
function content(blob::GitBlob) | ||
return ccall((:git_blob_rawcontent, :libgit2), Ptr{Void}, (Ptr{Void},), blob.ptr) | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,3 +88,9 @@ function push{T<:AbstractString}(rmt::GitRemote, refspecs::Vector{T}; | |
!no_refs && finalize(sa) | ||
end | ||
end | ||
|
||
function name(rmt::GitRemote) | ||
str_ptr = ccall((:git_remote_name, :libgit2), Cstring, (Ptr{Void}, ), rmt.ptr) | ||
str_ptr == C_NULL && return nothing | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. empty string or error? edit: just saw the above
why would we want There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or empty string |
||
return unsafe_string(str_ptr) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,16 @@ const LIBGIT2_VER = v"0.23.0" | |
finally | ||
finalize(sa2) | ||
end | ||
vs = vec([p1,p2]) | ||
sa4 = LibGit2.StrArrayStruct(vs) | ||
try | ||
arr3 = convert(Vector{AbstractString}, sa4) | ||
@test arr3[1] == p1 | ||
@test arr3[2] == p2 | ||
finally | ||
finalize(sa4) | ||
end | ||
|
||
#end | ||
|
||
#@testset "Signature" begin | ||
|
@@ -119,8 +129,30 @@ mktempdir() do dir | |
|
||
config = joinpath(cache_repo, ".git", "config") | ||
lines = split(open(readstring, config, "r"), "\n") | ||
@test any(map(x->x == "[remote \"upstream\"]", lines)) | ||
@test any(x->x == "[remote \"upstream\"]", lines) | ||
|
||
remote = LibGit2.get(LibGit2.GitRemote, repo, branch) | ||
@test LibGit2.url(remote) == repo_url | ||
@test LibGit2.isattached(repo) | ||
finalize(remote) | ||
finally | ||
finalize(repo) | ||
end | ||
#end | ||
|
||
#@testset "with remote branch and refspec" begin | ||
repo = LibGit2.init(cache_repo) | ||
try | ||
@test isdir(cache_repo) | ||
@test isdir(joinpath(cache_repo, ".git")) | ||
|
||
# set a remote branch | ||
branch = "upstream2" | ||
LibGit2.GitRemote(repo, branch, repo_url,"+refs/heads/$branch:refs/remotes/origin/$branch") |> finalize | ||
|
||
config = joinpath(cache_repo, ".git", "config") | ||
lines = split(open(readstring, config, "r"), "\n") | ||
@test any(x->x == "[remote \"upstream\"]", lines) | ||
remote = LibGit2.get(LibGit2.GitRemote, repo, branch) | ||
@test LibGit2.url(remote) == repo_url | ||
@test LibGit2.isattached(repo) | ||
|
@@ -130,6 +162,24 @@ mktempdir() do dir | |
end | ||
#end | ||
|
||
#@testset "anonymous" begin | ||
repo = LibGit2.init(cache_repo) | ||
try | ||
@test isdir(cache_repo) | ||
@test isdir(joinpath(cache_repo, ".git")) | ||
|
||
# set a remote branch | ||
branch = "upstream3" | ||
LibGit2.GitRemoteAnon(repo, repo_url) |> finalize | ||
|
||
config = joinpath(cache_repo, ".git", "config") | ||
lines = split(open(readstring, config, "r"), "\n") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd want to check that these don't fail if they get windows newlines in them (or check that it's impossible for that to be the case) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I should just do a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that would modify the file and rely on that program being installed - maybe do something with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it might if you edit it with something dumb |
||
@test any(x->x == "[remote \"upstream\"]", lines) | ||
finally | ||
finalize(repo) | ||
end | ||
#end | ||
|
||
#@testset "bare" begin | ||
path = joinpath(dir, "Example.Bare") | ||
repo = LibGit2.init(path, true) | ||
|
@@ -177,6 +227,7 @@ mktempdir() do dir | |
@test LibGit2.fetch_refspecs(rmt)[1] == "+refs/*:refs/*" | ||
@test LibGit2.isattached(repo) | ||
@test LibGit2.remotes(repo) == ["origin"] | ||
@test LibGit2.name(rmt) == "origin" | ||
finally | ||
finalize(rmt) | ||
end | ||
|
@@ -229,6 +280,10 @@ mktempdir() do dir | |
@test auth.email == test_sig.email | ||
end | ||
|
||
@test LibGit2.iscommit(string(commit_oid1),repo) | ||
@test LibGit2.iscommit(string(commit_oid2),repo) | ||
@test LibGit2.is_ancestor_of(string(commit_oid1),string(commit_oid2),repo) | ||
@test LibGit2.revcount(repo, string(commit_oid1), string(commit_oid2)) == (-1,1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the inconsistency in argument order between these is unfortunate |
||
# lookup commits | ||
cmt = LibGit2.get(LibGit2.GitCommit, repo, commit_oid1) | ||
try | ||
|
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.
put at least one blank line after the license header