add an extra level of indirection to main()
authorJeff King <peff@peff.net>
Fri, 1 Jul 2016 05:58:58 +0000 (01:58 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 1 Jul 2016 22:09:10 +0000 (15:09 -0700)
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>
52 files changed:
Makefile
common-main.c [new file with mode: 0644]
credential-cache--daemon.c
credential-cache.c
credential-store.c
daemon.c
fast-import.c
git-compat-util.h
git.c
http-backend.c
http-fetch.c
http-push.c
imap-send.c
remote-curl.c
remote-testsvn.c
sh-i18n--envsubst.c
shell.c
show-index.c
test-chmtime.c
test-config.c
test-ctype.c
test-date.c
test-delta.c
test-dump-cache-tree.c
test-dump-split-index.c
test-dump-untracked-cache.c
test-fake-ssh.c
test-genrandom.c
test-hashmap.c
test-index-version.c
test-line-buffer.c
test-match-trees.c
test-mergesort.c
test-mktemp.c
test-parse-options.c
test-path-utils.c
test-prio-queue.c
test-read-cache.c
test-regex.c
test-revision-walking.c
test-run-command.c
test-scrap-cache-tree.c
test-sha1-array.c
test-sha1.c
test-sigchain.c
test-string-list.c
test-submodule-config.c
test-subprocess.c
test-svn-fe.c
test-urlmatch-normalization.c
test-wildmatch.c
upload-pack.c
index e11e626d05213f4734815f03f8077ffae6793a51..15f37d58e9ed1c0236b3a67f4474e67522fa8ab1 100644 (file)
--- 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 (file)
index 0000000..2b96bbf
--- /dev/null
@@ -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);
+}
index 291c0fd5e935b5abedc629697d44e5a9f57727bd..a4bf2366ab49701c99453d805e47eeade204d2c5 100644 (file)
@@ -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;
index 86e21de49be4d48defd3e9da5cde170291bca600..cc8a6ee19214b12758fc3d4b39ff4a07f4442d91 100644 (file)
@@ -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;
index 57141679abdaa804282a0cc2d808e7c6687d924a..55ca1b1334319924dcbbf69ec39b2335e6a452aa 100644 (file)
@@ -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>",
index 8d45c336f5f816768962c39e8af6b10e0bb0e21e..e6b86d215325d51262f7507af3230d3b5f9cf21b 100644 (file)
--- 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)) {
index 9fc7093406b1e2085a3b2180a8506bcd6d486e06..bd649268b20b746e887f7e47c332faf53407a3f5 100644 (file)
@@ -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;
 
index 1f8b5f3b1f1ac17716681fee2d72b9c124a9b99c..91e366d1dd50902dc5249907e405339ed104e964 100644 (file)
@@ -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 968a8a464588f10c5c1564440e06d5e5afe8d37a..e2444046f5894fba768430c4d2e0aa66d6cd1fd5 100644 (file)
--- 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;
 
index 8870a2681eb375505e4273b03a0d3e034e59a48e..3249652b3df157e98a605549370fb714f0232e9a 100644 (file)
@@ -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;
index ba3ea106708de01fc933e6743ab109bef2697f75..eb559eb83bc3d9cc66046af6039fbaeae865f605 100644 (file)
@@ -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;
index bd60668707b956160edd9fb22767758023571ebb..98228a426268abc348e68fee2304004bb4f77e31 100644 (file)
@@ -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")) {
index 938c6915858b93b7c860e49e906c45e0e2ea5d03..890e1cbb64fa391892abae04b491dd3232ecd032 100644 (file)
@@ -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;
index 15e48e25fb9fb8cd2e9e3e7a63cf08d2f9483ea2..6ebc2a0c11b1e28feddaf5c13fcc9c4c9daf216c 100644 (file)
@@ -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;
index f05ff45298207258c257c2118206fbbfa0a4c670..32631eb14a04d769cc5a185477ee93aca69b663a 100644 (file)
@@ -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,
index 2842a22d7fdda33d62d617d5ba9b826ad428c17e..e06b2c1311f72d1023b34c937ab48cd56ae8e206 100644 (file)
@@ -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 c5439a63e9678e1dc3dfa7d4e1f2a97c331e54d6..3dd7fdcfe61479f213ebeaedbfd3090cd5a93852 100644 (file)
--- 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;
index acf8d5445ad96aacf6d2c3ccc2d77a3815291228..575f9c589456a054d208fd9c38666bb351cb0b70 100644 (file)
@@ -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;
index dfe8a83261b3623e64f99ddf8dc775616771ec4d..e760256406fa9c2fe0f9b2cde0ffb97ff11c6cab 100644 (file)
@@ -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;
 
index 6a775522105d9bfc5c1c60f36944bc43e64badef..d143cd72223dec9c947fbf84d0f72945745a09c6 100644 (file)
@@ -33,7 +33,7 @@
  */
 
 
-int main(int argc, char **argv)
+int cmd_main(int argc, const char **argv)
 {
        int i, val;
        const char *v;
index 707a821f03d59b1b3685b380fa4f3e83535c5342..bb72c47df570d9c07ae4567fd6d31ea49fe49656 100644 (file)
@@ -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");
index 63f373557e7236d294fb580d38db9e6d331e53d3..0f3cfb1721b641b25267458edce93c9de2f923e2 100644 (file)
@@ -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;
index 4595cd6433f9fd543791ee5a8a59a9112b50c046..59937dc1be1c4f0b3d80e3ef3a86e09bff3703b6 100644 (file)
@@ -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;
index bb53c0aa655c7a2df09638024b304a79e8b07fc6..44f3290258a003317e4aad4f90d17ce5529e3b07 100644 (file)
@@ -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();
index 861d28c9b6c1b4d95f74ffbd95bc279ea0d377eb..d1689248b4937fbecaf16129c4016814554b983d 100644 (file)
@@ -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;
index 0a1c28524668f02d3aa4d073c0c6991652cbf850..50112cc8586c75cf9f9b5fac65ea2f7dbc1a69e2 100644 (file)
@@ -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;
index 980de216e10990a6406cae6e0b023c5fee7de488..12beee99ad2f4e70e804b21895522d6d362929d2 100644 (file)
@@ -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;
index 54824d075421e792f337beb5cdce170a33b00e68..8d11d22d98649900b6d558cc174e2af1dbff9948 100644 (file)
@@ -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;
index cc2891dd971edfa70733eb327d12ccb66fd09f3e..7aa9440e274fb443a30b3f61a241f4fea1601f10 100644 (file)
@@ -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;
index 05d4699c4a6cf32b2b6291e275dafa2744fe19d6..f569f6b7eff87227f82dbe6390fd31fb970a5fca 100644 (file)
@@ -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;
index 1e58f0476f3465f9b8b361cc4776abf5c051430b..81575fe2ab91b550067ce8180650b003bdd939b7 100644 (file)
@@ -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;
index 4dad7095f10bb324f043ff8132678488b65d4537..afcdc143b51e0143f8d8761b927ff02b42ca7580 100644 (file)
@@ -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;
index ea3b959e94ff6f53726d4fce955bca1181a3be07..335cf6b6264cdaf9563736fbcfa40e7a3006a432 100644 (file)
@@ -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;
index c8c54213a3916c4adffd7396a37ed83e88af34fb..89d9b2f7bee05ff5c9fde31ba6798651ccee2947 100644 (file)
@@ -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");
index 2c8c8f18edb46378b39c170b4ae6f7250ec631f5..7adae43b87a8e89652681b850e6e6d586ef30462 100644 (file)
@@ -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[] = {
index ba805b374c57a4e5ad2e6e4a4b9071a11c165afa..1ebe0f750c648cd4d92983c11ace9e8a86327dd1 100644 (file)
@@ -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);
index 7be72f0086ba4b80cecf9f324bd5152a8531cdbd..ae58fff35972a09c08a47d2bc0abb67c96ba20eb 100644 (file)
@@ -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 };
 
index b25bcf139b2bf61292eb9910cb4f92d8ce7763bd..2a7990efc31d042121122a17890c623d7714c128 100644 (file)
@@ -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)
index 0dc598ecdc2696af956b1c517166f9e28b37dc68..37b7f06e552ef51c852f54e70d66c434ca50b6b2 100644 (file)
@@ -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";
index 3d0313354b3e100fe3624b58c61af7cc7e0f8e7b..b8e6fe1d007449d30dd30ccd4319b26f151bbf23 100644 (file)
@@ -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;
index 30a64a98dc8b53a3a2d7edfaa57a8ee51d5d63e7..c71ea4f759bf15253841bda5dd95f0783d0f7ad6 100644 (file)
@@ -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;
index 6efee31a4867b4ff8493161376e5a9cfdd48fe44..5b2fd0990894dd59a074ded5822bbcf215a989aa 100644 (file)
@@ -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)
index 60ea1d5f14e2572df5716da5815143ed26a5be4b..09f77909716326bdb76a79d3c32d10b74702e1d5 100644 (file)
@@ -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;
index e57eae10bf73baac79fd8b95ddb0ff1b4c8c0cd6..a1c13f54eca0db7d11a5df134d565171d70b8cce 100644 (file)
@@ -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];
index e499fce60ff50069ace6174ef9fa3ca4aff0cdc8..b71edbd4429184b59b4bd1355d5cfb53970a1876 100644 (file)
@@ -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);
index 14bdf9d2153a98d0b2a5d03395c1adcc166f8a07..4a68967bd126e5ab74ec2b39113cce58e7c021bf 100644 (file)
@@ -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;
index dab8c27768160d4cfa61c41a95004eb7a8a336b6..2cffded116f77d7c62ee718fa08558b52574a205 100644 (file)
@@ -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;
index 56881a032471752ca16880d98ea1510e16d38eed..30c5765bfc3590421c21bc2350eed882752de3a0 100644 (file)
@@ -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;
index 120ec96b0dbd94e7be9ffc81d0fb87ccbd30a7df..7667c0803f1231152190a1a5b4c61a2fb2677048 100644 (file)
@@ -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]))
index 090bf219a7d499ae246f80c0d478eb37fdef8f8f..49b6e836be257c0689601bf17138439cff0d61a0 100644 (file)
@@ -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;
index 578b164fe603f11dfe67e25be36a6ab38aa6d645..52be876fed3bcc3bb5a1def5de8febe8b29c0ec4 100644 (file)
@@ -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++) {
index dc802a07c2225463c2e4ee923b9cf144d57a00cc..909ce68cfb8bb18ea7e6b6c9d27fbd8620ba73d3 100644 (file)
@@ -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;