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

At least WARN if revparse{id} fails #20136

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions base/libgit2/repository.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,25 @@ end
""" Returns a found object """
function revparse(repo::GitRepo, objname::AbstractString)
obj_ptr_ptr = Ref{Ptr{Void}}(C_NULL)
err = ccall((:git_revparse_single, :libgit2), Cint,
(Ptr{Ptr{Void}}, Ptr{Void}, Cstring), obj_ptr_ptr, repo.ptr, objname)
err != 0 && return nothing
@check ccall((:git_revparse_single, :libgit2), Cint,
(Ptr{Ptr{Void}}, Ptr{Void}, Cstring), obj_ptr_ptr, repo.ptr, objname)
return GitUnknownObject(repo, obj_ptr_ptr[])
end

""" Returns id of a found object """
function revparseid(repo::GitRepo, objname::AbstractString)
obj = revparse(repo, objname)
obj === nothing && return GitHash()
local obj
try
obj = revparse(repo, objname)
Copy link
Contributor

Choose a reason for hiding this comment

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

How frequently does this get called? a try-catch might be fairly expensive. Is there a specific return code for "not found" in git_revparse_single ? I'd prefer returning a Nullable in the not found case if there's a specific return code for it, and throwing any other types of errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tkelman there are a few specific options, see here. It can be not found, ambiguous, invalid spec, or something else.

Copy link
Contributor

Choose a reason for hiding this comment

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

we shouldn't be returning status codes only via the warning display, that's very side-channel and not useful

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, should we throw an error then? And let things that call revparseid do their own try and catch?

Copy link
Contributor

Choose a reason for hiding this comment

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

There are a few ways we could go here, and the best option depends on how the surrounding code is structured and which direction we generally want to go in with these binding API's. Are all of the possible not-found conditions errors, or should it be recoverable? Exceptions for control flow in the latter case should be avoided, we could do something with a nullable and/or also return the status code so the callers can decide what to do if things aren't found.

catch err
if isa(err, GitError)
warn("Problem in revparse for $objname:")
show(err)
return GitHash()
else
rethrow(err)
end
end
oid = GitHash(obj.ptr)
close(obj)
return oid
Expand Down