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

1.8.0 requires code changes around functions taking git_commit #6793

Open
carrotIndustries opened this issue Apr 9, 2024 · 2 comments
Open

Comments

@carrotIndustries
Copy link

Reproduction steps

Compile code that was written against version prior to 1.8.0 such as

https://github.com/horizon-eda/horizon/blob/5300ccd7f9ba81818eb34d9ffc1b8fe80df6c658/src/pool-prj-mgr/pool-mgr/pool_git_box.cpp#L634-L642

std::array<const git_commit *, 2> parents;
parents.at(0) = master_commit;
parents.at(1) = pr_commit;
if (git_commit_create(&new_commit_oid, repo, "HEAD", signature, signature, NULL,
                      ("merge pr " + std::to_string(pr_id)).c_str(), tree, parents.size(), parents.data())
    != 0) {
    throw std::runtime_error("error committing");
}
git_repository_state_cleanup(repo);

Expected behavior

Should compile, the release notes don't include any related breaking changes in that regard.

Actual behavior

Doesn't compile, see https://github.com/horizon-eda/horizon/actions/runs/8589355641/job/23582932883#step:6:559

The offending commit is cf19ddc

For the git_commit_create method, I'm not quite sure if this commit actually did the right thing:

  • As far as I can tell, git_commit_create should not have to modify the passed git_commit objects, so the const was in fact correct
  • I think const git_commit * const parents[] is what we need. This also doesn't have the compatibility problem

The current situation would require some annoying version check macros and casts to be compatible with versions prior to 1.8.0 and 1.8.0.

Version of libgit2 (release number or SHA1)

1.8.0

Operating system(s) tested

Linux

@ethomson
Copy link
Member

ethomson commented Apr 11, 2024

Right, I wasn't intending or expecting this change to be quite so troublesome. Indeed, I can imagine that C++ and const correctness would require some changes. I didn't realize that C++ enforced const correctness on extern C but that's little surprise as I'm not a C++ programmer and this is not a C++ library.

In any case, git_commits aren't const. They have an internal state that points into an internal cache, those pointers can change, and they're refcounted which will change. Making this const git_commit ** was a mistake in the first place, which you can see by the unnecessary casts that existed in the examples, etc.

However:

  1. There are a surprising number of places that take a const git_commit *. Which surprises me.
  2. I wasn't intending for this to be a breaking change. (Even if you are using C++.)

I need to have a deeper look at this, but I wanted to provide the rationale behind the change.

@carrotIndustries
Copy link
Author

For reference, I've added a workaround in the meantime: horizon-eda/horizon@af6c626

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

No branches or pull requests

2 participants