]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin-receive-pack.c
Merge branch 'jc/1.7.0-push-safety'
[thirdparty/git.git] / builtin-receive-pack.c
index db12b813acbe9bade2b854b3a94fed13f6210499..4320c93e700a08911e42e3e949656af67b675244 100644 (file)
@@ -28,6 +28,8 @@ static int transfer_unpack_limit = -1;
 static int unpack_limit = 100;
 static int report_status;
 static int prefer_ofs_delta = 1;
+static int auto_update_server_info;
+static int auto_gc = 1;
 static const char *head_name;
 static char *capabilities_to_send;
 
@@ -88,6 +90,16 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
                return 0;
        }
 
+       if (strcmp(var, "receive.updateserverinfo") == 0) {
+               auto_update_server_info = git_config_bool(var, value);
+               return 0;
+       }
+
+       if (strcmp(var, "receive.autogc") == 0) {
+               auto_gc = git_config_bool(var, value);
+               return 0;
+       }
+
        return git_default_config(var, value, cb);
 }
 
@@ -123,31 +135,6 @@ static struct command *commands;
 static const char pre_receive_hook[] = "hooks/pre-receive";
 static const char post_receive_hook[] = "hooks/post-receive";
 
-static int run_status(int code, const char *cmd_name)
-{
-       switch (code) {
-       case 0:
-               return 0;
-       case -ERR_RUN_COMMAND_FORK:
-               return error("fork of %s failed", cmd_name);
-       case -ERR_RUN_COMMAND_EXEC:
-               return error("execute of %s failed", cmd_name);
-       case -ERR_RUN_COMMAND_PIPE:
-               return error("pipe failed");
-       case -ERR_RUN_COMMAND_WAITPID:
-               return error("waitpid failed");
-       case -ERR_RUN_COMMAND_WAITPID_WRONG_PID:
-               return error("waitpid is confused");
-       case -ERR_RUN_COMMAND_WAITPID_SIGNAL:
-               return error("%s died of signal", cmd_name);
-       case -ERR_RUN_COMMAND_WAITPID_NOEXIT:
-               return error("%s died strangely", cmd_name);
-       default:
-               error("%s exited with error code %d", cmd_name, -code);
-               return -code;
-       }
-}
-
 static int run_receive_hook(const char *hook_name)
 {
        static char buf[sizeof(commands->old_sha1) * 2 + PATH_MAX + 4];
@@ -174,7 +161,7 @@ static int run_receive_hook(const char *hook_name)
 
        code = start_command(&proc);
        if (code)
-               return run_status(code, hook_name);
+               return code;
        for (cmd = commands; cmd; cmd = cmd->next) {
                if (!cmd->error_string) {
                        size_t n = snprintf(buf, sizeof(buf), "%s %s %s\n",
@@ -186,7 +173,7 @@ static int run_receive_hook(const char *hook_name)
                }
        }
        close(proc.in);
-       return run_status(finish_command(&proc), hook_name);
+       return finish_command(&proc);
 }
 
 static int run_update_hook(struct command *cmd)
@@ -203,9 +190,8 @@ static int run_update_hook(struct command *cmd)
        argv[3] = sha1_to_hex(cmd->new_sha1);
        argv[4] = NULL;
 
-       return run_status(run_command_v_opt(argv, RUN_COMMAND_NO_STDIN |
-                                       RUN_COMMAND_STDOUT_TO_STDERR),
-                       update_hook);
+       return run_command_v_opt(argv, RUN_COMMAND_NO_STDIN |
+                                       RUN_COMMAND_STDOUT_TO_STDERR);
 }
 
 static int is_ref_checked_out(const char *ref)
@@ -343,9 +329,9 @@ static const char *update(struct command *cmd)
                                break;
                free_commit_list(bases);
                if (!ent) {
-                       error("denying non-fast forward %s"
+                       error("denying non-fast-forward %s"
                              " (you should pull first)", name);
-                       return "non-fast forward";
+                       return "non-fast-forward";
                }
        }
        if (run_update_hook(cmd)) {
@@ -407,7 +393,6 @@ static void run_update_post_hook(struct command *cmd)
        argv[argc] = NULL;
        status = run_command_v_opt(argv, RUN_COMMAND_NO_STDIN
                        | RUN_COMMAND_STDOUT_TO_STDERR);
-       run_status(status, update_post_hook);
 }
 
 static void execute_commands(const char *unpacker_error)
@@ -525,7 +510,6 @@ static const char *unpack(void)
                code = run_command_v_opt(unpacker, RUN_GIT_CMD);
                if (!code)
                        return NULL;
-               run_status(code, unpacker[0]);
                return "unpack-objects abnormal exit";
        } else {
                const char *keeper[7];
@@ -551,7 +535,6 @@ static const char *unpack(void)
                ip.git_cmd = 1;
                status = start_command(&ip);
                if (status) {
-                       run_status(status, keeper[0]);
                        return "index-pack fork failed";
                }
                pack_lockfile = index_pack_lockfile(ip.out);
@@ -561,7 +544,6 @@ static const char *unpack(void)
                        reprepare_packed_git();
                        return NULL;
                }
-               run_status(status, keeper[0]);
                return "index-pack abnormal exit";
        }
 }
@@ -633,6 +615,8 @@ static void add_alternate_refs(void)
 
 int cmd_receive_pack(int argc, const char **argv, const char *prefix)
 {
+       int advertise_refs = 0;
+       int stateless_rpc = 0;
        int i;
        char *dir = NULL;
 
@@ -641,7 +625,15 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
                const char *arg = *argv++;
 
                if (*arg == '-') {
-                       /* Do flag handling here */
+                       if (!strcmp(arg, "--advertise-refs")) {
+                               advertise_refs = 1;
+                               continue;
+                       }
+                       if (!strcmp(arg, "--stateless-rpc")) {
+                               stateless_rpc = 1;
+                               continue;
+                       }
+
                        usage(receive_pack_usage);
                }
                if (dir)
@@ -670,12 +662,16 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
                " report-status delete-refs ofs-delta " :
                " report-status delete-refs ";
 
-       add_alternate_refs();
-       write_head_info();
-       clear_extra_refs();
+       if (advertise_refs || !stateless_rpc) {
+               add_alternate_refs();
+               write_head_info();
+               clear_extra_refs();
 
-       /* EOF */
-       packet_flush(1);
+               /* EOF */
+               packet_flush(1);
+       }
+       if (advertise_refs)
+               return 0;
 
        read_head_info();
        if (commands) {
@@ -690,6 +686,14 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
                        report(unpack_status);
                run_receive_hook(post_receive_hook);
                run_update_post_hook(commands);
+               if (auto_gc) {
+                       const char *argv_gc_auto[] = {
+                               "gc", "--auto", "--quiet", NULL,
+                       };
+                       run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
+               }
+               if (auto_update_server_info)
+                       update_server_info(0);
        }
        return 0;
 }