Code

Merge branch 'ph/push-to-delete-nothing'
authorJunio C Hamano <gitster@pobox.com>
Tue, 18 Oct 2011 04:37:10 +0000 (21:37 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Oct 2011 04:37:10 +0000 (21:37 -0700)
* ph/push-to-delete-nothing:
  receive-pack: don't pass non-existent refs to post-{receive,update} hooks

Conflicts:
builtin/receive-pack.c

1  2 
builtin/receive-pack.c

index e2d3f94661ffd89e08a1bf0e52ff07b366612b65,b73f18a57bf44eaab0465f5236009d4f004df595..261b610d24017557c137d83a9c005b662e795b6a
@@@ -262,47 -264,6 +263,51 @@@ static int run_and_feed_hook(const cha
        return finish_command(&proc);
  }
  
-       while (cmd && cmd->error_string)
 +struct receive_hook_feed_state {
 +      struct command *cmd;
++      int skip_broken;
 +      struct strbuf buf;
 +};
 +
 +static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep)
 +{
 +      struct receive_hook_feed_state *state = state_;
 +      struct command *cmd = state->cmd;
 +
- static int run_receive_hook(struct command *commands, const char *hook_name)
++      while (cmd &&
++             state->skip_broken && (cmd->error_string || cmd->did_not_exist))
 +              cmd = cmd->next;
 +      if (!cmd)
 +              return -1; /* EOF */
 +      strbuf_reset(&state->buf);
 +      strbuf_addf(&state->buf, "%s %s %s\n",
 +                  sha1_to_hex(cmd->old_sha1), sha1_to_hex(cmd->new_sha1),
 +                  cmd->ref_name);
 +      state->cmd = cmd->next;
 +      if (bufp) {
 +              *bufp = state->buf.buf;
 +              *sizep = state->buf.len;
 +      }
 +      return 0;
 +}
 +
++static int run_receive_hook(struct command *commands, const char *hook_name,
++                          int skip_broken)
 +{
 +      struct receive_hook_feed_state state;
 +      int status;
 +
 +      strbuf_init(&state.buf, 0);
 +      state.cmd = commands;
++      state.skip_broken = skip_broken;
 +      if (feed_receive_hook(&state, NULL, NULL))
 +              return 0;
 +      state.cmd = commands;
 +      status = run_and_feed_hook(hook_name, feed_receive_hook, &state);
 +      strbuf_release(&state.buf);
 +      return status;
 +}
 +
  static int run_update_hook(struct command *cmd)
  {
        static const char update_hook[] = "hooks/update";
@@@ -667,12 -596,7 +677,12 @@@ static void execute_commands(struct com
                return;
        }
  
 -      if (run_receive_hook(commands, pre_receive_hook)) {
 +      cmd = commands;
 +      if (check_everything_connected(iterate_receive_command_list,
 +                                     0, &cmd))
 +              set_connectivity_errors(commands);
 +
-       if (run_receive_hook(commands, pre_receive_hook)) {
++      if (run_receive_hook(commands, pre_receive_hook, 0)) {
                for (cmd = commands; cmd; cmd = cmd->next)
                        cmd->error_string = "pre-receive hook declined";
                return;
@@@ -940,7 -859,7 +950,7 @@@ int cmd_receive_pack(int argc, const ch
                        unlink_or_warn(pack_lockfile);
                if (report_status)
                        report(commands, unpack_status);
--              run_receive_hook(commands, post_receive_hook);
++              run_receive_hook(commands, post_receive_hook, 1);
                run_update_post_hook(commands);
                if (auto_gc) {
                        const char *argv_gc_auto[] = {