aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-07-01 01:58:58 -0400
committerJunio C Hamano <gitster@pobox.com>2016-07-01 15:09:10 -0700
commit3f2e2297b9c88a6ab5fc4bff02cf2a07ce057589 (patch)
tree957f37bbb0e0097c480f3eaa5398eb88471755af
parent0b65a8dbdb38962e700ee16776a3042beb489060 (diff)
downloadgit-3f2e2297b9c88a6ab5fc4bff02cf2a07ce057589.tar.gz
git-3f2e2297b9c88a6ab5fc4bff02cf2a07ce057589.tar.xz
add an extra level of indirection to main()
There are certain startup tasks that we expect every git process to do. In some cases this is just to improve the quality of the program (e.g., setting up gettext()). In others it is a requirement for using certain functions in libgit.a (e.g., system_path() expects that you have called git_extract_argv0_path()). Most commands are builtins and are covered by the git.c version of main(). However, there are still a few external commands that use their own main(). Each of these has to remember to include the correct startup sequence, and we are not always consistent. Rather than just fix the inconsistencies, let's make this harder to get wrong by providing a common main() that can run this standard startup. We basically have two options to do this: - the compat/mingw.h file already does something like this by adding a #define that replaces the definition of main with a wrapper that calls mingw_startup(). The upside is that the code in each program doesn't need to be changed at all; it's rewritten on the fly by the preprocessor. The downside is that it may make debugging of the startup sequence a bit more confusing, as the preprocessor is quietly inserting new code. - the builtin functions are all of the form cmd_foo(), and git.c's main() calls them. This is much more explicit, which may make things more obvious to somebody reading the code. It's also more flexible (because of course we have to figure out _which_ cmd_foo() to call). The downside is that each of the builtins must define cmd_foo(), instead of just main(). This patch chooses the latter option, preferring the more explicit approach, even though it is more invasive. We introduce a new file common-main.c, with the "real" main. It expects to call cmd_main() from whatever other objects it is linked against. We link common-main.o against anything that links against libgit.a, since we know that such programs will need to do this setup. Note that common-main.o can't actually go inside libgit.a, as the linker would not pick up its main() function automatically (it has no callers). The rest of the patch is just adjusting all of the various external programs (mostly in t/helper) to use cmd_main(). I've provided a global declaration for cmd_main(), which means that all of the programs also need to match its signature. In particular, many functions need to switch to "const char **" instead of "char **" for argv. This effect ripples out to a few other variables and functions, as well. This makes the patch even more invasive, but the end result is much better. We should be treating argv strings as const anyway, and now all programs conform to the same signature (which also matches the way builtins are defined). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--Makefile17
-rw-r--r--common-main.c12
-rw-r--r--credential-cache--daemon.c2
-rw-r--r--credential-cache.c2
-rw-r--r--credential-store.c2
-rw-r--r--daemon.c8
-rw-r--r--fast-import.c4
-rw-r--r--git-compat-util.h2
-rw-r--r--git.c3
-rw-r--r--http-backend.c2
-rw-r--r--http-fetch.c2
-rw-r--r--http-push.c6
-rw-r--r--imap-send.c2
-rw-r--r--remote-curl.c2
-rw-r--r--remote-testsvn.c2
-rw-r--r--sh-i18n--envsubst.c2
-rw-r--r--shell.c2
-rw-r--r--show-index.c2
-rw-r--r--test-chmtime.c2
-rw-r--r--test-config.c2
-rw-r--r--test-ctype.c2
-rw-r--r--test-date.c8
-rw-r--r--test-delta.c2
-rw-r--r--test-dump-cache-tree.c2
-rw-r--r--test-dump-split-index.c2
-rw-r--r--test-dump-untracked-cache.c2
-rw-r--r--test-fake-ssh.c2
-rw-r--r--test-genrandom.c2
-rw-r--r--test-hashmap.c2
-rw-r--r--test-index-version.c2
-rw-r--r--test-line-buffer.c2
-rw-r--r--test-match-trees.c2
-rw-r--r--test-mergesort.c2
-rw-r--r--test-mktemp.c2
-rw-r--r--test-parse-options.c2
-rw-r--r--test-path-utils.c4
-rw-r--r--test-prio-queue.c2
-rw-r--r--test-read-cache.c2
-rw-r--r--test-regex.c2
-rw-r--r--test-revision-walking.c2
-rw-r--r--test-run-command.c2
-rw-r--r--test-scrap-cache-tree.c2
-rw-r--r--test-sha1-array.c2
-rw-r--r--test-sha1.c2
-rw-r--r--test-sigchain.c2
-rw-r--r--test-string-list.c2
-rw-r--r--test-submodule-config.c6
-rw-r--r--test-subprocess.c2
-rw-r--r--test-svn-fe.c4
-rw-r--r--test-urlmatch-normalization.c2
-rw-r--r--test-wildmatch.c2
-rw-r--r--upload-pack.c6
52 files changed, 91 insertions, 69 deletions
diff --git a/Makefile b/Makefile
index e11e626d0..15f37d58e 100644
--- a/Makefile
+++ b/Makefile
@@ -943,7 +943,7 @@ BUILTIN_OBJS += builtin/verify-tag.o
BUILTIN_OBJS += builtin/worktree.o
BUILTIN_OBJS += builtin/write-tree.o
-GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
+GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB)
EXTLIBS =
GIT_USER_AGENT = git/$(GIT_VERSION)
@@ -1572,7 +1572,15 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
DIFF_SQ = $(subst ','\'',$(DIFF))
PERLLIB_EXTRA_SQ = $(subst ','\'',$(PERLLIB_EXTRA))
-LIBS = $(GITLIBS) $(EXTLIBS)
+# We must filter out any object files from $(GITLIBS),
+# as it is typically used like:
+#
+# foo: foo.o $(GITLIBS)
+# $(CC) $(filter %.o,$^) $(LIBS)
+#
+# where we use it as a dependency. Since we also pull object files
+# from the dependency list, that would make each entry appear twice.
+LIBS = $(filter-out %.o, $(GITLIBS)) $(EXTLIBS)
BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \
$(COMPAT_CFLAGS)
@@ -1708,8 +1716,8 @@ git.sp git.s git.o: EXTRA_CPPFLAGS = \
'-DGIT_INFO_PATH="$(infodir_relative_SQ)"'
git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS)
- $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) git.o \
- $(BUILTIN_OBJS) $(LIBS)
+ $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
+ $(filter %.o,$^) $(LIBS)
help.sp help.s help.o: common-cmds.h
@@ -1902,6 +1910,7 @@ TEST_OBJS := $(patsubst test-%$X,test-%.o,$(TEST_PROGRAMS))
OBJECTS := $(LIB_OBJS) $(BUILTIN_OBJS) $(PROGRAM_OBJS) $(TEST_OBJS) \
$(XDIFF_OBJS) \
$(VCSSVN_OBJS) \
+ common-main.o \
git.o
ifndef NO_CURL
OBJECTS += http.o http-walker.o remote-curl.o
diff --git a/common-main.c b/common-main.c
new file mode 100644
index 000000000..2b96bbf43
--- /dev/null
+++ b/common-main.c
@@ -0,0 +1,12 @@
+#include "git-compat-util.h"
+
+int main(int argc, char **av)
+{
+ /*
+ * This const trickery is explained in
+ * 84d32bf7678259c08406571cd6ce4b7a6724dcba
+ */
+ const char **argv = (const char **)av;
+
+ return cmd_main(argc, argv);
+}
diff --git a/credential-cache--daemon.c b/credential-cache--daemon.c
index 291c0fd5e..a4bf2366a 100644
--- a/credential-cache--daemon.c
+++ b/credential-cache--daemon.c
@@ -257,7 +257,7 @@ static void init_socket_directory(const char *path)
free(path_copy);
}
-int main(int argc, const char **argv)
+int cmd_main(int argc, const char **argv)
{
const char *socket_path;
int ignore_sighup = 0;
diff --git a/credential-cache.c b/credential-cache.c
index 86e21de49..cc8a6ee19 100644
--- a/credential-cache.c
+++ b/credential-cache.c
@@ -83,7 +83,7 @@ static void do_cache(const char *socket, const char *action, int timeout,
strbuf_release(&buf);
}
-int main(int argc, const char **argv)
+int cmd_main(int argc, const char **argv)
{
char *socket_path = NULL;
int timeout = 900;
diff --git a/credential-store.c b/credential-store.c
index 57141679a..55ca1b133 100644
--- a/credential-store.c
+++ b/credential-store.c
@@ -142,7 +142,7 @@ static void lookup_credential(const struct string_list *fns, struct credential *
return; /* Found credential */
}
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
const char * const usage[] = {
"git credential-store [<options>] <action>",
diff --git a/daemon.c b/daemon.c
index 8d45c336f..e6b86d215 100644
--- a/daemon.c
+++ b/daemon.c
@@ -32,7 +32,7 @@ static const char daemon_usage[] =
" [<directory>...]";
/* List of acceptable pathname prefixes */
-static char **ok_paths;
+static const char **ok_paths;
static int strict_paths;
/* If this is set, git-daemon-export-ok is not required */
@@ -240,7 +240,7 @@ static const char *path_ok(const char *directory, struct hostinfo *hi)
}
if ( ok_paths && *ok_paths ) {
- char **pp;
+ const char **pp;
int pathlen = strlen(path);
/* The validation is done on the paths after enter_repo
@@ -1178,7 +1178,7 @@ static int serve(struct string_list *listen_addr, int listen_port,
return service_loop(&socklist);
}
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
int listen_port = 0;
struct string_list listen_addr = STRING_LIST_INIT_NODUP;
@@ -1193,7 +1193,7 @@ int main(int argc, char **argv)
git_extract_argv0_path(argv[0]);
for (i = 1; i < argc; i++) {
- char *arg = argv[i];
+ const char *arg = argv[i];
const char *v;
if (skip_prefix(arg, "--listen=", &v)) {
diff --git a/fast-import.c b/fast-import.c
index 9fc709340..bd649268b 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -300,7 +300,7 @@ static int failure;
static FILE *pack_edges;
static unsigned int show_stats = 1;
static int global_argc;
-static char **global_argv;
+static const char **global_argv;
/* Memory pools */
static size_t mem_pool_alloc = 2*1024*1024 - sizeof(struct mem_pool);
@@ -3381,7 +3381,7 @@ static void parse_argv(void)
read_marks();
}
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
unsigned int i;
diff --git a/git-compat-util.h b/git-compat-util.h
index 1f8b5f3b1..91e366d1d 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -1043,3 +1043,5 @@ struct tm *git_gmtime_r(const time_t *, struct tm *);
#endif
#endif
+
+extern int cmd_main(int, const char **);
diff --git a/git.c b/git.c
index 968a8a464..e2444046f 100644
--- a/git.c
+++ b/git.c
@@ -630,9 +630,8 @@ static void restore_sigpipe_to_default(void)
signal(SIGPIPE, SIG_DFL);
}
-int main(int argc, char **av)
+int cmd_main(int argc, const char **argv)
{
- const char **argv = (const char **) av;
const char *cmd;
int done_help = 0;
diff --git a/http-backend.c b/http-backend.c
index 8870a2681..3249652b3 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -632,7 +632,7 @@ static struct service_cmd {
{"POST", "/git-receive-pack$", service_rpc}
};
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
char *method = getenv("REQUEST_METHOD");
char *dir;
diff --git a/http-fetch.c b/http-fetch.c
index ba3ea1067..eb559eb83 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -6,7 +6,7 @@
static const char http_fetch_usage[] = "git http-fetch "
"[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url";
-int main(int argc, const char **argv)
+int cmd_main(int argc, const char **argv)
{
struct walker *walker;
int commits_on_stdin = 0;
diff --git a/http-push.c b/http-push.c
index bd6066870..98228a426 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1692,12 +1692,12 @@ static void run_request_queue(void)
#endif
}
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
struct transfer_request *request;
struct transfer_request *next_request;
int nr_refspec = 0;
- char **refspec = NULL;
+ const char **refspec = NULL;
struct remote_lock *ref_lock = NULL;
struct remote_lock *info_ref_lock = NULL;
struct rev_info revs;
@@ -1717,7 +1717,7 @@ int main(int argc, char **argv)
argv++;
for (i = 1; i < argc; i++, argv++) {
- char *arg = *argv;
+ const char *arg = *argv;
if (*arg == '-') {
if (!strcmp(arg, "--all")) {
diff --git a/imap-send.c b/imap-send.c
index 938c69158..890e1cbb6 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1494,7 +1494,7 @@ static int curl_append_msgs_to_imap(struct imap_server_conf *server,
}
#endif
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
struct strbuf all_msgs = STRBUF_INIT;
int total;
diff --git a/remote-curl.c b/remote-curl.c
index 15e48e25f..6ebc2a0c1 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -984,7 +984,7 @@ static void parse_push(struct strbuf *buf)
free(specs);
}
-int main(int argc, const char **argv)
+int cmd_main(int argc, const char **argv)
{
struct strbuf buf = STRBUF_INIT;
int nongit;
diff --git a/remote-testsvn.c b/remote-testsvn.c
index f05ff4529..32631eb14 100644
--- a/remote-testsvn.c
+++ b/remote-testsvn.c
@@ -284,7 +284,7 @@ static int do_command(struct strbuf *line)
return 0;
}
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
struct strbuf buf = STRBUF_INIT, url_sb = STRBUF_INIT,
private_ref_sb = STRBUF_INIT, marksfilename_sb = STRBUF_INIT,
diff --git a/sh-i18n--envsubst.c b/sh-i18n--envsubst.c
index 2842a22d7..e06b2c131 100644
--- a/sh-i18n--envsubst.c
+++ b/sh-i18n--envsubst.c
@@ -64,7 +64,7 @@ static void note_variables (const char *string);
static void subst_from_stdin (void);
int
-main (int argc, char *argv[])
+cmd_main (int argc, const char *argv[])
{
/* Default values for command line options. */
/* unsigned short int show_variables = 0; */
diff --git a/shell.c b/shell.c
index c5439a63e..3dd7fdcfe 100644
--- a/shell.c
+++ b/shell.c
@@ -138,7 +138,7 @@ static struct commands {
{ NULL },
};
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
char *prog;
const char **user_argv;
diff --git a/show-index.c b/show-index.c
index acf8d5445..575f9c589 100644
--- a/show-index.c
+++ b/show-index.c
@@ -4,7 +4,7 @@
static const char show_index_usage[] =
"git show-index";
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
int i;
unsigned nr;
diff --git a/test-chmtime.c b/test-chmtime.c
index dfe8a8326..e76025640 100644
--- a/test-chmtime.c
+++ b/test-chmtime.c
@@ -56,7 +56,7 @@ static int timespec_arg(const char *arg, long int *set_time, int *set_eq)
return 1;
}
-int main(int argc, char *argv[])
+int cmd_main(int argc, const char **argv)
{
static int verbose;
diff --git a/test-config.c b/test-config.c
index 6a7755221..d143cd722 100644
--- a/test-config.c
+++ b/test-config.c
@@ -33,7 +33,7 @@
*/
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
int i, val;
const char *v;
diff --git a/test-ctype.c b/test-ctype.c
index 707a821f0..bb72c47df 100644
--- a/test-ctype.c
+++ b/test-ctype.c
@@ -28,7 +28,7 @@ static int is_in(const char *s, int ch)
#define LOWER "abcdefghijklmnopqrstuvwxyz"
#define UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
TEST_CLASS(isdigit, DIGIT);
TEST_CLASS(isspace, " \n\r\t");
diff --git a/test-date.c b/test-date.c
index 63f373557..0f3cfb172 100644
--- a/test-date.c
+++ b/test-date.c
@@ -5,7 +5,7 @@ static const char *usage_msg = "\n"
" test-date parse [date]...\n"
" test-date approxidate [date]...\n";
-static void show_dates(char **argv, struct timeval *now)
+static void show_dates(const char **argv, struct timeval *now)
{
struct strbuf buf = STRBUF_INIT;
@@ -17,7 +17,7 @@ static void show_dates(char **argv, struct timeval *now)
strbuf_release(&buf);
}
-static void parse_dates(char **argv, struct timeval *now)
+static void parse_dates(const char **argv, struct timeval *now)
{
struct strbuf result = STRBUF_INIT;
@@ -36,7 +36,7 @@ static void parse_dates(char **argv, struct timeval *now)
strbuf_release(&result);
}
-static void parse_approxidate(char **argv, struct timeval *now)
+static void parse_approxidate(const char **argv, struct timeval *now)
{
for (; *argv; argv++) {
time_t t;
@@ -45,7 +45,7 @@ static void parse_approxidate(char **argv, struct timeval *now)
}
}
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
struct timeval now;
const char *x;
diff --git a/test-delta.c b/test-delta.c
index 4595cd643..59937dc1b 100644
--- a/test-delta.c
+++ b/test-delta.c
@@ -15,7 +15,7 @@
static const char usage_str[] =
"test-delta (-d|-p) <from_file> <data_file> <out_file>";
-int main(int argc, char *argv[])
+int cmd_main(int argc, const char **argv)
{
int fd;
struct stat st;
diff --git a/test-dump-cache-tree.c b/test-dump-cache-tree.c
index bb53c0aa6..44f329025 100644
--- a/test-dump-cache-tree.c
+++ b/test-dump-cache-tree.c
@@ -54,7 +54,7 @@ static int dump_cache_tree(struct cache_tree *it,
return errs;
}
-int main(int ac, char **av)
+int cmd_main(int ac, const char **av)
{
struct index_state istate;
struct cache_tree *another = cache_tree();
diff --git a/test-dump-split-index.c b/test-dump-split-index.c
index 861d28c9b..d1689248b 100644
--- a/test-dump-split-index.c
+++ b/test-dump-split-index.c
@@ -7,7 +7,7 @@ static void show_bit(size_t pos, void *data)
printf(" %d", (int)pos);
}
-int main(int ac, char **av)
+int cmd_main(int ac, const char **av)
{
struct split_index *si;
int i;
diff --git a/test-dump-untracked-cache.c b/test-dump-untracked-cache.c
index 0a1c28524..50112cc85 100644
--- a/test-dump-untracked-cache.c
+++ b/test-dump-untracked-cache.c
@@ -40,7 +40,7 @@ static void dump(struct untracked_cache_dir *ucd, struct strbuf *base)
strbuf_setlen(base, len);
}
-int main(int ac, char **av)
+int cmd_main(int ac, const char **av)
{
struct untracked_cache *uc;
struct strbuf base = STRBUF_INIT;
diff --git a/test-fake-ssh.c b/test-fake-ssh.c
index 980de216e..12beee99a 100644
--- a/test-fake-ssh.c
+++ b/test-fake-ssh.c
@@ -2,7 +2,7 @@
#include "run-command.h"
#include "strbuf.h"
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
const char *trash_directory = getenv("TRASH_DIRECTORY");
struct strbuf buf = STRBUF_INIT;
diff --git a/test-genrandom.c b/test-genrandom.c
index 54824d075..8d11d22d9 100644
--- a/test-genrandom.c
+++ b/test-genrandom.c
@@ -6,7 +6,7 @@
#include "git-compat-util.h"
-int main(int argc, char *argv[])
+int cmd_main(int argc, const char **argv)
{
unsigned long count, next = 0;
unsigned char *c;
diff --git a/test-hashmap.c b/test-hashmap.c
index cc2891dd9..7aa9440e2 100644
--- a/test-hashmap.c
+++ b/test-hashmap.c
@@ -138,7 +138,7 @@ static void perf_hashmap(unsigned int method, unsigned int rounds)
*
* perfhashmap method rounds -> test hashmap.[ch] performance
*/
-int main(int argc, char *argv[])
+int cmd_main(int argc, const char **argv)
{
char line[1024];
struct hashmap map;
diff --git a/test-index-version.c b/test-index-version.c
index 05d4699c4..f569f6b7e 100644
--- a/test-index-version.c
+++ b/test-index-version.c
@@ -1,6 +1,6 @@
#include "cache.h"
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
struct cache_header hdr;
int version;
diff --git a/test-line-buffer.c b/test-line-buffer.c
index 1e58f0476..81575fe2a 100644
--- a/test-line-buffer.c
+++ b/test-line-buffer.c
@@ -50,7 +50,7 @@ static void handle_line(const char *line, struct line_buffer *stdin_buf)
handle_command(line, arg + 1, stdin_buf);
}
-int main(int argc, char *argv[])
+int cmd_main(int argc, const char **argv)
{
struct line_buffer stdin_buf = LINE_BUFFER_INIT;
struct line_buffer file_buf = LINE_BUFFER_INIT;
diff --git a/test-match-trees.c b/test-match-trees.c
index 4dad7095f..afcdc143b 100644
--- a/test-match-trees.c
+++ b/test-match-trees.c
@@ -1,7 +1,7 @@
#include "cache.h"
#include "tree.h"
-int main(int ac, char **av)
+int cmd_main(int ac, const char **av)
{
unsigned char hash1[20], hash2[20], shifted[20];
struct tree *one, *two;
diff --git a/test-mergesort.c b/test-mergesort.c
index ea3b959e9..335cf6b62 100644
--- a/test-mergesort.c
+++ b/test-mergesort.c
@@ -22,7 +22,7 @@ static int compare_strings(const void *a, const void *b)
return strcmp(x->text, y->text);
}
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
struct line *line, *p = NULL, *lines = NULL;
struct strbuf sb = STRBUF_INIT;
diff --git a/test-mktemp.c b/test-mktemp.c
index c8c54213a..89d9b2f7b 100644
--- a/test-mktemp.c
+++ b/test-mktemp.c
@@ -3,7 +3,7 @@
*/
#include "git-compat-util.h"
-int main(int argc, char *argv[])
+int cmd_main(int argc, const char **argv)
{
if (argc != 2)
usage("Expected 1 parameter defining the temporary file template");
diff --git a/test-parse-options.c b/test-parse-options.c
index 2c8c8f18e..7adae43b8 100644
--- a/test-parse-options.c
+++ b/test-parse-options.c
@@ -30,7 +30,7 @@ static int number_callback(const struct option *opt, const char *arg, int unset)
return 0;
}
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
const char *prefix = "prefix/";
const char *usage[] = {
diff --git a/test-path-utils.c b/test-path-utils.c
index ba805b374..1ebe0f750 100644
--- a/test-path-utils.c
+++ b/test-path-utils.c
@@ -156,7 +156,7 @@ static struct test_data dirname_data[] = {
{ NULL, NULL }
};
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
char *buf = xmallocz(strlen(argv[2]));
@@ -213,7 +213,7 @@ int main(int argc, char **argv)
}
if (argc >= 4 && !strcmp(argv[1], "prefix_path")) {
- char *prefix = argv[2];
+ const char *prefix = argv[2];
int prefix_len = strlen(prefix);
int nongit_ok;
setup_git_directory_gently(&nongit_ok);
diff --git a/test-prio-queue.c b/test-prio-queue.c
index 7be72f008..ae58fff35 100644
--- a/test-prio-queue.c
+++ b/test-prio-queue.c
@@ -16,7 +16,7 @@ static void show(int *v)
free(v);
}
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
struct prio_queue pq = { intcmp };
diff --git a/test-read-cache.c b/test-read-cache.c
index b25bcf139..2a7990efc 100644
--- a/test-read-cache.c
+++ b/test-read-cache.c
@@ -1,6 +1,6 @@
#include "cache.h"
-int main (int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
int i, cnt = 1;
if (argc == 2)
diff --git a/test-regex.c b/test-regex.c
index 0dc598ecd..37b7f06e5 100644
--- a/test-regex.c
+++ b/test-regex.c
@@ -1,6 +1,6 @@
#include "git-compat-util.h"
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
char *pat = "[^={} \t]+";
char *str = "={}\nfred";
diff --git a/test-revision-walking.c b/test-revision-walking.c
index 3d0313354..b8e6fe1d0 100644
--- a/test-revision-walking.c
+++ b/test-revision-walking.c
@@ -45,7 +45,7 @@ static int run_revision_walk(void)
return got_revision;
}
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
if (argc < 2)
return 1;
diff --git a/test-run-command.c b/test-run-command.c
index 30a64a98d..c71ea4f75 100644
--- a/test-run-command.c
+++ b/test-run-command.c
@@ -49,7 +49,7 @@ static int task_finished(int result,
return 1;
}
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
struct child_process proc = CHILD_PROCESS_INIT;
int jobs;
diff --git a/test-scrap-cache-tree.c b/test-scrap-cache-tree.c
index 6efee31a4..5b2fd0990 100644
--- a/test-scrap-cache-tree.c
+++ b/test-scrap-cache-tree.c
@@ -5,7 +5,7 @@
static struct lock_file index_lock;
-int main(int ac, char **av)
+int cmd_main(int ac, const char **av)
{
hold_locked_index(&index_lock, 1);
if (read_cache() < 0)
diff --git a/test-sha1-array.c b/test-sha1-array.c
index 60ea1d5f1..09f779097 100644
--- a/test-sha1-array.c
+++ b/test-sha1-array.c
@@ -6,7 +6,7 @@ static void print_sha1(const unsigned char sha1[20], void *data)
puts(sha1_to_hex(sha1));
}
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
struct sha1_array array = SHA1_ARRAY_INIT;
struct strbuf line = STRBUF_INIT;
diff --git a/test-sha1.c b/test-sha1.c
index e57eae10b..a1c13f54e 100644
--- a/test-sha1.c
+++ b/test-sha1.c
@@ -1,6 +1,6 @@
#include "cache.h"
-int main(int ac, char **av)
+int cmd_main(int ac, const char **av)
{
git_SHA_CTX ctx;
unsigned char sha1[20];
diff --git a/test-sigchain.c b/test-sigchain.c
index e499fce60..b71edbd44 100644
--- a/test-sigchain.c
+++ b/test-sigchain.c
@@ -13,7 +13,7 @@ X(two)
X(three)
#undef X
-int main(int argc, char **argv) {
+int cmd_main(int argc, const char **argv) {
sigchain_push(SIGTERM, one);
sigchain_push(SIGTERM, two);
sigchain_push(SIGTERM, three);
diff --git a/test-string-list.c b/test-string-list.c
index 14bdf9d21..4a68967bd 100644
--- a/test-string-list.c
+++ b/test-string-list.c
@@ -41,7 +41,7 @@ static int prefix_cb(struct string_list_item *item, void *cb_data)
return starts_with(item->string, prefix);
}
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
if (argc == 5 && !strcmp(argv[1], "split")) {
struct string_list list = STRING_LIST_INIT_DUP;
diff --git a/test-submodule-config.c b/test-submodule-config.c
index dab8c2776..2cffded11 100644
--- a/test-submodule-config.c
+++ b/test-submodule-config.c
@@ -2,7 +2,7 @@
#include "submodule-config.h"
#include "submodule.h"
-static void die_usage(int argc, char **argv, const char *msg)
+static void die_usage(int argc, const char **argv, const char *msg)
{
fprintf(stderr, "%s\n", msg);
fprintf(stderr, "Usage: %s [<commit> <submodulepath>] ...\n", argv[0]);
@@ -14,9 +14,9 @@ static int git_test_config(const char *var, const char *value, void *cb)
return parse_submodule_config_option(var, value);
}
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
- char **arg = argv;
+ const char **arg = argv;
int my_argc = argc;
int output_url = 0;
int lookup_name = 0;
diff --git a/test-subprocess.c b/test-subprocess.c
index 56881a032..30c5765bf 100644
--- a/test-subprocess.c
+++ b/test-subprocess.c
@@ -1,7 +1,7 @@
#include "cache.h"
#include "run-command.h"
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
struct child_process cp = CHILD_PROCESS_INIT;
int nogit = 0;
diff --git a/test-svn-fe.c b/test-svn-fe.c
index 120ec96b0..7667c0803 100644
--- a/test-svn-fe.c
+++ b/test-svn-fe.c
@@ -11,7 +11,7 @@
static const char test_svnfe_usage[] =
"test-svn-fe (<dumpfile> | [-d] <preimage> <delta> <len>)";
-static int apply_delta(int argc, char *argv[])
+static int apply_delta(int argc, const char **argv)
{
struct line_buffer preimage = LINE_BUFFER_INIT;
struct line_buffer delta = LINE_BUFFER_INIT;
@@ -35,7 +35,7 @@ static int apply_delta(int argc, char *argv[])
return 0;
}
-int main(int argc, char *argv[])
+int cmd_main(int argc, const char **argv)
{
if (argc == 2) {
if (svndump_init(argv[1]))
diff --git a/test-urlmatch-normalization.c b/test-urlmatch-normalization.c
index 090bf219a..49b6e836b 100644
--- a/test-urlmatch-normalization.c
+++ b/test-urlmatch-normalization.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "urlmatch.h"
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
const char usage[] = "test-urlmatch-normalization [-p | -l] <url1> | <url1> <url2>";
char *url1, *url2;
diff --git a/test-wildmatch.c b/test-wildmatch.c
index 578b164fe..52be876fe 100644
--- a/test-wildmatch.c
+++ b/test-wildmatch.c
@@ -1,6 +1,6 @@
#include "cache.h"
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
int i;
for (i = 2; i < argc; i++) {
diff --git a/upload-pack.c b/upload-pack.c
index dc802a07c..909ce68cf 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -817,9 +817,9 @@ static int upload_pack_config(const char *var, const char *value, void *unused)
return parse_hide_refs_config(var, value, "uploadpack");
}
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
{
- char *dir;
+ const char *dir;
int i;
int strict = 0;
@@ -830,7 +830,7 @@ int main(int argc, char **argv)
check_replace_refs = 0;
for (i = 1; i < argc; i++) {
- char *arg = argv[i];
+ const char *arg = argv[i];
if (arg[0] != '-')
break;