diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2019-01-27 03:35:33 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-01-28 03:28:18 +0300 |
commit | d473e2e0e8eedf2ab07ddc545e00bff7c8f450e7 (patch) | |
tree | f66d33f65f12cf6a4cbab3837cceee7d203c164b /diff.c | |
parent | cc013c224cfc73cf7d29ce4d336749f00c3bf1c7 (diff) |
diff.c: convert -U|--unified
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r-- | diff.c | 23 |
1 files changed, 20 insertions, 3 deletions
@@ -4867,6 +4867,22 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg) return 1; } +static int diff_opt_unified(const struct option *opt, + const char *arg, int unset) +{ + struct diff_options *options = opt->value; + char *s; + + BUG_ON_OPT_NEG(unset); + + options->context = strtol(arg, &s, 10); + if (*s) + return error(_("%s expects a numerical value"), "--unified"); + enable_patch_output(&options->output_format); + + return 0; +} + static void prep_parse_options(struct diff_options *options) { struct option parseopts[] = { @@ -4877,6 +4893,9 @@ static void prep_parse_options(struct diff_options *options) OPT_BITOP('u', NULL, &options->output_format, N_("generate patch"), DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT), + OPT_CALLBACK_F('U', "unified", options, N_("<n>"), + N_("generate diffs with <n> lines context"), + PARSE_OPT_NONEG, diff_opt_unified), OPT_END() }; @@ -4905,9 +4924,7 @@ int diff_opt_parse(struct diff_options *options, return ac; /* Output format options */ - if (opt_arg(arg, 'U', "unified", &options->context)) - enable_patch_output(&options->output_format); - else if (!strcmp(arg, "--raw")) + if (!strcmp(arg, "--raw")) options->output_format |= DIFF_FORMAT_RAW; else if (!strcmp(arg, "--patch-with-raw")) { enable_patch_output(&options->output_format); |