diff options
-rw-r--r-- | src/attr.c | 6 | ||||
-rw-r--r-- | src/cc-compat.h | 3 | ||||
-rw-r--r-- | src/config_file.c | 3 | ||||
-rw-r--r-- | src/diff.c | 2 | ||||
-rw-r--r-- | src/diff_output.c | 12 | ||||
-rw-r--r-- | src/hashtable.h | 28 | ||||
-rw-r--r-- | src/odb_pack.c | 4 | ||||
-rw-r--r-- | src/pkt.c | 6 | ||||
-rw-r--r-- | src/refs.c | 29 | ||||
-rw-r--r-- | src/remote.c | 4 | ||||
-rw-r--r-- | src/revwalk.c | 6 | ||||
-rw-r--r-- | src/transport.c | 4 | ||||
-rw-r--r-- | src/transports/local.c | 6 | ||||
-rw-r--r-- | src/win32/posix.h | 10 | ||||
-rw-r--r-- | src/win32/pthread.c | 8 | ||||
-rw-r--r-- | tests-clar/attr/repo.c | 8 | ||||
-rw-r--r-- | tests-clar/clar_helpers.c | 49 | ||||
-rw-r--r-- | tests-clar/clar_libgit2.h | 5 | ||||
-rw-r--r-- | tests-clar/config/multivar.c | 8 | ||||
-rw-r--r-- | tests-clar/core/dirent.c | 6 | ||||
-rw-r--r-- | tests-clar/diff/blob.c | 9 | ||||
-rw-r--r-- | tests-clar/diff/index.c | 8 | ||||
-rw-r--r-- | tests-clar/diff/iterator.c | 50 | ||||
-rw-r--r-- | tests-clar/diff/tree.c | 9 | ||||
-rw-r--r-- | tests-clar/diff/workdir.c | 8 | ||||
-rw-r--r-- | tests-clar/status/ignore.c | 13 | ||||
-rw-r--r-- | tests-clar/status/worktree.c | 67 | ||||
-rw-r--r-- | tests/t00-core.c | 6 | ||||
-rw-r--r-- | tests/t07-hashtable.c | 5 | ||||
-rw-r--r-- | tests/t18-status.c | 8 | ||||
-rw-r--r-- | tests/test_main.c | 6 |
31 files changed, 181 insertions, 215 deletions
@@ -408,10 +408,9 @@ void git_attr_cache_flush( return; if (repo->attrcache.files) { - const void *GIT_UNUSED(name); git_attr_file *file; - GIT_HASHTABLE_FOREACH(repo->attrcache.files, name, file, + GIT_HASHTABLE_FOREACH_VALUE(repo->attrcache.files, file, git_attr_file__free(file)); git_hashtable_free(repo->attrcache.files); @@ -419,10 +418,9 @@ void git_attr_cache_flush( } if (repo->attrcache.macros) { - const void *GIT_UNUSED(name); git_attr_rule *rule; - GIT_HASHTABLE_FOREACH(repo->attrcache.macros, name, rule, + GIT_HASHTABLE_FOREACH_VALUE(repo->attrcache.macros, rule, git_attr_rule__free(rule)); git_hashtable_free(repo->attrcache.macros); diff --git a/src/cc-compat.h b/src/cc-compat.h index bbccd1f5..3df36b61 100644 --- a/src/cc-compat.h +++ b/src/cc-compat.h @@ -33,8 +33,7 @@ # define GIT_TYPEOF(x) #endif -#define GIT_UNUSED(x) x -#define GIT_UNUSED_ARG(x) ((void)(x)) +#define GIT_UNUSED(x) ((void)(x)) /* Define the printf format specifer to use for size_t output */ #if defined(_MSC_VER) || defined(__MINGW32__) diff --git a/src/config_file.c b/src/config_file.c index ce76493c..3c7c593e 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -125,13 +125,12 @@ static int normalize_name(const char *in, char **out) static void free_vars(git_hashtable *values) { - const char *GIT_UNUSED(_unused) = NULL; cvar_t *var = NULL; if (values == NULL) return; - GIT_HASHTABLE_FOREACH(values, _unused, var, + GIT_HASHTABLE_FOREACH_VALUE(values, var, do { cvar_t *next = CVAR_LIST_NEXT(var); cvar_free(var); @@ -325,7 +325,7 @@ static int maybe_modified( int error = GIT_SUCCESS; git_oid noid, *use_noid = NULL; - GIT_UNUSED_ARG(old); + GIT_UNUSED(old); /* support "assume unchanged" & "skip worktree" bits */ if ((oitem->flags_extended & GIT_IDXENTRY_INTENT_TO_ADD) != 0 || diff --git a/src/diff_output.c b/src/diff_output.c index ac60e982..b800be93 100644 --- a/src/diff_output.c +++ b/src/diff_output.c @@ -161,7 +161,7 @@ static int file_is_binary_by_content( git_map *old_data, git_map *new_data) { - GIT_UNUSED_ARG(diff); + GIT_UNUSED(diff); if ((delta->old.flags & BINARY_DIFF_FLAGS) == 0) { size_t search_len = min(old_data->len, 4000); @@ -448,7 +448,7 @@ static int print_compact(void *data, git_diff_delta *delta, float progress) diff_print_info *pi = data; char code, old_suffix, new_suffix; - GIT_UNUSED_ARG(progress); + GIT_UNUSED(progress); switch (delta->status) { case GIT_STATUS_ADDED: code = 'A'; break; @@ -546,7 +546,7 @@ static int print_patch_file(void *data, git_diff_delta *delta, float progress) const char *newpfx = pi->diff->opts.dst_prefix; const char *newpath = delta->new.path; - GIT_UNUSED_ARG(progress); + GIT_UNUSED(progress); git_buf_clear(pi->buf); git_buf_printf(pi->buf, "diff --git %s%s %s%s\n", oldpfx, delta->old.path, newpfx, delta->new.path); @@ -593,8 +593,8 @@ static int print_patch_hunk( { diff_print_info *pi = data; - GIT_UNUSED_ARG(d); - GIT_UNUSED_ARG(r); + GIT_UNUSED(d); + GIT_UNUSED(r); git_buf_clear(pi->buf); @@ -613,7 +613,7 @@ static int print_patch_line( { diff_print_info *pi = data; - GIT_UNUSED_ARG(delta); + GIT_UNUSED(delta); git_buf_clear(pi->buf); diff --git a/src/hashtable.h b/src/hashtable.h index f6fbb858..e0996596 100644 --- a/src/hashtable.h +++ b/src/hashtable.h @@ -65,20 +65,20 @@ GIT_INLINE(int) git_hashtable_insert(git_hashtable *h, const void *key, void *va #define git_hashtable_node_at(nodes, pos) ((git_hashtable_node *)(&nodes[pos])) -#define GIT_HASHTABLE_FOREACH(self, pkey, pvalue, code) {\ - git_hashtable *_self = (self);\ - git_hashtable_node *_nodes = _self->nodes;\ - unsigned int _i, _size = _self->size;\ - for (_i = 0; _i < _size; _i ++) {\ - git_hashtable_node *_node = git_hashtable_node_at(_nodes, _i);\ - if (_node->key)\ - {\ - pkey = _node->key;\ - pvalue = _node->value;\ - code;\ - }\ - }\ -} +#define GIT_HASHTABLE__FOREACH(self,block) { \ + unsigned int _c; \ + git_hashtable_node *_n = (self)->nodes; \ + for (_c = (self)->size; _c > 0; _c--, _n++) { \ + if (!_n->key) continue; block } } + +#define GIT_HASHTABLE_FOREACH(self, pkey, pvalue, code)\ + GIT_HASHTABLE__FOREACH(self,{(pkey)=_n->key;(pvalue)=_n->value;code;}) + +#define GIT_HASHTABLE_FOREACH_KEY(self, pkey, code)\ + GIT_HASHTABLE__FOREACH(self,{(pkey)=_n->key;code;}) + +#define GIT_HASHTABLE_FOREACH_VALUE(self, pvalue, code)\ + GIT_HASHTABLE__FOREACH(self,{(pvalue)=_n->value;code;}) #define GIT_HASHTABLE_FOREACH_DELETE() {\ _node->key = NULL; _node->value = NULL; _self->key_count--;\ diff --git a/src/odb_pack.c b/src/odb_pack.c index 9e1004eb..249144a3 100644 --- a/src/odb_pack.c +++ b/src/odb_pack.c @@ -159,9 +159,9 @@ static int pack_entry_find_prefix(struct git_pack_entry *e, * ***********************************************************/ -GIT_INLINE(void) pack_window_free_all(struct pack_backend *GIT_UNUSED(backend), struct git_pack_file *p) +GIT_INLINE(void) pack_window_free_all(struct pack_backend *backend, struct git_pack_file *p) { - GIT_UNUSED_ARG(backend); + GIT_UNUSED(backend); git_mwindow_free_all(&p->mwf); } @@ -41,11 +41,11 @@ static int flush_pkt(git_pkt **out) } /* the rest of the line will be useful for multi_ack */ -static int ack_pkt(git_pkt **out, const char *GIT_UNUSED(line), size_t GIT_UNUSED(len)) +static int ack_pkt(git_pkt **out, const char *line, size_t len) { git_pkt *pkt; - GIT_UNUSED_ARG(line); - GIT_UNUSED_ARG(len); + GIT_UNUSED(line); + GIT_UNUSED(len); pkt = git__malloc(sizeof(git_pkt)); if (pkt == NULL) @@ -105,7 +105,7 @@ static int reference_alloc( reference->name = git__strdup(name); if (reference->name == NULL) { - free(reference); + git__free(reference); return GIT_ENOMEM; } @@ -222,7 +222,7 @@ static int loose_lookup(git_reference *ref) return GIT_SUCCESS; if (ref->flags & GIT_REF_SYMBOLIC) { - free(ref->target.symbolic); + git__free(ref->target.symbolic); ref->target.symbolic = NULL; } @@ -278,7 +278,8 @@ static int loose_lookup_to_packfile( cleanup: git_buf_free(&ref_file); - free(ref); + git__free(ref); + return git__rethrow(error, "Failed to lookup loose reference"); } @@ -420,7 +421,7 @@ static int packed_parse_oid( return GIT_SUCCESS; cleanup: - free(ref); + git__free(ref); return git__rethrow(error, "Failed to parse OID of packed reference"); } @@ -495,7 +496,7 @@ static int packed_load(git_repository *repo) error = git_hashtable_insert(ref_cache->packfile, ref->name, ref); if (error < GIT_SUCCESS) { - free(ref); + git__free(ref); goto cleanup; } } @@ -560,12 +561,12 @@ static int _dirent_loose_load(void *data, git_buf *full_path) if (git_hashtable_insert2( repository->references.packfile, ref->name, ref, &old_ref) < GIT_SUCCESS) { - free(ref); + git__free(ref); return GIT_ENOMEM; } if (old_ref != NULL) - free(old_ref); + git__free(old_ref); } return error == GIT_SUCCESS ? @@ -773,9 +774,8 @@ static int packed_write(git_repository *repo) /* Load all the packfile into a vector */ { struct packref *reference; - const void *GIT_UNUSED(_unused); - GIT_HASHTABLE_FOREACH(repo->references.packfile, _unused, reference, + GIT_HASHTABLE_FOREACH_VALUE(repo->references.packfile, reference, /* cannot fail: vector already has the right size */ git_vector_insert(&packing_list, reference); ); @@ -929,7 +929,7 @@ static int packed_lookup(git_reference *ref) return GIT_SUCCESS; if (ref->flags & GIT_REF_SYMBOLIC) { - free(ref->target.symbolic); + git__free(ref->target.symbolic); ref->target.symbolic = NULL; } @@ -1513,12 +1513,11 @@ int git_reference_foreach( /* list all the packed references first */ if (list_flags & GIT_REF_PACKED) { const char *ref_name; - void *GIT_UNUSED(_unused); if ((error = packed_load(repo)) < GIT_SUCCESS) return git__rethrow(error, "Failed to list references"); - GIT_HASHTABLE_FOREACH(repo->references.packfile, ref_name, _unused, + GIT_HASHTABLE_FOREACH_KEY(repo->references.packfile, ref_name, if ((error = callback(ref_name, payload)) < GIT_SUCCESS) return git__throw(error, "Failed to list references. User callback failed"); @@ -1595,12 +1594,10 @@ void git_repository__refcache_free(git_refcache *refs) assert(refs); if (refs->packfile) { - const void *GIT_UNUSED(_unused); struct packref *reference; - GIT_HASHTABLE_FOREACH(refs->packfile, _unused, reference, - free(reference); - ); + GIT_HASHTABLE_FOREACH_VALUE( + refs->packfile, reference, git__free(reference)); git_hashtable_free(refs->packfile); } diff --git a/src/remote.c b/src/remote.c index 5b442e93..52b6aacc 100644 --- a/src/remote.c +++ b/src/remote.c @@ -431,13 +431,13 @@ struct cb_data { regex_t *preg; }; -static int remote_list_cb(const char *name, const char *GIT_UNUSED(value), void *data_) +static int remote_list_cb(const char *name, const char *value, void *data_) { struct cb_data *data = (struct cb_data *)data_; size_t nmatch = 2; regmatch_t pmatch[2]; int error; - GIT_UNUSED_ARG(value); + GIT_UNUSED(value); if (!regexec(data->preg, name, nmatch, pmatch, 0)) { char *remote_name = git__strndup(&name[pmatch[1].rm_so], pmatch[1].rm_eo - pmatch[1].rm_so); diff --git a/src/revwalk.c b/src/revwalk.c index cd971b5d..997771f0 100644 --- a/src/revwalk.c +++ b/src/revwalk.c @@ -590,7 +590,6 @@ int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo) void git_revwalk_free(git_revwalk *walk) { unsigned int i; - const void *GIT_UNUSED(_unused); commit_object *commit; if (walk == NULL) @@ -602,7 +601,7 @@ void git_revwalk_free(git_revwalk *walk) /* if the parent has more than PARENTS_PER_COMMIT parents, * we had to allocate a separate array for those parents. * make sure it's being free'd */ - GIT_HASHTABLE_FOREACH(walk->commits, _unused, commit, { + GIT_HASHTABLE_FOREACH_VALUE(walk->commits, commit, { if (commit->out_degree > PARENTS_PER_COMMIT) git__free(commit->parents); }); @@ -669,12 +668,11 @@ int git_revwalk_next(git_oid *oid, git_revwalk *walk) void git_revwalk_reset(git_revwalk *walk) { - const void *GIT_UNUSED(_unused); commit_object *commit; assert(walk); - GIT_HASHTABLE_FOREACH(walk->commits, _unused, commit, + GIT_HASHTABLE_FOREACH_VALUE(walk->commits, commit, commit->seen = 0; commit->in_degree = 0; commit->topo_delay = 0; diff --git a/src/transport.c b/src/transport.c index 672eb6e8..785ddc35 100644 --- a/src/transport.c +++ b/src/transport.c @@ -43,9 +43,9 @@ static git_transport_cb transport_find_fn(const char *url) * Public API * **************/ -int git_transport_dummy(git_transport **GIT_UNUSED(transport)) +int git_transport_dummy(git_transport **transport) { - GIT_UNUSED_ARG(transport); + GIT_UNUSED(transport); return git__throw(GIT_ENOTIMPLEMENTED, "This protocol isn't implemented. Sorry"); } diff --git a/src/transports/local.c b/src/transports/local.c index 1dfc8ed2..eb24db0f 100644 --- a/src/transports/local.c +++ b/src/transports/local.c @@ -154,7 +154,7 @@ static int local_ls(git_transport *transport, git_headlist_cb list_cb, void *pay * Try to open the url as a git directory. The direction doesn't * matter in this case because we're calulating the heads ourselves. */ -static int local_connect(git_transport *transport, int GIT_UNUSED(direction)) +static int local_connect(git_transport *transport, int direction) { git_repository *repo; int error; @@ -162,7 +162,7 @@ static int local_connect(git_transport *transport, int GIT_UNUSED(direction)) const char *path; git_buf buf = GIT_BUF_INIT; - GIT_UNUSED_ARG(direction); + GIT_UNUSED(direction); /* The repo layer doesn't want the prefix */ if (!git__prefixcmp(transport->url, "file://")) { @@ -194,7 +194,7 @@ static int local_connect(git_transport *transport, int GIT_UNUSED(direction)) return GIT_SUCCESS; } -static int local_close(git_transport *GIT_UNUSED(transport)) +static int local_close(git_transport *transport) { transport_local *t = (transport_local *)transport; diff --git a/src/win32/posix.h b/src/win32/posix.h index f4c1c121..60adc966 100644 --- a/src/win32/posix.h +++ b/src/win32/posix.h @@ -11,20 +11,20 @@ #include "fnmatch.h" #include "utf-conv.h" -GIT_INLINE(int) p_link(const char *GIT_UNUSED(old), const char *GIT_UNUSED(new)) +GIT_INLINE(int) p_link(const char *old, const char *new) { - GIT_UNUSED_ARG(old); - GIT_UNUSED_ARG(new); + GIT_UNUSED(old); + GIT_UNUSED(new); errno = ENOSYS; return -1; } -GIT_INLINE(int) p_mkdir(const char *path, mode_t GIT_UNUSED(mode)) +GIT_INLINE(int) p_mkdir(const char *path, mode_t mode) { wchar_t* buf = gitwin_to_utf16(path); int ret = _wmkdir(buf); - GIT_UNUSED_ARG(mode); + GIT_UNUSED(mode); git__free(buf); return ret; diff --git a/src/win32/pthread.c b/src/win32/pthread.c index cbce639c..3db53684 100644 --- a/src/win32/pthread.c +++ b/src/win32/pthread.c @@ -8,10 +8,10 @@ #include "pthread.h" int pthread_create(pthread_t *GIT_RESTRICT thread, - const pthread_attr_t *GIT_RESTRICT GIT_UNUSED(attr), + const pthread_attr_t *GIT_RESTRICT attr, void *(*start_routine)(void*), void *GIT_RESTRICT arg) { - GIT_UNUSED_ARG(attr); + GIT_UNUSED(attr); *thread = (pthread_t) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, arg, 0, NULL); return *thread ? GIT_SUCCESS : git__throw(GIT_EOSERR, "Failed to create pthread"); } @@ -26,9 +26,9 @@ int pthread_join(pthread_t thread, void **value_ptr) } int pthread_mutex_init(pthread_mutex_t *GIT_RESTRICT mutex, - const pthread_mutexattr_t *GIT_RESTRICT GIT_UNUSED(mutexattr)) + const pthread_mutexattr_t *GIT_RESTRICT mutexattr) { - GIT_UNUSED_ARG(mutexattr); + GIT_UNUSED(mutexattr); InitializeCriticalSection(mutex); return 0; } diff --git a/tests-clar/attr/repo.c b/tests-clar/attr/repo.c index 9f6a49bf..2afea23d 100644 --- a/tests-clar/attr/repo.c +++ b/tests-clar/attr/repo.c @@ -104,12 +104,12 @@ void test_attr_repo__get_many(void) } static int count_attrs( - const char *GIT_UNUSED(name), - const char *GIT_UNUSED(value), + const char *name, + const char *value, void *payload) { - GIT_UNUSED_ARG(name); - GIT_UNUSED_ARG(value); + GIT_UNUSED(name); + GIT_UNUSED(value); *((int *)payload) += 1; diff --git a/tests-clar/clar_helpers.c b/tests-clar/clar_helpers.c index 1ef5a9bf..22db56f0 100644 --- a/tests-clar/clar_helpers.c +++ b/tests-clar/clar_helpers.c @@ -39,3 +39,52 @@ void cl_git_append2file(const char *filename, const char *new_content) cl_must_pass(p_chmod(filename, 0644)); } +static const char *_cl_sandbox = NULL; +static git_repository *_cl_repo = NULL; + +git_repository *cl_git_sandbox_init(const char *sandbox) +{ + /* Copy the whole sandbox folder from our fixtures to our test sandbox + * area. After this it can be accessed with `./sandbox` + */ + cl_fixture_sandbox(sandbox); + _cl_sandbox = sandbox; + + p_chdir(sandbox); + + /* Rename `sandbox/.gitted` to `sandbox/.git` which must be done since + * we cannot store a folder named `.git` inside the fixtures folder of + * our libgit2 repo. + */ + cl_git_pass(p_rename(".gitted", ".git")); + + /* If we have `gitattributes`, rename to `.gitattributes`. This may + * be necessary if we don't want the attributes to be applied in the + * libgit2 repo, but just during testing. + */ + if (p_access("gitattributes", F_OK) == 0) + cl_git_pass(p_rename("gitattributes", ".gitattributes")); + + /* As with `gitattributes`, we may need `gitignore` just for testing. */ + if (p_access("gitignore", F_OK) == 0) + cl_git_pass(p_rename("gitignore", ".gitignore")); + + p_chdir(".."); + + /* Now open the sandbox repository and make it available for tests */ + cl_git_pass(git_repository_open(&_cl_repo, sandbox)); + + return _cl_repo; +} + +void cl_git_sandbox_cleanup(void) +{ + if (_cl_repo) { + git_repository_free(_cl_repo); + _cl_repo = NULL; + } + if (_cl_sandbox) { + cl_fixture_cleanup(_cl_sandbox); + _cl_sandbox = NULL; + } +} diff --git a/tests-clar/clar_libgit2.h b/tests-clar/clar_libgit2.h index 43dc4e84..5c034a38 100644 --- a/tests-clar/clar_libgit2.h +++ b/tests-clar/clar_libgit2.h @@ -58,4 +58,9 @@ GIT_INLINE(void) cl_assert_strequal_internal( void cl_git_mkfile(const char *filename, const char *content); void cl_git_append2file(const char *filename, const char *new_content); +/* Git sandbox setup helpers */ + +git_repository *cl_git_sandbox_init(const char *sandbox); +void cl_git_sandbox_cleanup(void); + #endif diff --git a/tests-clar/config/multivar.c b/tests-clar/config/multivar.c index bccdc128..a8451aca 100644 --- a/tests-clar/config/multivar.c +++ b/tests-clar/config/multivar.c @@ -12,10 +12,12 @@ void test_config_multivar__cleanup(void) cl_fixture_cleanup("config"); } -static int mv_read_cb(const char *name, const char *GIT_UNUSED(value), void *data) +static int mv_read_cb(const char *name, const char *value, void *data) { int *n = (int *) data; + GIT_UNUSED(value); + if (!strcmp(name, _name)) (*n)++; @@ -35,10 +37,12 @@ void test_config_multivar__foreach(void) git_config_free(cfg); } -static int cb(const char *GIT_UNUSED(val), void *data) +static int cb(const char *val, void *data) { int *n = (int *) data; + GIT_UNUSED(val); + (*n)++; return GIT_SUCCESS; diff --git a/tests-clar/core/dirent.c b/tests-clar/core/dirent.c index 78237096..9c366bf9 100644 --- a/tests-clar/core/dirent.c +++ b/tests-clar/core/dirent.c @@ -88,10 +88,10 @@ static int one_entry(void *state, git_buf *path) return GIT_ERROR; } -static int dont_call_me(void *GIT_UNUSED(state), git_buf *GIT_UNUSED(path)) +static int dont_call_me(void *state, git_buf *path) { - GIT_UNUSED_ARG(state); - GIT_UNUSED_ARG(path); + GIT_UNUSED(state); + GIT_UNUSED(path); return GIT_ERROR; } diff --git a/tests-clar/diff/blob.c b/tests-clar/diff/blob.c index 7aa8ceb2..bdfe8baa 100644 --- a/tests-clar/diff/blob.c +++ b/tests-clar/diff/blob.c @@ -5,17 +5,12 @@ static git_repository *g_repo = NULL; void test_diff_blob__initialize(void) { - cl_fixture_sandbox("attr"); - cl_git_pass(p_rename("attr/.gitted", "attr/.git")); - cl_git_pass(p_rename("attr/gitattributes", "attr/.gitattributes")); - cl_git_pass(git_repository_open(&g_repo, "attr/.git")); + g_repo = cl_git_sandbox_init("attr"); } void test_diff_blob__cleanup(void) { - git_repository_free(g_repo); - g_repo = NULL; - cl_fixture_cleanup("attr"); + cl_git_sandbox_cleanup(); } void test_diff_blob__0(void) diff --git a/tests-clar/diff/index.c b/tests-clar/diff/index.c index 0941c7c2..171815df 100644 --- a/tests-clar/diff/index.c +++ b/tests-clar/diff/index.c @@ -5,16 +5,12 @@ static git_repository *g_repo = NULL; void test_diff_index__initialize(void) { - cl_fixture_sandbox("status"); - cl_git_pass(p_rename("status/.gitted", "status/.git")); - cl_git_pass(git_repository_open(&g_repo, "status/.git")); + g_repo = cl_git_sandbox_init("status"); } void test_diff_index__cleanup(void) { - git_repository_free(g_repo); - g_repo = NULL; - cl_fixture_cleanup("status"); + cl_git_sandbox_cleanup(); } void test_diff_index__0(void) diff --git a/tests-clar/diff/iterator.c b/tests-clar/diff/iterator.c index 1ad126ca..3953fd83 100644 --- a/tests-clar/diff/iterator.c +++ b/tests-clar/diff/iterator.c @@ -2,37 +2,6 @@ #include "diff_helpers.h" #include "iterator.h" -static git_repository *g_repo = NULL; -static const char *g_sandbox = NULL; - -static void setup_sandbox(const char *sandbox) -{ - cl_fixture_sandbox(sandbox); - g_sandbox = sandbox; - - p_chdir(sandbox); - cl_git_pass(p_rename(".gitted", ".git")); - if (p_access("gitattributes", F_OK) == 0) - cl_git_pass(p_rename("gitattributes", ".gitattributes")); - if (p_access("gitignore", F_OK) == 0) - cl_git_pass(p_rename("gitignore", ".gitignore")); - p_chdir(".."); - - cl_git_pass(git_repository_open(&g_repo, sandbox)); -} - -static void cleanup_sandbox(void) -{ - if (g_repo) { - git_repository_free(g_repo); - g_repo = NULL; - } - if (g_sandbox) { - cl_fixture_cleanup(g_sandbox); - g_sandbox = NULL; - } -} - void test_diff_iterator__initialize(void) { /* since we are doing tests with different sandboxes, defer setup @@ -44,7 +13,7 @@ void test_diff_iterator__initialize(void) void test_diff_iterator__cleanup(void) { - cleanup_sandbox(); + cl_git_sandbox_cleanup(); } @@ -60,11 +29,10 @@ static void tree_iterator_test( git_iterator *i; const git_index_entry *entry; int count = 0; + git_repository *repo = cl_git_sandbox_init(sandbox); - setup_sandbox(sandbox); - - cl_assert(t = resolve_commit_oid_to_tree(g_repo, treeish)); - cl_git_pass(git_iterator_for_tree(g_repo, t, &i)); + cl_assert(t = resolve_commit_oid_to_tree(repo, treeish)); + cl_git_pass(git_iterator_for_tree(repo, t, &i)); cl_git_pass(git_iterator_current(i, &entry)); while (entry != NULL) { @@ -183,10 +151,9 @@ static void index_iterator_test( git_iterator *i; const git_index_entry *entry; int count = 0; + git_repository *repo = cl_git_sandbox_init(sandbox); - setup_sandbox(sandbox); - - cl_git_pass(git_iterator_for_index(g_repo, &i)); + cl_git_pass(git_iterator_for_index(repo, &i)); cl_git_pass(git_iterator_current(i, &entry)); while (entry != NULL) { @@ -303,10 +270,9 @@ static void workdir_iterator_test( git_iterator *i; const git_index_entry *entry; int count = 0, count_all = 0; + git_repository *repo = cl_git_sandbox_init(sandbox); - setup_sandbox(sandbox); - - cl_git_pass(git_iterator_for_workdir(g_repo, &i)); + cl_git_pass(git_iterator_for_workdir(repo, &i)); cl_git_pass(git_iterator_current(i, &entry)); while (entry != NULL) { diff --git a/tests-clar/diff/tree.c b/tests-clar/diff/tree.c index f5fdfba1..91e1343c 100644 --- a/tests-clar/diff/tree.c +++ b/tests-clar/diff/tree.c @@ -5,17 +5,12 @@ static git_repository *g_repo = NULL; void test_diff_tree__initialize(void) { - cl_fixture_sandbox("attr"); - cl_git_pass(p_rename("attr/.gitted", "attr/.git")); - cl_git_pass(p_rename("attr/gitattributes", "attr/.gitattributes")); - cl_git_pass(git_repository_open(&g_repo, "attr/.git")); + g_repo = cl_git_sandbox_init("attr"); } void test_diff_tree__cleanup(void) { - git_repository_free(g_repo); - g_repo = NULL; - cl_fixture_cleanup("attr"); + cl_git_sandbox_cleanup(); } void test_diff_tree__0(void) diff --git a/tests-clar/diff/workdir.c b/tests-clar/diff/workdir.c index 7312a72a..28cfa23e 100644 --- a/tests-clar/diff/workdir.c +++ b/tests-clar/diff/workdir.c @@ -5,16 +5,12 @@ static git_repository *g_repo = NULL; void test_diff_workdir__initialize(void) { - cl_fixture_sandbox("status"); - cl_git_pass(p_rename("status/.gitted", "status/.git")); - cl_git_pass(git_repository_open(&g_repo, "status/.git")); + g_repo = cl_git_sandbox_init("status"); } void test_diff_workdir__cleanup(void) { - git_repository_free(g_repo); - g_repo = NULL; - cl_fixture_cleanup("status"); + cl_git_sandbox_cleanup(); } void test_diff_workdir__to_index(void) diff --git a/tests-clar/status/ignore.c b/tests-clar/status/ignore.c index 67aecba3..99cb9e8b 100644 --- a/tests-clar/status/ignore.c +++ b/tests-clar/status/ignore.c @@ -7,21 +7,12 @@ static git_repository *g_repo = NULL; void test_status_ignore__initialize(void) { - /* Before each test, instantiate the attr repo from the fixtures and - * rename the .gitted to .git so it is a repo with a working dir. Also - * rename gitignore to .gitignore. - */ - cl_fixture_sandbox("attr"); - cl_git_pass(p_rename("attr/.gitted", "attr/.git")); - cl_git_pass(p_rename("attr/gitignore", "attr/.gitignore")); - cl_git_pass(git_repository_open(&g_repo, "attr/.git")); + g_repo = cl_git_sandbox_init("attr"); } void test_status_ignore__cleanup(void) { - git_repository_free(g_repo); - g_repo = NULL; - cl_fixture_cleanup("attr"); + cl_git_sandbox_cleanup(); } void test_status_ignore__0(void) diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c index 7d730bb9..f654b8a9 100644 --- a/tests-clar/status/worktree.c +++ b/tests-clar/status/worktree.c @@ -5,12 +5,6 @@ /** - * Test fixtures - */ -static git_repository *_repository = NULL; - - -/** * Auxiliary methods */ static int @@ -37,48 +31,27 @@ exit: } static int -cb_status__count(const char *GIT_UNUSED(p), unsigned int GIT_UNUSED(s), void *payload) +cb_status__count(const char *p, unsigned int s, void *payload) { volatile int *count = (int *)payload; - GIT_UNUSED_ARG(p); - GIT_UNUSED_ARG(s); + GIT_UNUSED(p); + GIT_UNUSED(s); - *count++; + (*count)++; return GIT_SUCCESS; } - /** * Initializer * - * This method is called once before starting each - * test, and will load the required fixtures + * Not all of the tests in this file use the same fixtures, so we allow each + * test to load their fixture at the top of the test function. */ void test_status_worktree__initialize(void) { - /* - * Sandbox the `status/` repository from our Fixtures. - * This will copy the whole folder to our sandbox, - * so now it can be accessed with `./status` - */ - cl_fixture_sandbox("status"); - - /* - * Rename `status/.gitted` to `status/.git` - * We do this because we cannot store a folder named `.git` - * inside the fixtures folder in our libgit2 repo. - */ - cl_git_pass( - p_rename("status/.gitted", "status/.git") - ); - - /* - * Open the sandboxed "status" repository - */ - cl_git_pass(git_repository_open(&_repository, "status/.git")); } /** @@ -89,10 +62,7 @@ void test_status_worktree__initialize(void) */ void test_status_worktree__cleanup(void) { - git_repository_free(_repository); - _repository = NULL; - - cl_fixture_cleanup("status"); + cl_git_sandbox_cleanup(); } /** @@ -101,6 +71,7 @@ void test_status_worktree__cleanup(void) void test_status_worktree__whole_repository(void) { struct status_entry_counts counts; + git_repository *repo = cl_git_sandbox_init("status"); memset(&counts, 0x0, sizeof(struct status_entry_counts)); counts.expected_entry_count = entry_count0; @@ -108,7 +79,7 @@ void test_status_worktree__whole_repository(void) counts.expected_statuses = entry_statuses0; cl_git_pass( - git_status_foreach(_repository, cb_status__normal, &counts) + git_status_foreach(repo, cb_status__normal, &counts) ); cl_assert(counts.entry_count == counts.expected_entry_count); @@ -119,8 +90,10 @@ void test_status_worktree__whole_repository(void) void test_status_worktree__empty_repository(void) { int count = 0; + git_repository *repo = cl_git_sandbox_init("empty_standard_repo"); + + cl_git_pass(git_status_foreach(repo, cb_status__count, &count)); - git_status_foreach(_repository, cb_status__count, &count); cl_assert(count == 0); } @@ -128,10 +101,11 @@ void test_status_worktree__single_file(void) { int i; unsigned int status_flags; + git_repository *repo = cl_git_sandbox_init("status"); for (i = 0; i < (int)entry_count0; i++) { cl_git_pass( - git_status_file(&status_flags, _repository, entry_paths0[i]) + git_status_file(&status_flags, repo, entry_paths0[i]) ); cl_assert(entry_statuses0[i] == status_flags); } @@ -140,15 +114,22 @@ void test_status_worktree__single_file(void) void test_status_worktree__ignores(void) { int i, ignored; + git_repository *repo = cl_git_sandbox_init("status"); for (i = 0; i < (int)entry_count0; i++) { - cl_git_pass(git_status_should_ignore(_repository, entry_paths0[i], &ignored)); + cl_git_pass( + git_status_should_ignore(repo, entry_paths0[i], &ignored) + ); cl_assert(ignored == (entry_statuses0[i] == GIT_STATUS_WT_IGNORED)); } - cl_git_pass(git_status_should_ignore(_repository, "nonexistent_file", &ignored)); + cl_git_pass( + git_status_should_ignore(repo, "nonexistent_file", &ignored) + ); cl_assert(!ignored); - cl_git_pass(git_status_should_ignore(_repository, "ignored_nonexistent_file", &ignored)); + cl_git_pass( + git_status_should_ignore(repo, "ignored_nonexistent_file", &ignored) + ); cl_assert(ignored); } diff --git a/tests/t00-core.c b/tests/t00-core.c index aff48b07..7f142ba2 100644 --- a/tests/t00-core.c +++ b/tests/t00-core.c @@ -424,10 +424,10 @@ static walk_data empty = { GIT_BUF_INIT }; -static int dont_call_me(void *GIT_UNUSED(state), git_buf *GIT_UNUSED(path)) +static int dont_call_me(void *state, git_buf *path) { - GIT_UNUSED_ARG(state); - GIT_UNUSED_ARG(path); + GIT_UNUSED(state); + GIT_UNUSED(path); return GIT_ERROR; } diff --git a/tests/t07-hashtable.c b/tests/t07-hashtable.c index 41d52af1..6beaeac6 100644 --- a/tests/t07-hashtable.c +++ b/tests/t07-hashtable.c @@ -154,7 +154,6 @@ BEGIN_TEST(tableit0, "iterate through all the contents of the table") const int objects_n = 32; int i; table_item *objects, *ob; - const void *GIT_UNUSED(_unused); git_hashtable *table = NULL; @@ -170,9 +169,7 @@ BEGIN_TEST(tableit0, "iterate through all the contents of the table") must_pass(git_hashtable_insert(table, &(objects[i].id), &(objects[i]))); } - GIT_HASHTABLE_FOREACH(table, _unused, ob, - ob->visited = 1; - ); + GIT_HASHTABLE_FOREACH_VALUE(table, ob, ob->visited = 1); /* make sure all nodes have been visited */ for (i = 0; i < objects_n; ++i) diff --git a/tests/t18-status.c b/tests/t18-status.c index 8bccb710..aeadd5e6 100644 --- a/tests/t18-status.c +++ b/tests/t18-status.c @@ -156,14 +156,14 @@ BEGIN_TEST(statuscb0, "test retrieving status for worktree of repository") git_futils_rmdir_r(TEMP_REPO_FOLDER, 1); END_TEST -static int status_cb1(const char *GIT_UNUSED(path), unsigned int GIT_UNUSED(status_flags), void *payload) +static int status_cb1(const char *path, unsigned int status_flags, void *payload) { int *count = (int *)payload;; - GIT_UNUSED_ARG(path); - GIT_UNUSED_ARG(status_flags); + GIT_UNUSED(path); + GIT_UNUSED(status_flags); - (void) *count++; + (*count)++; return GIT_SUCCESS; } diff --git a/tests/test_main.c b/tests/test_main.c index 732d25a9..50256e97 100644 --- a/tests/test_main.c +++ b/tests/test_main.c @@ -70,12 +70,12 @@ int __cdecl #else int #endif -main(int GIT_UNUSED(argc), char *GIT_UNUSED(argv[])) +main(int argc, char *argv[]) { unsigned int i, failures; - GIT_UNUSED_ARG(argc); - GIT_UNUSED_ARG(argv); + GIT_UNUSED(argc); + GIT_UNUSED(argv); git_threads_init(); |