-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RFC: Rename LibGit2.Oid to LibGit2.GitHash (#19878)
* Rename LibGit2.Oid to LibGit2.GitHash
- Loading branch information
1 parent
13da0b9
commit 0b8b6f1
Showing
17 changed files
with
134 additions
and
131 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
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
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
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 |
---|---|---|
@@ -1,88 +1,88 @@ | ||
# This file is a part of Julia. License is MIT: http://julialang.org/license | ||
|
||
Oid(id::Oid) = id | ||
Oid(ptr::Ptr{Oid}) = unsafe_load(ptr)::Oid | ||
GitHash(id::GitHash) = id | ||
GitHash(ptr::Ptr{GitHash}) = unsafe_load(ptr)::GitHash | ||
|
||
function Oid(ptr::Ptr{UInt8}) | ||
function GitHash(ptr::Ptr{UInt8}) | ||
if ptr == C_NULL | ||
throw(ArgumentError("NULL pointer passed to Oid() constructor")) | ||
throw(ArgumentError("NULL pointer passed to GitHash() constructor")) | ||
end | ||
oid_ptr = Ref(Oid()) | ||
ccall((:git_oid_fromraw, :libgit2), Void, (Ptr{Oid}, Ptr{UInt8}), oid_ptr, ptr) | ||
oid_ptr = Ref(GitHash()) | ||
ccall((:git_oid_fromraw, :libgit2), Void, (Ptr{GitHash}, Ptr{UInt8}), oid_ptr, ptr) | ||
return oid_ptr[] | ||
end | ||
|
||
function Oid(id::Array{UInt8,1}) | ||
function GitHash(id::Array{UInt8,1}) | ||
if length(id) != OID_RAWSZ | ||
throw(ArgumentError("invalid raw buffer size")) | ||
end | ||
return Oid(pointer(id)) | ||
return GitHash(pointer(id)) | ||
end | ||
|
||
function Oid(id::AbstractString) | ||
function GitHash(id::AbstractString) | ||
bstr = String(id) | ||
len = sizeof(bstr) | ||
oid_ptr = Ref(Oid()) | ||
oid_ptr = Ref(GitHash()) | ||
err = if len < OID_HEXSZ | ||
ccall((:git_oid_fromstrn, :libgit2), Cint, | ||
(Ptr{Oid}, Ptr{UInt8}, Csize_t), oid_ptr, bstr, len) | ||
(Ptr{GitHash}, Ptr{UInt8}, Csize_t), oid_ptr, bstr, len) | ||
else | ||
ccall((:git_oid_fromstrp, :libgit2), Cint, | ||
(Ptr{Oid}, Cstring), oid_ptr, bstr) | ||
(Ptr{GitHash}, Cstring), oid_ptr, bstr) | ||
end | ||
err != 0 && return Oid() | ||
err != 0 && return GitHash() | ||
return oid_ptr[] | ||
end | ||
|
||
function Oid(ref::GitReference) | ||
isempty(ref) && return Oid() | ||
reftype(ref) != Consts.REF_OID && return Oid() | ||
function GitHash(ref::GitReference) | ||
isempty(ref) && return GitHash() | ||
reftype(ref) != Consts.REF_OID && return GitHash() | ||
oid_ptr = ccall((:git_reference_target, :libgit2), Ptr{UInt8}, (Ptr{Void},), ref.ptr) | ||
oid_ptr == C_NULL && return Oid() | ||
return Oid(oid_ptr) | ||
oid_ptr == C_NULL && return GitHash() | ||
return GitHash(oid_ptr) | ||
end | ||
|
||
function Oid(repo::GitRepo, ref_name::AbstractString) | ||
isempty(repo) && return Oid() | ||
oid_ptr = Ref(Oid()) | ||
function GitHash(repo::GitRepo, ref_name::AbstractString) | ||
isempty(repo) && return GitHash() | ||
oid_ptr = Ref(GitHash()) | ||
@check ccall((:git_reference_name_to_id, :libgit2), Cint, | ||
(Ptr{Oid}, Ptr{Void}, Cstring), | ||
(Ptr{GitHash}, Ptr{Void}, Cstring), | ||
oid_ptr, repo.ptr, ref_name) | ||
return oid_ptr[] | ||
end | ||
|
||
function Oid(obj::Ptr{Void}) | ||
function GitHash(obj::Ptr{Void}) | ||
oid_ptr = ccall((:git_object_id, :libgit2), Ptr{UInt8}, (Ptr{Void},), obj) | ||
oid_ptr == C_NULL && return Oid() | ||
return Oid(oid_ptr) | ||
oid_ptr == C_NULL && return GitHash() | ||
return GitHash(oid_ptr) | ||
end | ||
|
||
function Oid{T<:GitObject}(obj::T) | ||
obj === nothing && return Oid() | ||
return Oid(obj.ptr) | ||
function GitHash{T<:GitObject}(obj::T) | ||
obj === nothing && return GitHash() | ||
return GitHash(obj.ptr) | ||
end | ||
|
||
Base.hex(id::Oid) = join([hex(i,2) for i in id.val]) | ||
Base.hex(id::GitHash) = join([hex(i,2) for i in id.val]) | ||
|
||
raw(id::Oid) = collect(id.val) | ||
raw(id::GitHash) = collect(id.val) | ||
|
||
Base.string(id::Oid) = hex(id) | ||
Base.string(id::GitHash) = hex(id) | ||
|
||
Base.show(io::IO, id::Oid) = print(io, "Oid($(string(id)))") | ||
Base.show(io::IO, id::GitHash) = print(io, "GitHash($(string(id)))") | ||
|
||
Base.hash(id::Oid, h::UInt) = hash(id.val, h) | ||
Base.hash(id::GitHash, h::UInt) = hash(id.val, h) | ||
|
||
cmp(id1::Oid, id2::Oid) = Int(ccall((:git_oid_cmp, :libgit2), Cint, | ||
(Ptr{Oid}, Ptr{Oid}), Ref(id1), Ref(id2))) | ||
cmp(id1::GitHash, id2::GitHash) = Int(ccall((:git_oid_cmp, :libgit2), Cint, | ||
(Ptr{GitHash}, Ptr{GitHash}), Ref(id1), Ref(id2))) | ||
|
||
==(id1::Oid, id2::Oid) = cmp(id1, id2) == 0 | ||
Base.isless(id1::Oid, id2::Oid) = cmp(id1, id2) < 0 | ||
==(id1::GitHash, id2::GitHash) = cmp(id1, id2) == 0 | ||
Base.isless(id1::GitHash, id2::GitHash) = cmp(id1, id2) < 0 | ||
|
||
function iszero(id::Oid) | ||
function iszero(id::GitHash) | ||
for i in 1:OID_RAWSZ | ||
id.val[i] != zero(UInt8) && return false | ||
end | ||
return true | ||
end | ||
|
||
Base.zero(::Type{Oid}) = Oid() | ||
Base.zero(::Type{GitHash}) = GitHash() |
Oops, something went wrong.