Skip to content

Commit

Permalink
Merge pull request JuliaLang#20052 from JuliaLang/ksh/shows
Browse files Browse the repository at this point in the history
Even more show methods for libgit2
  • Loading branch information
kshyatt authored Jan 17, 2017
2 parents 9c4631b + 04ae272 commit 8313964
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions base/libgit2/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,7 @@ function Base.find(path::String, idx::GitIndex)
end

stage(ie::IndexEntry) = ccall((:git_index_entry_stage, :libgit2), Cint, (Ptr{IndexEntry},), Ref(ie))

function Base.show(io::IO, idx::GitIndex)
println(io, "GitIndex:\nOwner: ", owner(idk), "\nNumber of elements: ", count(idx))
end
15 changes: 15 additions & 0 deletions base/libgit2/reference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ function isremote(ref::GitReference)
return err == 1
end

function Base.show(io::IO, ref::GitReference)
println(io, "GitReference:")
if isremote(ref)
println(io, "Remote with name ", name(ref))
elseif isbranch(ref)
println(io, "Branch with name ", name(ref))
if ishead(ref)
println(io, "Branch is HEAD.")
else
println(io, "Branch is not HEAD.")
end
elseif istag(ref)
println(io, "Tag with name ", name(ref))
end
end
function peel{T <: GitObject}(::Type{T}, ref::GitReference)
git_otype = getobjecttype(T)
obj_ptr_ptr = Ref{Ptr{Void}}(C_NULL)
Expand Down
22 changes: 22 additions & 0 deletions base/libgit2/tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ function treewalk(f::Function, tree::GitTree, payload=Any[], post::Bool = false)
return cbf_payload
end

function owner(tree::GitTree)
repo_ptr = ccall((:git_tree_owner, :libgit2), Ptr{Void},
(Ptr{Void},), tree.ptr)
return GitRepo(repo_ptr)
end

function filename(te::GitTreeEntry)
str = ccall((:git_tree_entry_name, :libgit2), Cstring, (Ptr{Void},), te.ptr)
str != C_NULL && return unsafe_string(str)
Expand All @@ -26,6 +32,15 @@ function filemode(te::GitTreeEntry)
return ccall((:git_tree_entry_filemode, :libgit2), Cint, (Ptr{Void},), te.ptr)
end

function entrytype(te::GitTreeEntry)
otype = ccall((:git_tree_entry_type, :libgit2), Cint, (Ptr{Void},), te.ptr)
return getobjecttype(otype)
end

function entryid(te::GitTreeEntry)
oid_ptr = ccall((:git_tree_entry_id, :libgit2), Cint, (Ptr{Void},), te.ptr)
return GitHash(oid_ptr[])
end

function object(repo::GitRepo, te::GitTreeEntry)
obj_ptr_ptr = Ref{Ptr{Void}}(C_NULL)
Expand All @@ -34,3 +49,10 @@ function object(repo::GitRepo, te::GitTreeEntry)
obj_ptr_ptr, repo.ptr, te.ptr)
return GitUnknownObject(repo, obj_ptr_ptr[])
end

function Base.show(io::IO, te::GitTreeEntry)
println(io, "GitTreeEntry:")
println(io, "Entry name: ", filename(te))
println(io, "Entry type: ", entrytype(te))
println(io, "Entry OID: ", entryid(te))
end
3 changes: 3 additions & 0 deletions test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ mktempdir() do dir
@test tag1 in tags
tag1ref = LibGit2.GitReference(repo, "refs/tags/$tag1")
@test isempty(LibGit2.fullname(tag1ref)) #because this is a reference to an OID
show_strs = split(sprint(show, tag1ref), "\n")
@test show_strs[1] == "GitReference:"
@test show_strs[2] == "Tag with name refs/tags/$tag1"
tag1tag = LibGit2.peel(LibGit2.GitTag,tag1ref)
@test LibGit2.name(tag1tag) == tag1
@test LibGit2.target(tag1tag) == commit_oid1
Expand Down

0 comments on commit 8313964

Please sign in to comment.