Skip to content

Have git_branch_lookup accept GIT_BRANCH_ALL#5000

Merged
ethomson merged 2 commits intolibgit2:masterfrom
augfab:branch_lookup_all
Feb 25, 2019
Merged

Have git_branch_lookup accept GIT_BRANCH_ALL#5000
ethomson merged 2 commits intolibgit2:masterfrom
augfab:branch_lookup_all

Conversation

@augfab
Copy link
Copy Markdown
Contributor

@augfab augfab commented Feb 21, 2019

This PR is a proposed fix for issue #4938.

Copy link
Copy Markdown
Member

@ethomson ethomson left a 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.

Comment thread src/branch.c Outdated
break;
case GIT_BRANCH_ALL:
error = retrieve_branch_reference(ref_out, repo, branch_name, false);
if (error < 0)
Copy link
Copy Markdown
Member

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.

Comment thread src/branch.c Outdated
error = retrieve_branch_reference(ref_out, repo, branch_name, true);
break;
default:
abort();
Copy link
Copy Markdown
Member

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.

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));
}
Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Contributor Author

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

@augfab
Copy link
Copy Markdown
Contributor Author

augfab commented Feb 22, 2019

Thanks a lot @ethomson for the review!
I'll submit a new branch soon.

@ethomson
Copy link
Copy Markdown
Member

Awesome, thanks @augfab for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants