diff options
-rw-r--r-- | examples/describe.c | 2 | ||||
-rw-r--r-- | src/config_file.c | 4 | ||||
-rw-r--r-- | src/fnmatch.c | 10 | ||||
-rw-r--r-- | src/global.c | 16 | ||||
-rw-r--r-- | src/iterator.c | 8 | ||||
-rw-r--r-- | src/netops.c | 6 | ||||
-rw-r--r-- | src/odb.c | 2 | ||||
-rw-r--r-- | src/path.c | 8 | ||||
-rw-r--r-- | src/transports/cred.c | 6 | ||||
-rw-r--r-- | src/util.c | 18 | ||||
-rw-r--r-- | src/util.h | 9 | ||||
-rw-r--r-- | tests/core/path.c | 2 | ||||
-rw-r--r-- | tests/core/string.c | 42 | ||||
-rw-r--r-- | tests/diff/index.c | 2 | ||||
-rw-r--r-- | tests/diff/workdir.c | 2 | ||||
-rw-r--r-- | tests/index/addall.c | 5 | ||||
-rw-r--r-- | tests/odb/foreach.c | 20 | ||||
-rw-r--r-- | tests/stash/apply.c | 8 | ||||
-rw-r--r-- | tests/status/worktree.c | 4 |
19 files changed, 138 insertions, 36 deletions
diff --git a/examples/describe.c b/examples/describe.c index f7b4b1c20..4cdf61f75 100644 --- a/examples/describe.c +++ b/examples/describe.c @@ -135,6 +135,8 @@ static void parse_options(describe_options *opts, int argc, char **argv) } else if (match_int_arg((int *)&opts->format_options.abbreviated_size, &args, "--abbrev", 0)) { } else if (match_int_arg((int *)&opts->describe_options.max_candidates_tags, &args, "--candidates", 0)) { } else if (match_str_arg(&opts->describe_options.pattern, &args, "--match")) { + } else { + print_usage(); } } diff --git a/src/config_file.c b/src/config_file.c index d6a62b85c..52a5376bd 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -156,7 +156,7 @@ int git_config_file_normalize_section(char *start, char *end) if (end && scan >= end) break; if (isalnum(*scan)) - *scan = (char)tolower(*scan); + *scan = (char)git__tolower(*scan); else if (*scan != '-' || scan == start) return GIT_EINVALIDSPEC; } @@ -1083,7 +1083,7 @@ static int parse_section_header(struct reader *reader, char **section_out) goto fail_parse; } - name[name_length++] = (char) tolower(c); + name[name_length++] = (char)git__tolower(c); } while ((c = line[pos++]) != ']'); diff --git a/src/fnmatch.c b/src/fnmatch.c index d7899e3e6..a2945b8db 100644 --- a/src/fnmatch.c +++ b/src/fnmatch.c @@ -164,8 +164,8 @@ p_fnmatchx(const char *pattern, const char *string, int flags, size_t recurs) default: normal: if (c != *string && !((flags & FNM_CASEFOLD) && - (tolower((unsigned char)c) == - tolower((unsigned char)*string)))) + (git__tolower((unsigned char)c) == + git__tolower((unsigned char)*string)))) return (FNM_NOMATCH); ++string; break; @@ -190,7 +190,7 @@ rangematch(const char *pattern, char test, int flags, char **newp) ++pattern; if (flags & FNM_CASEFOLD) - test = (char)tolower((unsigned char)test); + test = (char)git__tolower((unsigned char)test); /* * A right bracket shall lose its special meaning and represent @@ -207,7 +207,7 @@ rangematch(const char *pattern, char test, int flags, char **newp) if (c == '/' && (flags & FNM_PATHNAME)) return (RANGE_NOMATCH); if ((flags & FNM_CASEFOLD)) - c = (char)tolower((unsigned char)c); + c = (char)git__tolower((unsigned char)c); if (*pattern == '-' && (c2 = *(pattern+1)) != EOS && c2 != ']') { pattern += 2; @@ -216,7 +216,7 @@ rangematch(const char *pattern, char test, int flags, char **newp) if (c2 == EOS) return (RANGE_ERROR); if (flags & FNM_CASEFOLD) - c2 = (char)tolower((unsigned char)c2); + c2 = (char)git__tolower((unsigned char)c2); if (c <= test && test <= c2) ok = 1; } else if (c == test) diff --git a/src/global.c b/src/global.c index 9f1a0bf10..3f20bfd31 100644 --- a/src/global.c +++ b/src/global.c @@ -116,6 +116,20 @@ static void init_ssl(void) #endif } +/** + * This function aims to clean-up the SSL context which + * we allocated. + */ +static void uninit_ssl(void) +{ +#ifdef GIT_OPENSSL + if (git__ssl_ctx) { + SSL_CTX_free(git__ssl_ctx); + git__ssl_ctx = NULL; + } +#endif +} + int git_openssl_set_locking(void) { #ifdef GIT_OPENSSL @@ -333,6 +347,7 @@ int git_libgit2_shutdown(void) /* Shut down any subsystems that have global state */ git__shutdown(); + uninit_ssl(); ptr = pthread_getspecific(_tls_key); pthread_setspecific(_tls_key, NULL); @@ -391,6 +406,7 @@ int git_libgit2_shutdown(void) git__shutdown(); git__global_state_cleanup(&__state); + uninit_ssl(); return 0; } diff --git a/src/iterator.c b/src/iterator.c index 93303a87d..7807a1636 100644 --- a/src/iterator.c +++ b/src/iterator.c @@ -1405,10 +1405,10 @@ GIT_INLINE(bool) workdir_path_is_dotgit(const git_buf *path) if (path->ptr[len - 1] == '/') len--; - if (tolower(path->ptr[len - 1]) != 't' || - tolower(path->ptr[len - 2]) != 'i' || - tolower(path->ptr[len - 3]) != 'g' || - tolower(path->ptr[len - 4]) != '.') + if (git__tolower(path->ptr[len - 1]) != 't' || + git__tolower(path->ptr[len - 2]) != 'i' || + git__tolower(path->ptr[len - 3]) != 'g' || + git__tolower(path->ptr[len - 4]) != '.') return false; return (len == 4 || path->ptr[len - 5] == '/'); diff --git a/src/netops.c b/src/netops.c index 6047cf1ac..5e8075597 100644 --- a/src/netops.c +++ b/src/netops.c @@ -84,7 +84,7 @@ void gitno_consume_n(gitno_buffer *buf, size_t cons) int gitno__match_host(const char *pattern, const char *host) { for (;;) { - char c = tolower(*pattern++); + char c = git__tolower(*pattern++); if (c == '\0') return *host ? -1 : 0; @@ -102,7 +102,7 @@ int gitno__match_host(const char *pattern, const char *host) */ while(*host) { - char h = tolower(*host); + char h = git__tolower(*host); if (c == h) return gitno__match_host(pattern, host++); if (h == '.') @@ -112,7 +112,7 @@ int gitno__match_host(const char *pattern, const char *host) return -1; } - if (c != tolower(*host++)) + if (c != git__tolower(*host++)) return -1; } @@ -53,7 +53,7 @@ static int load_alternates(git_odb *odb, const char *objects_dir, int alternate_ int git_odb__format_object_header(char *hdr, size_t n, git_off_t obj_len, git_otype obj_type) { const char *type_str = git_object_type2string(obj_type); - int len = p_snprintf(hdr, n, "%s %"PRIuZ, type_str, obj_len); + int len = p_snprintf(hdr, n, "%s %lld", type_str, obj_len); assert(len > 0 && len <= (int)n); return len+1; } diff --git a/src/path.c b/src/path.c index 81b4d51df..02917607a 100644 --- a/src/path.c +++ b/src/path.c @@ -1066,8 +1066,10 @@ int git_path_direach( git_buf_truncate(path, wd_len); /* restore path */ /* Only set our own error if the callback did not set one already */ - if (error != 0 && !giterr_last()) { - giterr_set_after_callback(error); + if (error != 0) { + if (!giterr_last()) + giterr_set_after_callback(error); + break; } } @@ -1471,7 +1473,7 @@ static int32_t next_hfs_char(const char **in, size_t *len) * the ASCII range, which is perfectly fine, because the * git folder name can only be composed of ascii characters */ - return tolower(codepoint); + return git__tolower(codepoint); } return 0; /* NULL byte -- end of string */ } diff --git a/src/transports/cred.c b/src/transports/cred.c index 006cd2c52..044b2a262 100644 --- a/src/transports/cred.c +++ b/src/transports/cred.c @@ -209,6 +209,12 @@ int git_cred_ssh_key_memory_new( passphrase, GIT_CREDTYPE_SSH_MEMORY); #else + GIT_UNUSED(cred); + GIT_UNUSED(username); + GIT_UNUSED(publickey); + GIT_UNUSED(privatekey); + GIT_UNUSED(passphrase); + giterr_set(GITERR_INVALID, "This version of libgit2 was not built with ssh memory credentials."); return -1; diff --git a/src/util.c b/src/util.c index 6bb7d03ee..c62826420 100644 --- a/src/util.c +++ b/src/util.c @@ -171,9 +171,9 @@ int git__strcmp(const char *a, const char *b) int git__strcasecmp(const char *a, const char *b) { - while (*a && *b && tolower(*a) == tolower(*b)) + while (*a && *b && git__tolower(*a) == git__tolower(*b)) ++a, ++b; - return (tolower(*a) - tolower(*b)); + return ((unsigned char)git__tolower(*a) - (unsigned char)git__tolower(*b)); } int git__strcasesort_cmp(const char *a, const char *b) @@ -182,7 +182,7 @@ int git__strcasesort_cmp(const char *a, const char *b) while (*a && *b) { if (*a != *b) { - if (tolower(*a) != tolower(*b)) + if (git__tolower(*a) != git__tolower(*b)) break; /* use case in sort order even if not in equivalence */ if (!cmp) @@ -193,7 +193,7 @@ int git__strcasesort_cmp(const char *a, const char *b) } if (*a || *b) - return tolower(*a) - tolower(*b); + return (unsigned char)git__tolower(*a) - (unsigned char)git__tolower(*b); return cmp; } @@ -212,8 +212,8 @@ int git__strncasecmp(const char *a, const char *b, size_t sz) int al, bl; do { - al = (unsigned char)tolower(*a); - bl = (unsigned char)tolower(*b); + al = (unsigned char)git__tolower(*a); + bl = (unsigned char)git__tolower(*b); ++a, ++b; } while (--sz && al && al == bl); @@ -225,7 +225,7 @@ void git__strntolower(char *str, size_t len) size_t i; for (i = 0; i < len; ++i) { - str[i] = (char) tolower(str[i]); + str[i] = (char)git__tolower(str[i]); } } @@ -255,8 +255,8 @@ int git__prefixncmp_icase(const char *str, size_t str_n, const char *prefix) int s, p; while(str_n--) { - s = (unsigned char)tolower(*str++); - p = (unsigned char)tolower(*prefix++); + s = (unsigned char)git__tolower(*str++); + p = (unsigned char)git__tolower(*prefix++); if (s != p) return s - p; diff --git a/src/util.h b/src/util.h index be6534580..b2abbe6a6 100644 --- a/src/util.h +++ b/src/util.h @@ -275,6 +275,15 @@ extern char *git__strsep(char **end, const char *sep); extern void git__strntolower(char *str, size_t len); extern void git__strtolower(char *str); +#ifdef GIT_WIN32 +GIT_INLINE(int) git__tolower(int c) +{ + return (c >= 'A' && c <= 'Z') ? (c + 32) : c; +} +#else +# define git__tolower(a) tolower(a) +#endif + GIT_INLINE(const char *) git__next_line(const char *s) { while (*s && *s != '\n') s++; diff --git a/tests/core/path.c b/tests/core/path.c index 7d3e4938f..c3e622f02 100644 --- a/tests/core/path.c +++ b/tests/core/path.c @@ -492,7 +492,7 @@ void test_core_path__13_cannot_prettify_a_non_existing_file(void) { git_buf p = GIT_BUF_INIT; - cl_must_pass(git_path_exists(NON_EXISTING_FILEPATH) == false); + cl_assert_equal_b(git_path_exists(NON_EXISTING_FILEPATH), false); cl_assert_equal_i(GIT_ENOTFOUND, git_path_prettify(&p, NON_EXISTING_FILEPATH, NULL)); cl_assert_equal_i(GIT_ENOTFOUND, git_path_prettify(&p, NON_EXISTING_FILEPATH "/so-do-i", NULL)); diff --git a/tests/core/string.c b/tests/core/string.c index ec9575685..90e8fa027 100644 --- a/tests/core/string.c +++ b/tests/core/string.c @@ -39,3 +39,45 @@ void test_core_string__2(void) cl_assert(git__strcasesort_cmp("BAR", "foo") < 0); cl_assert(git__strcasesort_cmp("fooBar", "foobar") < 0); } + +void test_core_string__strcmp(void) +{ + cl_assert(git__strcmp("", "") == 0); + cl_assert(git__strcmp("foo", "foo") == 0); + cl_assert(git__strcmp("Foo", "foo") < 0); + cl_assert(git__strcmp("foo", "FOO") > 0); + cl_assert(git__strcmp("foo", "fOO") > 0); + + cl_assert(strcmp("rt\303\202of", "rt dev\302\266h") > 0); + cl_assert(strcmp("e\342\202\254ghi=", "et") > 0); + cl_assert(strcmp("rt dev\302\266h", "rt\303\202of") < 0); + cl_assert(strcmp("et", "e\342\202\254ghi=") < 0); + cl_assert(strcmp("\303\215", "\303\255") < 0); + + cl_assert(git__strcmp("rt\303\202of", "rt dev\302\266h") > 0); + cl_assert(git__strcmp("e\342\202\254ghi=", "et") > 0); + cl_assert(git__strcmp("rt dev\302\266h", "rt\303\202of") < 0); + cl_assert(git__strcmp("et", "e\342\202\254ghi=") < 0); + cl_assert(git__strcmp("\303\215", "\303\255") < 0); +} + +void test_core_string__strcasecmp(void) +{ + cl_assert(git__strcasecmp("", "") == 0); + cl_assert(git__strcasecmp("foo", "foo") == 0); + cl_assert(git__strcasecmp("foo", "Foo") == 0); + cl_assert(git__strcasecmp("foo", "FOO") == 0); + cl_assert(git__strcasecmp("foo", "fOO") == 0); + + cl_assert(strcasecmp("rt\303\202of", "rt dev\302\266h") > 0); + cl_assert(strcasecmp("e\342\202\254ghi=", "et") > 0); + cl_assert(strcasecmp("rt dev\302\266h", "rt\303\202of") < 0); + cl_assert(strcasecmp("et", "e\342\202\254ghi=") < 0); + cl_assert(strcasecmp("\303\215", "\303\255") < 0); + + cl_assert(git__strcasecmp("rt\303\202of", "rt dev\302\266h") > 0); + cl_assert(git__strcasecmp("e\342\202\254ghi=", "et") > 0); + cl_assert(git__strcasecmp("rt dev\302\266h", "rt\303\202of") < 0); + cl_assert(git__strcasecmp("et", "e\342\202\254ghi=") < 0); + cl_assert(git__strcasecmp("\303\215", "\303\255") < 0); +} diff --git a/tests/diff/index.c b/tests/diff/index.c index a544b83c7..cf883f12a 100644 --- a/tests/diff/index.c +++ b/tests/diff/index.c @@ -168,7 +168,7 @@ static void do_conflicted_diff(diff_expects *exp, unsigned long flags) const char *a_commit = "26a125ee1bf"; /* the current HEAD */ git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit); git_diff_options opts = GIT_DIFF_OPTIONS_INIT; - git_index_entry ancestor = {0}, ours = {0}, theirs = {0}; + git_index_entry ancestor = {{0}}, ours = {{0}}, theirs = {{0}}; git_diff *diff = NULL; git_index *index; diff --git a/tests/diff/workdir.c b/tests/diff/workdir.c index 460f1b592..65005f927 100644 --- a/tests/diff/workdir.c +++ b/tests/diff/workdir.c @@ -73,7 +73,7 @@ void test_diff_workdir__to_index_with_conflicts(void) git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff *diff = NULL; git_index *index; - git_index_entry our_entry = {0}, their_entry = {0}; + git_index_entry our_entry = {{0}}, their_entry = {{0}}; diff_expects exp = {0}; g_repo = cl_git_sandbox_init("status"); diff --git a/tests/index/addall.c b/tests/index/addall.c index 211e76228..f344cc6ae 100644 --- a/tests/index/addall.c +++ b/tests/index/addall.c @@ -288,7 +288,6 @@ void test_index_addall__repo_lifecycle(void) void test_index_addall__files_in_folders(void) { git_index *index; - git_strarray paths = { NULL, 0 }; addall_create_test_repo(true); @@ -408,7 +407,7 @@ void test_index_addall__adds_conflicts(void) cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/branch")); cl_git_pass(git_annotated_commit_from_ref(&annotated, g_repo, ref)); - cl_git_pass(git_merge(g_repo, &annotated, 1, NULL, NULL)); + cl_git_pass(git_merge(g_repo, (const git_annotated_commit**)&annotated, 1, NULL, NULL)); check_status(g_repo, 0, 1, 2, 0, 0, 0, 0, 1); cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL)); @@ -433,7 +432,7 @@ void test_index_addall__removes_deleted_conflicted_files(void) cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/branch")); cl_git_pass(git_annotated_commit_from_ref(&annotated, g_repo, ref)); - cl_git_pass(git_merge(g_repo, &annotated, 1, NULL, NULL)); + cl_git_pass(git_merge(g_repo, (const git_annotated_commit**)&annotated, 1, NULL, NULL)); check_status(g_repo, 0, 1, 2, 0, 0, 0, 0, 1); cl_git_rmfile("merge-resolve/conflicting.txt"); diff --git a/tests/odb/foreach.c b/tests/odb/foreach.c index 75448a2f7..12b81b4f1 100644 --- a/tests/odb/foreach.c +++ b/tests/odb/foreach.c @@ -71,15 +71,35 @@ static int foreach_stop_cb(const git_oid *oid, void *data) return (*nobj == 1000) ? -321 : 0; } +static int foreach_stop_first_cb(const git_oid *oid, void *data) +{ + int *nobj = data; + (*nobj)++; + + GIT_UNUSED(oid); + + return -123; +} + void test_odb_foreach__interrupt_foreach(void) { int nobj = 0; + git_oid id; cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git"))); git_repository_odb(&_odb, _repo); cl_assert_equal_i(-321, git_odb_foreach(_odb, foreach_stop_cb, &nobj)); cl_assert(nobj == 1000); + + git_odb_free(_odb); + git_repository_free(_repo); + + cl_git_pass(git_repository_init(&_repo, "onlyloose.git", true)); + git_repository_odb(&_odb, _repo); + + cl_git_pass(git_odb_write(&id, _odb, "", 0, GIT_OBJ_BLOB)); + cl_assert_equal_i(-123, git_odb_foreach(_odb, foreach_stop_first_cb, &nobj)); } void test_odb_foreach__files_in_objects_dir(void) diff --git a/tests/stash/apply.c b/tests/stash/apply.c index e9b56f8c6..c242536be 100644 --- a/tests/stash/apply.c +++ b/tests/stash/apply.c @@ -254,6 +254,11 @@ int checkout_notify( { struct seen_paths *seen_paths = (struct seen_paths *)payload; + GIT_UNUSED(why); + GIT_UNUSED(baseline); + GIT_UNUSED(target); + GIT_UNUSED(workdir); + if (strcmp(path, "what") == 0) seen_paths->what = 1; else if (strcmp(path, "how") == 0) @@ -318,6 +323,8 @@ int aborting_progress_cb( git_stash_apply_progress_t progress, void *payload) { + GIT_UNUSED(payload); + if (progress == GIT_STASH_APPLY_PROGRESS_ANALYZE_MODIFIED) return -44; @@ -327,7 +334,6 @@ int aborting_progress_cb( void test_stash_apply__progress_cb_can_abort(void) { git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT; - git_stash_apply_progress_t progress = GIT_STASH_APPLY_PROGRESS_NONE; opts.progress_cb = aborting_progress_cb; diff --git a/tests/status/worktree.c b/tests/status/worktree.c index e272c0a10..3b18ae6c0 100644 --- a/tests/status/worktree.c +++ b/tests/status/worktree.c @@ -649,10 +649,10 @@ void test_status_worktree__conflict_has_no_oid(void) { git_repository *repo = cl_git_sandbox_init("status"); git_index *index; - git_index_entry entry = {0}; + git_index_entry entry = {{0}}; git_status_list *statuslist; const git_status_entry *status; - git_oid zero_id = {0}; + git_oid zero_id = {{0}}; entry.mode = 0100644; entry.path = "modified_file"; |