Merge pull request #6882 from HamedMasafi/main

Add LIBGIT2_VER_CHECK Macro for Version Comparison
This commit is contained in:
Edward Thomson
2024-09-30 23:26:41 +01:00
committed by GitHub
6 changed files with 67 additions and 16 deletions

View File

@@ -892,6 +892,24 @@ GIT_EXTERN(void) git_strarray_free(git_strarray *array);
/**@}*/
/** @name Deprecated Version Constants
*
* These constants are retained for backward compatibility. The newer
* versions of these constants should be preferred in all new code.
*
* There is no plan to remove these backward compatibility constants at
* this time.
*/
/**@{*/
#define LIBGIT2_VER_MAJOR LIBGIT2_VERSION_MAJOR
#define LIBGIT2_VER_MINOR LIBGIT2_VERSION_MINOR
#define LIBGIT2_VER_REVISION LIBGIT2_VERSION_REVISION
#define LIBGIT2_VER_PATCH LIBGIT2_VERSION_PATCH
#define LIBGIT2_VER_PRERELEASE LIBGIT2_VERSION_PRERELEASE
/**@}*/
/** @name Deprecated Options Initialization Functions
*
* These functions are retained for backward compatibility. The newer

View File

@@ -11,19 +11,19 @@
* The version string for libgit2. This string follows semantic
* versioning (v2) guidelines.
*/
#define LIBGIT2_VERSION "1.8.2"
#define LIBGIT2_VERSION "1.8.2"
/** The major version number for this version of libgit2. */
#define LIBGIT2_VER_MAJOR 1
#define LIBGIT2_VERSION_MAJOR 1
/** The minor version number for this version of libgit2. */
#define LIBGIT2_VER_MINOR 8
#define LIBGIT2_VERSION_MINOR 8
/** The revision ("teeny") version number for this version of libgit2. */
#define LIBGIT2_VER_REVISION 2
#define LIBGIT2_VERSION_REVISION 2
/** The Windows DLL patch number for this version of libgit2. */
#define LIBGIT2_VER_PATCH 0
#define LIBGIT2_VERSION_PATCH 0
/**
* The prerelease string for this version of libgit2. For development
@@ -31,13 +31,34 @@
* a prerelease name like "beta" or "rc1". For final releases, this will
* be `NULL`.
*/
#define LIBGIT2_VER_PRERELEASE NULL
#define LIBGIT2_VERSION_PRERELEASE NULL
/**
* The library ABI soversion for this version of libgit2. This should
* only be changed when the library has a breaking ABI change, and so
* may trail the library's version number.
*/
#define LIBGIT2_SOVERSION "1.8"
#define LIBGIT2_SOVERSION "1.8"
/**
* An integer value representing the libgit2 version number. For example,
* libgit2 1.6.3 is 1060300.
*/
#define LIBGIT2_VERSION_NUMBER ( \
(LIBGIT2_VERSION_MAJOR * 1000000) + \
(LIBGIT2_VERSION_MINOR * 10000) + \
(LIBGIT2_VERSION_REVISION * 100))
/**
* Compare the libgit2 version against a given version. Evaluates to true
* if the given major, minor, and revision values are greater than or equal
* to the currently running libgit2 version. For example:
*
* #if LIBGIT2_VERSION_CHECK(1, 6, 3)
* # error libgit2 version is >= 1.6.3
* #endif
*/
#define LIBGIT2_VERSION_CHECK(major, minor, revision) \
(LIBGIT2_VERSION_NUMBER >= ((major)*1000000)+((minor)*10000)+((revision)*100))
#endif

View File

@@ -25,8 +25,8 @@ VS_VERSION_INFO VERSIONINFO
#else
VS_VERSION_INFO VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
#endif
FILEVERSION LIBGIT2_VER_MAJOR,LIBGIT2_VER_MINOR,LIBGIT2_VER_REVISION,LIBGIT2_VER_PATCH
PRODUCTVERSION LIBGIT2_VER_MAJOR,LIBGIT2_VER_MINOR,LIBGIT2_VER_REVISION,LIBGIT2_VER_PATCH
FILEVERSION LIBGIT2_VERSION_MAJOR,LIBGIT2_VERSION_MINOR,LIBGIT2_VERSION_REVISION,LIBGIT2_VERSION_PATCH
PRODUCTVERSION LIBGIT2_VERSION_MAJOR,LIBGIT2_VERSION_MINOR,LIBGIT2_VERSION_REVISION,LIBGIT2_VERSION_PATCH
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG

View File

@@ -66,16 +66,16 @@ int git_libgit2_shutdown(void)
int git_libgit2_version(int *major, int *minor, int *rev)
{
*major = LIBGIT2_VER_MAJOR;
*minor = LIBGIT2_VER_MINOR;
*rev = LIBGIT2_VER_REVISION;
*major = LIBGIT2_VERSION_MAJOR;
*minor = LIBGIT2_VERSION_MINOR;
*rev = LIBGIT2_VERSION_REVISION;
return 0;
}
const char *git_libgit2_prerelease(void)
{
return LIBGIT2_VER_PRERELEASE;
return LIBGIT2_VERSION_PRERELEASE;
}
int git_libgit2_features(void)

View File

@@ -5,9 +5,9 @@ void test_core_features__0(void)
int major, minor, rev, caps;
git_libgit2_version(&major, &minor, &rev);
cl_assert_equal_i(LIBGIT2_VER_MAJOR, major);
cl_assert_equal_i(LIBGIT2_VER_MINOR, minor);
cl_assert_equal_i(LIBGIT2_VER_REVISION, rev);
cl_assert_equal_i(LIBGIT2_VERSION_MAJOR, major);
cl_assert_equal_i(LIBGIT2_VERSION_MINOR, minor);
cl_assert_equal_i(LIBGIT2_VERSION_REVISION, rev);
caps = git_libgit2_features();

View File

@@ -0,0 +1,12 @@
#include "clar_libgit2.h"
void test_core_version__check(void)
{
#if !LIBGIT2_VERSION_CHECK(1,6,3)
cl_fail("version check");
#endif
#if LIBGIT2_VERSION_CHECK(99,99,99)
cl_fail("version check");
#endif
}