Skip to content

Commit 74cf1b1

Browse files
authored
Revert "LibGit2: added tree related functions & tests"
1 parent b7abcd2 commit 74cf1b1

File tree

3 files changed

+19
-128
lines changed

3 files changed

+19
-128
lines changed

base/libgit2/tree.jl

+5-60
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This file is a part of Julia. License is MIT: http://julialang.org/license
22

3-
"""Traverse the entries in a tree and its subtrees in post or preorder.
3+
"""
4+
Traverse the entries in a tree and its subtrees in post or pre order.
45
56
Function parameter should have following signature:
67
@@ -15,77 +16,21 @@ function treewalk(f::Function, tree::GitTree, payload=Any[], post::Bool = false)
1516
return cbf_payload
1617
end
1718

18-
"Returns a file name, as a `String`, of a tree entry."
1919
function filename(te::GitTreeEntry)
2020
str = ccall((:git_tree_entry_name, :libgit2), Cstring, (Ptr{Void},), te.ptr)
21-
str == C_NULL && throw(Error.GitError(Error.Tree,
22-
LibGit2.Error.ENOTFOUND, "filename not found"))
23-
return unsafe_string(str)
21+
str != C_NULL && return unsafe_string(str)
22+
return nothing
2423
end
2524

26-
"Returns UNIX file attributes, as a `Cint`, of a tree entry."
2725
function filemode(te::GitTreeEntry)
2826
return ccall((:git_tree_entry_filemode, :libgit2), Cint, (Ptr{Void},), te.ptr)
2927
end
3028

31-
"Returns a `GitAnyObject` which is referenced by a tree entry."
29+
3230
function object(repo::GitRepo, te::GitTreeEntry)
3331
obj_ptr_ptr = Ref{Ptr{Void}}(C_NULL)
3432
@check ccall((:git_tree_entry_to_object, :libgit2), Cint,
3533
(Ptr{Ptr{Void}}, Ptr{Void}, Ref{Void}),
3634
obj_ptr_ptr, repo.ptr, te.ptr)
3735
return GitAnyObject(obj_ptr_ptr[])
3836
end
39-
40-
"Returns an object identifier, as a `Oid`, of a tree entry."
41-
function oid(te::GitTreeEntry)
42-
oid_ptr = ccall((:git_tree_entry_id, :libgit2), Ptr{Oid}, (Ptr{Void},), te.ptr)
43-
oid_ptr == C_NULL && throw(Error.GitError(Error.Tree,
44-
LibGit2.Error.ENOTFOUND, "oid not found"))
45-
return Oid(oid_ptr)
46-
end
47-
48-
"""Retrieve a tree entry contained in a tree or in any of its subtrees, given its relative path.
49-
50-
The returned tree entry is owned by the user and must be freed explicitly.
51-
"""
52-
function GitTreeEntry(tree::GitTree, tepath::AbstractString)
53-
te_ptr_ptr = Ref{Ptr{Void}}(C_NULL)
54-
err = ccall((:git_tree_entry_bypath, :libgit2), Cint,
55-
(Ptr{Ptr{Void}}, Ref{Void}, Cstring),
56-
te_ptr_ptr, tree.ptr, tepath)
57-
if err == Cint(Error.ENOTFOUND)
58-
return Nullable{GitTreeEntry}()
59-
elseif err != Cint(Error.GIT_OK)
60-
if te_ptr_ptr[] != C_NULL
61-
finalize(GitTreeEntry(te_ptr_ptr[]))
62-
end
63-
throw(Error.GitError(err))
64-
end
65-
return Nullable(GitTreeEntry(te_ptr_ptr[]))
66-
end
67-
68-
"""Lookup a tree entry by SHA value.
69-
70-
This returns a `GitTreeEntry` that is owned by the `GitTree`.
71-
You don't have to free it, but you must not use it after the `GitTree` is released.
72-
"""
73-
function GitTreeEntry(tree::GitTree, teoid::Oid)
74-
res = ccall((:git_tree_entry_byid, :libgit2), Ptr{Void},
75-
(Ref{Void}, Ref{Oid}),
76-
tree.ptr, Ref(teoid))
77-
res == C_NULL && return Nullable{GitTreeEntry}()
78-
return Nullable(GitTreeEntry(res))
79-
end
80-
81-
"""Lookup a tree entry by its file name.
82-
83-
This returns a `GitTreeEntry` that is owned by the `GitTree`.
84-
You don't have to free it, but you must not use it after the `GitTree` is released.
85-
"""
86-
function lookup(tree::GitTree, fname::AbstractString)
87-
res = ccall((:git_tree_entry_byname, :libgit2), Ptr{Void},
88-
(Ref{Void}, Cstring), tree.ptr, fname)
89-
res == C_NULL && return Nullable{GitTreeEntry}()
90-
return Nullable(GitTreeEntry(res))
91-
end

base/libgit2/types.jl

+14-15
Original file line numberDiff line numberDiff line change
@@ -625,25 +625,24 @@ for (typ, ref, sup, fnc) in (
625625
(:GitTag, :Void, :GitObject, nothing)
626626
)
627627

628-
@eval begin
629-
type $typ <: $sup
630-
ptr::Ptr{$ref}
631-
function $typ(ptr::Ptr{$ref})
632-
@assert ptr != C_NULL
633-
obj = new(ptr)
634-
return obj
635-
end
628+
@eval type $typ <: $sup
629+
ptr::Ptr{$ref}
630+
function $typ(ptr::Ptr{$ref})
631+
@assert ptr != C_NULL
632+
obj = new(ptr)
633+
return obj
636634
end
637-
if $fnc !== nothing
638-
function Base.finalize(obj::$typ)
639-
if obj.ptr != C_NULL
640-
ccall(($fnc, :libgit2), Void, (Ptr{$ref},), obj.ptr)
641-
obj.ptr = C_NULL
642-
end
635+
end
636+
637+
if fnc !== nothing
638+
@eval function Base.finalize(obj::$typ)
639+
if obj.ptr != C_NULL
640+
ccall(($fnc, :libgit2), Void, (Ptr{$ref},), obj.ptr)
641+
obj.ptr = C_NULL
643642
end
644-
Base.finalize(obj::Nullable{$typ}) = !isnull(obj) && Base.finalize(Base.get(obj))
645643
end
646644
end
645+
647646
end
648647

649648
# Structure has the same layout as SignatureStruct

test/libgit2.jl

-53
Original file line numberDiff line numberDiff line change
@@ -443,59 +443,6 @@ mktempdir() do dir
443443
end
444444
#end
445445

446-
#@testset "tree" begin
447-
function addfile(root::Cstring, tentry::Ptr{Void}, payload::Ptr{Void})
448-
strarr = unsafe_pointer_to_objref(payload)
449-
sroot = unsafe_string(root)
450-
te = LibGit2.GitTreeEntry(tentry)
451-
fmode = LibGit2.filemode(te)
452-
fname = LibGit2.filename(te)
453-
if fmode == Cint(LibGit2.Consts.FILEMODE_BLOB)
454-
push!(strarr, fname)
455-
end
456-
return zero(Cint)
457-
end
458-
459-
repo = LibGit2.GitRepo(test_repo)
460-
head = LibGit2.head(repo)
461-
ht = LibGit2.peel(LibGit2.GitTree, head)
462-
try
463-
@test isnull(LibGit2.lookup(ht, "no such name"))
464-
tfte = get(LibGit2.lookup(ht, test_file))
465-
466-
# get tree entry by filename
467-
@test isnull(LibGit2.GitTreeEntry(ht, "no such name"))
468-
@test LibGit2.filename(tfte) == test_file
469-
@test LibGit2.filemode(tfte) == Cint(LibGit2.Consts.FILEMODE_BLOB)
470-
471-
tfoid = LibGit2.oid(tfte)
472-
473-
@test isnull(LibGit2.GitTreeEntry(ht, LibGit2.Oid()))
474-
tfte2 = LibGit2.GitTreeEntry(ht, tfoid)
475-
try
476-
@test !isnull(tfte2)
477-
@test LibGit2.filename(get(tfte2)) == test_file
478-
479-
tfcontent = LibGit2.with(LibGit2.object(repo, get(tfte2))) do obj
480-
LibGit2.with(LibGit2.peel(LibGit2.GitBlob, obj)) do blob
481-
unsafe_string(convert(Cstring, LibGit2.content(blob)))
482-
end
483-
end
484-
@test startswith(tfcontent, commit_msg1)
485-
finally
486-
finalize(tfte2)
487-
end
488-
489-
entrs = LibGit2.treewalk(addfile, ht, String[])[]
490-
@test length(find(e->e == test_file, entrs)) == 1
491-
492-
finally
493-
finalize(ht)
494-
finalize(head)
495-
finalize(repo)
496-
end
497-
#end
498-
499446
#@testset "commits with revwalk" begin
500447
repo = LibGit2.GitRepo(test_repo)
501448
cache = LibGit2.GitRepo(cache_repo)

0 commit comments

Comments
 (0)