summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Straub <bs@github.com>2012-11-30 20:34:50 -0800
committerBen Straub <bs@github.com>2012-11-30 20:34:50 -0800
commit0ab3a2ab2c39a99b7cb3c969fd7b896afcec4885 (patch)
treeab8f3c0aa63a7c27098c12a8b7f049008b396378
parentc7231c45fecf6c0ae91815a82db7e98c94689497 (diff)
downloadlibgit2-0ab3a2ab2c39a99b7cb3c969fd7b896afcec4885.tar.gz
Deploy GIT_INIT_STRUCTURE
-rw-r--r--src/checkout.c4
-rw-r--r--src/common.h10
-rw-r--r--tests-clar/checkout/checkout_util.h5
-rw-r--r--tests-clar/checkout/index.c5
-rw-r--r--tests-clar/checkout/tree.c3
-rw-r--r--tests-clar/diff/blob.c2
-rw-r--r--tests-clar/diff/diff_helpers.h6
7 files changed, 15 insertions, 20 deletions
diff --git a/src/checkout.c b/src/checkout.c
index 640b04857..ae4066243 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 b779d2800..3e7b0658f 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 d6aa7ed47..000000000
--- 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 e86dfe954..a67765b26 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 fe5bd4ff8..88dbe4ffc 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 ae3129c9f..d7fdba0e6 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 0f7c0e4f8..49c265285 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));
-}