Merge branch 'jc/am-mailinfo-direct'

"git am" used to spawn "git mailinfo" via run_command() API once
per each patch, but learned to make a direct call to mailinfo()
instead.

* jc/am-mailinfo-direct:
  am: make direct call to mailinfo
This commit is contained in:
Junio C Hamano 2015-10-29 13:59:23 -07:00
commit 95b86a60cf

View File

@ -27,6 +27,7 @@
#include "notes-utils.h" #include "notes-utils.h"
#include "rerere.h" #include "rerere.h"
#include "prompt.h" #include "prompt.h"
#include "mailinfo.h"
/** /**
* Returns 1 if the file is empty or does not exist, 0 otherwise. * Returns 1 if the file is empty or does not exist, 0 otherwise.
@ -1258,58 +1259,61 @@ static void am_append_signoff(struct am_state *state)
static int parse_mail(struct am_state *state, const char *mail) static int parse_mail(struct am_state *state, const char *mail)
{ {
FILE *fp; FILE *fp;
struct child_process cp = CHILD_PROCESS_INIT;
struct strbuf sb = STRBUF_INIT; struct strbuf sb = STRBUF_INIT;
struct strbuf msg = STRBUF_INIT; struct strbuf msg = STRBUF_INIT;
struct strbuf author_name = STRBUF_INIT; struct strbuf author_name = STRBUF_INIT;
struct strbuf author_date = STRBUF_INIT; struct strbuf author_date = STRBUF_INIT;
struct strbuf author_email = STRBUF_INIT; struct strbuf author_email = STRBUF_INIT;
int ret = 0; int ret = 0;
struct mailinfo mi;
cp.git_cmd = 1; setup_mailinfo(&mi);
cp.in = xopen(mail, O_RDONLY, 0);
cp.out = xopen(am_path(state, "info"), O_WRONLY | O_CREAT, 0777);
argv_array_push(&cp.args, "mailinfo"); if (state->utf8)
argv_array_push(&cp.args, state->utf8 ? "-u" : "-n"); mi.metainfo_charset = get_commit_output_encoding();
else
mi.metainfo_charset = NULL;
switch (state->keep) { switch (state->keep) {
case KEEP_FALSE: case KEEP_FALSE:
break; break;
case KEEP_TRUE: case KEEP_TRUE:
argv_array_push(&cp.args, "-k"); mi.keep_subject = 1;
break; break;
case KEEP_NON_PATCH: case KEEP_NON_PATCH:
argv_array_push(&cp.args, "-b"); mi.keep_non_patch_brackets_in_subject = 1;
break; break;
default: default:
die("BUG: invalid value for state->keep"); die("BUG: invalid value for state->keep");
} }
if (state->message_id) if (state->message_id)
argv_array_push(&cp.args, "-m"); mi.add_message_id = 1;
switch (state->scissors) { switch (state->scissors) {
case SCISSORS_UNSET: case SCISSORS_UNSET:
break; break;
case SCISSORS_FALSE: case SCISSORS_FALSE:
argv_array_push(&cp.args, "--no-scissors"); mi.use_scissors = 0;
break; break;
case SCISSORS_TRUE: case SCISSORS_TRUE:
argv_array_push(&cp.args, "--scissors"); mi.use_scissors = 1;
break; break;
default: default:
die("BUG: invalid value for state->scissors"); die("BUG: invalid value for state->scissors");
} }
argv_array_push(&cp.args, am_path(state, "msg")); mi.input = fopen(mail, "r");
argv_array_push(&cp.args, am_path(state, "patch")); if (!mi.input)
die("could not open input");
if (run_command(&cp) < 0) mi.output = fopen(am_path(state, "info"), "w");
if (!mi.output)
die("could not open output 'info'");
if (mailinfo(&mi, am_path(state, "msg"), am_path(state, "patch")))
die("could not parse patch"); die("could not parse patch");
close(cp.in); fclose(mi.input);
close(cp.out); fclose(mi.output);
/* Extract message and author information */ /* Extract message and author information */
fp = xfopen(am_path(state, "info"), "r"); fp = xfopen(am_path(state, "info"), "r");
@ -1341,8 +1345,7 @@ static int parse_mail(struct am_state *state, const char *mail)
} }
strbuf_addstr(&msg, "\n\n"); strbuf_addstr(&msg, "\n\n");
if (strbuf_read_file(&msg, am_path(state, "msg"), 0) < 0) strbuf_addbuf(&msg, &mi.log_message);
die_errno(_("could not read '%s'"), am_path(state, "msg"));
strbuf_stripspace(&msg, 0); strbuf_stripspace(&msg, 0);
if (state->signoff) if (state->signoff)
@ -1366,6 +1369,7 @@ finish:
strbuf_release(&author_email); strbuf_release(&author_email);
strbuf_release(&author_name); strbuf_release(&author_name);
strbuf_release(&sb); strbuf_release(&sb);
clear_mailinfo(&mi);
return ret; return ret;
} }