Skip to content

Commit ac9be3a

Browse files
simonbyrnetkelman
authored andcommitted
Fix Pkg require check (JuliaLang#20433)
* Fix Pkg require check Pkg previously used `iszero` as a check on the return value of `revparseid`. `revparseid` no longer returns a zero hash if the result does not exist. Fixes JuliaLang#20419. * fix another revparseid issue * remove extra paranthesis * Use the git index to check if REQUIRE exists. Also fix a few miscellaneous bugs. * add tests for GitObject specifiers * correct variable name
1 parent b3b4608 commit ac9be3a

File tree

6 files changed

+31
-9
lines changed

6 files changed

+31
-9
lines changed

base/libgit2/index.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ function Base.find(path::String, idx::GitIndex)
113113
pos_ref = Ref{Csize_t}(0)
114114
ret = ccall((:git_index_find, :libgit2), Cint,
115115
(Ref{Csize_t}, Ptr{Void}, Cstring), pos_ref, idx.ptr, path)
116-
ret == Error.ENOTFOUND && return Nullable{Csize_t}()
116+
ret == Cint(Error.ENOTFOUND) && return Nullable{Csize_t}()
117117
return Nullable(pos_ref[]+1)
118118
end
119119

120120
stage(ie::IndexEntry) = ccall((:git_index_entry_stage, :libgit2), Cint, (Ptr{IndexEntry},), Ref(ie))
121121

122122
function Base.show(io::IO, idx::GitIndex)
123-
println(io, "GitIndex:\nRepository: ", repository(idk), "\nNumber of elements: ", count(idx))
123+
println(io, "GitIndex:\nRepository: ", repository(idx), "\nNumber of elements: ", count(idx))
124124
end

base/libgit2/libgit2.jl

+1-3
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ tracked files in the working tree (if `cached=false`) or the index (if `cached=t
110110
Equivalent to `git diff-index <treeish> [-- <pathspecs>]`.
111111
"""
112112
function isdiff(repo::GitRepo, treeish::AbstractString, paths::AbstractString=""; cached::Bool=false)
113-
tree_oid = revparseid(repo, "$treeish^{tree}")
114-
result = false
115-
tree = GitTree(repo, tree_oid)
113+
tree = GitTree(repo, "$treeish^{tree}")
116114
try
117115
diff = diff_tree(repo, tree, paths, cached=cached)
118116
result = count(diff) > 0

base/libgit2/repository.jl

+5
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ function (::Type{T}){T<:GitObject}(repo::GitRepo, spec::AbstractString)
100100
obj_ptr_ptr = Ref{Ptr{Void}}(C_NULL)
101101
@check ccall((:git_revparse_single, :libgit2), Cint,
102102
(Ptr{Ptr{Void}}, Ptr{Void}, Cstring), obj_ptr_ptr, repo.ptr, spec)
103+
# check object is of correct type
104+
if T != GitObject && T != GitUnknownObject
105+
t = Consts.OBJECT(obj_ptr_ptr[])
106+
t == Consts.OBJECT(T) || throw(GitError(Error.Object, Error.ERROR, "Expected object of type $T, received object of type $(objtype(t))"))
107+
end
103108
return T(repo, obj_ptr_ptr[])
104109
end
105110

base/libgit2/types.jl

+4-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ end
535535

536536
## Calling `GitObject(repo, ...)` will automatically resolve to the appropriate type.
537537
function GitObject(repo::GitRepo, ptr::Ptr{Void})
538-
T = objtype(ccall((:git_object_type, :libgit2), Consts.OBJECT, (Ptr{Void},), ptr))
538+
T = objtype(Consts.OBJECT(ptr))
539539
T(repo, ptr)
540540
end
541541

@@ -602,6 +602,9 @@ Consts.OBJECT(::Type{GitTag}) = Consts.OBJ_TAG
602602
Consts.OBJECT(::Type{GitUnknownObject}) = Consts.OBJ_ANY
603603
Consts.OBJECT(::Type{GitObject}) = Consts.OBJ_ANY
604604

605+
Consts.OBJECT(ptr::Ptr{Void}) =
606+
ccall((:git_object_type, :libgit2), Consts.OBJECT, (Ptr{Void},), ptr)
607+
605608
"""
606609
objtype(obj_type::Consts.OBJECT)
607610

base/pkg/read.jl

+6-3
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ function isfixed(pkg::AbstractString, prepo::LibGit2.GitRepo, avail::Dict=availa
6464
LibGit2.isdirty(prepo) && return true
6565
LibGit2.isattached(prepo) && return true
6666
LibGit2.need_update(prepo)
67-
LibGit2.iszero(LibGit2.revparseid(prepo, "HEAD:REQUIRE")) && isfile(pkg,"REQUIRE") && return true
68-
67+
if isnull(find("REQUIRE", LibGit2.GitIndex(prepo)))
68+
isfile(pkg,"REQUIRE") && return true
69+
end
6970
head = string(LibGit2.head_oid(prepo))
7071
for (ver,info) in avail
7172
head == info.sha1 && return false
@@ -182,7 +183,9 @@ function requires_path(pkg::AbstractString, avail::Dict=available(pkg))
182183
head = LibGit2.with(LibGit2.GitRepo, pkg) do repo
183184
LibGit2.isdirty(repo, "REQUIRE") && return pkgreq
184185
LibGit2.need_update(repo)
185-
LibGit2.iszero(LibGit2.revparseid(repo, "HEAD:REQUIRE")) && isfile(pkgreq) && return pkgreq
186+
if isnull(find("REQUIRE", LibGit2.GitIndex(repo)))
187+
isfile(pkgreq) && return pkgreq
188+
end
186189
string(LibGit2.head_oid(repo))
187190
end
188191
for (ver,info) in avail

test/libgit2.jl

+13
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,16 @@ mktempdir() do dir
454454
close(repo)
455455
end
456456
end
457+
@testset "trees" begin
458+
repo = LibGit2.GitRepo(cache_repo)
459+
try
460+
@test_throws LibGit2.Error.GitError LibGit2.GitTree(repo, "HEAD")
461+
@test isa(LibGit2.GitTree(repo, "HEAD^{tree}"), LibGit2.GitTree)
462+
@test isa(LibGit2.GitObject(repo, "HEAD^{tree}"), LibGit2.GitTree)
463+
finally
464+
close(repo)
465+
end
466+
end
457467

458468
@testset "diff" begin
459469
repo = LibGit2.GitRepo(cache_repo)
@@ -596,6 +606,9 @@ mktempdir() do dir
596606
i = find(test_file, idx)
597607
@test !isnull(i)
598608
@test idx[get(i)] !== nothing
609+
610+
i = find("zzz", idx)
611+
@test isnull(i)
599612
end
600613

601614
# check non-existent file status

0 commit comments

Comments
 (0)