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

RFC: Rename LibGit2.Oid to LibGit2.GitHash #19878

Merged
merged 4 commits into from
Jan 9, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Rename LibGit2.Oid to LibGit2.GitHash
  • Loading branch information
ararslan committed Jan 8, 2017
commit 2803d764d5c436ff20c44fe8415f763f782462aa
3 changes: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,9 @@ end
# Calling promote_op is likely a bad idea, so deprecate its convenience wrapper promote_eltype_op
@deprecate promote_eltype_op(op, As...) promote_op(op, map(eltype, As)...)

# Rename LibGit2.Oid to LibGit2.GitHash (part of #19839)
eval(Base.LibGit2, :(Base.@deprecate_binding Oid GitHash))

function unsafe_wrap(::Type{String}, p::Union{Ptr{UInt8},Ptr{Int8}}, len::Integer, own::Bool=false)
Base.depwarn("unsafe_wrap(String, ...) is deprecated; use `unsafe_string` instead.", :unsafe_wrap)
#ccall(:jl_array_to_string, Ref{String}, (Any,),
Expand Down
4 changes: 2 additions & 2 deletions base/libgit2/blob.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ function Base.length(blob::GitBlob)
return ccall((:git_blob_rawsize, :libgit2), Int64, (Ptr{Void},), blob.ptr)
end

function lookup(repo::GitRepo, oid::Oid)
function lookup(repo::GitRepo, oid::GitHash)
blob_ptr_ptr = Ref{Ptr{Void}}(C_NULL)
@check ccall((:git_blob_lookup, :libgit2), Cint,
(Ptr{Ptr{Void}}, Ptr{Void}, Ref{Oid}),
(Ptr{Ptr{Void}}, Ptr{Void}, Ref{GitHash}),
blob_ptr_ptr, repo.ptr, Ref(oid))
return GitBlob(blob_ptr_ptr[])
end
6 changes: 3 additions & 3 deletions base/libgit2/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ function credentials_callback(libgit2credptr::Ptr{Ptr{Void}}, url_ptr::Cstring,
end

function fetchhead_foreach_callback(ref_name::Cstring, remote_url::Cstring,
oid::Ptr{Oid}, is_merge::Cuint, payload::Ptr{Void})
oid::Ptr{GitHash}, is_merge::Cuint, payload::Ptr{Void})
fhead_vec = unsafe_pointer_to_objref(payload)::Vector{FetchHead}
push!(fhead_vec, FetchHead(unsafe_string(ref_name), unsafe_string(remote_url), Oid(oid), is_merge == 1))
push!(fhead_vec, FetchHead(unsafe_string(ref_name), unsafe_string(remote_url), GitHash(oid), is_merge == 1))
return Cint(0)
end

Expand All @@ -266,4 +266,4 @@ mirror_cb() = cfunction(mirror_callback, Cint, (Ptr{Ptr{Void}}, Ptr{Void}, Cstri
"C function pointer for `credentials_callback`"
credentials_cb() = cfunction(credentials_callback, Cint, (Ptr{Ptr{Void}}, Cstring, Cstring, Cuint, Ptr{Void}))
"C function pointer for `fetchhead_foreach_callback`"
fetchhead_foreach_cb() = cfunction(fetchhead_foreach_callback, Cint, (Cstring, Cstring, Ptr{Oid}, Cuint, Ptr{Void}))
fetchhead_foreach_cb() = cfunction(fetchhead_foreach_callback, Cint, (Cstring, Cstring, Ptr{GitHash}, Cuint, Ptr{Void}))
12 changes: 6 additions & 6 deletions base/libgit2/commit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ function commit(repo::GitRepo,
committer::GitSignature,
tree::GitTree,
parents::GitCommit...)
commit_id_ptr = Ref(Oid())
commit_id_ptr = Ref(GitHash())
nparents = length(parents)
parentptrs = Ptr{Void}[c.ptr for c in parents]
@check ccall((:git_commit_create, :libgit2), Cint,
(Ptr{Oid}, Ptr{Void}, Ptr{UInt8},
(Ptr{GitHash}, Ptr{Void}, Ptr{UInt8},
Ptr{SignatureStruct}, Ptr{SignatureStruct},
Ptr{UInt8}, Ptr{UInt8}, Ptr{Void},
Csize_t, Ptr{Ptr{Void}}),
Expand All @@ -50,8 +50,8 @@ function commit(repo::GitRepo, msg::AbstractString;
refname::AbstractString=Consts.HEAD_FILE,
author::Signature = Signature(repo),
committer::Signature = Signature(repo),
tree_id::Oid = Oid(),
parent_ids::Vector{Oid}=Oid[])
tree_id::GitHash = GitHash(),
parent_ids::Vector{GitHash}=GitHash[])
# Retrieve tree identifier
if iszero(tree_id)
tree_id = with(GitIndex, repo) do idx; write_tree!(idx) end
Expand All @@ -60,12 +60,12 @@ function commit(repo::GitRepo, msg::AbstractString;
# Retrieve parents from HEAD
if isempty(parent_ids)
try # if throws then HEAD not found -> empty repo
push!(parent_ids, Oid(repo, refname))
push!(parent_ids, GitHash(repo, refname))
end
end

# return commit id
commit_id = Oid()
commit_id = GitHash()

# get necessary objects
tree = get(GitTree, repo, tree_id)
Expand Down
6 changes: 3 additions & 3 deletions base/libgit2/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ function write!(idx::GitIndex)
end

function write_tree!(idx::GitIndex)
oid_ptr = Ref(Oid())
oid_ptr = Ref(GitHash())
@check ccall((:git_index_write_tree, :libgit2), Cint,
(Ptr{Oid}, Ptr{Void}), oid_ptr, idx.ptr)
(Ptr{GitHash}, Ptr{Void}), oid_ptr, idx.ptr)
return oid_ptr[]
end

Expand All @@ -30,7 +30,7 @@ function owner(idx::GitIndex)
return GitRepo(repo_ptr)
end

function read_tree!(idx::GitIndex, tree_id::Oid)
function read_tree!(idx::GitIndex, tree_id::GitHash)
repo = owner(idx)
tree = get(GitTree, repo, tree_id)
try
Expand Down
26 changes: 13 additions & 13 deletions base/libgit2/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ include("callbacks.jl")
using .Error

immutable State
head::Oid
index::Oid
work::Oid
head::GitHash
index::GitHash
work::GitHash
end

"""Return HEAD Oid as string"""
"""Return HEAD GitHash as string"""
function head(pkg::AbstractString)
with(GitRepo, pkg) do repo
string(head_oid(repo))
Expand Down Expand Up @@ -213,18 +213,18 @@ function branch!(repo::GitRepo, branch_name::AbstractString,
if branch_rmt_ref === nothing
with(head(repo)) do head_ref
with(peel(GitCommit, head_ref)) do hrc
Oid(hrc)
GitHash(hrc)
end
end
else
tmpcmt = with(peel(GitCommit, branch_rmt_ref)) do hrc
Oid(hrc)
GitHash(hrc)
end
finalize(branch_rmt_ref)
tmpcmt
end
else
Oid(commit)
GitHash(commit)
end
iszero(commit_id) && return
cmt = get(GitCommit, repo, commit_id)
Expand Down Expand Up @@ -278,13 +278,13 @@ function checkout!(repo::GitRepo, commit::AbstractString = "";
head_name = shortname(head_ref)
# if it is HEAD use short OID instead
if head_name == Consts.HEAD_FILE
head_name = string(Oid(head_ref))
head_name = string(GitHash(head_ref))
end
end
end

# search for commit to get a commit object
obj = get(GitAnyObject, repo, Oid(commit))
obj = get(GitAnyObject, repo, GitHash(commit))
obj === nothing && return
try
peeled = peel(obj, Consts.OBJ_COMMIT)
Expand All @@ -293,7 +293,7 @@ function checkout!(repo::GitRepo, commit::AbstractString = "";
CheckoutOptions()
try
# detach commit
obj_oid = Oid(peeled)
obj_oid = GitHash(peeled)
ref = GitReference(repo, obj_oid, force=force,
msg="libgit2.checkout: moving from $head_name to $(string(obj_oid))")
finalize(ref)
Expand Down Expand Up @@ -340,7 +340,7 @@ function reset!(repo::GitRepo, committish::AbstractString, pathspecs::AbstractSt
end

""" git reset [--soft | --mixed | --hard] <commit> """
function reset!(repo::GitRepo, commit::Oid, mode::Cint = Consts.RESET_MIXED)
function reset!(repo::GitRepo, commit::GitHash, mode::Cint = Consts.RESET_MIXED)
obj = get(GitAnyObject, repo, commit)
# object must exist for reset
obj === nothing && throw(GitError(Error.Object, Error.ERROR, "Commit `$(string(commit))` object not found"))
Expand Down Expand Up @@ -425,7 +425,7 @@ function merge!(repo::GitRepo;
LibGit2.get(String, cfg, "branch.$branchname.remote")
end
obj = with(GitReference(repo, "refs/remotes/$remotename/$branchname")) do ref
LibGit2.Oid(ref)
LibGit2.GitHash(ref)
end
with(get(GitCommit, repo, obj)) do cmt
LibGit2.create_branch(repo, branchname, cmt)
Expand Down Expand Up @@ -523,7 +523,7 @@ function authors(repo::GitRepo)
end

function snapshot(repo::GitRepo)
head = Oid(repo, Consts.HEAD_FILE)
head = GitHash(repo, Consts.HEAD_FILE)
index = with(GitIndex, repo) do idx; write_tree!(idx) end
work = try
with(GitIndex, repo) do idx
Expand Down
22 changes: 11 additions & 11 deletions base/libgit2/merge.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# This file is a part of Julia. License is MIT: http:https://julialang.org/license

function GitAnnotated(repo::GitRepo, commit_id::Oid)
function GitAnnotated(repo::GitRepo, commit_id::GitHash)
ann_ptr_ptr = Ref{Ptr{Void}}(C_NULL)
@check ccall((:git_annotated_commit_lookup, :libgit2), Cint,
(Ptr{Ptr{Void}}, Ptr{Void}, Ptr{Oid}),
(Ptr{Ptr{Void}}, Ptr{Void}, Ptr{GitHash}),
ann_ptr_ptr, repo.ptr, Ref(commit_id))
return GitAnnotated(ann_ptr_ptr[])
end
Expand All @@ -19,7 +19,7 @@ end
function GitAnnotated(repo::GitRepo, fh::FetchHead)
ann_ref_ref = Ref{Ptr{Void}}(C_NULL)
@check ccall((:git_annotated_commit_from_fetchhead, :libgit2), Cint,
(Ptr{Ptr{Void}}, Ptr{Void}, Cstring, Cstring, Ptr{Oid}),
(Ptr{Ptr{Void}}, Ptr{Void}, Cstring, Cstring, Ptr{GitHash}),
ann_ref_ref, repo.ptr, fh.name, fh.url, Ref(fh.oid))
return GitAnnotated(ann_ref_ref[])
end
Expand All @@ -29,14 +29,14 @@ function GitAnnotated(repo::GitRepo, comittish::AbstractString)
try
cmt = peel(obj, Consts.OBJ_COMMIT)
cmt === nothing && return nothing
return GitAnnotated(repo, Oid(cmt))
return GitAnnotated(repo, GitHash(cmt))
finally
finalize(obj)
end
end

function commit(ann::GitAnnotated)
return Oid(ccall((:git_annotated_commit_id, :libgit2), Ptr{Oid}, (Ptr{Void},), ann.ptr))
return GitHash(ccall((:git_annotated_commit_id, :libgit2), Ptr{GitHash}, (Ptr{Void},), ann.ptr))
end

function merge_analysis(repo::GitRepo, anns::Vector{GitAnnotated})
Expand All @@ -58,7 +58,7 @@ function ffmerge!(repo::GitRepo, ann::GitAnnotated)
try
checkout_tree(repo, cmt)
with(head(repo)) do head_ref
cmt_oid = Oid(cmt)
cmt_oid = GitHash(cmt)
msg = "libgit2.merge: fastforward $(string(cmt_oid)) into $(name(head_ref))"
new_head_ref = if reftype(head_ref) == Consts.REF_OID
target!(head_ref, cmt_oid, msg=msg)
Expand Down Expand Up @@ -148,17 +148,17 @@ function merge!(repo::GitRepo, anns::Vector{GitAnnotated}, fastforward::Bool;
end

function merge_base(repo::GitRepo, one::AbstractString, two::AbstractString)
oid1_ptr = Ref(Oid(one))
oid2_ptr = Ref(Oid(two))
moid_ptr = Ref(Oid())
oid1_ptr = Ref(GitHash(one))
oid2_ptr = Ref(GitHash(two))
moid_ptr = Ref(GitHash())
moid = try
@check ccall((:git_merge_base, :libgit2), Cint,
(Ptr{Oid}, Ptr{Void}, Ptr{Oid}, Ptr{Oid}),
(Ptr{GitHash}, Ptr{Void}, Ptr{GitHash}, Ptr{GitHash}),
moid_ptr, repo.ptr, oid1_ptr, oid2_ptr)
moid_ptr[]
catch e
#warn("Pkg:",path(repo),"=>",e.msg)
Oid()
GitHash()
end
return moid
end
78 changes: 39 additions & 39 deletions base/libgit2/oid.jl
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:https://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()
Loading