Since d1c5f2a (Add git-am, applymbox replacement., 2005-10-07), git-am.sh supported the -k/--keep option to pass the -k option to git-mailsplit. Since f7e5ea1 (am: learn passing -b to mailinfo, 2012-01-16), git-am.sh supported the --keep-non-patch option to pass the -b option to git-mailsplit. Re-implement these two options in builtin/am.c. Signed-off-by: Paul Tan <pyokagan@xxxxxxxxx> --- builtin/am.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/builtin/am.c b/builtin/am.c index bbef91f..b73549f 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -81,6 +81,12 @@ enum patch_format { PATCH_FORMAT_MBOX }; +enum keep_type { + KEEP_FALSE = 0, + KEEP_TRUE, /* pass -k flag to git-mailinfo */ + KEEP_NON_PATCH /* pass -b flag to git-mailinfo */ +}; + struct am_state { /* state directory path */ struct strbuf dir; @@ -104,6 +110,9 @@ struct am_state { int sign; + /* one of the enum keep_type values */ + int keep; + /* override error message when patch failure occurs */ const char *resolvemsg; @@ -333,6 +342,14 @@ static void am_load(struct am_state *state) read_state_file(&sb, am_path(state, "sign"), 2, 1); state->sign = !strcmp(sb.buf, "t"); + read_state_file(&sb, am_path(state, "keep"), 2, 1); + if (!strcmp(sb.buf, "t")) + state->keep = KEEP_TRUE; + else if (!strcmp(sb.buf, "b")) + state->keep = KEEP_NON_PATCH; + else + state->keep = KEEP_FALSE; + state->rebasing = !!file_exists(am_path(state, "rebasing")); strbuf_release(&sb); @@ -497,6 +514,7 @@ static void am_setup(struct am_state *state, enum patch_format patch_format, struct string_list *paths) { unsigned char curr_head[GIT_SHA1_RAWSZ]; + const char *str; if (!patch_format) patch_format = detect_patch_format(paths); @@ -527,6 +545,21 @@ static void am_setup(struct am_state *state, enum patch_format patch_format, write_file(am_path(state, "sign"), 1, state->sign ? "t" : "f"); + switch (state->keep) { + case KEEP_FALSE: + str = "f"; + break; + case KEEP_TRUE: + str = "t"; + break; + case KEEP_NON_PATCH: + str = "b"; + break; + default: + die("BUG: invalid value for state->keep"); + } + write_file(am_path(state, "keep"), 1, "%s", str); + if (state->rebasing) write_file(am_path(state, "rebasing"), 1, "%s", ""); else @@ -653,6 +686,20 @@ static int parse_patch(struct am_state *state, const char *patch) cp.out = xopen(am_path(state, "info"), O_WRONLY | O_CREAT, 0777); argv_array_push(&cp.args, "mailinfo"); + + switch (state->keep) { + case KEEP_FALSE: + break; + case KEEP_TRUE: + argv_array_push(&cp.args, "-k"); + break; + case KEEP_NON_PATCH: + argv_array_push(&cp.args, "-b"); + break; + default: + die("BUG: invalid value for state->keep"); + } + argv_array_push(&cp.args, am_path(state, "msg")); argv_array_push(&cp.args, am_path(state, "patch")); @@ -1326,6 +1373,10 @@ static struct option am_options[] = { OPT__QUIET(&state.quiet, N_("be quiet")), OPT_BOOL('s', "signoff", &state.sign, N_("add a Signed-off-by line to the commit message")), + OPT_SET_INT('k', "keep", &state.keep, + N_("pass -k flag to git-mailinfo"), KEEP_TRUE), + OPT_SET_INT(0, "keep-non-patch", &state.keep, + N_("pass -b flag to git-mailinfo"), KEEP_NON_PATCH), OPT_CALLBACK(0, "patch-format", &opt_patch_format, N_("format"), N_("format the patch(es) are in"), parse_opt_patchformat), OPT_STRING(0, "resolvemsg", &state.resolvemsg, NULL, -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html