apply, ls-files: simplify "-z" parsing
As a short option, we cannot handle negation. Thus a callback handling "unset" is overkill, and we can just use OPT_SET_INT instead to handle setting the option. Anybody who adds "--nul" synonym to this later would need to be careful not to break "--no-nul", which should mean that lines are terminated with LF at the end. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jan 31, 2016 at 06:35 UTC
1f3c79a9d6c3278753e7fb63b48569a9ff8632df
2 files changed
+6
-24
builtin/apply.c
+3
-13
@@ -4464,16 +4464,6 @@ static int option_parse_p(const struct option *opt,
4464
return 0;
4465
}
4466
4467
-static int option_parse_z(const struct option *opt,
4468
- const char *arg, int unset)
4469
-{
4470
- if (unset)
4471
- line_termination = '\n';
4472
- else
4473
- line_termination = 0;
4474
- return 0;
4475
-}
4476
-
4467
static int option_parse_space_change(const struct option *opt,
4468
const char *arg, int unset)
4469
{
@@ -4546,9 +4536,9 @@ int cmd_apply(int argc, const char **argv, const char *prefix_)
4536
N_( "attempt three-way merge if a patch does not apply")),
4537
OPT_FILENAME(0, "build-fake-ancestor", &fake_ancestor,
4538
N_("build a temporary index based on embedded index information")),
4549
- { OPTION_CALLBACK, 'z', NULL, NULL, NULL,
4550
- N_("paths are separated with NUL character"),
4551
- PARSE_OPT_NOARG, option_parse_z },
4539
+ /* Think twice before adding "--nul" synonym to this */
4540
+ OPT_SET_INT('z', NULL, &line_termination,
4541
+ N_("paths are separated with NUL character"), '\0'),
4542
OPT_INTEGER('C', NULL, &p_context,
4543
N_("ensure at least <n> lines of context match")),
4544
{ OPTION_CALLBACK, 0, "whitespace", &whitespace_option, N_("action"),
builtin/ls-files.c
+3
-11
@@ -359,14 +359,6 @@ static const char * const ls_files_usage[] = {
359
NULL
360
};
361
362
-static int option_parse_z(const struct option *opt,
363
- const char *arg, int unset)
364
-{
365
- line_terminator = unset ? '\n' : '\0';
366
-
367
- return 0;
368
-}
369
-
362
static int option_parse_exclude(const struct option *opt,
363
const char *arg, int unset)
364
{
@@ -408,9 +400,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
400
struct exclude_list *el;
401
struct string_list exclude_list = STRING_LIST_INIT_NODUP;
402
struct option builtin_ls_files_options[] = {
411
- { OPTION_CALLBACK, 'z', NULL, NULL, NULL,
412
- N_("paths are separated with NUL character"),
413
- PARSE_OPT_NOARG, option_parse_z },
403
+ /* Think twice before adding "--nul" synonym to this */
404
+ OPT_SET_INT('z', NULL, &line_terminator,
405
+ N_("paths are separated with NUL character"), '\0'),
406
OPT_BOOL('t', NULL, &show_tag,
407
N_("identify the file status with tags")),
408
OPT_BOOL('v', NULL, &show_valid_bit,