Use run_command() to spawn external diff programs instead of fork/exec.
[gitweb.git] / builtin-fetch-pack.c
index 77eb181b5f3aba8dfd5dd40ae8c3349d78c75706..f56592fea7ad56f01568dc06c46aaa4e0c8914d3 100644 (file)
@@ -670,18 +670,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;
@@ -756,26 +762,25 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,
 {
        int i, ret;
        int fd[2];
-       pid_t pid;
+       struct child_process *conn;
        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,
+       conn = git_connect(fd, (char *)dest, uploadpack,
                           args.verbose ? CONNECT_VERBOSE : 0);
-       if (pid < 0)
-               return NULL;
        if (heads && nr_heads)
                nr_heads = remove_duplicates(nr_heads, heads);
        ref = do_fetch_pack(fd, nr_heads, heads, pack_lockfile);
        close(fd[0]);
        close(fd[1]);
-       ret = finish_connect(pid);
+       ret = finish_connect(conn);
 
        if (!ret && nr_heads) {
                /* If the heads to pull were given, we should have