8000 Allow consumers to query the "backends" that libgit2 was built with by ethomson · Pull Request #6971 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

Allow consumers to query the "backends" that libgit2 was built with #6971

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 3 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmake/SelectZlib.cmake
Original file line number Diff line number Diff line change
8000 Expand Up @@ -4,6 +4,7 @@ include(SanitizeBool)
SanitizeBool(USE_BUNDLED_ZLIB)
if(USE_BUNDLED_ZLIB STREQUAL ON)
set(USE_BUNDLED_ZLIB "Bundled")
set(GIT_COMPRESSION_BUILTIN)
endif()

if(USE_BUNDLED_ZLIB STREQUAL "OFF")
Expand All @@ -17,6 +18,7 @@ if(USE_BUNDLED_ZLIB STREQUAL "OFF")
list(APPEND LIBGIT2_PC_REQUIRES "zlib")
endif()
add_feature_info(zlib ON "using system zlib")
set(GIT_COMPRESSION_ZLIB 1)
else()
message(STATUS "zlib was not found; using bundled 3rd-party sources." )
endif()
Expand All @@ -26,9 +28,11 @@ if(USE_BUNDLED_ZLIB STREQUAL "Chromium")
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/chromium-zlib")
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:chromium_zlib>)
add_feature_info(zlib ON "using (Chromium) bundled zlib")
set(GIT_COMPRESSION_BUILTIN 1)
elseif(USE_BUNDLED_ZLIB OR NOT ZLIB_FOUND)
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/zlib" "${PROJECT_BINARY_DIR}/deps/zlib")
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/zlib")
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:zlib>)
add_feature_info(zlib ON "using bundled zlib")
set(GIT_COMPRESSION_BUILTIN 1)
endif()
98 changes: 61 additions & 37 deletions include/git2/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,56 +130,80 @@ GIT_EXTERN(int) git_libgit2_version(int *major, int *minor, int *rev);
GIT_EXTERN(const char *) git_libgit2_prerelease(void);

/**
* Combinations of these values describe the features with which libgit2
* was compiled
* Configurable features of libgit2; either optional settings (like
* threading), or features that can be enabled by one of a number of
* different backend "providers" (like HTTPS, which can be provided by
* OpenSSL, mbedTLS, or system libraries).
*/
typedef enum {
/**
* If set, libgit2 was built thread-aware and can be safely used from multiple
* threads.
*/
GIT_FEATURE_THREADS = (1 << 0),
/**
* If set, libgit2 was built with and linked against a TLS implementation.
* Custom TLS streams may still be added by the user to support HTTPS
* regardless of this.
*/
GIT_FEATURE_HTTPS = (1 << 1),
/**
* If set, libgit2 was built with and linked against libssh2. A custom
* transport may still be added by the user to support libssh2 regardless of
* this.
*/
GIT_FEATURE_SSH = (1 << 2),
/**
* If set, libgit2 was built with support for sub-second resolution in file
* modification times.
*/
GIT_FEATURE_NSEC = (1 << 3)
/**
* libgit2 is thread-aware and can be used from multiple threads
* (as described in the documentation).
*/
GIT_FEATURE_THREADS = (1 << 0),

/** HTTPS remotes */
GIT_FEATURE_HTTPS = (1 << 1),

/** SSH remotes */
GIT_FEATURE_SSH = (1 << 2),

/** Sub-second resolution in index timestamps */
GIT_FEATURE_NSEC = (1 << 3),

/** HTTP parsing; always available */
GIT_FEATURE_HTTP_PARSER = (1 << 4),

/** Regular expression support; always available */
GIT_FEATURE_REGEX = (1 << 5),

/** Internationalization support for filename translation */
GIT_FEATURE_I18N = (1 << 6),

/** NTLM support over HTTPS */
GIT_FEATURE_AUTH_NTLM = (1 << 7),

/** Kerberos (SPNEGO) authentication support over HTTPS */
GIT_FEATURE_AUTH_NEGOTIATE = (1 << 8),

/** zlib support; always available */
GIT_FEATURE_COMPRESSION = (1 << 9),

/** SHA1 object support; always available */
GIT_FEATURE_SHA1 = (1 << 10),

/** SHA256 object support */
GIT_FEATURE_SHA256 = (1 << 11)
} git_feature_t;

/**
* Query compile time options for libgit2.
*
* @return A combination of GIT_FEATURE_* values.
*/
GIT_EXTERN(int) git_libgit2_features(void);

/**
* Query the backend details for the compile-time feature in libgit2.
*
* - GIT_FEATURE_THREADS
* Libgit2 was compiled with thread support. Note that thread support is
* still to be seen as a 'work in progress' - basic object lookups are
* believed to be threadsafe, but other operations may not be.
* This will return the "backend" for the feature, which is useful for
* things like HTTPS or SSH support, that can have multiple backends
* that could be compiled in.
*
* - GIT_FEATURE_HTTPS
* Libgit2 supports the https:// protocol. This requires the openssl
* library to be found when compiling libgit2.
* For example, when libgit2 is compiled with dynamic OpenSSL support,
* the feature backend will be `openssl-dynamic`. The feature backend
* names reflect the compilation options specified to the build system
* (though in all lower case). The backend _may_ be "builtin" for
* features that are provided by libgit2 itself.
*
* - GIT_FEATURE_SSH
* Libgit2 supports the SSH protocol for network operations. This requires
* the libssh2 library to be found when compiling libgit2
* If the feature is not supported by the library, this API returns
* `NULL`.
*
* - GIT_FEATURE_NSEC
* Libgit2 supports the sub-second resolution in file mo 8000 dification times.
* @param feature the feature to query details for
* @return the provider details, or NULL if the feature is not supported
*/
GIT_EXTERN(int) git_libgit2_features(void);
GIT_EXTERN(const char *) git_libgit2_feature_backend(
git_feature_t feature);

/**
* Global library options
Expand Down
171 changes: 171 additions & 0 deletions src/libgit2/libgit2.c
9E88
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,177 @@ int git_libgit2_features(void)
#endif
#ifdef GIT_USE_NSEC
| GIT_FEATURE_NSEC
#endif
| GIT_FEATURE_HTTP_PARSER
| GIT_FEATURE_REGEX
#ifdef GIT_USE_ICONV
| GIT_FEATURE_I18N
#endif
#if defined(GIT_NTLM) || defined(GIT_WIN32)
| GIT_FEATURE_AUTH_NTLM
#endif
#if defined(GIT_GSSAPI) || defined(GIT_GSSFRAMEWORK) || defined(GIT_WIN32)
| GIT_FEATURE_AUTH_NEGOTIATE
#endif
| GIT_FEATURE_COMPRESSION
| GIT_FEATURE_SHA1
#ifdef GIT_EXPERIMENTAL_SHA256
| GIT_FEATURE_SHA256
#endif
;
}

const char *git_libgit2_feature_backend(git_feature_t feature)
{
switch (feature) {
case GIT_FEATURE_THREADS:
#if defined(GIT_THREADS) && defined(GIT_WIN32)
return "win32";
#elif defined(GIT_THREADS)
return "pthread";
#endif
break;

case GIT_FEATURE_HTTPS:
#if defined(GIT_HTTPS) && defined(GIT_OPENSSL)
return "openssl";
#elif defined(GIT_HTTPS) && defined(GIT_OPENSSL_DYNAMIC)
return "openssl-dynamic";
#elif defined(GIT_HTTPS) && defined(GIT_MBEDTLS)
return "mbedtls";
#elif defined(GIT_HTTPS) && defined(GIT_SECURE_TRANSPORT)
return "securetransport";
#elif defined(GIT_HTTPS) && defined(GIT_SCHANNEL)
return "schannel";
#elif defined(GIT_HTTPS) && defined(GIT_WINHTTP)
return "winhttp";
#elif defined(GIT_HTTPS)
GIT_ASSERT_WITH_RETVAL(!"Unknown HTTPS backend", NULL);
#endif
break;

case GIT_FEATURE_SSH:
#if defined(GIT_SSH_EXEC)
return "exec";
#elif defined(GIT_SSH_LIBSSH2)
return "libssh2";
#elif defined(GIT_SSH)
GIT_ASSERT_WITH_RETVAL(!"Unknown SSH backend", NULL);
#endif
break;

case GIT_FEATURE_NSEC:
#if defined(GIT_USE_NSEC) && defined(GIT_USE_STAT_MTIMESPEC)
return "mtimespec";
#elif defined(GIT_USE_NSEC) && defined(GIT_USE_STAT_MTIM)
return "mtim";
#elif defined(GIT_USE_NSEC) && defined(GIT_USE_STAT_MTIME_NSEC)
return "mtime";
#elif defined(GIT_USE_NSEC) && defined(GIT_WIN32)
return "win32";
#elif defined(GIT_USE_NSEC)
GIT_ASSERT_WITH_RETVAL(!"Unknown high-resolution time backend", NULL);
#endif
break;

case GIT_FEATURE_HTTP_PARSER:
#if defined(GIT_HTTPPARSER_HTTPPARSER)
return "httpparser";
#elif defined(GIT_HTTPPARSER_LLHTTP)
return "llhttp";
#elif defined(GIT_HTTPPARSER_BUILTIN)
return "builtin";
#endif
GIT_ASSERT_WITH_RETVAL(!"Unknown HTTP parser backend", NULL);
break;

case GIT_FEATURE_REGEX:
#if defined(GIT_REGEX_REGCOMP_L)
return "regcomp_l";
#elif defined(GIT_REGEX_REGCOMP)
return "regcomp";
#elif defined(GIT_REGEX_PCRE)
return "pcre";
#elif defined(GIT_REGEX_PCRE2)
return "pcre2";
#elif defined(GIT_REGEX_BUILTIN)
return "builtin";
#endif
GIT_ASSERT_WITH_RETVAL(!"Unknown regular expression backend", NULL);
break;

case GIT_FEATURE_I18N:
#if defined(GIT_USE_ICONV)
return "iconv";
#endif
break;

case GIT_FEATURE_AUTH_NTLM:
#if defined(GIT_NTLM)
return "ntlmclient";
#elif defined(GIT_WIN32)
return "sspi";
#endif
break;

case GIT_FEATURE_AUTH_NEGOTIATE:
#if defined(GIT_GSSAPI)
return "gssapi";
#elif defined(GIT_WIN32)
return "sspi";
#endif
break;

case GIT_FEATURE_COMPRESSION:
#if defined(GIT_COMPRESSION_ZLIB)
return "zlib";
#elif defined(GIT_COMPRESSION_BUILTIN)
return "builtin";
#else
GIT_ASSERT_WITH_RETVAL(!"Unknown compression backend", NULL);
#endif
break;

case GIT_FEATURE_SHA1:
#if defined(GIT_SHA1_COLLISIONDETECT)
return "builtin";
#elif defined(GIT_SHA1_OPENSSL)
return "openssl";
#elif defined(GIT_SHA1_OPENSSL_FIPS)
return "openssl-fips";
#elif defined(GIT_SHA1_OPENSSL_DYNAMIC)
return "openssl-dynamic";
#elif defined(GIT_SHA1_MBEDTLS)
return "mbedtls";
#elif defined(GIT_SHA1_COMMON_CRYPTO)
return "commoncrypto";
#elif defined(GIT_SHA1_WIN32)
return "win32";
#else
GIT_ASSERT_WITH_RETVAL(!"Unknown SHA1 backend", NULL);
#endif
break;

case GIT_FEATURE_SHA256:
#if defined(GIT_EXPERIMENTAL_SHA256) && defined(GIT_SHA256_BUILTIN)
return "builtin";
#elif defined(GIT_EXPERIMENTAL_SHA256) && defined(GIT_SHA256_OPENSSL)
return "openssl";
#elif defined(GIT_EXPERIMENTAL_SHA256) && defined(GIT_SHA256_OPENSSL_FIPS)
return "openssl-fips";
#elif defined(GIT_EXPERIMENTAL_SHA256) && defined(GIT_SHA256_OPENSSL_DYNAMIC)
return "openssl-dynamic";
#elif defined(GIT_EXPERIMENTAL_SHA256) && defined(GIT_SHA256_MBEDTLS)
return "mbedtls";
#elif defined(GIT_EXPERIMENTAL_SHA256) && defined(GIT_SHA256_COMMON_CRYPTO)
return "commoncrypto";
#elif defined(GIT_EXPERIMENTAL_SHA256) && defined(GIT_SHA256_WIN32)
return "win32";
#elif defined(GIT_EXPERIMENTAL_SHA256)
GIT_ASSERT_WITH_RETVAL(!"Unknown SHA256 backend", NULL);
#endif
break;
}

return NULL;
}
3 changes: 3 additions & 0 deletions src/util/git2_features.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
#cmakedefine GIT_SHA256_OPENSSL_DYNAMIC 1
#cmakedefine GIT_SHA256_MBEDTLS 1

#cmakedefine GIT_COMPRESSION_BUILTIN 1
#cmakedefine GIT_COMPRESSION_ZLIB 1

#cmakedefine GIT_RAND_GETENTROPY 1
#cmakedefine GIT_RAND_GETLOADAVG 1

Expand Down
Loading
Loading
0