From patchwork Sun Mar 24 08:20:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10867385 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BE2EF922 for ; Sun, 24 Mar 2019 08:22:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD97129829 for ; Sun, 24 Mar 2019 08:22:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A1E4829830; Sun, 24 Mar 2019 08:22:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34B9D29829 for ; Sun, 24 Mar 2019 08:22:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728592AbfCXIW0 (ORCPT ); Sun, 24 Mar 2019 04:22:26 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:42112 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728582AbfCXIWZ (ORCPT ); Sun, 24 Mar 2019 04:22:25 -0400 Received: by mail-pg1-f194.google.com with SMTP id p6so4343809pgh.9 for ; Sun, 24 Mar 2019 01:22:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kQKJyX6pIH0h0o6032BfFprRW4OqddV5C8R6Ngys9K8=; b=LskJUeY3xY4H4j1PazxvSH0ex6Q4oRwab/4EpYykF6ycsdlNRNA8on8Iaj2MGjRkoG fSQ85rc5TyYpdiBT7NPX9+pjSeSyTngrTmc+RvyQsuRC3i0Hgxu8NgyPr/7kpDlzNewu ASi8b1gNT3jEPQapNnjnt4+mV/eCPE7yxbTLf/FHqfZk4aLYaHUyAEiATnKocaxmgewY hlsg8LU/mrivLWvlRIQ5l9pR+Ten2sUjjFxzgKL478hljfqaxe49ZhkoOsGefM8JYTeQ hcYyXVfJt24fNqq5oShbEyHGqvAIbRdmBF8U4ExV8tM2JPNonrRbaXC5fIohRR7xbHvS UUNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kQKJyX6pIH0h0o6032BfFprRW4OqddV5C8R6Ngys9K8=; b=ps+WUjTzl8nd3CTl7c1abCP7An3JAh19AeCrGD3pGnlWbREv3UWrOzMpT2swPgrDof 8d4o6CqbOZBeBSYxoBt6YhHlxk0TKc+3d/+KwLnWcAy9nWWKraaTKpGim5H9U342tzJd KTELlt8CHcufYp+9nuVenxPvrFrWVoHENSowLM7Ru/x7YuZsLwkE3LyoajVbJaJbjJYV BZly7Qa8gGCCsNeK4pTGR0cqXRERiqAPfekOMTGAvLpmhJTLEAMzNuHgTDQ1LLVw0PFE bPfEMv3NMQBOfRVMBdvwiSjJscRc8YZ3gF6tr1ScgvbIMyj6GPkCDAgfqVoHRD28eJpx +JRQ== X-Gm-Message-State: APjAAAXzgRfj8oA9+F7kpt1ExRE0i8NPCWSmdzGCc3rLSTKEEG5hdSSA lkwQsUHM0QxnAPL15tzSZSQ= X-Google-Smtp-Source: APXvYqwBYiJc9Q/+8bMCNyBSpuaf3/pcXZEjBghztlSejrAms4rYn+lpITEXamxCf9VOvASDTiaXGA== X-Received: by 2002:a62:1197:: with SMTP id 23mr17996321pfr.210.1553415745243; Sun, 24 Mar 2019 01:22:25 -0700 (PDT) Received: from ash ([171.226.148.85]) by smtp.gmail.com with ESMTPSA id i13sm14785369pgq.17.2019.03.24.01.22.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 01:22:24 -0700 (PDT) Received: by ash (sSMTP sendmail emulation); Sun, 24 Mar 2019 15:22:20 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: git@vger.kernel.org, Junio C Hamano , =?utf-8?q?Marti?= =?utf-8?q?n_=C3=85gren?= Subject: [PATCH v2 14/20] diff-parseopt: convert --inter-hunk-context Date: Sun, 24 Mar 2019 15:20:08 +0700 Message-Id: <20190324082014.2041-15-pclouds@gmail.com> X-Mailer: git-send-email 2.21.0.548.gd3c7d92dc2 In-Reply-To: <20190324082014.2041-1-pclouds@gmail.com> References: <20190320114703.18659-1-pclouds@gmail.com> <20190324082014.2041-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- diff.c | 50 +++---------------------------------------------- parse-options.h | 3 ++- 2 files changed, 5 insertions(+), 48 deletions(-) diff --git a/diff.c b/diff.c index 6029f8de2d..8b65b03c0d 100644 --- a/diff.c +++ b/diff.c @@ -4573,50 +4573,6 @@ void diff_setup_done(struct diff_options *options) FREE_AND_NULL(options->parseopts); } -static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *val) -{ - char c, *eq; - int len; - - if (*arg != '-') - return 0; - c = *++arg; - if (!c) - return 0; - if (c == arg_short) { - c = *++arg; - if (!c) - return 1; - if (val && isdigit(c)) { - char *end; - int n = strtoul(arg, &end, 10); - if (*end) - return 0; - *val = n; - return 1; - } - return 0; - } - if (c != '-') - return 0; - arg++; - eq = strchrnul(arg, '='); - len = eq - arg; - if (!len || strncmp(arg, arg_long, len)) - return 0; - if (*eq) { - int n; - char *end; - if (!isdigit(*++eq)) - return 0; - n = strtoul(eq, &end, 10); - if (*end) - return 0; - *val = n; - } - return 1; -} - int parse_long_opt(const char *opt, const char **argv, const char **optarg) { @@ -5291,6 +5247,9 @@ static void prep_parse_options(struct diff_options *options) OPT_CALLBACK_F(0, "no-prefix", options, NULL, N_("do not show any source or destination prefix"), PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_no_prefix), + OPT_INTEGER_F(0, "inter-hunk-context", &options->interhunkcontext, + N_("show context between diff hunks up to the specified number of lines"), + PARSE_OPT_NONEG), OPT_CALLBACK_F(0, "output-indicator-new", &options->output_indicators[OUTPUT_INDICATOR_NEW], N_(""), @@ -5483,9 +5442,6 @@ int diff_opt_parse(struct diff_options *options, } /* misc options */ - else if (opt_arg(arg, '\0', "inter-hunk-context", - &options->interhunkcontext)) - ; else return 0; return 1; diff --git a/parse-options.h b/parse-options.h index c95cbe26f0..cca64d04cb 100644 --- a/parse-options.h +++ b/parse-options.h @@ -137,6 +137,7 @@ struct option { #define OPT_CALLBACK_F(s, l, v, a, h, f, cb) \ { OPTION_CALLBACK, (s), (l), (v), (a), (h), (f), (cb) } #define OPT_STRING_F(s, l, v, a, h, f) { OPTION_STRING, (s), (l), (v), (a), (h), (f) } +#define OPT_INTEGER_F(s, l, v, h, f) { OPTION_INTEGER, (s), (l), (v), N_("n"), (h), (f) } #define OPT_END() { OPTION_END } #define OPT_ARGUMENT(l, h) { OPTION_ARGUMENT, 0, (l), NULL, NULL, \ @@ -155,7 +156,7 @@ struct option { (h), PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1} #define OPT_CMDMODE(s, l, v, h, i) { OPTION_CMDMODE, (s), (l), (v), NULL, \ (h), PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, (i) } -#define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), N_("n"), (h) } +#define OPT_INTEGER(s, l, v, h) OPT_INTEGER_F(s, l, v, h, 0) #define OPT_MAGNITUDE(s, l, v, h) { OPTION_MAGNITUDE, (s), (l), (v), \ N_("n"), (h), PARSE_OPT_NONEG } #define OPT_STRING(s, l, v, a, h) OPT_STRING_F(s, l, v, a, h, 0)