From 6893894f4b4a54d5ed3677ec816e032a974ac506 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Mon, 5 Jan 2026 14:14:24 -0500 Subject: [PATCH] feat(remote): expose `git_remote_oid_type` This would be useful for user to determine whether they want to proceed or bail further remote operations. Particularily useful for downstream libgit2 bindings and applications to experiment SHA256 support behind a runtime feature flag. For example, `cargo` could compile with sha256 support unconditionally, but reject SHA256 usage at runtime if the `-Zgit=sha256` nightly flag was not on. Cargo would leverage this new API to determine if users are trying to fetch a SHA256 remote repository and bail when needed before any fetches happen. Note that this is not gated behind `GIT_EXPERIMENTAL_SHA256` as the oid_type is sha1 and available always. --- include/git2/remote.h | 13 +++++++++++++ src/libgit2/remote.h | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/git2/remote.h b/include/git2/remote.h index b8fa02184..b5e83ecc8 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -417,6 +417,19 @@ GIT_EXTERN(int) git_remote_ls(const git_remote_head ***out, size_t *size, git_r */ GIT_EXTERN(int) git_remote_connected(const git_remote *remote); +/** + * Get the remote repository's object format. + * + * The remote (or more exactly its transport) must have connected to + * the remote repository. This format is available as soon as the + * connection to the remote is initiated and stays connected. + * + * @param out the resulting object format type + * @param remote the remote + * @return 0 on success, or an error code + */ +GIT_EXTERN(int) git_remote_oid_type(git_oid_t *out, git_remote *remote); + /** * Cancel the operation * diff --git a/src/libgit2/remote.h b/src/libgit2/remote.h index 9e089be38..cc560f169 100644 --- a/src/libgit2/remote.h +++ b/src/libgit2/remote.h @@ -58,7 +58,6 @@ int git_remote_connect_options_normalize( const git_remote_connect_options *src); int git_remote_capabilities(unsigned int *out, git_remote *remote); -int git_remote_oid_type(git_oid_t *out, git_remote *remote); #define git_remote_connect_options__copy_opts(out, in) \