Commit 0ab3a2ab2c39a99b7cb3c969fd7b896afcec4885

Ben Straub 2012-11-30T20:34:50

Deploy GIT_INIT_STRUCTURE

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));
-}