Deploy GIT_INIT_STRUCTURE
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/src/checkout.c b/src/checkout.c
index 640b048..ae40662 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -225,12 +225,10 @@ static int retrieve_symlink_caps(git_repository *repo, bool *can_symlink)
static void normalize_options(
git_checkout_opts *normalized, git_checkout_opts *proposed)
{
- git_checkout_opts init_opts = GIT_CHECKOUT_OPTS_INIT;
-
assert(normalized);
if (!proposed)
- memmove(normalized, &init_opts, sizeof(git_checkout_opts));
+ GIT_INIT_STRUCTURE(normalized, GIT_CHECKOUT_OPTS_VERSION);
else
memmove(normalized, proposed, sizeof(git_checkout_opts));
diff --git a/src/common.h b/src/common.h
index b779d28..3e7b065 100644
--- a/src/common.h
+++ b/src/common.h
@@ -82,6 +82,16 @@ GIT_INLINE(bool) giterr__check_version(const void *structure, unsigned int expec
}
#define GITERR_CHECK_VERSION(S,V,N) if (!giterr__check_version(S,V,N)) return -1
+/**
+ * Initialize a structure with a version.
+ */
+GIT_INLINE(void) git__init_structure(void *structure, size_t len, unsigned int version)
+{
+ memset(structure, 0, len);
+ *((int*)structure) = version;
+}
+#define GIT_INIT_STRUCTURE(S,V) git__init_structure(S, sizeof(*S), V)
+
/* NOTE: other giterr functions are in the public errors.h header file */
#include "util.h"
diff --git a/tests-clar/checkout/checkout_util.h b/tests-clar/checkout/checkout_util.h
deleted file mode 100644
index d6aa7ed..0000000
--- a/tests-clar/checkout/checkout_util.h
+++ /dev/null
@@ -1,5 +0,0 @@
-GIT_INLINE(void) reset_checkout_opts(git_checkout_opts *opts)
-{
- git_checkout_opts init_opts = GIT_CHECKOUT_OPTS_INIT;
- memmove(opts, &init_opts, sizeof(git_checkout_opts));
-}
diff --git a/tests-clar/checkout/index.c b/tests-clar/checkout/index.c
index e86dfe9..a67765b 100644
--- a/tests-clar/checkout/index.c
+++ b/tests-clar/checkout/index.c
@@ -2,7 +2,6 @@
#include "git2/checkout.h"
#include "repository.h"
-#include "checkout_util.h"
static git_repository *g_repo;
static git_checkout_opts g_opts;
@@ -26,7 +25,7 @@ void test_checkout_index__initialize(void)
{
git_tree *tree;
- reset_checkout_opts(&g_opts);
+ GIT_INIT_STRUCTURE(&g_opts, GIT_CHECKOUT_OPTS_VERSION);
g_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
g_repo = cl_git_sandbox_init("testrepo");
@@ -67,7 +66,7 @@ void test_checkout_index__cannot_checkout_a_bare_repository(void)
{
test_checkout_index__cleanup();
- reset_checkout_opts(&g_opts);
+ GIT_INIT_STRUCTURE(&g_opts, GIT_CHECKOUT_OPTS_VERSION);
g_repo = cl_git_sandbox_init("testrepo.git");
cl_git_fail(git_checkout_index(g_repo, NULL, NULL));
diff --git a/tests-clar/checkout/tree.c b/tests-clar/checkout/tree.c
index fe5bd4f..88dbe4f 100644
--- a/tests-clar/checkout/tree.c
+++ b/tests-clar/checkout/tree.c
@@ -2,7 +2,6 @@
#include "git2/checkout.h"
#include "repository.h"
-#include "checkout_util.h"
static git_repository *g_repo;
static git_checkout_opts g_opts;
@@ -12,7 +11,7 @@ void test_checkout_tree__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo");
- reset_checkout_opts(&g_opts);
+ GIT_INIT_STRUCTURE(&g_opts, GIT_CHECKOUT_OPTS_VERSION);
g_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
}
diff --git a/tests-clar/diff/blob.c b/tests-clar/diff/blob.c
index ae3129c..d7fdba0 100644
--- a/tests-clar/diff/blob.c
+++ b/tests-clar/diff/blob.c
@@ -12,7 +12,7 @@ void test_diff_blob__initialize(void)
g_repo = cl_git_sandbox_init("attr");
- reset_diff_opts(&opts);
+ GIT_INIT_STRUCTURE(&opts, GIT_DIFF_OPTIONS_VERSION);
opts.context_lines = 1;
opts.interhunk_lines = 0;
diff --git a/tests-clar/diff/diff_helpers.h b/tests-clar/diff/diff_helpers.h
index 0f7c0e4..49c2652 100644
--- a/tests-clar/diff/diff_helpers.h
+++ b/tests-clar/diff/diff_helpers.h
@@ -49,9 +49,3 @@ extern int diff_foreach_via_iterator(
extern void diff_print(FILE *fp, git_diff_list *diff);
-
-GIT_INLINE(void) reset_diff_opts(git_diff_options *opts)
-{
- git_diff_options init = GIT_DIFF_OPTIONS_INIT;
- memmove(opts, &init, sizeof(init));
-}