summaryrefslogtreecommitdiff
path: root/parse-options.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-03-09 18:21:19 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-03-09 18:21:19 (GMT)
commit0e0d717537547e8fcba441e4f65237c7fd227a34 (patch)
tree1cb5ad50202b03853e3baef2b26fd13a29df45ac /parse-options.c
parent9b7f726dfcf35d3a2dbfd150b64ca9b01e810b44 (diff)
parentaa416b22ea73321aba94c3c96db0491fb25ea7ea (diff)
downloadgit-0e0d717537547e8fcba441e4f65237c7fd227a34.zip
git-0e0d717537547e8fcba441e4f65237c7fd227a34.tar.gz
git-0e0d717537547e8fcba441e4f65237c7fd227a34.tar.bz2
Merge branch 'pb/am-show-current-patch'
"git am --short-current-patch" is a way to show the piece of e-mail for the stopped step, which is not suitable to directly feed "git apply" (it is designed to be a good "git am" input). It learned a new option to show only the patch part. * pb/am-show-current-patch: am: support --show-current-patch=diff to retrieve .git/rebase-apply/patch am: support --show-current-patch=raw as a synonym for--show-current-patch am: convert "resume" variable to a struct parse-options: convert "command mode" to a flag parse-options: add testcases for OPT_CMDMODE()
Diffstat (limited to 'parse-options.c')
-rw-r--r--parse-options.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/parse-options.c b/parse-options.c
index a0cef40..63d6bab 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -61,7 +61,7 @@ static enum parse_opt_result opt_command_mode_error(
*/
for (that = all_opts; that->type != OPTION_END; that++) {
if (that == opt ||
- that->type != OPTION_CMDMODE ||
+ !(that->flags & PARSE_OPT_CMDMODE) ||
that->value != opt->value ||
that->defval != *(int *)opt->value)
continue;
@@ -95,6 +95,14 @@ static enum parse_opt_result get_value(struct parse_opt_ctx_t *p,
if (!(flags & OPT_SHORT) && p->opt && (opt->flags & PARSE_OPT_NOARG))
return error(_("%s takes no value"), optname(opt, flags));
+ /*
+ * Giving the same mode option twice, although unnecessary,
+ * is not a grave error, so let it pass.
+ */
+ if ((opt->flags & PARSE_OPT_CMDMODE) &&
+ *(int *)opt->value && *(int *)opt->value != opt->defval)
+ return opt_command_mode_error(opt, all_opts, flags);
+
switch (opt->type) {
case OPTION_LOWLEVEL_CALLBACK:
return opt->ll_callback(p, opt, NULL, unset);
@@ -130,16 +138,6 @@ static enum parse_opt_result get_value(struct parse_opt_ctx_t *p,
*(int *)opt->value = unset ? 0 : opt->defval;
return 0;
- case OPTION_CMDMODE:
- /*
- * Giving the same mode option twice, although is unnecessary,
- * is not a grave error, so let it pass.
- */
- if (*(int *)opt->value && *(int *)opt->value != opt->defval)
- return opt_command_mode_error(opt, all_opts, flags);
- *(int *)opt->value = opt->defval;
- return 0;
-
case OPTION_STRING:
if (unset)
*(const char **)opt->value = NULL;