Make git_odb_foreach_cb take const param This makes the first OID param of the ODB callback a const pointer and also propogates that change all the way to the backends.
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
diff --git a/include/git2/odb.h b/include/git2/odb.h
index d41c2fb..f2633d1 100644
--- a/include/git2/odb.h
+++ b/include/git2/odb.h
@@ -23,11 +23,6 @@
GIT_BEGIN_DECL
/**
- * Function type for callbacks from git_odb_foreach.
- */
-typedef int (*git_odb_foreach_cb)(git_oid *id, void *payload);
-
-/**
* Create a new object database with no backends.
*
* Before the ODB can be used for read/writing, a custom database
diff --git a/include/git2/odb_backend.h b/include/git2/odb_backend.h
index 694803e..04658f9 100644
--- a/include/git2/odb_backend.h
+++ b/include/git2/odb_backend.h
@@ -24,7 +24,14 @@ GIT_BEGIN_DECL
struct git_odb_stream;
struct git_odb_writepack;
-/** An instance for a custom backend */
+/**
+ * Function type for callbacks from git_odb_foreach.
+ */
+typedef int (*git_odb_foreach_cb)(const git_oid *id, void *payload);
+
+/**
+ * An instance for a custom backend
+ */
struct git_odb_backend {
git_odb *odb;
@@ -79,7 +86,7 @@ struct git_odb_backend {
int (* foreach)(
struct git_odb_backend *,
- int (*cb)(git_oid *oid, void *payload),
+ git_odb_foreach_cb cb,
void *payload);
int (* writepack)(
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 41121ae..e2f1aec 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -678,7 +678,7 @@ static int loose_backend__exists(git_odb_backend *backend, const git_oid *oid)
struct foreach_state {
size_t dir_len;
- int (*cb)(git_oid *oid, void *data);
+ git_odb_foreach_cb cb;
void *data;
int cb_error;
};
@@ -734,7 +734,7 @@ static int foreach_cb(void *_state, git_buf *path)
return git_path_direach(path, foreach_object_dir_cb, state);
}
-static int loose_backend__foreach(git_odb_backend *_backend, int (*cb)(git_oid *oid, void *data), void *data)
+static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb cb, void *data)
{
char *objects_dir;
int error;
diff --git a/src/odb_pack.c b/src/odb_pack.c
index 9f7a6ee..35bf158 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -458,7 +458,7 @@ static int pack_backend__exists(git_odb_backend *backend, const git_oid *oid)
return pack_entry_find(&e, (struct pack_backend *)backend, oid) == 0;
}
-static int pack_backend__foreach(git_odb_backend *_backend, int (*cb)(git_oid *oid, void *data), void *data)
+static int pack_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb cb, void *data)
{
int error;
struct git_pack_file *p;
diff --git a/src/pack.c b/src/pack.c
index a2a2fbc..6cb46d3 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -698,7 +698,7 @@ static int git__memcmp4(const void *a, const void *b) {
int git_pack_foreach_entry(
struct git_pack_file *p,
- int (*cb)(git_oid *oid, void *data),
+ git_odb_foreach_cb cb,
void *data)
{
const unsigned char *index = p->index_map.data, *current;
diff --git a/src/pack.h b/src/pack.h
index af87b7c..9fb26b6 100644
--- a/src/pack.h
+++ b/src/pack.h
@@ -105,7 +105,7 @@ int git_pack_entry_find(
size_t len);
int git_pack_foreach_entry(
struct git_pack_file *p,
- int (*cb)(git_oid *oid, void *data),
+ git_odb_foreach_cb cb,
void *data);
#endif
diff --git a/tests-clar/odb/foreach.c b/tests-clar/odb/foreach.c
index bf52cc1..37158d4 100644
--- a/tests-clar/odb/foreach.c
+++ b/tests-clar/odb/foreach.c
@@ -16,7 +16,7 @@ void test_odb_foreach__cleanup(void)
_repo = NULL;
}
-static int foreach_cb(git_oid *oid, void *data)
+static int foreach_cb(const git_oid *oid, void *data)
{
GIT_UNUSED(data);
GIT_UNUSED(oid);
@@ -59,7 +59,7 @@ void test_odb_foreach__one_pack(void)
cl_assert(nobj == 1628);
}
-static int foreach_stop_cb(git_oid *oid, void *data)
+static int foreach_stop_cb(const git_oid *oid, void *data)
{
GIT_UNUSED(data);
GIT_UNUSED(oid);