Skip to content

Commit

Permalink
Show methods for Signatures and Commits
Browse files Browse the repository at this point in the history
Add `show` methods for `Signature` and `Commit`s in LibGit2.
Display the time of the commit using Julia's built-in date handling.
  • Loading branch information
kshyatt committed Jan 9, 2017
1 parent 23c5450 commit deb6a9b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions base/libgit2/commit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ function committer(c::GitCommit)
return Signature(ptr)
end

function Base.show(io::IO, c::GitCommit)
authstr = sprint(show, author(c))
cmtrstr = sprint(show, committer(c))
print(io, "Commit Author: $authstr\nCommitter: $cmtrstr\nSHA: $(Oid(c))\nMessage:\n$(message(c))")
end

""" Wrapper around `git_commit_create` """
function commit(repo::GitRepo,
refname::AbstractString,
Expand Down
2 changes: 2 additions & 0 deletions base/libgit2/signature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ function Base.convert(::Type{GitSignature}, sig::Signature)
return GitSignature(sig_ptr_ptr[])
end

Base.show(io::IO, sig::Signature) = print(io, "Name: $(sig.name), Email: $(sig.email), Time: $(Dates.unix2datetime(sig.time + sig.time_offset))")

"""Return signature object. Free it after use."""
function default_signature(repo::GitRepo)
sig_ptr_ptr = Ref{Ptr{SignatureStruct}}(C_NULL)
Expand Down
7 changes: 7 additions & 0 deletions test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ mktempdir() do dir
@test cmtr.time == test_sig.time
@test cmtr.email == test_sig.email
@test LibGit2.message(cmt) == commit_msg1
showstr = split(sprint(show, cmt), "\n")
# the time of the commit will vary so just test the first two parts
@test contains(showstr[1], "Commit Author: Name: TEST, Email: [email protected], Time:")
@test contains(showstr[2], "Committer: Name: TEST, Email: [email protected], Time:")
@test contains(showstr[3], "SHA:")
@test showstr[4] == "Message:"
@test showstr[5] == commit_msg1
finally
finalize(cmt)
end
Expand Down

0 comments on commit deb6a9b

Please sign in to comment.