Browse Source

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>
maint
Jeff King 9 years ago committed by Junio C Hamano
parent
commit
1f3c79a9d6
  1. 16
      builtin/apply.c
  2. 14
      builtin/ls-files.c

16
builtin/apply.c

@ -4464,16 +4464,6 @@ static int option_parse_p(const struct option *opt,
return 0; return 0;
} }


static int option_parse_z(const struct option *opt,
const char *arg, int unset)
{
if (unset)
line_termination = '\n';
else
line_termination = 0;
return 0;
}

static int option_parse_space_change(const struct option *opt, static int option_parse_space_change(const struct option *opt,
const char *arg, int unset) const char *arg, int unset)
{ {
@ -4546,9 +4536,9 @@ int cmd_apply(int argc, const char **argv, const char *prefix_)
N_( "attempt three-way merge if a patch does not apply")), N_( "attempt three-way merge if a patch does not apply")),
OPT_FILENAME(0, "build-fake-ancestor", &fake_ancestor, OPT_FILENAME(0, "build-fake-ancestor", &fake_ancestor,
N_("build a temporary index based on embedded index information")), N_("build a temporary index based on embedded index information")),
{ OPTION_CALLBACK, 'z', NULL, NULL, NULL, /* Think twice before adding "--nul" synonym to this */
N_("paths are separated with NUL character"), OPT_SET_INT('z', NULL, &line_termination,
PARSE_OPT_NOARG, option_parse_z }, N_("paths are separated with NUL character"), '\0'),
OPT_INTEGER('C', NULL, &p_context, OPT_INTEGER('C', NULL, &p_context,
N_("ensure at least <n> lines of context match")), N_("ensure at least <n> lines of context match")),
{ OPTION_CALLBACK, 0, "whitespace", &whitespace_option, N_("action"), { OPTION_CALLBACK, 0, "whitespace", &whitespace_option, N_("action"),

14
builtin/ls-files.c

@ -359,14 +359,6 @@ static const char * const ls_files_usage[] = {
NULL NULL
}; };


static int option_parse_z(const struct option *opt,
const char *arg, int unset)
{
line_terminator = unset ? '\n' : '\0';

return 0;
}

static int option_parse_exclude(const struct option *opt, static int option_parse_exclude(const struct option *opt,
const char *arg, int unset) const char *arg, int unset)
{ {
@ -408,9 +400,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
struct exclude_list *el; struct exclude_list *el;
struct string_list exclude_list = STRING_LIST_INIT_NODUP; struct string_list exclude_list = STRING_LIST_INIT_NODUP;
struct option builtin_ls_files_options[] = { struct option builtin_ls_files_options[] = {
{ OPTION_CALLBACK, 'z', NULL, NULL, NULL, /* Think twice before adding "--nul" synonym to this */
N_("paths are separated with NUL character"), OPT_SET_INT('z', NULL, &line_terminator,
PARSE_OPT_NOARG, option_parse_z }, N_("paths are separated with NUL character"), '\0'),
OPT_BOOL('t', NULL, &show_tag, OPT_BOOL('t', NULL, &show_tag,
N_("identify the file status with tags")), N_("identify the file status with tags")),
OPT_BOOL('v', NULL, &show_valid_bit, OPT_BOOL('v', NULL, &show_valid_bit,

Loading…
Cancel
Save