Skip to content

Commit 257e8ce

Browse files
pyokagangitster
authored andcommitted
builtin-am: pass git-apply's options to git-apply
git-am.sh recognizes some of git-apply's options, and would pass them to git-apply: * --whitespace, since 8c31cb8 (git-am: --whitespace=x option., 2006-02-28) * -C, since 67dad68 (add -C[NUM] to git-am, 2007-02-08) * -p, since 2092a1f (Teach git-am to pass -p option down to git-apply, 2007-02-11) * --directory, since b47dfe9 (git-am: add --directory=<dir> option, 2009-01-11) * --reject, since b80da42 (git-am: implement --reject option passed to git-apply, 2009-01-23) * --ignore-space-change, --ignore-whitespace, since 86c91f9 (git apply: option to ignore whitespace differences, 2009-08-04) * --exclude, since 77e9e49 (am: pass exclude down to apply, 2011-08-03) * --include, since 58725ef (am: support --include option, 2012-03-28) * --reject, since b80da42 (git-am: implement --reject option passed to git-apply, 2009-01-23) Re-implement support for these options in builtin/am.c. Signed-off-by: Paul Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9b64661 commit 257e8ce

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

builtin/am.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ struct am_state {
106106
int keep; /* enum keep_type */
107107
int message_id;
108108
int scissors; /* enum scissors_type */
109+
struct argv_array git_apply_opts;
109110
const char *resolvemsg;
110111
int rebasing;
111112
};
@@ -128,6 +129,8 @@ static void am_state_init(struct am_state *state, const char *dir)
128129
git_config_get_bool("am.messageid", &state->message_id);
129130

130131
state->scissors = SCISSORS_UNSET;
132+
133+
argv_array_init(&state->git_apply_opts);
131134
}
132135

133136
/**
@@ -140,6 +143,7 @@ static void am_state_release(struct am_state *state)
140143
free(state->author_email);
141144
free(state->author_date);
142145
free(state->msg);
146+
argv_array_clear(&state->git_apply_opts);
143147
}
144148

145149
/**
@@ -411,6 +415,11 @@ static void am_load(struct am_state *state)
411415
else
412416
state->scissors = SCISSORS_UNSET;
413417

418+
read_state_file(&sb, state, "apply-opt", 1);
419+
argv_array_clear(&state->git_apply_opts);
420+
if (sq_dequote_to_argv_array(sb.buf, &state->git_apply_opts) < 0)
421+
die(_("could not parse %s"), am_path(state, "apply-opt"));
422+
414423
state->rebasing = !!file_exists(am_path(state, "rebasing"));
415424

416425
strbuf_release(&sb);
@@ -585,6 +594,7 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
585594
{
586595
unsigned char curr_head[GIT_SHA1_RAWSZ];
587596
const char *str;
597+
struct strbuf sb = STRBUF_INIT;
588598

589599
if (!patch_format)
590600
patch_format = detect_patch_format(paths);
@@ -647,6 +657,9 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
647657

648658
write_file(am_path(state, "scissors"), 1, "%s", str);
649659

660+
sq_quote_argv(&sb, state->git_apply_opts.argv, 0);
661+
write_file(am_path(state, "apply-opt"), 1, "%s", sb.buf);
662+
650663
if (state->rebasing)
651664
write_file(am_path(state, "rebasing"), 1, "%s", "");
652665
else
@@ -671,6 +684,8 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
671684
write_file(am_path(state, "next"), 1, "%d", state->cur);
672685

673686
write_file(am_path(state, "last"), 1, "%d", state->last);
687+
688+
strbuf_release(&sb);
674689
}
675690

676691
/**
@@ -1058,6 +1073,8 @@ static int run_apply(const struct am_state *state, const char *index_file)
10581073

10591074
argv_array_push(&cp.args, "apply");
10601075

1076+
argv_array_pushv(&cp.args, state->git_apply_opts.argv);
1077+
10611078
if (index_file)
10621079
argv_array_push(&cp.args, "--cached");
10631080
else
@@ -1084,6 +1101,7 @@ static int build_fake_ancestor(const struct am_state *state, const char *index_f
10841101

10851102
cp.git_cmd = 1;
10861103
argv_array_push(&cp.args, "apply");
1104+
argv_array_pushv(&cp.args, state->git_apply_opts.argv);
10871105
argv_array_pushf(&cp.args, "--build-fake-ancestor=%s", index_file);
10881106
argv_array_push(&cp.args, am_path(state, "patch"));
10891107

@@ -1599,9 +1617,36 @@ int cmd_am(int argc, const char **argv, const char *prefix)
15991617
PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 0},
16001618
OPT_BOOL('c', "scissors", &state.scissors,
16011619
N_("strip everything before a scissors line")),
1620+
OPT_PASSTHRU_ARGV(0, "whitespace", &state.git_apply_opts, N_("action"),
1621+
N_("pass it through git-apply"),
1622+
0),
1623+
OPT_PASSTHRU_ARGV(0, "ignore-space-change", &state.git_apply_opts, NULL,
1624+
N_("pass it through git-apply"),
1625+
PARSE_OPT_NOARG),
1626+
OPT_PASSTHRU_ARGV(0, "ignore-whitespace", &state.git_apply_opts, NULL,
1627+
N_("pass it through git-apply"),
1628+
PARSE_OPT_NOARG),
1629+
OPT_PASSTHRU_ARGV(0, "directory", &state.git_apply_opts, N_("root"),
1630+
N_("pass it through git-apply"),
1631+
0),
1632+
OPT_PASSTHRU_ARGV(0, "exclude", &state.git_apply_opts, N_("path"),
1633+
N_("pass it through git-apply"),
1634+
0),
1635+
OPT_PASSTHRU_ARGV(0, "include", &state.git_apply_opts, N_("path"),
1636+
N_("pass it through git-apply"),
1637+
0),
1638+
OPT_PASSTHRU_ARGV('C', NULL, &state.git_apply_opts, N_("n"),
1639+
N_("pass it through git-apply"),
1640+
0),
1641+
OPT_PASSTHRU_ARGV('p', NULL, &state.git_apply_opts, N_("num"),
1642+
N_("pass it through git-apply"),
1643+
0),
16021644
OPT_CALLBACK(0, "patch-format", &patch_format, N_("format"),
16031645
N_("format the patch(es) are in"),
16041646
parse_opt_patchformat),
1647+
OPT_PASSTHRU_ARGV(0, "reject", &state.git_apply_opts, NULL,
1648+
N_("pass it through git-apply"),
1649+
PARSE_OPT_NOARG),
16051650
OPT_STRING(0, "resolvemsg", &state.resolvemsg, NULL,
16061651
N_("override error message when patch failure occurs")),
16071652
OPT_CMDMODE(0, "continue", &resume,

0 commit comments

Comments
 (0)