Skip to content

Commit 8313964

Browse files
authored
Merge pull request JuliaLang#20052 from JuliaLang/ksh/shows
Even more show methods for libgit2
2 parents 9c4631b + 04ae272 commit 8313964

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

base/libgit2/index.jl

+4
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,7 @@ function Base.find(path::String, idx::GitIndex)
127127
end
128128

129129
stage(ie::IndexEntry) = ccall((:git_index_entry_stage, :libgit2), Cint, (Ptr{IndexEntry},), Ref(ie))
130+
131+
function Base.show(io::IO, idx::GitIndex)
132+
println(io, "GitIndex:\nOwner: ", owner(idk), "\nNumber of elements: ", count(idx))
133+
end

base/libgit2/reference.jl

+15
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@ function isremote(ref::GitReference)
9999
return err == 1
100100
end
101101

102+
function Base.show(io::IO, ref::GitReference)
103+
println(io, "GitReference:")
104+
if isremote(ref)
105+
println(io, "Remote with name ", name(ref))
106+
elseif isbranch(ref)
107+
println(io, "Branch with name ", name(ref))
108+
if ishead(ref)
109+
println(io, "Branch is HEAD.")
110+
else
111+
println(io, "Branch is not HEAD.")
112+
end
113+
elseif istag(ref)
114+
println(io, "Tag with name ", name(ref))
115+
end
116+
end
102117
function peel{T <: GitObject}(::Type{T}, ref::GitReference)
103118
git_otype = getobjecttype(T)
104119
obj_ptr_ptr = Ref{Ptr{Void}}(C_NULL)

base/libgit2/tree.jl

+22
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ function treewalk(f::Function, tree::GitTree, payload=Any[], post::Bool = false)
1616
return cbf_payload
1717
end
1818

19+
function owner(tree::GitTree)
20+
repo_ptr = ccall((:git_tree_owner, :libgit2), Ptr{Void},
21+
(Ptr{Void},), tree.ptr)
22+
return GitRepo(repo_ptr)
23+
end
24+
1925
function filename(te::GitTreeEntry)
2026
str = ccall((:git_tree_entry_name, :libgit2), Cstring, (Ptr{Void},), te.ptr)
2127
str != C_NULL && return unsafe_string(str)
@@ -26,6 +32,15 @@ function filemode(te::GitTreeEntry)
2632
return ccall((:git_tree_entry_filemode, :libgit2), Cint, (Ptr{Void},), te.ptr)
2733
end
2834

35+
function entrytype(te::GitTreeEntry)
36+
otype = ccall((:git_tree_entry_type, :libgit2), Cint, (Ptr{Void},), te.ptr)
37+
return getobjecttype(otype)
38+
end
39+
40+
function entryid(te::GitTreeEntry)
41+
oid_ptr = ccall((:git_tree_entry_id, :libgit2), Cint, (Ptr{Void},), te.ptr)
42+
return GitHash(oid_ptr[])
43+
end
2944

3045
function object(repo::GitRepo, te::GitTreeEntry)
3146
obj_ptr_ptr = Ref{Ptr{Void}}(C_NULL)
@@ -34,3 +49,10 @@ function object(repo::GitRepo, te::GitTreeEntry)
3449
obj_ptr_ptr, repo.ptr, te.ptr)
3550
return GitUnknownObject(repo, obj_ptr_ptr[])
3651
end
52+
53+
function Base.show(io::IO, te::GitTreeEntry)
54+
println(io, "GitTreeEntry:")
55+
println(io, "Entry name: ", filename(te))
56+
println(io, "Entry type: ", entrytype(te))
57+
println(io, "Entry OID: ", entryid(te))
58+
end

test/libgit2.jl

+3
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,9 @@ mktempdir() do dir
399399
@test tag1 in tags
400400
tag1ref = LibGit2.GitReference(repo, "refs/tags/$tag1")
401401
@test isempty(LibGit2.fullname(tag1ref)) #because this is a reference to an OID
402+
show_strs = split(sprint(show, tag1ref), "\n")
403+
@test show_strs[1] == "GitReference:"
404+
@test show_strs[2] == "Tag with name refs/tags/$tag1"
402405
tag1tag = LibGit2.peel(LibGit2.GitTag,tag1ref)
403406
@test LibGit2.name(tag1tag) == tag1
404407
@test LibGit2.target(tag1tag) == commit_oid1

0 commit comments

Comments
 (0)