Skip to content

Commit 0e35107

Browse files
committed
Merge branch 'ab/retire-option-argument'
An oddball OPTION_ARGUMENT feature has been removed from the parse-options API. * ab/retire-option-argument: parse-options API: remove OPTION_ARGUMENT feature difftool: use run_command() API in run_file_diff() difftool: prepare "diff" cmdline in cmd_difftool() difftool: prepare "struct child_process" in cmd_difftool()
2 parents 0a4cb1f + 4c25356 commit 0e35107

File tree

6 files changed

+26
-52
lines changed

6 files changed

+26
-52
lines changed

Documentation/technical/api-parse-options.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,6 @@ There are some macros to easily define options:
198198
The filename will be prefixed by passing the filename along with
199199
the prefix argument of `parse_options()` to `prefix_filename()`.
200200

201-
`OPT_ARGUMENT(long, &int_var, description)`::
202-
Introduce a long-option argument that will be kept in `argv[]`.
203-
If this option was seen, `int_var` will be set to one (except
204-
if a `NULL` pointer was passed).
205-
206201
`OPT_NUMBER_CALLBACK(&var, description, func_ptr)`::
207202
Recognize numerical options like -123 and feed the integer as
208203
if it was an argument to the function given by `func_ptr`.

builtin/difftool.c

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ static int checkout_path(unsigned mode, struct object_id *oid,
331331
}
332332

333333
static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
334-
int argc, const char **argv)
334+
struct child_process *child)
335335
{
336336
char tmpdir[PATH_MAX];
337337
struct strbuf info = STRBUF_INIT, lpath = STRBUF_INIT;
@@ -352,7 +352,6 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
352352
struct index_state wtindex;
353353
struct checkout lstate, rstate;
354354
int rc, flags = RUN_GIT_CMD, err = 0;
355-
struct child_process child = CHILD_PROCESS_INIT;
356355
const char *helper_argv[] = { "difftool--helper", NULL, NULL, NULL };
357356
struct hashmap wt_modified, tmp_modified;
358357
int indices_loaded = 0;
@@ -387,19 +386,15 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
387386
rdir_len = rdir.len;
388387
wtdir_len = wtdir.len;
389388

390-
child.no_stdin = 1;
391-
child.git_cmd = 1;
392-
child.use_shell = 0;
393-
child.clean_on_exit = 1;
394-
child.dir = prefix;
395-
child.out = -1;
396-
strvec_pushl(&child.args, "diff", "--raw", "--no-abbrev", "-z",
397-
NULL);
398-
for (i = 0; i < argc; i++)
399-
strvec_push(&child.args, argv[i]);
400-
if (start_command(&child))
389+
child->no_stdin = 1;
390+
child->git_cmd = 1;
391+
child->use_shell = 0;
392+
child->clean_on_exit = 1;
393+
child->dir = prefix;
394+
child->out = -1;
395+
if (start_command(child))
401396
die("could not obtain raw diff");
402-
fp = xfdopen(child.out, "r");
397+
fp = xfdopen(child->out, "r");
403398

404399
/* Build index info for left and right sides of the diff */
405400
i = 0;
@@ -525,7 +520,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
525520

526521
fclose(fp);
527522
fp = NULL;
528-
if (finish_command(&child)) {
523+
if (finish_command(child)) {
529524
ret = error("error occurred running diff --raw");
530525
goto finish;
531526
}
@@ -668,25 +663,23 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
668663
}
669664

670665
static int run_file_diff(int prompt, const char *prefix,
671-
int argc, const char **argv)
666+
struct child_process *child)
672667
{
673-
struct strvec args = STRVEC_INIT;
674668
const char *env[] = {
675669
"GIT_PAGER=", "GIT_EXTERNAL_DIFF=git-difftool--helper", NULL,
676670
NULL
677671
};
678-
int i;
679672

680673
if (prompt > 0)
681674
env[2] = "GIT_DIFFTOOL_PROMPT=true";
682675
else if (!prompt)
683676
env[2] = "GIT_DIFFTOOL_NO_PROMPT=true";
684677

678+
child->git_cmd = 1;
679+
child->dir = prefix;
680+
strvec_pushv(&child->env_array, env);
685681

686-
strvec_push(&args, "diff");
687-
for (i = 0; i < argc; i++)
688-
strvec_push(&args, argv[i]);
689-
return run_command_v_opt_cd_env(args.v, RUN_GIT_CMD, prefix, env);
682+
return run_command(child);
690683
}
691684

692685
int cmd_difftool(int argc, const char **argv, const char *prefix)
@@ -716,9 +709,10 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
716709
"tool returns a non - zero exit code")),
717710
OPT_STRING('x', "extcmd", &extcmd, N_("command"),
718711
N_("specify a custom command for viewing diffs")),
719-
OPT_ARGUMENT("no-index", &no_index, N_("passed to `diff`")),
712+
OPT_BOOL(0, "no-index", &no_index, N_("passed to `diff`")),
720713
OPT_END()
721714
};
715+
struct child_process child = CHILD_PROCESS_INIT;
722716

723717
git_config(difftool_config, NULL);
724718
symlinks = has_symlinks;
@@ -768,7 +762,14 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
768762
* will invoke a separate instance of 'git-difftool--helper' for
769763
* each file that changed.
770764
*/
765+
strvec_push(&child.args, "diff");
766+
if (no_index)
767+
strvec_push(&child.args, "--no-index");
768+
if (dir_diff)
769+
strvec_pushl(&child.args, "--raw", "--no-abbrev", "-z", NULL);
770+
strvec_pushv(&child.args, argv);
771+
771772
if (dir_diff)
772-
return run_dir_diff(extcmd, symlinks, prefix, argc, argv);
773-
return run_file_diff(prompt, prefix, argc, argv);
773+
return run_dir_diff(extcmd, symlinks, prefix, &child);
774+
return run_file_diff(prompt, prefix, &child);
774775
}

parse-options.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -310,19 +310,6 @@ static enum parse_opt_result parse_long_opt(
310310
again:
311311
if (!skip_prefix(arg, long_name, &rest))
312312
rest = NULL;
313-
if (options->type == OPTION_ARGUMENT) {
314-
if (!rest)
315-
continue;
316-
if (*rest == '=')
317-
return error(_("%s takes no value"),
318-
optname(options, flags));
319-
if (*rest)
320-
continue;
321-
if (options->value)
322-
*(int *)options->value = options->defval;
323-
p->out[p->cpidx++] = arg - 2;
324-
return PARSE_OPT_DONE;
325-
}
326313
if (!rest) {
327314
/* abbreviated? */
328315
if (!(p->flags & PARSE_OPT_KEEP_UNKNOWN) &&

parse-options.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
enum parse_opt_type {
99
/* special types */
1010
OPTION_END,
11-
OPTION_ARGUMENT,
1211
OPTION_GROUP,
1312
OPTION_NUMBER,
1413
OPTION_ALIAS,
@@ -155,8 +154,6 @@ struct option {
155154
#define OPT_INTEGER_F(s, l, v, h, f) { OPTION_INTEGER, (s), (l), (v), N_("n"), (h), (f) }
156155

157156
#define OPT_END() { OPTION_END }
158-
#define OPT_ARGUMENT(l, v, h) { OPTION_ARGUMENT, 0, (l), (v), NULL, \
159-
(h), PARSE_OPT_NOARG, NULL, 1 }
160157
#define OPT_GROUP(h) { OPTION_GROUP, 0, NULL, NULL, NULL, (h) }
161158
#define OPT_BIT(s, l, v, h, b) OPT_BIT_F(s, l, v, h, b, 0)
162159
#define OPT_BITOP(s, l, v, h, set, clear) { OPTION_BITOP, (s), (l), (v), NULL, (h), \

t/helper/test-parse-options.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ int cmd__parse_options(int argc, const char **argv)
134134
OPT_NOOP_NOARG(0, "obsolete"),
135135
OPT_STRING_LIST(0, "list", &list, "str", "add str to list"),
136136
OPT_GROUP("Magic arguments"),
137-
OPT_ARGUMENT("quux", NULL, "means --quux"),
138137
OPT_NUMBER_CALLBACK(&integer, "set integer to NUM",
139138
number_callback),
140139
{ OPTION_COUNTUP, '+', NULL, &boolean, NULL, "same as -b",

t/t0040-parse-options.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ String options
3737
--list <str> add str to list
3838
3939
Magic arguments
40-
--quux means --quux
4140
-NUM set integer to NUM
4241
+ same as -b
4342
--ambiguous positive ambiguity
@@ -263,10 +262,6 @@ test_expect_success 'detect possible typos' '
263262
test_cmp typo.err output.err
264263
'
265264

266-
test_expect_success 'keep some options as arguments' '
267-
test-tool parse-options --expect="arg 00: --quux" --quux
268-
'
269-
270265
cat >expect <<\EOF
271266
Callback: "four", 0
272267
boolean: 5

0 commit comments

Comments
 (0)