diff options
Diffstat (limited to 't/helper')
67 files changed, 345 insertions, 169 deletions
diff --git a/t/helper/test-advise.c b/t/helper/test-advise.c index cb881139f7..8a3fd0009a 100644 --- a/t/helper/test-advise.c +++ b/t/helper/test-advise.c @@ -1,7 +1,7 @@ #include "test-tool.h" -#include "cache.h" #include "advice.h" #include "config.h" +#include "setup.h" int cmd__advise_if_enabled(int argc, const char **argv) { diff --git a/t/helper/test-bitmap.c b/t/helper/test-bitmap.c index ff35f5999b..af43ee1cb5 100644 --- a/t/helper/test-bitmap.c +++ b/t/helper/test-bitmap.c @@ -1,6 +1,7 @@ #include "test-tool.h" -#include "cache.h" +#include "git-compat-util.h" #include "pack-bitmap.h" +#include "setup.h" static int bitmap_list_commits(void) { diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c index 6c900ca668..aabe31d724 100644 --- a/t/helper/test-bloom.c +++ b/t/helper/test-bloom.c @@ -1,7 +1,9 @@ -#include "git-compat-util.h" -#include "bloom.h" #include "test-tool.h" +#include "bloom.h" +#include "hex.h" #include "commit.h" +#include "repository.h" +#include "setup.h" static struct bloom_filter_settings settings = DEFAULT_BLOOM_FILTER_SETTINGS; diff --git a/t/helper/test-bundle-uri.c b/t/helper/test-bundle-uri.c index b18e760310..475058592d 100644 --- a/t/helper/test-bundle-uri.c +++ b/t/helper/test-bundle-uri.c @@ -1,6 +1,7 @@ #include "test-tool.h" #include "parse-options.h" #include "bundle-uri.h" +#include "gettext.h" #include "strbuf.h" #include "string-list.h" #include "transport.h" diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c index 9159a17301..9507b356e2 100644 --- a/t/helper/test-cache-tree.c +++ b/t/helper/test-cache-tree.c @@ -1,9 +1,13 @@ #define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" +#include "gettext.h" +#include "hex.h" #include "tree.h" #include "cache-tree.h" #include "parse-options.h" +#include "repository.h" +#include "setup.h" static char const * const test_cache_tree_usage[] = { N_("test-tool cache-tree <options> (control|prime|update)"), diff --git a/t/helper/test-chmtime.c b/t/helper/test-chmtime.c index dc28890a18..0e5538833a 100644 --- a/t/helper/test-chmtime.c +++ b/t/helper/test-chmtime.c @@ -94,7 +94,7 @@ int cmd__chmtime(int argc, const char **argv) if (timespec_arg(argv[i], &set_time, &set_eq)) { ++i; } else { - if (get == 0) { + if (get == 0 && verbose == 0) { fprintf(stderr, "Not a base-10 integer: %s\n", argv[i] + 1); goto usage; } diff --git a/t/helper/test-config.c b/t/helper/test-config.c index 4ba9eb6560..ad78fc1768 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -1,6 +1,6 @@ #include "test-tool.h" -#include "cache.h" #include "config.h" +#include "setup.h" #include "string-list.h" /* @@ -14,6 +14,8 @@ * get_value_multi -> prints all values for the entered key in increasing order * of priority * + * get -> print return value for the entered key + * * get_int -> print integer value for the entered key or die * * get_bool -> print bool value for the entered key or die @@ -30,6 +32,9 @@ * iterate -> iterate over all values using git_config(), and print some * data for each * + * git_config_int -> iterate over all values using git_config() and print the + * integer value for the entered key or die + * * Examples: * * To print the value with highest priority for key "foo.bAr Baz.rock": @@ -54,6 +59,17 @@ static int iterate_cb(const char *var, const char *value, void *data UNUSED) return 0; } +static int parse_int_cb(const char *var, const char *value, void *data) +{ + const char *key_to_match = data; + + if (!strcmp(key_to_match, var)) { + int parsed = git_config_int(value, value); + printf("%d\n", parsed); + } + return 0; +} + static int early_config_cb(const char *var, const char *value, void *vdata) { const char *key = vdata; @@ -95,8 +111,7 @@ int cmd__config(int argc, const char **argv) goto exit1; } } else if (argc == 3 && !strcmp(argv[1], "get_value_multi")) { - strptr = git_config_get_value_multi(argv[2]); - if (strptr) { + if (!git_config_get_value_multi(argv[2], &strptr)) { for (i = 0; i < strptr->nr; i++) { v = strptr->items[i].string; if (!v) @@ -109,6 +124,26 @@ int cmd__config(int argc, const char **argv) printf("Value not found for \"%s\"\n", argv[2]); goto exit1; } + } else if (argc == 3 && !strcmp(argv[1], "get")) { + int ret; + + if (!(ret = git_config_get(argv[2]))) + goto exit0; + else if (ret == 1) + printf("Value not found for \"%s\"\n", argv[2]); + else if (ret == -CONFIG_INVALID_KEY) + printf("Key \"%s\" is invalid\n", argv[2]); + else if (ret == -CONFIG_NO_SECTION_OR_NAME) + printf("Key \"%s\" has no section\n", argv[2]); + else + /* + * A normal caller should just check "ret < + * 0", but for our own tests let's BUG() if + * our whitelist of git_config_parse_key() + * return values isn't exhaustive. + */ + BUG("Key \"%s\" has unknown return %d", argv[2], ret); + goto exit1; } else if (argc == 3 && !strcmp(argv[1], "get_int")) { if (!git_config_get_int(argv[2], &val)) { printf("%d\n", val); @@ -159,8 +194,7 @@ int cmd__config(int argc, const char **argv) goto exit2; } } - strptr = git_configset_get_value_multi(&cs, argv[2]); - if (strptr) { + if (!git_configset_get_value_multi(&cs, argv[2], &strptr)) { for (i = 0; i < strptr->nr; i++) { v = strptr->items[i].string; if (!v) @@ -176,6 +210,9 @@ int cmd__config(int argc, const char **argv) } else if (!strcmp(argv[1], "iterate")) { git_config(iterate_cb, NULL); goto exit0; + } else if (argc == 3 && !strcmp(argv[1], "git_config_int")) { + git_config(parse_int_cb, (void *) argv[2]); + goto exit0; } die("%s: Please check the syntax and the function name", argv[0]); diff --git a/t/helper/test-crontab.c b/t/helper/test-crontab.c index e6c1b1e22b..597027a96e 100644 --- a/t/helper/test-crontab.c +++ b/t/helper/test-crontab.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "cache.h" /* * Usage: test-tool crontab <file> -l|<input> diff --git a/t/helper/test-ctype.c b/t/helper/test-ctype.c index 92c4c2313e..e5659df40b 100644 --- a/t/helper/test-ctype.c +++ b/t/helper/test-ctype.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "cache.h" static int rc; @@ -11,9 +10,14 @@ static void report_error(const char *class, int ch) static int is_in(const char *s, int ch) { - /* We can't find NUL using strchr. It's classless anyway. */ + /* + * We can't find NUL using strchr. Accept it as the first + * character in the spec -- there are no empty classes. + */ if (ch == '\0') - return 0; + return ch == *s; + if (*s == '\0') + s++; return !!strchr(s, ch); } @@ -23,13 +27,29 @@ static int is_in(const char *s, int ch) if (is_in(s, i) != t(i)) \ report_error(#t, i); \ } \ + if (t(EOF)) \ + report_error(#t, EOF); \ } #define DIGIT "0123456789" #define LOWER "abcdefghijklmnopqrstuvwxyz" #define UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +#define PUNCT "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" +#define ASCII \ + "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" \ + "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" \ + "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f" \ + "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f" \ + "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f" \ + "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f" \ + "\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f" \ + "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f" +#define CNTRL \ + "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" \ + "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" \ + "\x7f" -int cmd__ctype(int argc, const char **argv) +int cmd__ctype(int argc UNUSED, const char **argv UNUSED) { TEST_CLASS(isdigit, DIGIT); TEST_CLASS(isspace, " \n\r\t"); @@ -38,6 +58,13 @@ int cmd__ctype(int argc, const char **argv) TEST_CLASS(is_glob_special, "*?[\\"); TEST_CLASS(is_regex_special, "$()*+.?[\\^{|"); TEST_CLASS(is_pathspec_magic, "!\"#%&',-/:;<=>@_`~"); + TEST_CLASS(isascii, ASCII); + TEST_CLASS(islower, LOWER); + TEST_CLASS(isupper, UPPER); + TEST_CLASS(iscntrl, CNTRL); + TEST_CLASS(ispunct, PUNCT); + TEST_CLASS(isxdigit, DIGIT "abcdefABCDEF"); + TEST_CLASS(isprint, LOWER UPPER DIGIT PUNCT " "); return rc; } diff --git a/t/helper/test-date.c b/t/helper/test-date.c index 45951b1df8..0683d46574 100644 --- a/t/helper/test-date.c +++ b/t/helper/test-date.c @@ -1,6 +1,6 @@ #include "test-tool.h" -#include "cache.h" #include "date.h" +#include "trace.h" static const char *usage_msg = "\n" " test-tool date relative [time_t]...\n" @@ -81,7 +81,7 @@ static void parse_approxidate(const char **argv) { for (; *argv; argv++) { timestamp_t t; - t = approxidate_relative(*argv); + t = approxidate(*argv); printf("%s -> %s\n", *argv, show_date(t, 0, DATE_MODE(ISO8601))); } } @@ -90,7 +90,7 @@ static void parse_approx_timestamp(const char **argv) { for (; *argv; argv++) { timestamp_t t; - t = approxidate_relative(*argv); + t = approxidate(*argv); printf("%s -> %"PRItime"\n", *argv, t); } } @@ -104,7 +104,7 @@ static void getnanos(const char **argv) printf("%lf\n", seconds); } -int cmd__date(int argc, const char **argv) +int cmd__date(int argc UNUSED, const char **argv) { const char *x; diff --git a/t/helper/test-delta.c b/t/helper/test-delta.c index b15481ea59..e7d134ec25 100644 --- a/t/helper/test-delta.c +++ b/t/helper/test-delta.c @@ -11,7 +11,7 @@ #include "test-tool.h" #include "git-compat-util.h" #include "delta.h" -#include "cache.h" +#include "wrapper.h" static const char usage_str[] = "test-tool delta (-d|-p) <from_file> <data_file> <out_file>"; diff --git a/t/helper/test-dir-iterator.c b/t/helper/test-dir-iterator.c index 659b6bfa81..6b297bd753 100644 --- a/t/helper/test-dir-iterator.c +++ b/t/helper/test-dir-iterator.c @@ -15,7 +15,7 @@ static const char *error_name(int error_number) /* * usage: - * tool-test dir-iterator [--follow-symlinks] [--pedantic] directory_path + * tool-test dir-iterator [--pedantic] directory_path */ int cmd__dir_iterator(int argc, const char **argv) { @@ -24,9 +24,7 @@ int cmd__dir_iterator(int argc, const char **argv) int iter_status; for (++argv, --argc; *argv && starts_with(*argv, "--"); ++argv, --argc) { - if (strcmp(*argv, "--follow-symlinks") == 0) - flags |= DIR_ITERATOR_FOLLOW_SYMLINKS; - else if (strcmp(*argv, "--pedantic") == 0) + if (strcmp(*argv, "--pedantic") == 0) flags |= DIR_ITERATOR_PEDANTIC; else die("invalid option '%s'", *argv); diff --git a/t/helper/test-drop-caches.c b/t/helper/test-drop-caches.c index e37396dd9c..73e551cfc2 100644 --- a/t/helper/test-drop-caches.c +++ b/t/helper/test-drop-caches.c @@ -155,7 +155,7 @@ static int cmd_dropcaches(void) #endif -int cmd__drop_caches(int argc, const char **argv) +int cmd__drop_caches(int argc UNUSED, const char **argv UNUSED) { cmd_sync(); return cmd_dropcaches(); diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c index 454f17b1a0..f22f7bd84a 100644 --- a/t/helper/test-dump-cache-tree.c +++ b/t/helper/test-dump-cache-tree.c @@ -1,9 +1,12 @@ #define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" +#include "hash.h" +#include "hex.h" #include "tree.h" #include "cache-tree.h" - +#include "repository.h" +#include "setup.h" static void dump_one(struct cache_tree *it, const char *pfx, const char *x) { @@ -56,7 +59,7 @@ static int dump_cache_tree(struct cache_tree *it, return errs; } -int cmd__dump_cache_tree(int ac, const char **av) +int cmd__dump_cache_tree(int ac UNUSED, const char **av UNUSED) { struct index_state istate; struct cache_tree *another = cache_tree(); diff --git a/t/helper/test-dump-fsmonitor.c b/t/helper/test-dump-fsmonitor.c index 975f0ac890..9a098a25cb 100644 --- a/t/helper/test-dump-fsmonitor.c +++ b/t/helper/test-dump-fsmonitor.c @@ -1,7 +1,9 @@ #include "test-tool.h" #include "cache.h" +#include "repository.h" +#include "setup.h" -int cmd__dump_fsmonitor(int ac, const char **av) +int cmd__dump_fsmonitor(int ac UNUSED, const char **av UNUSED) { struct index_state *istate = the_repository->index; int i; diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c index 0ea97b8407..d1badd7112 100644 --- a/t/helper/test-dump-split-index.c +++ b/t/helper/test-dump-split-index.c @@ -1,6 +1,8 @@ #define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" +#include "hex.h" +#include "setup.h" #include "split-index.h" #include "ewah/ewok.h" @@ -9,7 +11,7 @@ static void show_bit(size_t pos, void *data) printf(" %d", (int)pos); } -int cmd__dump_split_index(int ac, const char **av) +int cmd__dump_split_index(int ac UNUSED, const char **av) { struct split_index *si; int i; diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c index 6d53683f13..df70be549f 100644 --- a/t/helper/test-dump-untracked-cache.c +++ b/t/helper/test-dump-untracked-cache.c @@ -2,6 +2,9 @@ #include "test-tool.h" #include "cache.h" #include "dir.h" +#include "hex.h" +#include "repository.h" +#include "setup.h" static int compare_untracked(const void *a_, const void *b_) { @@ -40,7 +43,7 @@ static void dump(struct untracked_cache_dir *ucd, struct strbuf *base) strbuf_setlen(base, len); } -int cmd__dump_untracked_cache(int ac, const char **av) +int cmd__dump_untracked_cache(int ac UNUSED, const char **av UNUSED) { struct untracked_cache *uc; struct strbuf base = STRBUF_INIT; diff --git a/t/helper/test-example-decorate.c b/t/helper/test-example-decorate.c index b9d1200eb9..2ed910adaa 100644 --- a/t/helper/test-example-decorate.c +++ b/t/helper/test-example-decorate.c @@ -1,9 +1,10 @@ #include "test-tool.h" -#include "cache.h" +#include "git-compat-util.h" #include "object.h" #include "decorate.h" +#include "repository.h" -int cmd__example_decorate(int argc, const char **argv) +int cmd__example_decorate(int argc UNUSED, const char **argv UNUSED) { struct decoration n; struct object_id one_oid = { {1} }; diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c index efc82dd80c..d1d63feaa9 100644 --- a/t/helper/test-fast-rebase.c +++ b/t/helper/test-fast-rebase.c @@ -12,20 +12,26 @@ #define USE_THE_INDEX_VARIABLE #include "test-tool.h" - +#include "cache.h" #include "cache-tree.h" #include "commit.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "lockfile.h" #include "merge-ort.h" +#include "object-name.h" #include "refs.h" #include "revision.h" #include "sequencer.h" +#include "setup.h" #include "strvec.h" #include "tree.h" static const char *short_commit_name(struct commit *commit) { - return find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV); + return repo_find_unique_abbrev(the_repository, &commit->object.oid, + DEFAULT_ABBREV); } static struct commit *peel_committish(const char *name) @@ -33,10 +39,11 @@ static struct commit *peel_committish(const char *name) struct object *obj; struct object_id oid; - if (get_oid(name, &oid)) + if (repo_get_oid(the_repository, name, &oid)) return NULL; obj = parse_object(the_repository, &oid); - return (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT); + return (struct commit *)repo_peel_to_type(the_repository, name, 0, obj, + OBJ_COMMIT); } static char *get_author(const char *message) @@ -63,7 +70,8 @@ static struct commit *create_commit(struct tree *tree, struct commit_extra_header *extra; struct strbuf msg = STRBUF_INIT; const char *out_enc = get_commit_output_encoding(); - const char *message = logmsg_reencode(based_on, NULL, out_enc); + const char *message = repo_logmsg_reencode(the_repository, based_on, + NULL, out_enc); const char *orig_message = NULL; const char *exclude_gpgsig[] = { "gpgsig", NULL }; @@ -119,7 +127,7 @@ int cmd__fast_rebase(int argc, const char **argv) strbuf_addf(&branch_name, "refs/heads/%s", argv[4]); /* Sanity check */ - if (get_oid("HEAD", &head)) + if (repo_get_oid(the_repository, "HEAD", &head)) die(_("Cannot read HEAD")); assert(oideq(&onto->object.oid, &head)); @@ -154,7 +162,7 @@ int cmd__fast_rebase(int argc, const char **argv) memset(&result, 0, sizeof(result)); merge_opt.show_rename_progress = 1; merge_opt.branch1 = "HEAD"; - head_tree = get_commit_tree(onto); + head_tree = repo_get_commit_tree(the_repository, onto); result.tree = head_tree; last_commit = onto; while ((commit = get_revision(&revs))) { @@ -165,8 +173,8 @@ int cmd__fast_rebase(int argc, const char **argv) assert(commit->parents && !commit->parents->next); base = commit->parents->item; - next_tree = get_commit_tree(commit); - base_tree = get_commit_tree(base); + next_tree = repo_get_commit_tree(the_repository, commit); + base_tree = repo_get_commit_tree(the_repository, base); merge_opt.branch2 = short_commit_name(commit); merge_opt.ancestor = xstrfmt("parent of %s", merge_opt.branch2); diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c index 54a4856c48..9f18c685b7 100644 --- a/t/helper/test-fsmonitor-client.c +++ b/t/helper/test-fsmonitor-client.c @@ -7,11 +7,14 @@ #include "cache.h" #include "parse-options.h" #include "fsmonitor-ipc.h" +#include "repository.h" +#include "setup.h" #include "thread-utils.h" #include "trace2.h" +#include "wrapper.h" #ifndef HAVE_FSMONITOR_DAEMON_BACKEND -int cmd__fsmonitor_client(int argc, const char **argv) +int cmd__fsmonitor_client(int argc UNUSED, const char **argv UNUSED) { die("fsmonitor--daemon not available on this platform"); } diff --git a/t/helper/test-genzeros.c b/t/helper/test-genzeros.c index 8ca988d621..47af843b68 100644 --- a/t/helper/test-genzeros.c +++ b/t/helper/test-genzeros.c @@ -17,15 +17,16 @@ int cmd__genzeros(int argc, const char **argv) /* Writing out individual NUL bytes is slow... */ while (count < 0) - if (write(1, zeros, ARRAY_SIZE(zeros)) < 0) - return -1; + if (xwrite(1, zeros, ARRAY_SIZE(zeros)) < 0) + die_errno("write error"); while (count > 0) { - n = write(1, zeros, count < ARRAY_SIZE(zeros) ? - count : ARRAY_SIZE(zeros)); + n = xwrite(1, zeros, + count < ARRAY_SIZE(zeros) + ? count : ARRAY_SIZE(zeros)); if (n < 0) - return -1; + die_errno("write error"); count -= n; } diff --git a/t/helper/test-hash.c b/t/helper/test-hash.c index 5860dab0ff..45d829c908 100644 --- a/t/helper/test-hash.c +++ b/t/helper/test-hash.c @@ -1,5 +1,5 @@ #include "test-tool.h" -#include "cache.h" +#include "hex.h" int cmd_hash_impl(int ac, const char **av, int algo) { diff --git a/t/helper/test-hashmap.c b/t/helper/test-hashmap.c index 36ff07bd4b..0eb0b3d49c 100644 --- a/t/helper/test-hashmap.c +++ b/t/helper/test-hashmap.c @@ -2,6 +2,7 @@ #include "git-compat-util.h" #include "hashmap.h" #include "strbuf.h" +#include "string-list.h" struct test_entry { @@ -150,6 +151,7 @@ static void perf_hashmap(unsigned int method, unsigned int rounds) */ int cmd__hashmap(int argc, const char **argv) { + struct string_list parts = STRING_LIST_INIT_NODUP; struct strbuf line = STRBUF_INIT; int icase; struct hashmap map = HASHMAP_INIT(test_entry_cmp, &icase); @@ -159,21 +161,26 @@ int cmd__hashmap(int argc, const char **argv) /* process commands from stdin */ while (strbuf_getline(&line, stdin) != EOF) { - char *cmd, *p1 = NULL, *p2 = NULL; + char *cmd, *p1, *p2; unsigned int hash = 0; struct test_entry *entry; /* break line into command and up to two parameters */ - cmd = strtok(line.buf, DELIM); + string_list_setlen(&parts, 0); + string_list_split_in_place(&parts, line.buf, DELIM, 2); + string_list_remove_empty_items(&parts, 0); + /* ignore empty lines */ - if (!cmd || *cmd == '#') + if (!parts.nr) + continue; + if (!*parts.items[0].string || *parts.items[0].string == '#') continue; - p1 = strtok(NULL, DELIM); - if (p1) { + cmd = parts.items[0].string; + p1 = parts.nr >= 1 ? parts.items[1].string : NULL; + p2 = parts.nr >= 2 ? parts.items[2].string : NULL; + if (p1) hash = icase ? strihash(p1) : strhash(p1); - p2 = strtok(NULL, DELIM); - } if (!strcmp("add", cmd) && p1 && p2) { @@ -260,6 +267,7 @@ int cmd__hashmap(int argc, const char **argv) } } + string_list_clear(&parts, 0); strbuf_release(&line); hashmap_clear_and_free(&map, struct test_entry, ent); return 0; diff --git a/t/helper/test-hexdump.c b/t/helper/test-hexdump.c index 811e89c1bc..05f55eca21 100644 --- a/t/helper/test-hexdump.c +++ b/t/helper/test-hexdump.c @@ -4,7 +4,7 @@ /* * Read stdin and print a hexdump to stdout. */ -int cmd__hexdump(int argc, const char **argv) +int cmd__hexdump(int argc UNUSED, const char **argv UNUSED) { char buf[1024]; ssize_t i, len; diff --git a/t/helper/test-index-version.c b/t/helper/test-index-version.c index fcd10968cc..a06c45c1f8 100644 --- a/t/helper/test-index-version.c +++ b/t/helper/test-index-version.c @@ -1,7 +1,7 @@ #include "test-tool.h" #include "cache.h" -int cmd__index_version(int argc, const char **argv) +int cmd__index_version(int argc UNUSED, const char **argv UNUSED) { struct cache_header hdr; int version; diff --git a/t/helper/test-json-writer.c b/t/helper/test-json-writer.c index 8c3edacc00..afe393f597 100644 --- a/t/helper/test-json-writer.c +++ b/t/helper/test-json-writer.c @@ -1,6 +1,6 @@ #include "test-tool.h" -#include "cache.h" #include "json-writer.h" +#include "string-list.h" static const char *expect_obj1 = "{\"a\":\"abc\",\"b\":42,\"c\":true}"; static const char *expect_obj2 = "{\"a\":-1,\"b\":2147483647,\"c\":0}"; @@ -395,35 +395,41 @@ static int unit_tests(void) return 0; } -static void get_s(int line_nr, char **s_in) +struct line { + struct string_list *parts; + size_t consumed_nr; + int nr; +}; + +static void get_s(struct line *line, char **s_in) { - *s_in = strtok(NULL, " "); - if (!*s_in) - die("line[%d]: expected: <s>", line_nr); + if (line->consumed_nr > line->parts->nr) + die("line[%d]: expected: <s>", line->nr); + *s_in = line->parts->items[line->consumed_nr++].string; } -static void get_i(int line_nr, intmax_t *s_in) +static void get_i(struct line *line, intmax_t *s_in) { char *s; char *endptr; - get_s(line_nr, &s); + get_s(line, &s); *s_in = strtol(s, &endptr, 10); if (*endptr || errno == ERANGE) - die("line[%d]: invalid integer value", line_nr); + die("line[%d]: invalid integer value", line->nr); } -static void get_d(int line_nr, double *s_in) +static void get_d(struct line *line, double *s_in) { char *s; char *endptr; - get_s(line_nr, &s); + get_s(line, &s); *s_in = strtod(s, &endptr); if (*endptr || errno == ERANGE) - die("line[%d]: invalid float value", line_nr); + die("line[%d]: invalid float value", line->nr); } static int pretty; @@ -454,6 +460,7 @@ static char *get_trimmed_line(char *buf, int buf_size) static int scripted(void) { + struct string_list parts = STRING_LIST_INIT_NODUP; struct json_writer jw = JSON_WRITER_INIT; char buf[MAX_LINE_LENGTH]; char *line; @@ -471,66 +478,77 @@ static int scripted(void) die("expected first line to be 'object' or 'array'"); while ((line = get_trimmed_line(buf, MAX_LINE_LENGTH)) != NULL) { + struct line state = { 0 }; char *verb; char *key; char *s_value; intmax_t i_value; double d_value; - line_nr++; + state.parts = &parts; + state.nr = ++line_nr; + + /* break line into command and zero or more tokens */ + string_list_setlen(&parts, 0); + string_list_split_in_place(&parts, line, " ", -1); + string_list_remove_empty_items(&parts, 0); + + /* ignore empty lines */ + if (!parts.nr || !*parts.items[0].string) + continue; - verb = strtok(line, " "); + verb = parts.items[state.consumed_nr++].string; if (!strcmp(verb, "end")) { jw_end(&jw); } else if (!strcmp(verb, "object-string")) { - get_s(line_nr, &key); - get_s(line_nr, &s_value); + get_s(&state, &key); + get_s(&state, &s_value); jw_object_string(&jw, key, s_value); } else if (!strcmp(verb, "object-int")) { - get_s(line_nr, &key); - get_i(line_nr, &i_value); + get_s(&state, &key); + get_i(&state, &i_value); jw_object_intmax(&jw, key, i_value); } else if (!strcmp(verb, "object-double")) { - get_s(line_nr, &key); - get_i(line_nr, &i_value); - get_d(line_nr, &d_value); + get_s(&state, &key); + get_i(&state, &i_value); + get_d(&state, &d_value); jw_object_double(&jw, key, i_value, d_value); } else if (!strcmp(verb, "object-true")) { - get_s(line_nr, &key); + get_s(&state, &key); jw_object_true(&jw, key); } else if (!strcmp(verb, "object-false")) { - get_s(line_nr, &key); + get_s(&state, &key); jw_object_false(&jw, key); } else if (!strcmp(verb, "object-null")) { - get_s(line_nr, &key); + get_s(&state, &key); jw_object_null(&jw, key); } else if (!strcmp(verb, "object-object")) { - get_s(line_nr, &key); + get_s(&state, &key); jw_object_inline_begin_object(&jw, key); } else if (!strcmp(verb, "object-array")) { - get_s(line_nr, &key); + get_s(&state, &key); jw_object_inline_begin_array(&jw, key); } else if (!strcmp(verb, "array-string")) { - get_s(line_nr, &s_value); + get_s(&state, &s_value); jw_array_string(&jw, s_value); } else if (!strcmp(verb, "array-int")) { - get_i(line_nr, &i_value); + get_i(&state, &i_value); jw_array_intmax(&jw, i_value); } else if (!strcmp(verb, "array-double")) { - get_i(line_nr, &i_value); - get_d(line_nr, &d_value); + get_i(&state, &i_value); + get_d(&state, &d_value); jw_array_double(&jw, i_value, d_value); } else if (!strcmp(verb, "array-true")) @@ -553,6 +571,7 @@ static int scripted(void) printf("%s\n", jw.json.buf); jw_release(&jw); + string_list_clear(&parts, 0); return 0; } diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c index ab86c14c8b..b83a75d19f 100644 --- a/t/helper/test-lazy-init-name-hash.c +++ b/t/helper/test-lazy-init-name-hash.c @@ -1,7 +1,11 @@ #define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" +#include "environment.h" #include "parse-options.h" +#include "repository.h" +#include "setup.h" +#include "trace.h" static int single; static int multi; diff --git a/t/helper/test-match-trees.c b/t/helper/test-match-trees.c index 4079fdee06..d0db5ff26f 100644 --- a/t/helper/test-match-trees.c +++ b/t/helper/test-match-trees.c @@ -1,17 +1,21 @@ #include "test-tool.h" -#include "cache.h" +#include "hex.h" +#include "match-trees.h" +#include "object-name.h" +#include "repository.h" +#include "setup.h" #include "tree.h" -int cmd__match_trees(int ac, const char **av) +int cmd__match_trees(int ac UNUSED, const char **av) { struct object_id hash1, hash2, shifted; struct tree *one, *two; setup_git_directory(); - if (get_oid(av[1], &hash1)) + if (repo_get_oid(the_repository, av[1], &hash1)) die("cannot parse %s as an object name", av[1]); - if (get_oid(av[2], &hash2)) + if (repo_get_oid(the_repository, av[2], &hash2)) die("cannot parse %s as an object name", av[2]); one = parse_tree_indirect(&hash1); if (!one) diff --git a/t/helper/test-mergesort.c b/t/helper/test-mergesort.c index 335e5bb3a9..42ccc87051 100644 --- a/t/helper/test-mergesort.c +++ b/t/helper/test-mergesort.c @@ -1,6 +1,7 @@ #include "test-tool.h" -#include "cache.h" +#include "mem-pool.h" #include "mergesort.h" +#include "strbuf.h" static uint32_t minstd_rand(uint32_t *state) { diff --git a/t/helper/test-oid-array.c b/t/helper/test-oid-array.c index d1324d086a..eef68833b7 100644 --- a/t/helper/test-oid-array.c +++ b/t/helper/test-oid-array.c @@ -1,6 +1,8 @@ #include "test-tool.h" -#include "cache.h" +#include "hex.h" #include "oid-array.h" +#include "setup.h" +#include "strbuf.h" static int print_oid(const struct object_id *oid, void *data) { @@ -8,7 +10,7 @@ static int print_oid(const struct object_id *oid, void *data) return 0; } -int cmd__oid_array(int argc, const char **argv) +int cmd__oid_array(int argc UNUSED, const char **argv UNUSED) { struct oid_array array = OID_ARRAY_INIT; struct strbuf line = STRBUF_INIT; diff --git a/t/helper/test-oidmap.c b/t/helper/test-oidmap.c index 0acf99931e..bd30244a54 100644 --- a/t/helper/test-oidmap.c +++ b/t/helper/test-oidmap.c @@ -1,7 +1,11 @@ #include "test-tool.h" -#include "cache.h" +#include "hex.h" +#include "object-name.h" #include "oidmap.h" +#include "repository.h" +#include "setup.h" #include "strbuf.h" +#include "string-list.h" /* key is an oid and value is a name (could be a refname for example) */ struct test_entry { @@ -21,8 +25,9 @@ struct test_entry { * iterate -> oidkey1 namevalue1\noidkey2 namevalue2\n... * */ -int cmd__oidmap(int argc, const char **argv) +int cmd__oidmap(int argc UNUSED, const char **argv UNUSED) { + struct string_list parts = STRING_LIST_INIT_NODUP; struct strbuf line = STRBUF_INIT; struct oidmap map = OIDMAP_INIT; @@ -33,23 +38,28 @@ int cmd__oidmap(int argc, const char **argv) /* process commands from stdin */ while (strbuf_getline(&line, stdin) != EOF) { - char *cmd, *p1 = NULL, *p2 = NULL; + char *cmd, *p1, *p2; struct test_entry *entry; struct object_id oid; /* break line into command and up to two parameters */ - cmd = strtok(line.buf, DELIM); + string_list_setlen(&parts, 0); + string_list_split_in_place(&parts, line.buf, DELIM, 2); + string_list_remove_empty_items(&parts, 0); + /* ignore empty lines */ - if (!cmd || *cmd == '#') + if (!parts.nr) + continue; + if (!*parts.items[0].string || *parts.items[0].string == '#') continue; - p1 = strtok(NULL, DELIM); - if (p1) - p2 = strtok(NULL, DELIM); + cmd = parts.items[0].string; + p1 = parts.nr >= 1 ? parts.items[1].string : NULL; + p2 = parts.nr >= 2 ? parts.items[2].string : NULL; if (!strcmp("put", cmd) && p1 && p2) { - if (get_oid(p1, &oid)) { + if (repo_get_oid(the_repository, p1, &oid)) { printf("Unknown oid: %s\n", p1); continue; } @@ -67,7 +77,7 @@ int cmd__oidmap(int argc, const char **argv) } else if (!strcmp("get", cmd) && p1) { - if (get_oid(p1, &oid)) { + if (repo_get_oid(the_repository, p1, &oid)) { printf("Unknown oid: %s\n", p1); continue; } @@ -80,7 +90,7 @@ int cmd__oidmap(int argc, const char **argv) } else if (!strcmp("remove", cmd) && p1) { - if (get_oid(p1, &oid)) { + if (repo_get_oid(the_repository, p1, &oid)) { printf("Unknown oid: %s\n", p1); continue; } @@ -106,6 +116,7 @@ int cmd__oidmap(int argc, const char **argv) } } + string_list_clear(&parts, 0); strbuf_release(&line); oidmap_free(&map, 1); return 0; diff --git a/t/helper/test-oidtree.c b/t/helper/test-oidtree.c index d48a409f4e..c7a1d4c642 100644 --- a/t/helper/test-oidtree.c +++ b/t/helper/test-oidtree.c @@ -1,14 +1,16 @@ #include "test-tool.h" -#include "cache.h" +#include "hex.h" #include "oidtree.h" +#include "setup.h" +#include "strbuf.h" -static enum cb_next print_oid(const struct object_id *oid, void *data) +static enum cb_next print_oid(const struct object_id *oid, void *data UNUSED) { puts(oid_to_hex(oid)); return CB_CONTINUE; } -int cmd__oidtree(int argc, const char **argv) +int cmd__oidtree(int argc UNUSED, const char **argv UNUSED) { struct oidtree ot; struct strbuf line = STRBUF_INIT; diff --git a/t/helper/test-online-cpus.c b/t/helper/test-online-cpus.c index 8cb0d53840..47dc211711 100644 --- a/t/helper/test-online-cpus.c +++ b/t/helper/test-online-cpus.c @@ -2,7 +2,7 @@ #include "git-compat-util.h" #include "thread-utils.h" -int cmd__online_cpus(int argc, const char **argv) +int cmd__online_cpus(int argc UNUSED, const char **argv UNUSED) { printf("%d\n", online_cpus()); return 0; diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c index f7b79daf4c..0f3fbeec53 100644 --- a/t/helper/test-pack-mtimes.c +++ b/t/helper/test-pack-mtimes.c @@ -1,9 +1,10 @@ -#include "git-compat-util.h" #include "test-tool.h" +#include "hex.h" #include "strbuf.h" #include "object-store.h" #include "packfile.h" #include "pack-mtimes.h" +#include "setup.h" static void dump_mtimes(struct packed_git *p) { diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c index 506835521a..00fa281a9c 100644 --- a/t/helper/test-parse-options.c +++ b/t/helper/test-parse-options.c @@ -1,6 +1,6 @@ #include "test-tool.h" -#include "cache.h" #include "parse-options.h" +#include "strbuf.h" #include "string-list.h" #include "trace2.h" @@ -263,14 +263,14 @@ int cmd__parse_options_flags(int argc, const char **argv) return parse_options_flags__cmd(argc, argv, test_flags); } -static int subcmd_one(int argc, const char **argv, const char *prefix) +static int subcmd_one(int argc, const char **argv, const char *prefix UNUSED) { printf("fn: subcmd_one\n"); print_args(argc, argv); return 0; } -static int subcmd_two(int argc, const char **argv, const char *prefix) +static int subcmd_two(int argc, const char **argv, const char *prefix UNUSED) { printf("fn: subcmd_two\n"); print_args(argc, argv); diff --git a/t/helper/test-parse-pathspec-file.c b/t/helper/test-parse-pathspec-file.c index b3e08cef4b..89ecefd1cd 100644 --- a/t/helper/test-parse-pathspec-file.c +++ b/t/helper/test-parse-pathspec-file.c @@ -1,12 +1,11 @@ #include "test-tool.h" #include "parse-options.h" #include "pathspec.h" -#include "gettext.h" int cmd__parse_pathspec_file(int argc, const char **argv) { struct pathspec pathspec; - const char *pathspec_from_file = NULL; + char *pathspec_from_file = NULL; int pathspec_file_nul = 0, i; static const char *const usage[] = { @@ -29,5 +28,6 @@ int cmd__parse_pathspec_file(int argc, const char **argv) printf("%s\n", pathspec.items[i].original); clear_pathspec(&pathspec); + free(pathspec_from_file); return 0; } diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c index 3f102cfddd..362bd64a4c 100644 --- a/t/helper/test-partial-clone.c +++ b/t/helper/test-partial-clone.c @@ -1,7 +1,8 @@ -#include "cache.h" #include "test-tool.h" +#include "hex.h" #include "repository.h" #include "object-store.h" +#include "setup.h" /* * Prints the size of the object corresponding to the given hash in a specific diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c index f69709d674..2ef53d5f7a 100644 --- a/t/helper/test-path-utils.c +++ b/t/helper/test-path-utils.c @@ -1,6 +1,11 @@ #include "test-tool.h" #include "cache.h" +#include "abspath.h" +#include "environment.h" +#include "path.h" +#include "setup.h" #include "string-list.h" +#include "trace.h" #include "utf8.h" /* diff --git a/t/helper/test-pcre2-config.c b/t/helper/test-pcre2-config.c index 5258fdddba..5d0b2a2e10 100644 --- a/t/helper/test-pcre2-config.c +++ b/t/helper/test-pcre2-config.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "cache.h" #include "grep.h" int cmd__pcre2_config(int argc, const char **argv) diff --git a/t/helper/test-pkt-line.c b/t/helper/test-pkt-line.c index c5e052e537..f4d134a145 100644 --- a/t/helper/test-pkt-line.c +++ b/t/helper/test-pkt-line.c @@ -1,6 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" #include "test-tool.h" #include "pkt-line.h" +#include "write-or-die.h" static void pack_line(const char *line) { diff --git a/t/helper/test-prio-queue.c b/t/helper/test-prio-queue.c index 133b5e6f4a..f0bf255f5f 100644 --- a/t/helper/test-prio-queue.c +++ b/t/helper/test-prio-queue.c @@ -1,8 +1,7 @@ #include "test-tool.h" -#include "cache.h" #include "prio-queue.h" -static int intcmp(const void *va, const void *vb, void *data) +static int intcmp(const void *va, const void *vb, void *data UNUSED) { const int *a = va, *b = vb; return *a - *b; @@ -17,7 +16,7 @@ static void show(int *v) free(v); } -int cmd__prio_queue(int argc, const char **argv) +int cmd__prio_queue(int argc UNUSED, const char **argv) { struct prio_queue pq = { intcmp }; diff --git a/t/helper/test-proc-receive.c b/t/helper/test-proc-receive.c index a4b305f494..f30022d222 100644 --- a/t/helper/test-proc-receive.c +++ b/t/helper/test-proc-receive.c @@ -1,9 +1,10 @@ -#include "cache.h" +#include "test-tool.h" #include "connect.h" +#include "hex.h" #include "parse-options.h" #include "pkt-line.h" +#include "setup.h" #include "sigchain.h" -#include "test-tool.h" static const char *proc_receive_usage[] = { "test-tool proc-receive [<options>]", diff --git a/t/helper/test-progress.c b/t/helper/test-progress.c index 6cc9735b60..66acb6a06c 100644 --- a/t/helper/test-progress.c +++ b/t/helper/test-progress.c @@ -19,7 +19,6 @@ */ #define GIT_TEST_PROGRESS_ONLY #include "test-tool.h" -#include "gettext.h" #include "parse-options.h" #include "progress.h" #include "strbuf.h" diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c index 2f65c7f6a5..5b6f217441 100644 --- a/t/helper/test-reach.c +++ b/t/helper/test-reach.c @@ -1,10 +1,14 @@ #include "test-tool.h" -#include "cache.h" +#include "alloc.h" #include "commit.h" #include "commit-reach.h" #include "config.h" +#include "gettext.h" +#include "hex.h" +#include "object-name.h" #include "parse-options.h" #include "ref-filter.h" +#include "setup.h" #include "string-list.h" #include "tag.h" @@ -57,7 +61,7 @@ int cmd__reach(int ac, const char **av) if (buf.len < 3) continue; - if (get_oid_committish(buf.buf + 2, &oid)) + if (repo_get_oid_committish(the_repository, buf.buf + 2, &oid)) die("failed to resolve %s", buf.buf + 2); orig = parse_object(r, &oid); @@ -106,13 +110,17 @@ int cmd__reach(int ac, const char **av) if (!strcmp(av[1], "ref_newer")) printf("%s(A,B):%d\n", av[1], ref_newer(&oid_A, &oid_B)); else if (!strcmp(av[1], "in_merge_bases")) - printf("%s(A,B):%d\n", av[1], in_merge_bases(A, B)); + printf("%s(A,B):%d\n", av[1], + repo_in_merge_bases(the_repository, A, B)); else if (!strcmp(av[1], "in_merge_bases_many")) - printf("%s(A,X):%d\n", av[1], in_merge_bases_many(A, X_nr, X_array)); + printf("%s(A,X):%d\n", av[1], + repo_in_merge_bases_many(the_repository, A, X_nr, X_array)); else if (!strcmp(av[1], "is_descendant_of")) printf("%s(A,X):%d\n", av[1], repo_is_descendant_of(r, A, X)); else if (!strcmp(av[1], "get_merge_bases_many")) { - struct commit_list *list = get_merge_bases_many(A, X_nr, X_array); + struct commit_list *list = repo_get_merge_bases_many(the_repository, + A, X_nr, + X_array); printf("%s(A,X):\n", av[1]); print_sorted_commit_ids(list); } else if (!strcmp(av[1], "reduce_heads")) { diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c index 23e9e27109..c1ae276395 100644 --- a/t/helper/test-read-cache.c +++ b/t/helper/test-read-cache.c @@ -2,6 +2,9 @@ #include "test-tool.h" #include "cache.h" #include "config.h" +#include "repository.h" +#include "setup.h" +#include "wrapper.h" int cmd__read_cache(int argc, const char **argv) { diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c index 98b73bb8f2..3ac496e27e 100644 --- a/t/helper/test-read-graph.c +++ b/t/helper/test-read-graph.c @@ -1,11 +1,11 @@ #include "test-tool.h" -#include "cache.h" #include "commit-graph.h" #include "repository.h" #include "object-store.h" #include "bloom.h" +#include "setup.h" -int cmd__read_graph(int argc, const char **argv) +int cmd__read_graph(int argc UNUSED, const char **argv UNUSED) { struct commit_graph *graph = NULL; struct object_directory *odb; diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c index 27072ba94d..211addaa00 100644 --- a/t/helper/test-read-midx.c +++ b/t/helper/test-read-midx.c @@ -1,9 +1,11 @@ #include "test-tool.h" -#include "cache.h" +#include "hex.h" #include "midx.h" #include "repository.h" #include "object-store.h" #include "pack-bitmap.h" +#include "packfile.h" +#include "setup.h" static int read_midx_file(const char *object_dir, int show_objects) { diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index ae8a5648da..6d8f844e9c 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -1,6 +1,7 @@ #include "test-tool.h" -#include "cache.h" +#include "hex.h" #include "refs.h" +#include "setup.h" #include "worktree.h" #include "object-store.h" #include "repository.h" @@ -200,7 +201,8 @@ static int cmd_verify_ref(struct ref_store *refs, const char **argv) return ret; } -static int cmd_for_each_reflog(struct ref_store *refs, const char **argv) +static int cmd_for_each_reflog(struct ref_store *refs, + const char **argv UNUSED) { return refs_for_each_reflog(refs, each_ref, NULL); } @@ -322,7 +324,7 @@ static struct command commands[] = { { NULL, NULL } }; -int cmd__ref_store(int argc, const char **argv) +int cmd__ref_store(int argc UNUSED, const char **argv) { struct ref_store *refs; const char *func; diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index 1f0a28cbb6..00237ef0d9 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -1,3 +1,4 @@ +#include "reftable/system.h" #include "reftable/reftable-tests.h" #include "test-tool.h" diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c index 56f0e3c1be..bafd2a5bf9 100644 --- a/t/helper/test-repository.c +++ b/t/helper/test-repository.c @@ -1,11 +1,13 @@ #include "test-tool.h" -#include "cache.h" #include "commit-graph.h" #include "commit.h" #include "config.h" +#include "environment.h" +#include "hex.h" #include "object-store.h" #include "object.h" #include "repository.h" +#include "setup.h" #include "tree.h" static void test_parse_commit_in_graph(const char *gitdir, const char *worktree, diff --git a/t/helper/test-revision-walking.c b/t/helper/test-revision-walking.c index 4a45d5bac2..0c62b9de18 100644 --- a/t/helper/test-revision-walking.c +++ b/t/helper/test-revision-walking.c @@ -9,17 +9,18 @@ */ #include "test-tool.h" -#include "cache.h" #include "commit.h" #include "diff.h" #include "revision.h" +#include "setup.h" static void print_commit(struct commit *commit) { struct strbuf sb = STRBUF_INIT; struct pretty_print_context ctx = {0}; ctx.date_mode.type = DATE_NORMAL; - format_commit_message(commit, " %m %s", &sb, &ctx); + repo_format_commit_message(the_repository, commit, " %m %s", &sb, + &ctx); printf("%s\n", sb.buf); strbuf_release(&sb); } diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c index 3ecb830f4a..c0ed8722c8 100644 --- a/t/helper/test-run-command.c +++ b/t/helper/test-run-command.c @@ -9,8 +9,6 @@ */ #include "test-tool.h" -#include "git-compat-util.h" -#include "cache.h" #include "run-command.h" #include "strvec.h" #include "strbuf.h" @@ -18,13 +16,12 @@ #include "string-list.h" #include "thread-utils.h" #include "wildmatch.h" -#include "gettext.h" static int number_callbacks; static int parallel_next(struct child_process *cp, struct strbuf *err, void *cb, - void **task_cb) + void **task_cb UNUSED) { struct child_process *d = cb; if (number_callbacks >= 4) @@ -40,10 +37,10 @@ static int parallel_next(struct child_process *cp, return 1; } -static int no_job(struct child_process *cp, +static int no_job(struct child_process *cp UNUSED, struct strbuf *err, - void *cb, - void **task_cb) + void *cb UNUSED, + void **task_cb UNUSED) { if (err) strbuf_addstr(err, "no further jobs available\n"); @@ -52,10 +49,10 @@ static int no_job(struct child_process *cp, return 0; } -static int task_finished(int result, +static int task_finished(int result UNUSED, struct strbuf *err, - void *pp_cb, - void *pp_task_cb) + void *pp_cb UNUSED, + void *pp_task_cb UNUSED) { if (err) strbuf_addstr(err, "asking for a quick stop\n"); diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c index a26107ed70..6e17f50d22 100644 --- a/t/helper/test-scrap-cache-tree.c +++ b/t/helper/test-scrap-cache-tree.c @@ -2,10 +2,12 @@ #include "test-tool.h" #include "cache.h" #include "lockfile.h" +#include "repository.h" +#include "setup.h" #include "tree.h" #include "cache-tree.h" -int cmd__scrap_cache_tree(int ac, const char **av) +int cmd__scrap_cache_tree(int ac UNUSED, const char **av UNUSED) { struct lock_file index_lock = LOCK_INIT; diff --git a/t/helper/test-serve-v2.c b/t/helper/test-serve-v2.c index 824e5c0a95..054cbcf5d8 100644 --- a/t/helper/test-serve-v2.c +++ b/t/helper/test-serve-v2.c @@ -1,7 +1,8 @@ #include "test-tool.h" -#include "cache.h" +#include "gettext.h" #include "parse-options.h" #include "serve.h" +#include "setup.h" static char const * const serve_usage[] = { N_("test-tool serve-v2 [<options>]"), diff --git a/t/helper/test-sigchain.c b/t/helper/test-sigchain.c index d013bccdda..2d5ecf7383 100644 --- a/t/helper/test-sigchain.c +++ b/t/helper/test-sigchain.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "cache.h" #include "sigchain.h" #define X(f) \ @@ -14,7 +13,7 @@ X(two) X(three) #undef X -int cmd__sigchain(int argc, const char **argv) +int cmd__sigchain(int argc UNUSED, const char **argv UNUSED) { sigchain_push(SIGTERM, one); sigchain_push(SIGTERM, two); diff --git a/t/helper/test-simple-ipc.c b/t/helper/test-simple-ipc.c index 28365ff85b..3d1436da59 100644 --- a/t/helper/test-simple-ipc.c +++ b/t/helper/test-simple-ipc.c @@ -3,13 +3,14 @@ */ #include "test-tool.h" -#include "cache.h" +#include "gettext.h" #include "strbuf.h" #include "simple-ipc.h" #include "parse-options.h" #include "thread-utils.h" #include "strvec.h" #include "run-command.h" +#include "trace2.h" #ifndef SUPPORTS_SIMPLE_IPC int cmd__simple_ipc(int argc, const char **argv) diff --git a/t/helper/test-strcmp-offset.c b/t/helper/test-strcmp-offset.c index 44e4a6d143..96b9a5b529 100644 --- a/t/helper/test-strcmp-offset.c +++ b/t/helper/test-strcmp-offset.c @@ -1,7 +1,7 @@ #include "test-tool.h" #include "cache.h" -int cmd__strcmp_offset(int argc, const char **argv) +int cmd__strcmp_offset(int argc UNUSED, const char **argv) { int result; size_t offset; diff --git a/t/helper/test-string-list.c b/t/helper/test-string-list.c index 2123dda85b..e2aad611d1 100644 --- a/t/helper/test-string-list.c +++ b/t/helper/test-string-list.c @@ -1,5 +1,5 @@ #include "test-tool.h" -#include "cache.h" +#include "strbuf.h" #include "string-list.h" /* @@ -62,7 +62,7 @@ int cmd__string_list(int argc, const char **argv) struct string_list list = STRING_LIST_INIT_NODUP; int i; char *s = xstrdup(argv[2]); - int delim = *argv[3]; + const char *delim = argv[3]; int maxsplit = atoi(argv[4]); i = string_list_split_in_place(&list, s, delim, maxsplit); @@ -111,7 +111,7 @@ int cmd__string_list(int argc, const char **argv) */ if (sb.len && sb.buf[sb.len - 1] == '\n') strbuf_setlen(&sb, sb.len - 1); - string_list_split_in_place(&list, sb.buf, '\n', -1); + string_list_split_in_place(&list, sb.buf, "\n", -1); string_list_sort(&list); diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c index 22a41c4092..9df2f03ac8 100644 --- a/t/helper/test-submodule-config.c +++ b/t/helper/test-submodule-config.c @@ -1,10 +1,13 @@ #include "test-tool.h" -#include "cache.h" #include "config.h" +#include "hash.h" +#include "object-name.h" +#include "repository.h" +#include "setup.h" #include "submodule-config.h" #include "submodule.h" -static void die_usage(int argc, const char **argv, const char *msg) +static void die_usage(int argc UNUSED, const char **argv, const char *msg) { fprintf(stderr, "%s\n", msg); fprintf(stderr, "Usage: %s [<commit> <submodulepath>] ...\n", argv[0]); @@ -42,7 +45,7 @@ int cmd__submodule_config(int argc, const char **argv) if (commit[0] == '\0') oidclr(&commit_oid); - else if (get_oid(commit, &commit_oid) < 0) + else if (repo_get_oid(the_repository, commit, &commit_oid) < 0) die_usage(argc, argv, "Commit not found."); if (lookup_name) { diff --git a/t/helper/test-submodule-nested-repo-config.c b/t/helper/test-submodule-nested-repo-config.c index dc1c14bde3..ecd40ded99 100644 --- a/t/helper/test-submodule-nested-repo-config.c +++ b/t/helper/test-submodule-nested-repo-config.c @@ -1,4 +1,6 @@ #include "test-tool.h" +#include "repository.h" +#include "setup.h" #include "submodule-config.h" static void die_usage(const char **argv, const char *msg) diff --git a/t/helper/test-submodule.c b/t/helper/test-submodule.c index e060cc6226..356e0a26c5 100644 --- a/t/helper/test-submodule.c +++ b/t/helper/test-submodule.c @@ -1,8 +1,9 @@ #include "test-tool.h" #include "test-tool-utils.h" -#include "cache.h" #include "parse-options.h" #include "remote.h" +#include "repository.h" +#include "setup.h" #include "submodule-config.h" #include "submodule.h" @@ -174,7 +175,7 @@ static int cmd__submodule_config_unset(int argc, const char **argv) usage_with_options(usage, options); } -static int cmd__submodule_config_writeable(int argc, const char **argv) +static int cmd__submodule_config_writeable(int argc, const char **argv UNUSED) { struct option options[] = { OPT_END() diff --git a/t/helper/test-subprocess.c b/t/helper/test-subprocess.c index ff22f2fa2c..c344f1694d 100644 --- a/t/helper/test-subprocess.c +++ b/t/helper/test-subprocess.c @@ -1,6 +1,6 @@ #include "test-tool.h" -#include "cache.h" #include "run-command.h" +#include "setup.h" int cmd__subprocess(int argc, const char **argv) { diff --git a/t/helper/test-trace2.c b/t/helper/test-trace2.c index f374c21ec3..20c7495f38 100644 --- a/t/helper/test-trace2.c +++ b/t/helper/test-trace2.c @@ -1,9 +1,10 @@ #include "test-tool.h" -#include "cache.h" #include "strvec.h" #include "run-command.h" #include "exec-cmd.h" #include "config.h" +#include "repository.h" +#include "trace2.h" typedef int(fn_unit_test)(int argc, const char **argv); @@ -208,7 +209,7 @@ static int ut_007BUG(int argc, const char **argv) BUG("the bug message"); } -static int ut_008bug(int argc, const char **argv) +static int ut_008bug(int argc UNUSED, const char **argv UNUSED) { bug("a bug message"); bug("another bug message"); @@ -216,7 +217,7 @@ static int ut_008bug(int argc, const char **argv) return 0; } -static int ut_009bug_BUG(int argc, const char **argv) +static int ut_009bug_BUG(int argc UNUSED, const char **argv UNUSED) { bug("a bug message"); bug("another bug message"); @@ -224,7 +225,7 @@ static int ut_009bug_BUG(int argc, const char **argv) return 0; } -static int ut_010bug_BUG(int argc, const char **argv) +static int ut_010bug_BUG(int argc UNUSED, const char **argv UNUSED) { bug("a %s message", "bug"); BUG("a %s message", "BUG"); diff --git a/t/helper/test-userdiff.c b/t/helper/test-userdiff.c index a2b56b9cae..680124a676 100644 --- a/t/helper/test-userdiff.c +++ b/t/helper/test-userdiff.c @@ -1,5 +1,5 @@ #include "test-tool.h" -#include "cache.h" +#include "setup.h" #include "userdiff.h" #include "config.h" diff --git a/t/helper/test-wildmatch.c b/t/helper/test-wildmatch.c index 2c103d1824..a95bb4da9b 100644 --- a/t/helper/test-wildmatch.c +++ b/t/helper/test-wildmatch.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "cache.h" int cmd__wildmatch(int argc, const char **argv) { diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c index 7d45cd61e8..eace08072d 100644 --- a/t/helper/test-write-cache.c +++ b/t/helper/test-write-cache.c @@ -2,6 +2,8 @@ #include "test-tool.h" #include "cache.h" #include "lockfile.h" +#include "repository.h" +#include "setup.h" int cmd__write_cache(int argc, const char **argv) { diff --git a/t/helper/test-xml-encode.c b/t/helper/test-xml-encode.c index a648bbd961..b2f330d1a4 100644 --- a/t/helper/test-xml-encode.c +++ b/t/helper/test-xml-encode.c @@ -6,7 +6,7 @@ static const char *utf8_replace_character = "�"; * Encodes (possibly incorrect) UTF-8 on <stdin> to <stdout>, to be embedded * in an XML file. */ -int cmd__xml_encode(int argc, const char **argv) +int cmd__xml_encode(int argc UNUSED, const char **argv UNUSED) { unsigned char buf[1024], tmp[4], *tmp2 = NULL; ssize_t cur = 0, len = 1, remaining = 0; |