Thanks to visit codestin.com
Credit goes to github.com

Skip to content

git_repository_open_ext: fix handling of $GIT_NAMESPACE #3992

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

Merged
merged 1 commit into from
Nov 14, 2016

Conversation

joshtriplett
Copy link
Contributor

The existing code would set a namespace of "" (empty string) with
GIT_NAMESPACE unset. In a repository where refs/heads/namespaces/
exists, that can produce incorrect results. Detect that case and avoid
setting the namespace at all.

Since that makes the last assignment to error, and the previous
assignment can potentially get GIT_ENOTFOUND, set error to 0 explicitly
to prevent the call from incorrectly failing with GIT_ENOTFOUND.

Copy link
Member

@pks-t pks-t left a comment

Choose a reason for hiding this comment

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

The fix looks good, but I think previously existing code could be refactored a bit to improve readability here

if (error < 0)
goto error;
}
error = 0;
Copy link
Member

Choose a reason for hiding this comment

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

This looks a bit backwards here, as you are in fact not clearing the error of the leading block but instead the error from the previous git__getenv. It would be much clearer if you'd instead clear the error in the previous if (error == GIT_ENOTFOUND) condition, where we already call giterr_clear();.

Copy link
Member

Choose a reason for hiding this comment

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

An additional note, which is not your fault but might be improved when we're already touching this. I think the code would be nicer if you moved the call to git__getenv and setting the namespace together. So you could just move down getting the environment variable and then set the namespace based on the function's return value.

The existing code would set a namespace of "" (empty string) with
GIT_NAMESPACE unset.  In a repository where refs/heads/namespaces/
exists, that can produce incorrect results.  Detect that case and avoid
setting the namespace at all.

Since that makes the last assignment to error conditional, and the
previous assignment can potentially get GIT_ENOTFOUND, set error to 0
explicitly to prevent the call from incorrectly failing with
GIT_ENOTFOUND.
@joshtriplett
Copy link
Contributor Author

@pks-t Thanks for the review.

Updated to move the error handling to a clearer location.

@pks-t pks-t merged commit 2d20551 into libgit2:master Nov 14, 2016
@pks-t
Copy link
Member

pks-t commented Nov 14, 2016

Looks good now, thanks for this 👍

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