Skip to content

Commit

Permalink
remove lookup until error fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
wildart committed Jun 23, 2016
1 parent d8e9957 commit a43635c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 28 deletions.
30 changes: 19 additions & 11 deletions base/libgit2/tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,22 @@ function GitTreeEntry(tree::GitTree, teoid::Oid)
return Nullable(GitTreeEntry(res))
end

"""Lookup a tree entry by its file name.
This returns a `GitTreeEntry` that is owned by the `GitTree`.
You don't have to free it, but you must not use it after the `GitTree` is released.
"""
function lookup(tree::GitTree, fname::AbstractString)
res = ccall((:git_tree_entry_byname, :libgit2), Ptr{Void},
(Ref{Void}, Cstring), tree.ptr, fname)
res == C_NULL && return Nullable{GitTreeEntry}()
return Nullable(GitTreeEntry(res))
end
# TODO: Investigate OSX error
# julia(13191,0x7fff7c331310) malloc:
# *** error for object 0x7f7f6d863560: pointer being freed was not allocated
# *** set a breakpoint in malloc_error_break to debug
# signal (6): Abort trap: 6
# while loading /private/tmp/julia/share/julia/test/libgit2.jl, in expression starting on line 464
# __pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
# Allocations: 3075053 (Pool: 3073930; Big: 1123); GC: 5
#
# """Lookup a tree entry by its file name.
# This returns a `GitTreeEntry` that is owned by the `GitTree`.
# You don't have to free it, but you must not use it after the `GitTree` is released.
# """
# function lookup(tree::GitTree, fname::AbstractString)
# res = ccall((:git_tree_entry_byname, :libgit2), Ptr{Void},
# (Ref{Void}, Cstring), tree.ptr, fname)
# res == C_NULL && return Nullable{GitTreeEntry}()
# return Nullable(GitTreeEntry(res))
# end
34 changes: 17 additions & 17 deletions test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -460,31 +460,31 @@ mktempdir() do dir
head = LibGit2.head(repo)
ht = LibGit2.peel(LibGit2.GitTree, head)
try
# @test isnull(LibGit2.lookup(ht, "no such name"))
# tfte = get(LibGit2.lookup(ht, test_file))

# get tree entry by filename
@test isnull(LibGit2.lookup(ht, "no such name"))
tfte = get(LibGit2.lookup(ht, test_file))
try
@test isnull(LibGit2.GitTreeEntry(ht, "no such name"))
tfoid = LibGit2.with(get(LibGit2.GitTreeEntry(ht, test_file))) do tfte
@test LibGit2.filename(tfte) == test_file
@test LibGit2.filemode(tfte) == Cint(LibGit2.Consts.FILEMODE_BLOB)
LibGit2.oid(tfte)
end

@test isnull(LibGit2.GitTreeEntry(ht, LibGit2.Oid()))
tfoid = LibGit2.oid(tfte)
tfte2 = LibGit2.GitTreeEntry(ht, tfoid)
try
@test !isnull(tfte2)
@test LibGit2.filename(get(tfte2)) == test_file
@test isnull(LibGit2.GitTreeEntry(ht, LibGit2.Oid()))
tfte2 = LibGit2.GitTreeEntry(ht, tfoid)
try
@test !isnull(tfte2)
@test LibGit2.filename(get(tfte2)) == test_file

tfcontent = LibGit2.with(LibGit2.object(repo, get(tfte2))) do obj
LibGit2.with(LibGit2.peel(LibGit2.GitBlob, obj)) do blob
unsafe_string(convert(Cstring, LibGit2.content(blob)))
end
tfcontent = LibGit2.with(LibGit2.object(repo, get(tfte2))) do obj
LibGit2.with(LibGit2.peel(LibGit2.GitBlob, obj)) do blob
unsafe_string(convert(Cstring, LibGit2.content(blob)))
end
@test startswith(tfcontent, commit_msg1)
finally
finalize(tfte2)
end
@test startswith(tfcontent, commit_msg1)
finally
finalize(tfte)
finalize(tfte2)
end

entrs = LibGit2.treewalk(addfile, ht, String[])[]
Expand Down

0 comments on commit a43635c

Please sign in to comment.