Skip to content
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

Merged
merged 6 commits into from
Jul 13, 2016

Conversation

wildart
Copy link
Member

@wildart wildart commented May 23, 2016

These functions are required for reading repository blobs.

@kshyatt kshyatt added the test This change adds or pertains to unit tests label May 23, 2016
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused?

Copy link
Member Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer accurate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

darn, sorry

Copy link
Contributor

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?

@wildart wildart force-pushed the tree-funcs branch 2 times, most recently from b1079b9 to 3378600 Compare June 4, 2016 14:03
@kshyatt kshyatt added the libgit2 The libgit2 library or the LibGit2 stdlib module label Jun 6, 2016
@wildart wildart force-pushed the tree-funcs branch 3 times, most recently from 8dfa0a7 to a5b21ea Compare June 14, 2016 00:30
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 ""
Copy link
Contributor

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?

@StefanKarpinski
Copy link
Member

I get the overall impression that our libgit2 bindings should be considerably more conservative with error handling. In general, any kind of failure should be propagated upwards or the system very rapidly becomes completely unreliable.

@wildart
Copy link
Member Author

wildart commented Jun 15, 2016

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"))
Copy link
Contributor

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

Copy link
Contributor

@tkelman tkelman Jun 15, 2016

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)
Copy link
Contributor

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?

Copy link
Member Author

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 ...

Copy link
Contributor

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?

Copy link
Member Author

@wildart wildart Jun 15, 2016

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.

@wildart
Copy link
Member Author

wildart commented Jun 16, 2016

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.

@wildart wildart force-pushed the tree-funcs branch 2 times, most recently from 4c963b8 to b107272 Compare June 22, 2016 14:10
@@ -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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOT TO BE MERGED

@wildart
Copy link
Member Author

wildart commented Jun 23, 2016

I look that OSX build uses libgit2 v0.23.4 which might be the source of troubles for tree tests.
@tkelman Is there a way to update homebrew libgit2 version to v0.24.1?

@tkelman
Copy link
Contributor

tkelman commented Jun 23, 2016

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"))
Copy link
Contributor

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

@wildart wildart changed the title LibGit2: added tree related functions & tests WIP: LibGit2: added tree related functions & tests Jun 29, 2016
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))
Copy link
Contributor

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)

@tkelman
Copy link
Contributor

tkelman commented Jul 13, 2016

still wip? this looks pretty good now, assuming it passes on osx / linux

@wildart wildart changed the title WIP: LibGit2: added tree related functions & tests LibGit2: added tree related functions & tests Jul 13, 2016
@wildart
Copy link
Member Author

wildart commented Jul 13, 2016

It's ready to merge.

@tkelman tkelman merged commit 2ea885c into JuliaLang:master Jul 13, 2016
@tkelman
Copy link
Contributor

tkelman commented Jul 13, 2016

osx travis is having all sorts of issues. hopefully this passes there when that comes back.

@tkelman
Copy link
Contributor

tkelman commented Jul 14, 2016

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libgit2 The libgit2 library or the LibGit2 stdlib module test This change adds or pertains to unit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants