Skip to content

Commit 4f1b696

Browse files
pyokagangitster
authored andcommitted
builtin-am: implement -k/--keep, --keep-non-patch
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ef7ee16 commit 4f1b696

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

builtin/am.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ enum patch_format {
6868
PATCH_FORMAT_MBOX
6969
};
7070

71+
enum keep_type {
72+
KEEP_FALSE = 0,
73+
KEEP_TRUE, /* pass -k flag to git-mailinfo */
74+
KEEP_NON_PATCH /* pass -b flag to git-mailinfo */
75+
};
76+
7177
struct am_state {
7278
/* state directory path */
7379
char *dir;
@@ -91,6 +97,7 @@ struct am_state {
9197
int quiet;
9298
int signoff;
9399
int utf8;
100+
int keep; /* enum keep_type */
94101
const char *resolvemsg;
95102
int rebasing;
96103
};
@@ -373,6 +380,14 @@ static void am_load(struct am_state *state)
373380
read_state_file(&sb, state, "utf8", 1);
374381
state->utf8 = !strcmp(sb.buf, "t");
375382

383+
read_state_file(&sb, state, "keep", 1);
384+
if (!strcmp(sb.buf, "t"))
385+
state->keep = KEEP_TRUE;
386+
else if (!strcmp(sb.buf, "b"))
387+
state->keep = KEEP_NON_PATCH;
388+
else
389+
state->keep = KEEP_FALSE;
390+
376391
state->rebasing = !!file_exists(am_path(state, "rebasing"));
377392

378393
strbuf_release(&sb);
@@ -536,6 +551,7 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
536551
const char **paths)
537552
{
538553
unsigned char curr_head[GIT_SHA1_RAWSZ];
554+
const char *str;
539555

540556
if (!patch_format)
541557
patch_format = detect_patch_format(paths);
@@ -564,6 +580,22 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
564580

565581
write_file(am_path(state, "utf8"), 1, state->utf8 ? "t" : "f");
566582

583+
switch (state->keep) {
584+
case KEEP_FALSE:
585+
str = "f";
586+
break;
587+
case KEEP_TRUE:
588+
str = "t";
589+
break;
590+
case KEEP_NON_PATCH:
591+
str = "b";
592+
break;
593+
default:
594+
die("BUG: invalid value for state->keep");
595+
}
596+
597+
write_file(am_path(state, "keep"), 1, "%s", str);
598+
567599
if (state->rebasing)
568600
write_file(am_path(state, "rebasing"), 1, "%s", "");
569601
else
@@ -731,6 +763,20 @@ static int parse_mail(struct am_state *state, const char *mail)
731763

732764
argv_array_push(&cp.args, "mailinfo");
733765
argv_array_push(&cp.args, state->utf8 ? "-u" : "-n");
766+
767+
switch (state->keep) {
768+
case KEEP_FALSE:
769+
break;
770+
case KEEP_TRUE:
771+
argv_array_push(&cp.args, "-k");
772+
break;
773+
case KEEP_NON_PATCH:
774+
argv_array_push(&cp.args, "-b");
775+
break;
776+
default:
777+
die("BUG: invalid value for state->keep");
778+
}
779+
734780
argv_array_push(&cp.args, am_path(state, "msg"));
735781
argv_array_push(&cp.args, am_path(state, "patch"));
736782

@@ -1471,6 +1517,10 @@ int cmd_am(int argc, const char **argv, const char *prefix)
14711517
N_("add a Signed-off-by line to the commit message")),
14721518
OPT_BOOL('u', "utf8", &state.utf8,
14731519
N_("recode into utf8 (default)")),
1520+
OPT_SET_INT('k', "keep", &state.keep,
1521+
N_("pass -k flag to git-mailinfo"), KEEP_TRUE),
1522+
OPT_SET_INT(0, "keep-non-patch", &state.keep,
1523+
N_("pass -b flag to git-mailinfo"), KEEP_NON_PATCH),
14741524
OPT_CALLBACK(0, "patch-format", &patch_format, N_("format"),
14751525
N_("format the patch(es) are in"),
14761526
parse_opt_patchformat),

0 commit comments

Comments
 (0)