File: libgit-api-updates.patch

package info (click to toggle)
horizon-eda 2.6.0-2.3
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 33,416 kB
  • sloc: cpp: 270,162; ansic: 3,817; python: 2,098; xml: 402; sql: 219; sh: 190; ruby: 61; makefile: 19
file content (97 lines) | stat: -rw-r--r-- 4,108 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
From d5a46d2d7e879e82d0d2798715c1369f8ae54fcd Mon Sep 17 00:00:00 2001
From: "Lukas K." <lu@0x83.eu>
Date: Wed, 30 Oct 2024 00:09:03 +0100
Subject: [PATCH] work around libgit2 randomly changing the constness of
 arguments to git_commit

by detecting the constness using SFINAE
---
 src/pool-prj-mgr/pool-mgr/pool_git_box.cpp    |  7 ++-----
 src/pool-prj-mgr/pool-mgr/pool_remote_box.cpp | 13 +++---------
 src/util/git_util.hpp                         | 21 +++++++++++++++++++
 3 files changed, 26 insertions(+), 15 deletions(-)
 create mode 100644 src/util/git_util.hpp

--- a/src/pool-prj-mgr/pool-mgr/pool_git_box.cpp
+++ b/src/pool-prj-mgr/pool-mgr/pool_git_box.cpp
@@ -2,6 +2,7 @@
 #include <git2.h>
 #include "util/autofree_ptr.hpp"
 #include "util/gtk_util.hpp"
+#include "util/git_util.hpp"
 #include "pool_notebook.hpp"
 #include "util/str_util.hpp"
 #include "util/util.hpp"
@@ -631,11 +632,7 @@ void PoolGitBox::handle_pr()
             git_signature_default(&signature.ptr, repo);
 
             git_oid new_commit_oid;
-#if (LIBGIT2_VER_MAJOR == 1) && (LIBGIT2_VER_MINOR == 8)
-            std::array<git_commit *, 2> parents;
-#else
-            std::array<const git_commit *, 2> parents;
-#endif
+            std::array<git_util::git_commit_maybe_const *, 2> parents;
             parents.at(0) = master_commit;
             parents.at(1) = pr_commit;
             if (git_commit_create(&new_commit_oid, repo, "HEAD", signature, signature, NULL,
--- a/src/pool-prj-mgr/pool-mgr/pool_remote_box.cpp
+++ b/src/pool-prj-mgr/pool-mgr/pool_remote_box.cpp
@@ -3,6 +3,7 @@
 #include <git2/cred_helpers.h>
 #include "util/autofree_ptr.hpp"
 #include "util/gtk_util.hpp"
+#include "util/git_util.hpp"
 #include "pool_notebook.hpp"
 #include <thread>
 #include "pool-update/pool-update.hpp"
@@ -1137,11 +1138,7 @@ void PoolRemoteBox::create_pr_thread()
 
             autofree_ptr<git_commit> parent_commit(git_commit_free);
             git_commit_lookup(&parent_commit.ptr, repo, &parent_oid);
-#if (LIBGIT2_VER_MAJOR == 1) && (LIBGIT2_VER_MINOR == 8)
-            git_commit *parent_commit_p = parent_commit.ptr;
-#else
-            const git_commit *parent_commit_p = parent_commit.ptr;
-#endif
+            git_util::git_commit_maybe_const *parent_commit_p = parent_commit.ptr;
 
             autofree_ptr<git_signature> signature(git_signature_free);
             if (git_signature_default(&signature.ptr, repo) != 0) {
@@ -1287,11 +1284,7 @@ void PoolRemoteBox::update_pr_thread()
                 throw std::runtime_error("error getting default signature");
             }
 
-#if (LIBGIT2_VER_MAJOR == 1) && (LIBGIT2_VER_MINOR == 8)
-            git_commit *parent_commit_p = latest_commit.ptr;
-#else
-            const git_commit *parent_commit_p = latest_commit.ptr;
-#endif
+            git_util::git_commit_maybe_const *parent_commit_p = latest_commit.ptr;
 
             git_oid new_commit_oid;
             if (git_commit_create(&new_commit_oid, repo, NULL, signature, signature, "UTF-8", pr_title.c_str(), tree, 1,
--- /dev/null
+++ b/src/util/git_util.hpp
@@ -0,0 +1,21 @@
+#pragma once
+#include <git2.h>
+#include <type_traits>
+
+namespace horizon::git_util {
+template <typename T, typename = void> struct git_commit_needs_const : std::false_type {};
+
+template <typename T>
+struct git_commit_needs_const<
+        T, std::void_t<decltype(git_commit_create(std::declval<git_oid *>(), std::declval<git_repository *>(),
+                                                  std::declval<const char *>(), std::declval<const git_signature *>(),
+                                                  std::declval<const git_signature *>(), std::declval<const char *>(),
+                                                  std::declval<const char *>(), std::declval<const git_tree *>(),
+                                                  std::declval<size_t>(), std::declval<const T **>()))>>
+    : std::true_type {};
+
+using git_commit_maybe_const =
+        std::conditional_t<git_commit_needs_const<git_commit>::value, const git_commit, git_commit>;
+
+
+} // namespace horizon::git_util