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 docs for blob.jl #22555

Merged
merged 7 commits into from
Jul 8, 2017
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions base/libgit2/blob.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@ function Base.length(blob::GitBlob)
return ccall((:git_blob_rawsize, :libgit2), Int64, (Ptr{Void},), blob.ptr)
end

"""
rawcontent(blob::GitBlob) -> Array
Copy link
Member

Choose a reason for hiding this comment

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

Maybe Vector{UInt8} (assuming that's true)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


Fetch the *raw* contents of the [`GitBlob`](@ref) `blob`. This is a read-only
Copy link
Contributor

Choose a reason for hiding this comment

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

what does read only mean here? you can always write to julia arrays

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did the revised wording make this clearer?

`Array` containing the contents of the blob, which may be binary or may be Unicode.
Copy link
Member

Choose a reason for hiding this comment

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

"may or may not be valid Unicode"? I find "may be binary or may be Unicode" a little confusing since it's always binary; it doesn't return Chars.

`rawcontent` will allow the user to load the raw binary data into
the output `Array` and will not check to ensure it is a valid Unicode, so errors
Copy link
Member

Choose a reason for hiding this comment

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

Is "a valid Unicode" a typical phrase? Perhaps remove "a"?

may occur if the result is passed to functions which expect valid Unicode data.

See also [`content`](@ref), which *will* throw an error the content of the `blob`
Copy link
Contributor

Choose a reason for hiding this comment

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

throw an error if the content

is binary and not valid Unicode.
"""
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

"""
content(blob::GitBlob)
content(blob::GitBlob) -> String

Fetch the contents of the `GitBlob` `blob`. If the `blob` contains
Fetch the contents of the [`GitBlob`](@ref) `blob`. If the `blob` contains
binary data (which can be determined using [`isbinary`](@ref)),
throw an error. Otherwise, return a `String` containing the contents
of the `blob`.
Expand All @@ -24,6 +36,8 @@ function content(blob::GitBlob)
end

"""
isbinary(blob::GitBlob) -> Bool

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
the first 8000 bytes.
Expand All @@ -37,7 +51,7 @@ end
LibGit2.addblob!(repo::GitRepo, path::AbstractString)

Reads the file at `path` and adds it to the object database of `repo` as a loose blob.
Returns the `GitHash` of the resulting blob.
Returns the [`GitHash`](@ref) of the resulting blob.

# Example

Expand Down