builtin-am: implement --[no-]scissors

Since 017678b (am/mailinfo: Disable scissors processing by default, 2009-08-26), git-am supported the --[no-]scissors option, passing it to git-mailinfo. Re-implement support for this option in builtin/am.c. Since the default setting of --scissors in git-mailinfo can be configured with mailinfo.scissors (and perhaps through other settings in the future), to be safe we make an explicit distinction between SCISSORS_UNSET, SCISSORS_TRUE and SCISSORS_FALSE. Signed-off-by: Paul Tan <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Paul Tan committed Aug 4, 2015 at 21:51 UTC 9b646617b8b4894490a549e4db95c1303f40bd25
1 file changed +48
builtin/am.c
+48
@@ -74,6 +74,12 @@ enum keep_type {
74 KEEP_NON_PATCH /* pass -b flag to git-mailinfo */
75 };
76
77 +enum scissors_type {
78 + SCISSORS_UNSET = -1,
79 + SCISSORS_FALSE = 0, /* pass --no-scissors to git-mailinfo */
80 + SCISSORS_TRUE /* pass --scissors to git-mailinfo */
81 +};
82 +
83 struct am_state {
84 /* state directory path */
85 char *dir;
@@ -99,6 +105,7 @@ struct am_state {
105 int utf8;
106 int keep; /* enum keep_type */
107 int message_id;
108 + int scissors; /* enum scissors_type */
109 const char *resolvemsg;
110 int rebasing;
111 };
@@ -119,6 +126,8 @@ static void am_state_init(struct am_state *state, const char *dir)
126 state->utf8 = 1;
127
128 git_config_get_bool("am.messageid", &state->message_id);
129 +
130 + state->scissors = SCISSORS_UNSET;
131 }
132
133 /**
@@ -394,6 +403,14 @@ static void am_load(struct am_state *state)
403 read_state_file(&sb, state, "messageid", 1);
404 state->message_id = !strcmp(sb.buf, "t");
405
406 + read_state_file(&sb, state, "scissors", 1);
407 + if (!strcmp(sb.buf, "t"))
408 + state->scissors = SCISSORS_TRUE;
409 + else if (!strcmp(sb.buf, "f"))
410 + state->scissors = SCISSORS_FALSE;
411 + else
412 + state->scissors = SCISSORS_UNSET;
413 +
414 state->rebasing = !!file_exists(am_path(state, "rebasing"));
415
416 strbuf_release(&sb);
@@ -614,6 +631,22 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
631
632 write_file(am_path(state, "messageid"), 1, state->message_id ? "t" : "f");
633
634 + switch (state->scissors) {
635 + case SCISSORS_UNSET:
636 + str = "";
637 + break;
638 + case SCISSORS_FALSE:
639 + str = "f";
640 + break;
641 + case SCISSORS_TRUE:
642 + str = "t";
643 + break;
644 + default:
645 + die("BUG: invalid value for state->scissors");
646 + }
647 +
648 + write_file(am_path(state, "scissors"), 1, "%s", str);
649 +
650 if (state->rebasing)
651 write_file(am_path(state, "rebasing"), 1, "%s", "");
652 else
@@ -798,6 +831,19 @@ static int parse_mail(struct am_state *state, const char *mail)
831 if (state->message_id)
832 argv_array_push(&cp.args, "-m");
833
834 + switch (state->scissors) {
835 + case SCISSORS_UNSET:
836 + break;
837 + case SCISSORS_FALSE:
838 + argv_array_push(&cp.args, "--no-scissors");
839 + break;
840 + case SCISSORS_TRUE:
841 + argv_array_push(&cp.args, "--scissors");
842 + break;
843 + default:
844 + die("BUG: invalid value for state->scissors");
845 + }
846 +
847 argv_array_push(&cp.args, am_path(state, "msg"));
848 argv_array_push(&cp.args, am_path(state, "patch"));
849
@@ -1551,6 +1597,8 @@ int cmd_am(int argc, const char **argv, const char *prefix)
1597 { OPTION_SET_INT, 0, "no-keep-cr", &keep_cr, NULL,
1598 N_("do not pass --keep-cr flag to git-mailsplit independent of am.keepcr"),
1599 PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 0},
1600 + OPT_BOOL('c', "scissors", &state.scissors,
1601 + N_("strip everything before a scissors line")),
1602 OPT_CALLBACK(0, "patch-format", &patch_format, N_("format"),
1603 N_("format the patch(es) are in"),
1604 parse_opt_patchformat),