From 58758918d31b440671b78fbb1e8aa80260bf587a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois-Simon=20Fauteux-Chapleau?=
 <francois-simon.fauteux-chapleau@savoirfairelinux.com>
Date: Tue, 14 Jan 2025 09:44:21 -0500
Subject: [PATCH] contrib: fix build for libgit2 1.8-1.9

GitLab: #1093
Change-Id: Iaaed6d86dba597b7b4435a98022aad163599c9fb
---
 src/jamidht/conversationrepository.cpp | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/jamidht/conversationrepository.cpp b/src/jamidht/conversationrepository.cpp
index 40dbc1929..8112003aa 100644
--- a/src/jamidht/conversationrepository.cpp
+++ b/src/jamidht/conversationrepository.cpp
@@ -835,12 +835,13 @@ ConversationRepository::Impl::createMergeCommit(git_index* index, const std::str
 
     // Commit
     git_buf to_sign = {};
-    // Check if the libgit2 library version is 1.8.0 or higher
-#if( LIBGIT2_VER_MAJOR > 1 ) || ( LIBGIT2_VER_MAJOR == 1 && LIBGIT2_VER_MINOR >= 8 )
-    // For libgit2 version 1.8.0 and above
+    // The last argument of git_commit_create_buffer is of type
+    // 'const git_commit **' in all versions of libgit2 except 1.8.0,
+    // 1.8.1 and 1.8.3, in which it is of type 'git_commit *const *'.
+#if LIBGIT2_VER_MAJOR == 1 && LIBGIT2_VER_MINOR == 8 && \
+    (LIBGIT2_VER_REVISION == 0 || LIBGIT2_VER_REVISION == 1 || LIBGIT2_VER_REVISION == 3)
     git_commit* const parents_ptr[2] {parents[0].get(), parents[1].get()};
 #else
-    // For libgit2 versions older than 1.8.0
     const git_commit* parents_ptr[2] {parents[0].get(), parents[1].get()};
 #endif
     if (git_commit_create_buffer(&to_sign,
@@ -1929,9 +1930,11 @@ ConversationRepository::Impl::commit(const std::string& msg, bool verifyDevice)
     GitCommit head_commit {head_ptr, git_commit_free};
 
     git_buf to_sign = {};
-    // Check if the libgit2 library version is 1.8.0 or higher
-#if( LIBGIT2_VER_MAJOR > 1 ) || ( LIBGIT2_VER_MAJOR == 1 && LIBGIT2_VER_MINOR >= 8 )
-    // For libgit2 version 1.8.0 and above
+    // The last argument of git_commit_create_buffer is of type
+    // 'const git_commit **' in all versions of libgit2 except 1.8.0,
+    // 1.8.1 and 1.8.3, in which it is of type 'git_commit *const *'.
+#if LIBGIT2_VER_MAJOR == 1 && LIBGIT2_VER_MINOR == 8 && \
+    (LIBGIT2_VER_REVISION == 0 || LIBGIT2_VER_REVISION == 1 || LIBGIT2_VER_REVISION == 3)
     git_commit* const head_ref[1] = {head_commit.get()};
 #else
     const git_commit* head_ref[1] = {head_commit.get()};
-- 
GitLab