-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
LibGit2: added tree related functions & tests #16537
Conversation
You don't have to free it, but you must not use it after the `GitTree` is released. | ||
""" | ||
function lookup(tree::GitTree, fname::AbstractString) | ||
te_ptr_ptr = Ref{Ptr{Void}}(C_NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep
"Get the filename of a tree entry." | ||
"""Returns a file name, as a `String`, of a tree entry. | ||
|
||
In case of error, `nothing` is returned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no longer accurate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
darn, sorry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returning the empty string is also not that satisfying, what might cause this to error?
b1079b9
to
3378600
Compare
8dfa0a7
to
a5b21ea
Compare
function filename(te::GitTreeEntry) | ||
str = ccall((:git_tree_entry_name, :libgit2), Cstring, (Ptr{Void},), te.ptr) | ||
str != C_NULL && return unsafe_string(str) | ||
return nothing | ||
str == C_NULL && return "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this not an error? are there entries that have no name?
I get the overall impression that our |
I like an idea of using nullable types despite unfortunately long type names. |
str == C_NULL && return "" | ||
str == C_NULL && throw(Error.GitError(Error.Tree, | ||
LibGit2.Error.ENOTFOUND, | ||
"Entry file name is not found")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just say "not found," present tense is a bit off for an error message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant " not found", just drop the "is" - it's still useful to differentiate what wasn't found
end | ||
@test startswith(tfcontent, commit_msg1) | ||
finally | ||
finalize(tfte2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it necessary to have 3 nested finally blocks or could they be combined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, that what you do when you need to be sure that resource is going to be freed. I could replace it with LibGit2.with
call to make it more eye pleasing, but it is the same try block.
If only julia would have something similar to go-lang defer
statement ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay so some of the immediately following tests require these to have been cleaned up already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tree entries need to be freed before the tree object is freed. But because entries created in try-block, a new try-block is created for finalizing them. All of it can be rearranged so finalization can be postponed as much as possible. I usually free the object as early as possible - that is what LibGit2.with
does.
Something really strange with the OSX build, it gives a different error every time I run the test job. Today, it's memory handling error, yesterday one test failed. |
4c963b8
to
b107272
Compare
@@ -68,7 +68,7 @@ before_install: | |||
gcc --version; | |||
BUILDOPTS="-j3 VERBOSE=1 FORCE_ASSERTIONS=1 LLVM_ASSERTIONS=1"; | |||
echo "override ARCH=$ARCH" >> Make.user; | |||
TESTSTORUN="all"; | |||
TESTSTORUN="libgit2"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOT TO BE MERGED
I look that OSX build uses libgit2 v0.23.4 which might be the source of troubles for tree tests. |
See Homebrew/homebrew-core#492, annoyingly needs to wait for homebrew to update all of gnome because there's a libgit2-glib package that depends on it. Have I ranted lately about how homebrew's versioning practices (or lack thereof) annoy me? If needed we could maybe host our own copy of the libgit2 formula and update that faster in the homebrew-juliadeps tap. edit: looks like this was finished up in homebrew not long after I posted this |
str != C_NULL && return unsafe_string(str) | ||
return nothing | ||
str == C_NULL && throw(Error.GitError(Error.Tree, | ||
LibGit2.Error.ENOTFOUND, "not found")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should still say what was not found if this same message is used in multiple places
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to use lookup_branch
the other day, that would be another good one to make return nullable (ref #17364 where something is pretty broken)
still wip? this looks pretty good now, assuming it passes on osx / linux |
It's ready to merge. |
osx travis is having all sorts of issues. hopefully this passes there when that comes back. |
I think I spoke too soon, looks like this has been causing segfaults on osx in the libgit2 test since it was merged. I think we should revert for now if you don't have a fix. Can anyone reproduce locally? |
These functions are required for reading repository blobs.