Skip to content

Commit e8ef1e8

Browse files
bonzinigitster
authored andcommitted
am: convert "resume" variable to a struct
This will allow stashing the submode of --show-current-patch from a callback function. Using a struct will allow accessing both fields from outside cmd_am (through container_of). Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bc8620b commit e8ef1e8

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

builtin/am.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,7 +2118,7 @@ static int parse_opt_patchformat(const struct option *opt, const char *arg, int
21182118
return 0;
21192119
}
21202120

2121-
enum resume_mode {
2121+
enum resume_type {
21222122
RESUME_FALSE = 0,
21232123
RESUME_APPLY,
21242124
RESUME_RESOLVED,
@@ -2128,6 +2128,10 @@ enum resume_mode {
21282128
RESUME_SHOW_PATCH
21292129
};
21302130

2131+
struct resume_mode {
2132+
enum resume_type mode;
2133+
};
2134+
21312135
static int git_am_config(const char *k, const char *v, void *cb)
21322136
{
21332137
int status;
@@ -2145,7 +2149,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
21452149
int binary = -1;
21462150
int keep_cr = -1;
21472151
int patch_format = PATCH_FORMAT_UNKNOWN;
2148-
enum resume_mode resume = RESUME_FALSE;
2152+
struct resume_mode resume = { .mode = RESUME_FALSE };
21492153
int in_progress;
21502154
int ret = 0;
21512155

@@ -2214,22 +2218,22 @@ int cmd_am(int argc, const char **argv, const char *prefix)
22142218
PARSE_OPT_NOARG),
22152219
OPT_STRING(0, "resolvemsg", &state.resolvemsg, NULL,
22162220
N_("override error message when patch failure occurs")),
2217-
OPT_CMDMODE(0, "continue", &resume,
2221+
OPT_CMDMODE(0, "continue", &resume.mode,
22182222
N_("continue applying patches after resolving a conflict"),
22192223
RESUME_RESOLVED),
2220-
OPT_CMDMODE('r', "resolved", &resume,
2224+
OPT_CMDMODE('r', "resolved", &resume.mode,
22212225
N_("synonyms for --continue"),
22222226
RESUME_RESOLVED),
2223-
OPT_CMDMODE(0, "skip", &resume,
2227+
OPT_CMDMODE(0, "skip", &resume.mode,
22242228
N_("skip the current patch"),
22252229
RESUME_SKIP),
2226-
OPT_CMDMODE(0, "abort", &resume,
2230+
OPT_CMDMODE(0, "abort", &resume.mode,
22272231
N_("restore the original branch and abort the patching operation."),
22282232
RESUME_ABORT),
2229-
OPT_CMDMODE(0, "quit", &resume,
2233+
OPT_CMDMODE(0, "quit", &resume.mode,
22302234
N_("abort the patching operation but keep HEAD where it is."),
22312235
RESUME_QUIT),
2232-
OPT_CMDMODE(0, "show-current-patch", &resume,
2236+
OPT_CMDMODE(0, "show-current-patch", &resume.mode,
22332237
N_("show the patch being applied."),
22342238
RESUME_SHOW_PATCH),
22352239
OPT_BOOL(0, "committer-date-is-author-date",
@@ -2281,12 +2285,12 @@ int cmd_am(int argc, const char **argv, const char *prefix)
22812285
* intend to feed us a patch but wanted to continue
22822286
* unattended.
22832287
*/
2284-
if (argc || (resume == RESUME_FALSE && !isatty(0)))
2288+
if (argc || (resume.mode == RESUME_FALSE && !isatty(0)))
22852289
die(_("previous rebase directory %s still exists but mbox given."),
22862290
state.dir);
22872291

2288-
if (resume == RESUME_FALSE)
2289-
resume = RESUME_APPLY;
2292+
if (resume.mode == RESUME_FALSE)
2293+
resume.mode = RESUME_APPLY;
22902294

22912295
if (state.signoff == SIGNOFF_EXPLICIT)
22922296
am_append_signoff(&state);
@@ -2300,7 +2304,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
23002304
* stray directories.
23012305
*/
23022306
if (file_exists(state.dir) && !state.rebasing) {
2303-
if (resume == RESUME_ABORT || resume == RESUME_QUIT) {
2307+
if (resume.mode == RESUME_ABORT || resume.mode == RESUME_QUIT) {
23042308
am_destroy(&state);
23052309
am_state_release(&state);
23062310
return 0;
@@ -2311,7 +2315,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
23112315
state.dir);
23122316
}
23132317

2314-
if (resume)
2318+
if (resume.mode)
23152319
die(_("Resolve operation not in progress, we are not resuming."));
23162320

23172321
for (i = 0; i < argc; i++) {
@@ -2329,7 +2333,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
23292333
argv_array_clear(&paths);
23302334
}
23312335

2332-
switch (resume) {
2336+
switch (resume.mode) {
23332337
case RESUME_FALSE:
23342338
am_run(&state, 0);
23352339
break;

0 commit comments

Comments
 (0)