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 <pbonzini@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Paolo Bonzini committed
Feb 20, 2020 at 15:15 UTC
e8ef1e8d6edd835fcea7f88d2740d756a1353190
1 file changed
+18
-14
builtin/am.c
+18
-14
@@ -2118,7 +2118,7 @@ static int parse_opt_patchformat(const struct option *opt, const char *arg, int
2118
return 0;
2119
}
2120
2121
-enum resume_mode {
2121
+enum resume_type {
2122
RESUME_FALSE = 0,
2123
RESUME_APPLY,
2124
RESUME_RESOLVED,
@@ -2128,6 +2128,10 @@ enum resume_mode {
2128
RESUME_SHOW_PATCH
2129
};
2130
2131
+struct resume_mode {
2132
+ enum resume_type mode;
2133
+};
2134
+
2135
static int git_am_config(const char *k, const char *v, void *cb)
2136
{
2137
int status;
@@ -2145,7 +2149,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
2149
int binary = -1;
2150
int keep_cr = -1;
2151
int patch_format = PATCH_FORMAT_UNKNOWN;
2148
- enum resume_mode resume = RESUME_FALSE;
2152
+ struct resume_mode resume = { .mode = RESUME_FALSE };
2153
int in_progress;
2154
int ret = 0;
2155
@@ -2214,22 +2218,22 @@ int cmd_am(int argc, const char **argv, const char *prefix)
2218
PARSE_OPT_NOARG),
2219
OPT_STRING(0, "resolvemsg", &state.resolvemsg, NULL,
2220
N_("override error message when patch failure occurs")),
2217
- OPT_CMDMODE(0, "continue", &resume,
2221
+ OPT_CMDMODE(0, "continue", &resume.mode,
2222
N_("continue applying patches after resolving a conflict"),
2223
RESUME_RESOLVED),
2220
- OPT_CMDMODE('r', "resolved", &resume,
2224
+ OPT_CMDMODE('r', "resolved", &resume.mode,
2225
N_("synonyms for --continue"),
2226
RESUME_RESOLVED),
2223
- OPT_CMDMODE(0, "skip", &resume,
2227
+ OPT_CMDMODE(0, "skip", &resume.mode,
2228
N_("skip the current patch"),
2229
RESUME_SKIP),
2226
- OPT_CMDMODE(0, "abort", &resume,
2230
+ OPT_CMDMODE(0, "abort", &resume.mode,
2231
N_("restore the original branch and abort the patching operation."),
2232
RESUME_ABORT),
2229
- OPT_CMDMODE(0, "quit", &resume,
2233
+ OPT_CMDMODE(0, "quit", &resume.mode,
2234
N_("abort the patching operation but keep HEAD where it is."),
2235
RESUME_QUIT),
2232
- OPT_CMDMODE(0, "show-current-patch", &resume,
2236
+ OPT_CMDMODE(0, "show-current-patch", &resume.mode,
2237
N_("show the patch being applied."),
2238
RESUME_SHOW_PATCH),
2239
OPT_BOOL(0, "committer-date-is-author-date",
@@ -2281,12 +2285,12 @@ int cmd_am(int argc, const char **argv, const char *prefix)
2285
* intend to feed us a patch but wanted to continue
2286
* unattended.
2287
*/
2284
- if (argc || (resume == RESUME_FALSE && !isatty(0)))
2288
+ if (argc || (resume.mode == RESUME_FALSE && !isatty(0)))
2289
die(_("previous rebase directory %s still exists but mbox given."),
2290
state.dir);
2291
2288
- if (resume == RESUME_FALSE)
2289
- resume = RESUME_APPLY;
2292
+ if (resume.mode == RESUME_FALSE)
2293
+ resume.mode = RESUME_APPLY;
2294
2295
if (state.signoff == SIGNOFF_EXPLICIT)
2296
am_append_signoff(&state);
@@ -2300,7 +2304,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
2304
* stray directories.
2305
*/
2306
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) {
2308
am_destroy(&state);
2309
am_state_release(&state);
2310
return 0;
@@ -2311,7 +2315,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
2315
state.dir);
2316
}
2317
2314
- if (resume)
2318
+ if (resume.mode)
2319
die(_("Resolve operation not in progress, we are not resuming."));
2320
2321
for (i = 0; i < argc; i++) {
@@ -2329,7 +2333,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
2333
argv_array_clear(&paths);
2334
}
2335
2332
- switch (resume) {
2336
+ switch (resume.mode) {
2337
case RESUME_FALSE:
2338
am_run(&state, 0);
2339
break;