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

Make transport::Service Debug and add some HTTP constants from libgit2. #1069

Closed
wants to merge 2 commits into from

Conversation

vcfxb
Copy link
Contributor

@vcfxb vcfxb commented Jul 18, 2024

This PR adds a dependency on the http crate for the http::Method type, and adds some HTTP related constants defined in libgit2 at https://github.com/libgit2/libgit2/blob/2ecc8586f7eec4063b5da1563d0a33f9e9f9fcf7/src/libgit2/transports/http.c#L68-L95.

@ehuss
Copy link
Contributor

ehuss commented Jul 22, 2024

Can you say more about why this change would be added? What would it be used for?

Similar to my comment in #1066, adding a public dependency has a pretty high bar. Also, adding a new dependency also has a similar bar to reach of clearly justifying why the cost of adding it for all users is worth it.

@vcfxb
Copy link
Contributor Author

vcfxb commented Jul 22, 2024

This would be useful for users implementing their own git transport using one of rust's http(s) libraries (i.e. ureq, reqwest, etc). The headers and methods used by git protocol over http(s) are the same regardless of the client/implementation/etc, so making those available to anyone writing their own transport saves them from having to implement essentially identical functions.

I think it's super fair to not want to add more public dependencies (due to the cost downstream to match the version and have an extra crate to compile).

The solutions here are either to gate anything using/exposing the http crate behind a feature flag (thus making the dependency on the http crate optional, off by default), or replace the use of http::Method with a bespoke enum native to the git2 crate (eliminating the need to depend on http at all).

src/transport.rs Show resolved Hide resolved
/// The value of the HTTP "Accept" header that is used by libgit2's implementation for http(s) transport.
pub const fn http_accept_header(self) -> &'static str {
match self {
Service::UploadPackLs => "application/x-git-upload-pack-advertisement",
Copy link
Member

Choose a reason for hiding this comment

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

Is this a public interface exposed by libgit2? If not I tend not to add this. We don't really want to get into troubles that there is no stability guarantee in libgit2 while git2-rs exposes it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The entire Service type is native to git2-rs -- libgit2 doesn't have anything really matching it. The closest thing is https://github.com/libgit2/libgit2/blob/main/src/libgit2/transports/http.c but that is not publicly exposed. I can definitely understand not merging this because of that.

Copy link
Member

Choose a reason for hiding this comment

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

Really appreciate your understanding. Yeah we need to weight on that.

Anyway, as GitHub keeps diff in a pull request indefinitely, this can be used as a reference when people need such a glue code, which is great!

Per discussion, I am going to close this and thank you again!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course! You're welcome!

@weihanglo weihanglo closed this Aug 1, 2024
@vcfxb vcfxb deleted the transport-service-trivial branch August 1, 2024 23:17
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.

3 participants