Ad

Libgit2 - C: How Can I Tell Which Version Is Being Used

- 1 answer

I am writing an application that uses libgit2:

https://github.com/eantoranz/gitmod

At some point I am using a value from an enum defined in types.h:

https://github.com/libgit2/libgit2/blob/a83fd5107879d18b31ff8173ea062136256321be/include/git2/types.h#L77

But I just noticed that in previous versions it is called GIT_OBJ_TREE:

https://github.com/libgit2/libgit2/blob/45c6187cbfdcfee2bcf59a1ed3a853065142f203/include/git2/types.h#L72

Tnen the queston is, how can I know what version of libgit2 is being used? I though that perhaps there is a defined value that I could use that that I cold then use something like:

#ifdef GIT2_0_28
// use GIT_OBJECT_TREE
#else
// use GIT_OBJ_TREE
#endif

But I don't see something like that. What other trick can I use?

Ad

Answer

Ended up using stuff from https://github.com/libgit2/libgit2/blob/v0.28.0/include/git2/version.h.

In my file:

#if LIBGIT2_SOVERSION < 28 // old implementation
#define GIT2_OBJECT_TREE GIT_OBJ_TREE
#else // new implementation
#define GIT2_OBJECT_TREE GIT_OBJECT_TREE
#endif

Then in my code I use GIT2_OBJECT_TREE.

Will mark this as the answer until a better (simpler) one comes up.

Ad
source: stackoverflow.com
Ad