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>
This commit is contained in:
parent
5d123a4017
commit
9b646617b8
48
builtin/am.c
48
builtin/am.c
@ -74,6 +74,12 @@ enum keep_type {
|
|||||||
KEEP_NON_PATCH /* pass -b flag to git-mailinfo */
|
KEEP_NON_PATCH /* pass -b flag to git-mailinfo */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum scissors_type {
|
||||||
|
SCISSORS_UNSET = -1,
|
||||||
|
SCISSORS_FALSE = 0, /* pass --no-scissors to git-mailinfo */
|
||||||
|
SCISSORS_TRUE /* pass --scissors to git-mailinfo */
|
||||||
|
};
|
||||||
|
|
||||||
struct am_state {
|
struct am_state {
|
||||||
/* state directory path */
|
/* state directory path */
|
||||||
char *dir;
|
char *dir;
|
||||||
@ -99,6 +105,7 @@ struct am_state {
|
|||||||
int utf8;
|
int utf8;
|
||||||
int keep; /* enum keep_type */
|
int keep; /* enum keep_type */
|
||||||
int message_id;
|
int message_id;
|
||||||
|
int scissors; /* enum scissors_type */
|
||||||
const char *resolvemsg;
|
const char *resolvemsg;
|
||||||
int rebasing;
|
int rebasing;
|
||||||
};
|
};
|
||||||
@ -119,6 +126,8 @@ static void am_state_init(struct am_state *state, const char *dir)
|
|||||||
state->utf8 = 1;
|
state->utf8 = 1;
|
||||||
|
|
||||||
git_config_get_bool("am.messageid", &state->message_id);
|
git_config_get_bool("am.messageid", &state->message_id);
|
||||||
|
|
||||||
|
state->scissors = SCISSORS_UNSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -394,6 +403,14 @@ static void am_load(struct am_state *state)
|
|||||||
read_state_file(&sb, state, "messageid", 1);
|
read_state_file(&sb, state, "messageid", 1);
|
||||||
state->message_id = !strcmp(sb.buf, "t");
|
state->message_id = !strcmp(sb.buf, "t");
|
||||||
|
|
||||||
|
read_state_file(&sb, state, "scissors", 1);
|
||||||
|
if (!strcmp(sb.buf, "t"))
|
||||||
|
state->scissors = SCISSORS_TRUE;
|
||||||
|
else if (!strcmp(sb.buf, "f"))
|
||||||
|
state->scissors = SCISSORS_FALSE;
|
||||||
|
else
|
||||||
|
state->scissors = SCISSORS_UNSET;
|
||||||
|
|
||||||
state->rebasing = !!file_exists(am_path(state, "rebasing"));
|
state->rebasing = !!file_exists(am_path(state, "rebasing"));
|
||||||
|
|
||||||
strbuf_release(&sb);
|
strbuf_release(&sb);
|
||||||
@ -614,6 +631,22 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
|
|||||||
|
|
||||||
write_file(am_path(state, "messageid"), 1, state->message_id ? "t" : "f");
|
write_file(am_path(state, "messageid"), 1, state->message_id ? "t" : "f");
|
||||||
|
|
||||||
|
switch (state->scissors) {
|
||||||
|
case SCISSORS_UNSET:
|
||||||
|
str = "";
|
||||||
|
break;
|
||||||
|
case SCISSORS_FALSE:
|
||||||
|
str = "f";
|
||||||
|
break;
|
||||||
|
case SCISSORS_TRUE:
|
||||||
|
str = "t";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
die("BUG: invalid value for state->scissors");
|
||||||
|
}
|
||||||
|
|
||||||
|
write_file(am_path(state, "scissors"), 1, "%s", str);
|
||||||
|
|
||||||
if (state->rebasing)
|
if (state->rebasing)
|
||||||
write_file(am_path(state, "rebasing"), 1, "%s", "");
|
write_file(am_path(state, "rebasing"), 1, "%s", "");
|
||||||
else
|
else
|
||||||
@ -798,6 +831,19 @@ static int parse_mail(struct am_state *state, const char *mail)
|
|||||||
if (state->message_id)
|
if (state->message_id)
|
||||||
argv_array_push(&cp.args, "-m");
|
argv_array_push(&cp.args, "-m");
|
||||||
|
|
||||||
|
switch (state->scissors) {
|
||||||
|
case SCISSORS_UNSET:
|
||||||
|
break;
|
||||||
|
case SCISSORS_FALSE:
|
||||||
|
argv_array_push(&cp.args, "--no-scissors");
|
||||||
|
break;
|
||||||
|
case SCISSORS_TRUE:
|
||||||
|
argv_array_push(&cp.args, "--scissors");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
die("BUG: invalid value for state->scissors");
|
||||||
|
}
|
||||||
|
|
||||||
argv_array_push(&cp.args, am_path(state, "msg"));
|
argv_array_push(&cp.args, am_path(state, "msg"));
|
||||||
argv_array_push(&cp.args, am_path(state, "patch"));
|
argv_array_push(&cp.args, am_path(state, "patch"));
|
||||||
|
|
||||||
@ -1551,6 +1597,8 @@ int cmd_am(int argc, const char **argv, const char *prefix)
|
|||||||
{ OPTION_SET_INT, 0, "no-keep-cr", &keep_cr, NULL,
|
{ OPTION_SET_INT, 0, "no-keep-cr", &keep_cr, NULL,
|
||||||
N_("do not pass --keep-cr flag to git-mailsplit independent of am.keepcr"),
|
N_("do not pass --keep-cr flag to git-mailsplit independent of am.keepcr"),
|
||||||
PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 0},
|
PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 0},
|
||||||
|
OPT_BOOL('c', "scissors", &state.scissors,
|
||||||
|
N_("strip everything before a scissors line")),
|
||||||
OPT_CALLBACK(0, "patch-format", &patch_format, N_("format"),
|
OPT_CALLBACK(0, "patch-format", &patch_format, N_("format"),
|
||||||
N_("format the patch(es) are in"),
|
N_("format the patch(es) are in"),
|
||||||
parse_opt_patchformat),
|
parse_opt_patchformat),
|
||||||
|
Loading…
Reference in New Issue
Block a user