parse-options: make some arguments optional, add callbacks.
[gitweb.git] / builtin-fetch-pack.c
index 77eb181b5f3aba8dfd5dd40ae8c3349d78c75706..8753840a825d35249fa74ee80867f2dfd542708b 100644 (file)
 static int transfer_unpack_limit = -1;
 static int fetch_unpack_limit = -1;
 static int unpack_limit = 100;
-static struct fetch_pack_args args;
+static struct fetch_pack_args args = {
+       /* .uploadpack = */ "git-upload-pack",
+};
 
 static const char fetch_pack_usage[] =
 "git-fetch-pack [--all] [--quiet|-q] [--keep|-k] [--thin] [--upload-pack=<git-upload-pack>] [--depth=<n>] [--no-progress] [-v] [<host>:]<directory> [<refs>...]";
-static const char *uploadpack = "git-upload-pack";
 
 #define COMPLETE       (1U << 0)
 #define COMMON         (1U << 1)
@@ -670,18 +671,24 @@ static int fetch_pack_config(const char *var, const char *value)
 
 static struct lock_file lock;
 
-int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
+static void fetch_pack_setup(void)
 {
-       int i, ret, nr_heads;
-       struct ref *ref;
-       char *dest = NULL, **heads;
-
+       static int did_setup;
+       if (did_setup)
+               return;
        git_config(fetch_pack_config);
-
        if (0 <= transfer_unpack_limit)
                unpack_limit = transfer_unpack_limit;
        else if (0 <= fetch_unpack_limit)
                unpack_limit = fetch_unpack_limit;
+       did_setup = 1;
+}
+
+int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
+{
+       int i, ret, nr_heads;
+       struct ref *ref;
+       char *dest = NULL, **heads;
 
        nr_heads = 0;
        heads = NULL;
@@ -760,13 +767,14 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,
        struct ref *ref;
        struct stat st;
 
+       fetch_pack_setup();
        memcpy(&args, my_args, sizeof(args));
        if (args.depth > 0) {
                if (stat(git_path("shallow"), &st))
                        st.st_mtime = 0;
        }
 
-       pid = git_connect(fd, (char *)dest, uploadpack,
+       pid = git_connect(fd, (char *)dest, args.uploadpack,
                           args.verbose ? CONNECT_VERBOSE : 0);
        if (pid < 0)
                return NULL;