Skip to content

Commit 0b8b6f1

Browse files
ararslansimonbyrne
authored andcommitted
RFC: Rename LibGit2.Oid to LibGit2.GitHash (#19878)
* Rename LibGit2.Oid to LibGit2.GitHash
1 parent 13da0b9 commit 0b8b6f1

17 files changed

+134
-131
lines changed

base/deprecated.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,9 @@ _promote_eltype_op(op, A, B, C, D...) = (@_inline_meta; _promote_eltype_op(op, e
15171517
_promote_eltype_op(args...)
15181518
end
15191519

1520+
# Rename LibGit2.Oid to LibGit2.GitHash (part of #19839)
1521+
eval(Base.LibGit2, :(Base.@deprecate_binding Oid GitHash))
1522+
15201523
function unsafe_wrap(::Type{String}, p::Union{Ptr{UInt8},Ptr{Int8}}, len::Integer, own::Bool=false)
15211524
Base.depwarn("unsafe_wrap(String, ...) is deprecated; use `unsafe_string` instead.", :unsafe_wrap)
15221525
#ccall(:jl_array_to_string, Ref{String}, (Any,),

base/libgit2/blob.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ function Base.length(blob::GitBlob)
88
return ccall((:git_blob_rawsize, :libgit2), Int64, (Ptr{Void},), blob.ptr)
99
end
1010

11-
function lookup(repo::GitRepo, oid::Oid)
11+
function lookup(repo::GitRepo, oid::GitHash)
1212
blob_ptr_ptr = Ref{Ptr{Void}}(C_NULL)
1313
@check ccall((:git_blob_lookup, :libgit2), Cint,
14-
(Ptr{Ptr{Void}}, Ptr{Void}, Ref{Oid}),
14+
(Ptr{Ptr{Void}}, Ptr{Void}, Ref{GitHash}),
1515
blob_ptr_ptr, repo.ptr, Ref(oid))
1616
return GitBlob(blob_ptr_ptr[])
1717
end

base/libgit2/callbacks.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ function credentials_callback(libgit2credptr::Ptr{Ptr{Void}}, url_ptr::Cstring,
255255
end
256256

257257
function fetchhead_foreach_callback(ref_name::Cstring, remote_url::Cstring,
258-
oid::Ptr{Oid}, is_merge::Cuint, payload::Ptr{Void})
258+
oid::Ptr{GitHash}, is_merge::Cuint, payload::Ptr{Void})
259259
fhead_vec = unsafe_pointer_to_objref(payload)::Vector{FetchHead}
260-
push!(fhead_vec, FetchHead(unsafe_string(ref_name), unsafe_string(remote_url), Oid(oid), is_merge == 1))
260+
push!(fhead_vec, FetchHead(unsafe_string(ref_name), unsafe_string(remote_url), GitHash(oid), is_merge == 1))
261261
return Cint(0)
262262
end
263263

@@ -266,4 +266,4 @@ mirror_cb() = cfunction(mirror_callback, Cint, (Ptr{Ptr{Void}}, Ptr{Void}, Cstri
266266
"C function pointer for `credentials_callback`"
267267
credentials_cb() = cfunction(credentials_callback, Cint, (Ptr{Ptr{Void}}, Cstring, Cstring, Cuint, Ptr{Void}))
268268
"C function pointer for `fetchhead_foreach_callback`"
269-
fetchhead_foreach_cb() = cfunction(fetchhead_foreach_callback, Cint, (Cstring, Cstring, Ptr{Oid}, Cuint, Ptr{Void}))
269+
fetchhead_foreach_cb() = cfunction(fetchhead_foreach_callback, Cint, (Cstring, Cstring, Ptr{GitHash}, Cuint, Ptr{Void}))

base/libgit2/commit.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ function commit(repo::GitRepo,
3030
committer::GitSignature,
3131
tree::GitTree,
3232
parents::GitCommit...)
33-
commit_id_ptr = Ref(Oid())
33+
commit_id_ptr = Ref(GitHash())
3434
nparents = length(parents)
3535
parentptrs = Ptr{Void}[c.ptr for c in parents]
3636
@check ccall((:git_commit_create, :libgit2), Cint,
37-
(Ptr{Oid}, Ptr{Void}, Ptr{UInt8},
37+
(Ptr{GitHash}, Ptr{Void}, Ptr{UInt8},
3838
Ptr{SignatureStruct}, Ptr{SignatureStruct},
3939
Ptr{UInt8}, Ptr{UInt8}, Ptr{Void},
4040
Csize_t, Ptr{Ptr{Void}}),
@@ -50,8 +50,8 @@ function commit(repo::GitRepo, msg::AbstractString;
5050
refname::AbstractString=Consts.HEAD_FILE,
5151
author::Signature = Signature(repo),
5252
committer::Signature = Signature(repo),
53-
tree_id::Oid = Oid(),
54-
parent_ids::Vector{Oid}=Oid[])
53+
tree_id::GitHash = GitHash(),
54+
parent_ids::Vector{GitHash}=GitHash[])
5555
# Retrieve tree identifier
5656
if iszero(tree_id)
5757
tree_id = with(GitIndex, repo) do idx; write_tree!(idx) end
@@ -60,12 +60,12 @@ function commit(repo::GitRepo, msg::AbstractString;
6060
# Retrieve parents from HEAD
6161
if isempty(parent_ids)
6262
try # if throws then HEAD not found -> empty repo
63-
push!(parent_ids, Oid(repo, refname))
63+
push!(parent_ids, GitHash(repo, refname))
6464
end
6565
end
6666

6767
# return commit id
68-
commit_id = Oid()
68+
commit_id = GitHash()
6969

7070
# get necessary objects
7171
tree = get(GitTree, repo, tree_id)

base/libgit2/index.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ function write!(idx::GitIndex)
1818
end
1919

2020
function write_tree!(idx::GitIndex)
21-
oid_ptr = Ref(Oid())
21+
oid_ptr = Ref(GitHash())
2222
@check ccall((:git_index_write_tree, :libgit2), Cint,
23-
(Ptr{Oid}, Ptr{Void}), oid_ptr, idx.ptr)
23+
(Ptr{GitHash}, Ptr{Void}), oid_ptr, idx.ptr)
2424
return oid_ptr[]
2525
end
2626

@@ -29,7 +29,7 @@ function owner(idx::GitIndex)
2929
return Base.get(idx.nrepo)
3030
end
3131

32-
function read_tree!(idx::GitIndex, tree_id::Oid)
32+
function read_tree!(idx::GitIndex, tree_id::GitHash)
3333
repo = owner(idx)
3434
tree = get(GitTree, repo, tree_id)
3535
try

base/libgit2/libgit2.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ include("callbacks.jl")
3535
using .Error
3636

3737
immutable State
38-
head::Oid
39-
index::Oid
40-
work::Oid
38+
head::GitHash
39+
index::GitHash
40+
work::GitHash
4141
end
4242

43-
"""Return HEAD Oid as string"""
43+
"""Return HEAD GitHash as string"""
4444
function head(pkg::AbstractString)
4545
with(GitRepo, pkg) do repo
4646
string(head_oid(repo))
@@ -213,18 +213,18 @@ function branch!(repo::GitRepo, branch_name::AbstractString,
213213
if branch_rmt_ref === nothing
214214
with(head(repo)) do head_ref
215215
with(peel(GitCommit, head_ref)) do hrc
216-
Oid(hrc)
216+
GitHash(hrc)
217217
end
218218
end
219219
else
220220
tmpcmt = with(peel(GitCommit, branch_rmt_ref)) do hrc
221-
Oid(hrc)
221+
GitHash(hrc)
222222
end
223223
close(branch_rmt_ref)
224224
tmpcmt
225225
end
226226
else
227-
Oid(commit)
227+
GitHash(commit)
228228
end
229229
iszero(commit_id) && return
230230
cmt = get(GitCommit, repo, commit_id)
@@ -278,13 +278,13 @@ function checkout!(repo::GitRepo, commit::AbstractString = "";
278278
head_name = shortname(head_ref)
279279
# if it is HEAD use short OID instead
280280
if head_name == Consts.HEAD_FILE
281-
head_name = string(Oid(head_ref))
281+
head_name = string(GitHash(head_ref))
282282
end
283283
end
284284
end
285285

286286
# search for commit to get a commit object
287-
obj = get(GitUnknownObject, repo, Oid(commit))
287+
obj = get(GitUnknownObject, repo, GitHash(commit))
288288
obj === nothing && return
289289
try
290290
peeled = peel(obj, Consts.OBJ_COMMIT)
@@ -293,7 +293,7 @@ function checkout!(repo::GitRepo, commit::AbstractString = "";
293293
CheckoutOptions()
294294
try
295295
# detach commit
296-
obj_oid = Oid(peeled)
296+
obj_oid = GitHash(peeled)
297297
ref = GitReference(repo, obj_oid, force=force,
298298
msg="libgit2.checkout: moving from $head_name to $(string(obj_oid))")
299299
close(ref)
@@ -340,7 +340,7 @@ function reset!(repo::GitRepo, committish::AbstractString, pathspecs::AbstractSt
340340
end
341341

342342
""" git reset [--soft | --mixed | --hard] <commit> """
343-
function reset!(repo::GitRepo, commit::Oid, mode::Cint = Consts.RESET_MIXED)
343+
function reset!(repo::GitRepo, commit::GitHash, mode::Cint = Consts.RESET_MIXED)
344344
obj = get(GitUnknownObject, repo, commit)
345345
# object must exist for reset
346346
obj === nothing && throw(GitError(Error.Object, Error.ERROR, "Commit `$(string(commit))` object not found"))
@@ -425,7 +425,7 @@ function merge!(repo::GitRepo;
425425
LibGit2.get(String, cfg, "branch.$branchname.remote")
426426
end
427427
obj = with(GitReference(repo, "refs/remotes/$remotename/$branchname")) do ref
428-
LibGit2.Oid(ref)
428+
LibGit2.GitHash(ref)
429429
end
430430
with(get(GitCommit, repo, obj)) do cmt
431431
LibGit2.create_branch(repo, branchname, cmt)
@@ -528,7 +528,7 @@ function authors(repo::GitRepo)
528528
end
529529

530530
function snapshot(repo::GitRepo)
531-
head = Oid(repo, Consts.HEAD_FILE)
531+
head = GitHash(repo, Consts.HEAD_FILE)
532532
index = with(GitIndex, repo) do idx; write_tree!(idx) end
533533
work = try
534534
with(GitIndex, repo) do idx

base/libgit2/merge.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# This file is a part of Julia. License is MIT: http://julialang.org/license
22

3-
function GitAnnotated(repo::GitRepo, commit_id::Oid)
3+
function GitAnnotated(repo::GitRepo, commit_id::GitHash)
44
ann_ptr_ptr = Ref{Ptr{Void}}(C_NULL)
55
@check ccall((:git_annotated_commit_lookup, :libgit2), Cint,
6-
(Ptr{Ptr{Void}}, Ptr{Void}, Ptr{Oid}),
6+
(Ptr{Ptr{Void}}, Ptr{Void}, Ptr{GitHash}),
77
ann_ptr_ptr, repo.ptr, Ref(commit_id))
88
return GitAnnotated(repo, ann_ptr_ptr[])
99
end
@@ -19,7 +19,7 @@ end
1919
function GitAnnotated(repo::GitRepo, fh::FetchHead)
2020
ann_ref_ref = Ref{Ptr{Void}}(C_NULL)
2121
@check ccall((:git_annotated_commit_from_fetchhead, :libgit2), Cint,
22-
(Ptr{Ptr{Void}}, Ptr{Void}, Cstring, Cstring, Ptr{Oid}),
22+
(Ptr{Ptr{Void}}, Ptr{Void}, Cstring, Cstring, Ptr{GitHash}),
2323
ann_ref_ref, repo.ptr, fh.name, fh.url, Ref(fh.oid))
2424
return GitAnnotated(repo, ann_ref_ref[])
2525
end
@@ -29,14 +29,14 @@ function GitAnnotated(repo::GitRepo, comittish::AbstractString)
2929
try
3030
cmt = peel(obj, Consts.OBJ_COMMIT)
3131
cmt === nothing && return nothing
32-
return GitAnnotated(repo, Oid(cmt))
32+
return GitAnnotated(repo, GitHash(cmt))
3333
finally
3434
close(obj)
3535
end
3636
end
3737

3838
function commit(ann::GitAnnotated)
39-
return Oid(ccall((:git_annotated_commit_id, :libgit2), Ptr{Oid}, (Ptr{Void},), ann.ptr))
39+
return GitHash(ccall((:git_annotated_commit_id, :libgit2), Ptr{GitHash}, (Ptr{Void},), ann.ptr))
4040
end
4141

4242
function merge_analysis(repo::GitRepo, anns::Vector{GitAnnotated})
@@ -58,7 +58,7 @@ function ffmerge!(repo::GitRepo, ann::GitAnnotated)
5858
try
5959
checkout_tree(repo, cmt)
6060
with(head(repo)) do head_ref
61-
cmt_oid = Oid(cmt)
61+
cmt_oid = GitHash(cmt)
6262
msg = "libgit2.merge: fastforward $(string(cmt_oid)) into $(name(head_ref))"
6363
new_head_ref = if reftype(head_ref) == Consts.REF_OID
6464
target!(head_ref, cmt_oid, msg=msg)
@@ -148,17 +148,17 @@ function merge!(repo::GitRepo, anns::Vector{GitAnnotated}, fastforward::Bool;
148148
end
149149

150150
function merge_base(repo::GitRepo, one::AbstractString, two::AbstractString)
151-
oid1_ptr = Ref(Oid(one))
152-
oid2_ptr = Ref(Oid(two))
153-
moid_ptr = Ref(Oid())
151+
oid1_ptr = Ref(GitHash(one))
152+
oid2_ptr = Ref(GitHash(two))
153+
moid_ptr = Ref(GitHash())
154154
moid = try
155155
@check ccall((:git_merge_base, :libgit2), Cint,
156-
(Ptr{Oid}, Ptr{Void}, Ptr{Oid}, Ptr{Oid}),
156+
(Ptr{GitHash}, Ptr{Void}, Ptr{GitHash}, Ptr{GitHash}),
157157
moid_ptr, repo.ptr, oid1_ptr, oid2_ptr)
158158
moid_ptr[]
159159
catch e
160160
#warn("Pkg:",path(repo),"=>",e.msg)
161-
Oid()
161+
GitHash()
162162
end
163163
return moid
164164
end

base/libgit2/oid.jl

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,88 @@
11
# This file is a part of Julia. License is MIT: http://julialang.org/license
22

3-
Oid(id::Oid) = id
4-
Oid(ptr::Ptr{Oid}) = unsafe_load(ptr)::Oid
3+
GitHash(id::GitHash) = id
4+
GitHash(ptr::Ptr{GitHash}) = unsafe_load(ptr)::GitHash
55

6-
function Oid(ptr::Ptr{UInt8})
6+
function GitHash(ptr::Ptr{UInt8})
77
if ptr == C_NULL
8-
throw(ArgumentError("NULL pointer passed to Oid() constructor"))
8+
throw(ArgumentError("NULL pointer passed to GitHash() constructor"))
99
end
10-
oid_ptr = Ref(Oid())
11-
ccall((:git_oid_fromraw, :libgit2), Void, (Ptr{Oid}, Ptr{UInt8}), oid_ptr, ptr)
10+
oid_ptr = Ref(GitHash())
11+
ccall((:git_oid_fromraw, :libgit2), Void, (Ptr{GitHash}, Ptr{UInt8}), oid_ptr, ptr)
1212
return oid_ptr[]
1313
end
1414

15-
function Oid(id::Array{UInt8,1})
15+
function GitHash(id::Array{UInt8,1})
1616
if length(id) != OID_RAWSZ
1717
throw(ArgumentError("invalid raw buffer size"))
1818
end
19-
return Oid(pointer(id))
19+
return GitHash(pointer(id))
2020
end
2121

22-
function Oid(id::AbstractString)
22+
function GitHash(id::AbstractString)
2323
bstr = String(id)
2424
len = sizeof(bstr)
25-
oid_ptr = Ref(Oid())
25+
oid_ptr = Ref(GitHash())
2626
err = if len < OID_HEXSZ
2727
ccall((:git_oid_fromstrn, :libgit2), Cint,
28-
(Ptr{Oid}, Ptr{UInt8}, Csize_t), oid_ptr, bstr, len)
28+
(Ptr{GitHash}, Ptr{UInt8}, Csize_t), oid_ptr, bstr, len)
2929
else
3030
ccall((:git_oid_fromstrp, :libgit2), Cint,
31-
(Ptr{Oid}, Cstring), oid_ptr, bstr)
31+
(Ptr{GitHash}, Cstring), oid_ptr, bstr)
3232
end
33-
err != 0 && return Oid()
33+
err != 0 && return GitHash()
3434
return oid_ptr[]
3535
end
3636

37-
function Oid(ref::GitReference)
38-
isempty(ref) && return Oid()
39-
reftype(ref) != Consts.REF_OID && return Oid()
37+
function GitHash(ref::GitReference)
38+
isempty(ref) && return GitHash()
39+
reftype(ref) != Consts.REF_OID && return GitHash()
4040
oid_ptr = ccall((:git_reference_target, :libgit2), Ptr{UInt8}, (Ptr{Void},), ref.ptr)
41-
oid_ptr == C_NULL && return Oid()
42-
return Oid(oid_ptr)
41+
oid_ptr == C_NULL && return GitHash()
42+
return GitHash(oid_ptr)
4343
end
4444

45-
function Oid(repo::GitRepo, ref_name::AbstractString)
46-
isempty(repo) && return Oid()
47-
oid_ptr = Ref(Oid())
45+
function GitHash(repo::GitRepo, ref_name::AbstractString)
46+
isempty(repo) && return GitHash()
47+
oid_ptr = Ref(GitHash())
4848
@check ccall((:git_reference_name_to_id, :libgit2), Cint,
49-
(Ptr{Oid}, Ptr{Void}, Cstring),
49+
(Ptr{GitHash}, Ptr{Void}, Cstring),
5050
oid_ptr, repo.ptr, ref_name)
5151
return oid_ptr[]
5252
end
5353

54-
function Oid(obj::Ptr{Void})
54+
function GitHash(obj::Ptr{Void})
5555
oid_ptr = ccall((:git_object_id, :libgit2), Ptr{UInt8}, (Ptr{Void},), obj)
56-
oid_ptr == C_NULL && return Oid()
57-
return Oid(oid_ptr)
56+
oid_ptr == C_NULL && return GitHash()
57+
return GitHash(oid_ptr)
5858
end
5959

60-
function Oid{T<:GitObject}(obj::T)
61-
obj === nothing && return Oid()
62-
return Oid(obj.ptr)
60+
function GitHash{T<:GitObject}(obj::T)
61+
obj === nothing && return GitHash()
62+
return GitHash(obj.ptr)
6363
end
6464

65-
Base.hex(id::Oid) = join([hex(i,2) for i in id.val])
65+
Base.hex(id::GitHash) = join([hex(i,2) for i in id.val])
6666

67-
raw(id::Oid) = collect(id.val)
67+
raw(id::GitHash) = collect(id.val)
6868

69-
Base.string(id::Oid) = hex(id)
69+
Base.string(id::GitHash) = hex(id)
7070

71-
Base.show(io::IO, id::Oid) = print(io, "Oid($(string(id)))")
71+
Base.show(io::IO, id::GitHash) = print(io, "GitHash($(string(id)))")
7272

73-
Base.hash(id::Oid, h::UInt) = hash(id.val, h)
73+
Base.hash(id::GitHash, h::UInt) = hash(id.val, h)
7474

75-
cmp(id1::Oid, id2::Oid) = Int(ccall((:git_oid_cmp, :libgit2), Cint,
76-
(Ptr{Oid}, Ptr{Oid}), Ref(id1), Ref(id2)))
75+
cmp(id1::GitHash, id2::GitHash) = Int(ccall((:git_oid_cmp, :libgit2), Cint,
76+
(Ptr{GitHash}, Ptr{GitHash}), Ref(id1), Ref(id2)))
7777

78-
==(id1::Oid, id2::Oid) = cmp(id1, id2) == 0
79-
Base.isless(id1::Oid, id2::Oid) = cmp(id1, id2) < 0
78+
==(id1::GitHash, id2::GitHash) = cmp(id1, id2) == 0
79+
Base.isless(id1::GitHash, id2::GitHash) = cmp(id1, id2) < 0
8080

81-
function iszero(id::Oid)
81+
function iszero(id::GitHash)
8282
for i in 1:OID_RAWSZ
8383
id.val[i] != zero(UInt8) && return false
8484
end
8585
return true
8686
end
8787

88-
Base.zero(::Type{Oid}) = Oid()
88+
Base.zero(::Type{GitHash}) = GitHash()

0 commit comments

Comments
 (0)