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

Add some tests for libgit2 and a function to list all the reference names #16728

Merged
merged 4 commits into from
Jun 8, 2016
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
16 changes: 16 additions & 0 deletions base/libgit2/reference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ function isbranch(ref::GitReference)
return err == 1
end

function istag(ref::GitReference)
isempty(ref) && return false
err = ccall((:git_reference_is_tag, :libgit2), Cint,
(Ptr{Void},), ref.ptr)
return err == 1
end

function isremote(ref::GitReference)
isempty(ref) && return false
err = ccall((:git_reference_is_remote, :libgit2), Cint,
Expand All @@ -96,6 +103,15 @@ function peel{T <: GitObject}(::Type{T}, ref::GitReference)
return T(obj_ptr_ptr[])
end

function ref_list(repo::GitRepo)
with(StrArrayStruct()) do sa
sa_ref = Ref(sa)
@check ccall((:git_reference_list, :libgit2), Cint,
(Ptr{StrArrayStruct}, Ptr{Void}), sa_ref, repo.ptr)
convert(Vector{AbstractString}, sa_ref[])
end
end

function create_branch(repo::GitRepo,
bname::AbstractString,
commit_obj::GitCommit;
Expand Down
9 changes: 6 additions & 3 deletions base/libgit2/tag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ function tag_create(repo::GitRepo, tag::AbstractString, commit::Union{AbstractSt
end

function name(tag::GitTag)
return String(ccall((:git_tag_name, :libgit2), Cstring, (Ptr{Void}, ), tag.ptr))
str_ptr = ccall((:git_tag_name, :libgit2), Cstring, (Ptr{Void}, ), tag.ptr)
str_ptr == C_NULL && throw(Error.GitError(Error.ERROR))
return String(str_ptr)
end

function target(tag::GitTag)
oid_ptr = Ref(ccall((:git_tag_target_id, :libgit2), Ptr{Oid}, (Ptr{Void}, ), tag.ptr))
return oid_ptr[]
oid_ptr = ccall((:git_tag_target_id, :libgit2), Ptr{Oid}, (Ptr{Void}, ), tag.ptr)
oid_ptr == C_NULL && throw(Error.GitError(Error.ERROR))
return Oid(oid_ptr)
Copy link
Contributor

@tkelman tkelman Jun 7, 2016

Choose a reason for hiding this comment

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

Oh in this case the Oid constructor actually does check and throw for null pointers already.

Just so I'm clear, the old code was returning a Ptr{Oid} from the ccall, wrapping that in a Ref then dereferencing the Ref - what type was that returning, a Ptr{Oid} or an Oid?

edit: nevermind I was looking at the wrong Oid constructor, the Oid(ptr::Ptr{Oid}) just does unsafe_load(ptr)::Oid so leave the null check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That should return an Oid, I think. @wildart ?

Copy link
Member

Choose a reason for hiding this comment

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

OK, I never used this function, but I'm pretty sure that it should return Oid. My implementation was wrong.

end
15 changes: 15 additions & 0 deletions test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ mktempdir() do dir
@test LibGit2.iszero(commit_oid2)
commit_oid2 = LibGit2.commit(repo, commit_msg2; author=test_sig, committer=test_sig)
@test !LibGit2.iszero(commit_oid2)
auths = LibGit2.authors(repo)
@test length(auths) == 3
Copy link
Contributor

Choose a reason for hiding this comment

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

which repo is this, is it constructed from scratch in this test harness, or is it referring to something like Example.jl that may change over time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pretty sure it's from scratch
On Jun 3, 2016 10:43 AM, "Tony Kelman" notifications@github.com wrote:

In test/libgit2.jl
#16728 (comment):

@@ -219,6 +219,13 @@ mktempdir() do dir
@test LibGit2.iszero(commit_oid2)
commit_oid2 = LibGit2.commit(repo, commit_msg2; author=test_sig, committer=test_sig)
@test !LibGit2.iszero(commit_oid2)

  •            auths = LibGit2.authors(repo)
    
  •            @test length(auths) == 3
    

which repo is this, is it constructed from scratch in this test harness,
or is it referring to something like Example.jl that may change over time?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/JuliaLang/julia/pull/16728/files/4761fc6757a8ce5b5d8a049737ca7bc2a0293976#r65747279,
or mute the thread
https://github.com/notifications/unsubscribe/AAyk452oBDr8VRy17iIXaMEOESjv-t9eks5qIGejgaJpZM4Is-63
.

for auth in auths
Copy link
Contributor

Choose a reason for hiding this comment

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

how many should there be in this test case?

@test auth.name == test_sig.name
@test auth.time == test_sig.time
@test auth.email == test_sig.email
end

# lookup commits
cmt = LibGit2.get(LibGit2.GitCommit, repo, commit_oid1)
Expand Down Expand Up @@ -315,13 +322,21 @@ mktempdir() do dir
tags = LibGit2.tag_list(repo)
@test length(tags) == 1
@test tag1 in tags
tag1ref = LibGit2.GitReference(repo, "refs/tags/$tag1")
@test isempty(LibGit2.fullname(tag1ref)) #because this is a reference to an OID
tag1tag = LibGit2.peel(LibGit2.GitTag,tag1ref)
@test LibGit2.name(tag1tag) == tag1
@test LibGit2.target(tag1tag) == commit_oid1

tag_oid2 = LibGit2.tag_create(repo, tag2, commit_oid2)
@test !LibGit2.iszero(tag_oid2)
tags = LibGit2.tag_list(repo)
@test length(tags) == 2
@test tag2 in tags

refs = LibGit2.ref_list(repo)
@test refs == ["refs/heads/master","refs/heads/test_branch","refs/tags/tag1","refs/tags/tag2"]

LibGit2.tag_delete(repo, tag1)
tags = LibGit2.tag_list(repo)
@test length(tags) == 1
Expand Down