-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Have git_branch_lookup accept GIT_BRANCH_ALL #5000
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
Conversation
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.
Cool! Thanks for tackling this. I have just a few minor issues to request that you address, if you don't mind.
src/branch.c
Outdated
break; | ||
case GIT_BRANCH_ALL: | ||
error = retrieve_branch_reference(ref_out, repo, branch_name, false); | ||
if (error < 0) |
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.
We should probably only retry when error == GIT_ENOTFOUND
, otherwise we might hide potentially fatal errors by ignoring them and doing something else.
src/branch.c
Outdated
error = retrieve_branch_reference(ref_out, repo, branch_name, true); | ||
break; | ||
default: | ||
abort(); |
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.
abort
is probably a bit harsh here. I think assert(0)
is a reasonable compromise that we've used in the past.
@@ -23,17 +23,22 @@ void test_refs_branches_lookup__cleanup(void) | |||
void test_refs_branches_lookup__can_retrieve_a_local_branch(void) | |||
{ | |||
cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL)); | |||
cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_ALL)); | |||
cl_git_fail(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_REMOTE)); | |||
} |
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.
You're leaking memory here, namely the results of the prior git_branch_lookup
that are hidden with the new assignment to branch
. Probably best to just make each one of these calls their own test function
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 scratching my head about that, thanks for the explanation 🙂.
Thanks a lot @ethomson for the review! |
Awesome, thanks @augfab for the PR! |
This PR is a proposed fix for issue #4938.