8000 object: git_object_short_id fails with core.abbrev string values by lrm29 · Pull Request #6944 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

object: git_object_short_id fails with core.abbrev string values #6944

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. 8000 We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 12, 2024

Conversation

lrm29
Copy link
Contributor
@lrm29 lrm29 commented Nov 20, 2024

Fixes #6878.

Not sure if I went to far here, I noticed core.abbrev was used by diff_print.c. If the user sets core.abbrev to an integer outside of the allowed range that will now error.

I also added GIT_ABBREV_MINIMUM, which Git sets to 4. libgit2 was allowing anything above zero.

git_error_set(GIT_ERROR_CONFIG, "invalid oid abbreviation setting: '%d'", len);
return -1;
if ((size_t)len == oid_hexsize) {
if ((error = git_oid_cpy(&id, &obj->cached.oid)) < 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we early return here?

@@ -520,13 +520,38 @@ int git_object_lookup_bypath(
return error;
}

int git_object__abbrev_length(int *out, git_repository *repo)
Copy link
Member

Choose a reason for hiding this comment

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

I think that probably this should be in the git_repository group, instead of git_object. (It's really about the repository's abbreviation settings.) This is a minor nit, and I've kept you waiting on a review for a long time, so I'm happy to make this change later today if you prefer. 🙏

Thanks for investigating and fixing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will move to git_repository__abbrev_length. I just happened to run into this issue and used it to get more practice with C, no rush :)

@ethomson
Copy link
Member

Wow, there's some fun things going on here in git compatibility land:

  1. core.abbrev=0 (an integer value) fails, but core.abbrev=false (a boolean value) succeeds.
  2. core 8000 .abbrev=999 succeeds (clamping to the max oid length)

:sigh:

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

Some notes after poking with this in the context of git itself.

@lrm29
Copy link
Contributor Author
lrm29 commented Dec 11, 2024

Wow, there's some fun things going on here in git compatibility land:

1. `core.abbrev=0` (an integer value) fails, but `core.abbrev=false` (a boolean value) succeeds.

2. `core.abbrev=999` succeeds (clamping to the max oid length)

:sigh:

Good spots.

  1. I missed that, git has a git_parse_maybe_bool_text which doesn't allow 0.

  2. Erroring was the existing libgit2 behaviour right? But Git compatibility wins...

@ethomson
Copy link
Member

But Git compatibility wins...

We aim to be bug-for-bug compatible. 🤣 😭

@ethomson
Copy link
Member

Thanks for the fix!

@ethomson ethomson merged commit 0bb7d45 into libgit2:main Dec 12, 2024
19 checks passed
@lrm29 lrm29 deleted the pr_6724 branch December 12, 2024 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

git_object_short_id fails with core.abbrev string values
2 participants
0