Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
builtin-am: implement -k/--keep, --keep-non-patch
author
Paul Tan
<pyokagan@gmail.com>
Tue, 4 Aug 2015 13:51:46 +0000
(21:51 +0800)
committer
Junio C Hamano
<gitster@pobox.com>
Wed, 5 Aug 2015 05:02:11 +0000
(22:02 -0700)
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@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/am.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
ef7ee16
)
diff --git
a/builtin/am.c
b/builtin/am.c
index 528b2c94f4ed316d0dce5416326e8ae26e00e0cc..68dca2e8d3d2e7402d264dbc5e1b7d74ac685349 100644
(file)
--- a/
builtin/am.c
+++ b/
builtin/am.c
@@
-68,6
+68,12
@@
enum patch_format {
PATCH_FORMAT_MBOX
};
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 */
char *dir;
struct am_state {
/* state directory path */
char *dir;
@@
-91,6
+97,7
@@
struct am_state {
int quiet;
int signoff;
int utf8;
int quiet;
int signoff;
int utf8;
+ int keep; /* enum keep_type */
const char *resolvemsg;
int rebasing;
};
const char *resolvemsg;
int rebasing;
};
@@
-373,6
+380,14
@@
static void am_load(struct am_state *state)
read_state_file(&sb, state, "utf8", 1);
state->utf8 = !strcmp(sb.buf, "t");
read_state_file(&sb, state, "utf8", 1);
state->utf8 = !strcmp(sb.buf, "t");
+ read_state_file(&sb, state, "keep", 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);
state->rebasing = !!file_exists(am_path(state, "rebasing"));
strbuf_release(&sb);
@@
-536,6
+551,7
@@
static void am_setup(struct am_state *state, enum patch_format patch_format,
const char **paths)
{
unsigned char curr_head[GIT_SHA1_RAWSZ];
const char **paths)
{
unsigned char curr_head[GIT_SHA1_RAWSZ];
+ const char *str;
if (!patch_format)
patch_format = detect_patch_format(paths);
if (!patch_format)
patch_format = detect_patch_format(paths);
@@
-564,6
+580,22
@@
static void am_setup(struct am_state *state, enum patch_format patch_format,
write_file(am_path(state, "utf8"), 1, state->utf8 ? "t" : "f");
write_file(am_path(state, "utf8"), 1, state->utf8 ? "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
if (state->rebasing)
write_file(am_path(state, "rebasing"), 1, "%s", "");
else
@@
-731,6
+763,20
@@
static int parse_mail(struct am_state *state, const char *mail)
argv_array_push(&cp.args, "mailinfo");
argv_array_push(&cp.args, state->utf8 ? "-u" : "-n");
argv_array_push(&cp.args, "mailinfo");
argv_array_push(&cp.args, state->utf8 ? "-u" : "-n");
+
+ 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"));
argv_array_push(&cp.args, am_path(state, "msg"));
argv_array_push(&cp.args, am_path(state, "patch"));
@@
-1471,6
+1517,10
@@
int cmd_am(int argc, const char **argv, const char *prefix)
N_("add a Signed-off-by line to the commit message")),
OPT_BOOL('u', "utf8", &state.utf8,
N_("recode into utf8 (default)")),
N_("add a Signed-off-by line to the commit message")),
OPT_BOOL('u', "utf8", &state.utf8,
N_("recode into utf8 (default)")),
+ 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", &patch_format, N_("format"),
N_("format the patch(es) are in"),
parse_opt_patchformat),
OPT_CALLBACK(0, "patch-format", &patch_format, N_("format"),
N_("format the patch(es) are in"),
parse_opt_patchformat),