This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap, doc, test GitBlame (JuliaLang#22469)
* Wrap, doc, test GitBlame * Fixup docs * Fix counthunks * Fix char doc
- Loading branch information
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
function GitBlame(repo::GitRepo, path::AbstractString; options::BlameOptions=BlameOptions()) | ||
blame_ptr_ptr = Ref{Ptr{Void}}(C_NULL) | ||
@check ccall((:git_blame_file, :libgit2), Cint, | ||
(Ptr{Ptr{Void}}, Ptr{Void}, Cstring, Ptr{BlameOptions}), | ||
blame_ptr_ptr, repo.ptr, path, Ref(options)) | ||
return GitBlame(repo, blame_ptr_ptr[]) | ||
end | ||
|
||
function counthunks(blame::GitBlame) | ||
return ccall((:git_blame_get_hunk_count, :libgit2), Int32, (Ptr{Void},), blame.ptr) | ||
end | ||
|
||
function Base.getindex(blame::GitBlame, i::Integer) | ||
if !(1 <= i <= counthunks(blame)) | ||
throw(BoundsError(blame, (i,))) | ||
end | ||
hunk_ptr = ccall((:git_blame_get_hunk_byindex, :libgit2), | ||
Ptr{BlameHunk}, | ||
(Ptr{Void}, Csize_t), blame.ptr, i-1) | ||
return unsafe_load(hunk_ptr) | ||
end | ||
|
||
function Base.show(io::IO, blame_hunk::BlameHunk) | ||
println(io, "GitBlameHunk:") | ||
println(io, "Original path: ", blame_hunk.orig.path) | ||
println(io, "Lines in hunk: ", blame_hunk.lines_in_hunk) | ||
println(io, "Final commit oid: ", blame_hunk.final_commit_id) | ||
print(io, "Final signature: ") | ||
show(io, blame_hunk.final_signature) | ||
println() | ||
println(io, "Original commit oid: ", blame_hunk.orig_commit_id) | ||
print(io, "Original signature: ") | ||
show(io, blame_hunk.orig_signature) | ||
println() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters