Merge branch 'jk/unbreak-am-h' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 5 Jun 2017 00:03:15 +0000 (09:03 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 Jun 2017 00:03:15 +0000 (09:03 +0900)
"git am -h" triggered a BUG().

* jk/unbreak-am-h:
am: handle "-h" argument earlier

1  2 
builtin/am.c
diff --combined builtin/am.c
index e39142e4d20c50a9cae5f5776dc03621ffb6c663,c74df14722fb182dc9f50165d66484462c5f18a6..593c1b5dda953d146c66a479b3bc5028efad5bf8
@@@ -1312,7 -1312,7 +1312,7 @@@ static int parse_mail(struct am_state *
        }
  
        if (is_empty_file(am_path(state, "patch"))) {
 -              printf_ln(_("Patch is empty. Was it split wrong?"));
 +              printf_ln(_("Patch is empty."));
                die_user_resolve(state);
        }
  
@@@ -1351,16 -1351,19 +1351,16 @@@ static int get_mail_commit_oid(struct o
        struct strbuf sb = STRBUF_INIT;
        FILE *fp = xfopen(mail, "r");
        const char *x;
 +      int ret = 0;
  
 -      if (strbuf_getline_lf(&sb, fp))
 -              return -1;
 -
 -      if (!skip_prefix(sb.buf, "From ", &x))
 -              return -1;
 -
 -      if (get_oid_hex(x, commit_id) < 0)
 -              return -1;
 +      if (strbuf_getline_lf(&sb, fp) ||
 +          !skip_prefix(sb.buf, "From ", &x) ||
 +          get_oid_hex(x, commit_id) < 0)
 +              ret = -1;
  
        strbuf_release(&sb);
        fclose(fp);
 -      return 0;
 +      return ret;
  }
  
  /**
   */
  static void get_commit_info(struct am_state *state, struct commit *commit)
  {
 -      const char *buffer, *ident_line, *author_date, *msg;
 +      const char *buffer, *ident_line, *msg;
        size_t ident_len;
 -      struct ident_split ident_split;
 -      struct strbuf sb = STRBUF_INIT;
 +      struct ident_split id;
  
        buffer = logmsg_reencode(commit, NULL, get_commit_output_encoding());
  
        ident_line = find_commit_header(buffer, "author", &ident_len);
  
 -      if (split_ident_line(&ident_split, ident_line, ident_len) < 0) {
 -              strbuf_add(&sb, ident_line, ident_len);
 -              die(_("invalid ident line: %s"), sb.buf);
 -      }
 +      if (split_ident_line(&id, ident_line, ident_len) < 0)
 +              die(_("invalid ident line: %.*s"), (int)ident_len, ident_line);
  
        assert(!state->author_name);
 -      if (ident_split.name_begin) {
 -              strbuf_add(&sb, ident_split.name_begin,
 -                      ident_split.name_end - ident_split.name_begin);
 -              state->author_name = strbuf_detach(&sb, NULL);
 -      } else
 +      if (id.name_begin)
 +              state->author_name =
 +                      xmemdupz(id.name_begin, id.name_end - id.name_begin);
 +      else
                state->author_name = xstrdup("");
  
        assert(!state->author_email);
 -      if (ident_split.mail_begin) {
 -              strbuf_add(&sb, ident_split.mail_begin,
 -                      ident_split.mail_end - ident_split.mail_begin);
 -              state->author_email = strbuf_detach(&sb, NULL);
 -      } else
 +      if (id.mail_begin)
 +              state->author_email =
 +                      xmemdupz(id.mail_begin, id.mail_end - id.mail_begin);
 +      else
                state->author_email = xstrdup("");
  
 -      author_date = show_ident_date(&ident_split, DATE_MODE(NORMAL));
 -      strbuf_addstr(&sb, author_date);
        assert(!state->author_date);
 -      state->author_date = strbuf_detach(&sb, NULL);
 +      state->author_date = xstrdup(show_ident_date(&id, DATE_MODE(NORMAL)));
  
        assert(!state->msg);
        msg = strstr(buffer, "\n\n");
                die(_("unable to parse commit %s"), oid_to_hex(&commit->object.oid));
        state->msg = xstrdup(msg + 2);
        state->msg_len = strlen(state->msg);
 +      unuse_commit_buffer(commit, buffer);
  }
  
  /**
@@@ -1931,8 -1940,7 +1931,8 @@@ static void am_resolve(struct am_state 
  
        if (unmerged_cache()) {
                printf_ln(_("You still have unmerged paths in your index.\n"
 -                      "Did you forget to use 'git add'?"));
 +                      "You should 'git add' each file with resolved conflicts to mark them as such.\n"
 +                      "You might run `git rm` on a file to accept \"deleted by them\" for it."));
                die_user_resolve(state);
        }
  
@@@ -2148,7 -2156,7 +2148,7 @@@ static void am_abort(struct am_state *s
        am_rerere_clear();
  
        curr_branch = resolve_refdup("HEAD", 0, curr_head.hash, NULL);
 -      has_curr_head = !is_null_oid(&curr_head);
 +      has_curr_head = curr_branch && !is_null_oid(&curr_head);
        if (!has_curr_head)
                hashcpy(curr_head.hash, EMPTY_TREE_SHA1_BIN);
  
@@@ -2311,6 -2319,9 +2311,9 @@@ int cmd_am(int argc, const char **argv
                OPT_END()
        };
  
+       if (argc == 2 && !strcmp(argv[1], "-h"))
+               usage_with_options(usage, options);
        git_config(git_am_config, NULL);
  
        am_state_init(&state);