Skip to content

Commit 9b64661

Browse files
pyokagangitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5d123a4 commit 9b64661

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

builtin/am.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ enum keep_type {
7474
KEEP_NON_PATCH /* pass -b flag to git-mailinfo */
7575
};
7676

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+
7783
struct am_state {
7884
/* state directory path */
7985
char *dir;
@@ -99,6 +105,7 @@ struct am_state {
99105
int utf8;
100106
int keep; /* enum keep_type */
101107
int message_id;
108+
int scissors; /* enum scissors_type */
102109
const char *resolvemsg;
103110
int rebasing;
104111
};
@@ -119,6 +126,8 @@ static void am_state_init(struct am_state *state, const char *dir)
119126
state->utf8 = 1;
120127

121128
git_config_get_bool("am.messageid", &state->message_id);
129+
130+
state->scissors = SCISSORS_UNSET;
122131
}
123132

124133
/**
@@ -394,6 +403,14 @@ static void am_load(struct am_state *state)
394403
read_state_file(&sb, state, "messageid", 1);
395404
state->message_id = !strcmp(sb.buf, "t");
396405

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+
397414
state->rebasing = !!file_exists(am_path(state, "rebasing"));
398415

399416
strbuf_release(&sb);
@@ -614,6 +631,22 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
614631

615632
write_file(am_path(state, "messageid"), 1, state->message_id ? "t" : "f");
616633

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+
617650
if (state->rebasing)
618651
write_file(am_path(state, "rebasing"), 1, "%s", "");
619652
else
@@ -798,6 +831,19 @@ static int parse_mail(struct am_state *state, const char *mail)
798831
if (state->message_id)
799832
argv_array_push(&cp.args, "-m");
800833

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+
801847
argv_array_push(&cp.args, am_path(state, "msg"));
802848
argv_array_push(&cp.args, am_path(state, "patch"));
803849

@@ -1551,6 +1597,8 @@ int cmd_am(int argc, const char **argv, const char *prefix)
15511597
{ OPTION_SET_INT, 0, "no-keep-cr", &keep_cr, NULL,
15521598
N_("do not pass --keep-cr flag to git-mailsplit independent of am.keepcr"),
15531599
PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 0},
1600+
OPT_BOOL('c', "scissors", &state.scissors,
1601+
N_("strip everything before a scissors line")),
15541602
OPT_CALLBACK(0, "patch-format", &patch_format, N_("format"),
15551603
N_("format the patch(es) are in"),
15561604
parse_opt_patchformat),

0 commit comments

Comments
 (0)