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 GitShortHash type, remove some get methods #20104

Merged
merged 11 commits into from
Jan 31, 2017
15 changes: 11 additions & 4 deletions base/libgit2/blob.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

function content(blob::GitBlob)
unsafe_string(ccall((:git_blob_rawcontent, :libgit2), Ptr{UInt8}, (Ptr{Void},), blob.ptr))
end

function Base.length(blob::GitBlob)
return ccall((:git_blob_rawsize, :libgit2), Int64, (Ptr{Void},), blob.ptr)
end

function rawcontent(blob::GitBlob)
ptr = ccall((:git_blob_rawcontent, :libgit2), Ptr{UInt8}, (Ptr{Void},), blob.ptr)
copy(unsafe_wrap(Array, ptr, (length(blob),), false))
end

function content(blob::GitBlob)
s = String(rawcontent)
Copy link
Contributor

Choose a reason for hiding this comment

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

rawcontent(blob)

isvalid(s) || error("Blob does not contain valid UTF-8 data")
return s
end

"""
Use a heuristic to guess if a file is binary: searching for NULL bytes and
looking for a reasonable ratio of printable to non-printable characters among
Expand Down