From patchwork Thu Dec 27 16:25:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10743849 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 C0095924 for ; Thu, 27 Dec 2018 16:25:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFB522893F for ; Thu, 27 Dec 2018 16:25:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A48B728942; Thu, 27 Dec 2018 16:25:54 +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 2BBA22890E for ; Thu, 27 Dec 2018 16:25:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729323AbeL0QZu (ORCPT ); Thu, 27 Dec 2018 11:25:50 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:41656 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727086AbeL0QZu (ORCPT ); Thu, 27 Dec 2018 11:25:50 -0500 Received: by mail-lf1-f68.google.com with SMTP id c16so12991754lfj.8 for ; Thu, 27 Dec 2018 08:25:47 -0800 (PST) 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=2CuQGYHq9PKV2gr+Pn85/ehQnGk4QjWSetIpRhDp8Ig=; b=qKU10GhiDFrOsUwmt9gnBmLuNJGj7WY+rGl0wh5CwRbaqajyOVldRIWRSbWnw7Rhfl ztrlmY22JptQ+SYRa2R+hvqBcrAJ5ouvrlzxAzw7rsMbskSJpfyZlZOs+92bXqwZBr/C mRpQJ6uLc+XS6W7waZGOy6m2ylkQG5/dC5WFWW4vDywjOBeu/Yz4RdQLDm3dM0E+4nml +KA1hvIAQMcYt1Z74WrRlcP2oHUeT6IEaGLAn67gOCRwk3PkfBw4Yf7gTyVe/RSjWkMW eNAo1FbDkLHuFkJIMAJDB1zN4Jg5EGw1mByZwhLzufbnp0cMTbMukQALD5LivXkoIRW6 q12Q== 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=2CuQGYHq9PKV2gr+Pn85/ehQnGk4QjWSetIpRhDp8Ig=; b=ageax7G2QyRsWWvyfEZbjsrkecCR2s2gtqCMiRl7KlrRtzJlebzymqweXA3lw586aq 2PZCq/jzVlucO7f4RerNp/gOGp+PpSy0jhi3kYA5vV+gschLNVFapBSYZS598BGR7JkI le3xyepkFuW1xC6jRn6xmlsnOLo0V9iVu9gu8zFPSK9vEeu/+OAhJ8msMqyfpvM5kJMm Hvvpbk4H94nDj1eTFl5uXEl5MtxLiUl5+ktMdCyxeuaLNFBOtZwhkkGXxO602n1AMMF6 8Nzj2llrKGuAPW/Nu/ShbzxZ+obKxBE7wwly0CC+Q1wxNaF16FMI7jCNB1LVVfIj2UMh 30gg== X-Gm-Message-State: AA+aEWYRAujx7KoDrNoevz/48H0lxsA9ptkUvi4XV63oHwPD9UGOwEJr eoYfvIC+tp2WquWNQ+HkPuYDD330 X-Google-Smtp-Source: AFSGD/VYMUN6qiCuVTAN4vNpArdloDqvqK2yTC7ecSUQQy+rWNnewfJ1bKh7aT897vgzUB1rbtorVg== X-Received: by 2002:a19:9904:: with SMTP id b4mr11823353lfe.95.1545927946072; Thu, 27 Dec 2018 08:25:46 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id a127sm7643106lfe.73.2018.12.27.08.25.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 08:25:44 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 01/75] parse-options.h: remove extern on function prototypes Date: Thu, 27 Dec 2018 17:25:22 +0100 Message-Id: <20181227162536.15895-2-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.482.g66447595a7 In-Reply-To: <20181227162536.15895-1-pclouds@gmail.com> References: <20181227162536.15895-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 --- parse-options.h | 60 ++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/parse-options.h b/parse-options.h index a650a7d220..1947cb27cf 100644 --- a/parse-options.h +++ b/parse-options.h @@ -174,19 +174,19 @@ struct option { * for translation with N_(). * Returns the number of arguments left in argv[]. */ -extern int parse_options(int argc, const char **argv, const char *prefix, - const struct option *options, - const char * const usagestr[], int flags); +int parse_options(int argc, const char **argv, const char *prefix, + const struct option *options, + const char * const usagestr[], int flags); -extern NORETURN void usage_with_options(const char * const *usagestr, - const struct option *options); +NORETURN void usage_with_options(const char * const *usagestr, + const struct option *options); -extern NORETURN void usage_msg_opt(const char *msg, - const char * const *usagestr, - const struct option *options); +NORETURN void usage_msg_opt(const char *msg, + const char * const *usagestr, + const struct option *options); -extern int optbug(const struct option *opt, const char *reason); -extern int opterror(const struct option *opt, const char *reason, int flags); +int optbug(const struct option *opt, const char *reason); +int opterror(const struct option *opt, const char *reason, int flags); #if defined(__GNUC__) #define opterror(o,r,f) (opterror((o),(r),(f)), const_error()) #endif @@ -230,31 +230,31 @@ struct parse_opt_ctx_t { const char *prefix; }; -extern void parse_options_start(struct parse_opt_ctx_t *ctx, - int argc, const char **argv, const char *prefix, - const struct option *options, int flags); +void parse_options_start(struct parse_opt_ctx_t *ctx, + int argc, const char **argv, const char *prefix, + const struct option *options, int flags); -extern int parse_options_step(struct parse_opt_ctx_t *ctx, - const struct option *options, - const char * const usagestr[]); +int parse_options_step(struct parse_opt_ctx_t *ctx, + const struct option *options, + const char * const usagestr[]); -extern int parse_options_end(struct parse_opt_ctx_t *ctx); +int parse_options_end(struct parse_opt_ctx_t *ctx); -extern struct option *parse_options_concat(struct option *a, struct option *b); +struct option *parse_options_concat(struct option *a, struct option *b); /*----- some often used options -----*/ -extern int parse_opt_abbrev_cb(const struct option *, const char *, int); -extern int parse_opt_expiry_date_cb(const struct option *, const char *, int); -extern int parse_opt_color_flag_cb(const struct option *, const char *, int); -extern int parse_opt_verbosity_cb(const struct option *, const char *, int); -extern int parse_opt_object_name(const struct option *, const char *, int); -extern int parse_opt_commits(const struct option *, const char *, int); -extern int parse_opt_tertiary(const struct option *, const char *, int); -extern int parse_opt_string_list(const struct option *, const char *, int); -extern int parse_opt_noop_cb(const struct option *, const char *, int); -extern int parse_opt_unknown_cb(const struct option *, const char *, int); -extern int parse_opt_passthru(const struct option *, const char *, int); -extern int parse_opt_passthru_argv(const struct option *, const char *, int); +int parse_opt_abbrev_cb(const struct option *, const char *, int); +int parse_opt_expiry_date_cb(const struct option *, const char *, int); +int parse_opt_color_flag_cb(const struct option *, const char *, int); +int parse_opt_verbosity_cb(const struct option *, const char *, int); +int parse_opt_object_name(const struct option *, const char *, int); +int parse_opt_commits(const struct option *, const char *, int); +int parse_opt_tertiary(const struct option *, const char *, int); +int parse_opt_string_list(const struct option *, const char *, int); +int parse_opt_noop_cb(const struct option *, const char *, int); +int parse_opt_unknown_cb(const struct option *, const char *, int); +int parse_opt_passthru(const struct option *, const char *, int); +int parse_opt_passthru_argv(const struct option *, const char *, int); #define OPT__VERBOSE(var, h) OPT_COUNTUP('v', "verbose", (var), (h)) #define OPT__QUIET(var, h) OPT_COUNTUP('q', "quiet", (var), (h)) From patchwork Thu Dec 27 16:25:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10743851 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 DDC7991E for ; Thu, 27 Dec 2018 16:25:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF4C22890E for ; Thu, 27 Dec 2018 16:25:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C3E2F2893F; Thu, 27 Dec 2018 16:25:54 +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 569FD28923 for ; Thu, 27 Dec 2018 16:25:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729350AbeL0QZv (ORCPT ); Thu, 27 Dec 2018 11:25:51 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:33363 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729304AbeL0QZv (ORCPT ); Thu, 27 Dec 2018 11:25:51 -0500 Received: by mail-lj1-f193.google.com with SMTP id v1-v6so16692575ljd.0 for ; Thu, 27 Dec 2018 08:25:48 -0800 (PST) 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=zuT+7NMktV5SYOapeFt8h/XsAWWG22jYdIE8EgWILM8=; b=CmOtJhaoy+rr1izLqTSXM+NOTgwV4QISARWOdwcyRNoxrUsLUvshldWNIydMuyYCty Sz3KF1E84UVFnmPXFsJgdrv+BeJhxS9sa6CzlaySttKnfDE9d14LP5iopZ37Tk91mtRx 7Repe43nyOmajoCkG3TpvRfOFYw1ShksWU+PnnCUM1+c6IZMLYQecXLgMhQgBHyKYm/Y QdpUMj8quYywYN9GdO0UoYGAqdCWC8Srb65RqwuGtEzuWvTZ0EnkvbxXZdJzOA31qea2 mCAI/sPJNJLg39jU8wDbD3PMAsiozeB/20vFk5O+TJ9D6EdIMnr+RP4PEbQ0VxiekFHF 7YyQ== 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=zuT+7NMktV5SYOapeFt8h/XsAWWG22jYdIE8EgWILM8=; b=o09sGRrjSvm4w/In3IS0JKnhn57PPeVOtveqxo6ih8aXlSpmz3HZL1zpQQE9bB6BLB ogNc6r/c2sbEW99YhNEaFJ5pqgJZ/2L1ZoqHCrDGm9ikCeSr5lmAReovDjM8R/hLwybw Ikms1ju1XLHIMQvv/op76W6f4wsEtDUn5QD1XiIgawfyRo6gpktbNfHCFqza7z8nsMtg poXdMvuEOsZgw/udExDFIGWNAPk8Hk0oS8O/LnAu6gXf5OXqgyIbDhn64YX1Xh4WWFeF GZvWGcn+0ORHWnkcmip36ijU2US81vGG2O/kjiOHSw955jEIjgU8CbXqht3j+gABMi6w 6kZQ== X-Gm-Message-State: AJcUukezPiCFhbxnAAigaiLUqzRIIwa30OUs0zq+dGN+TtHQC375s13n Um2W7CcCCt5YRsFuvSJGYssUcjQI X-Google-Smtp-Source: ALg8bN52ewmspuq7Zq58Jpa/iohzTzmypVpbc73YNTIAeXH9uOkdRalVDTP8BBpjr6CgKl6zboleUw== X-Received: by 2002:a2e:5703:: with SMTP id l3-v6mr14579202ljb.106.1545927947383; Thu, 27 Dec 2018 08:25:47 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id a127sm7643106lfe.73.2018.12.27.08.25.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 08:25:46 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 02/75] parse-options: add one-shot mode Date: Thu, 27 Dec 2018 17:25:23 +0100 Message-Id: <20181227162536.15895-3-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.482.g66447595a7 In-Reply-To: <20181227162536.15895-1-pclouds@gmail.com> References: <20181227162536.15895-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 This is to help reimplement diff_opt_parse() using parse_options(). The behavior of parse_options() is changed to be the same as the other: - no argv0 in argv[], everything can be processed - argv[] must not be updated, it's the caller's job to do that - return the number of arguments processed - leave all unknown options / non-options alone (this one can already be achieved with PARSE_OPT_KEEP_UNKNOWN and PARSE_OPT_STOP_AT_NON_OPTION) This mode is NOT supposed to stay here for long. It's to help converting diff/rev option parsing. Once that work is over and we can just use parse_options() throughout the code base, this will be deleted. Signed-off-by: Nguyễn Thái Ngọc Duy --- parse-options.c | 23 ++++++++++++++++++++--- parse-options.h | 17 +++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/parse-options.c b/parse-options.c index 6932eaff61..d47e217b07 100644 --- a/parse-options.c +++ b/parse-options.c @@ -415,15 +415,23 @@ void parse_options_start(struct parse_opt_ctx_t *ctx, const struct option *options, int flags) { memset(ctx, 0, sizeof(*ctx)); - ctx->argc = ctx->total = argc - 1; - ctx->argv = argv + 1; - ctx->out = argv; + ctx->argc = argc; + ctx->argv = argv; + if (!(flags & PARSE_OPT_ONE_SHOT)) { + ctx->argc--; + ctx->argv++; + } + ctx->total = ctx->argc; + ctx->out = argv; ctx->prefix = prefix; ctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0); ctx->flags = flags; if ((flags & PARSE_OPT_KEEP_UNKNOWN) && (flags & PARSE_OPT_STOP_AT_NON_OPTION)) die("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together"); + if ((flags & PARSE_OPT_ONE_SHOT) && + (flags & PARSE_OPT_KEEP_ARGV0)) + BUG("Can't keep argv0 if you don't have it"); parse_options_check(options); } @@ -535,6 +543,10 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, for (; ctx->argc; ctx->argc--, ctx->argv++) { const char *arg = ctx->argv[0]; + if (ctx->flags & PARSE_OPT_ONE_SHOT && + ctx->argc != ctx->total) + break; + if (*arg != '-' || !arg[1]) { if (parse_nodash_opt(ctx, arg, options) == 0) continue; @@ -609,6 +621,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, } continue; unknown: + if (ctx->flags & PARSE_OPT_ONE_SHOT) + break; if (!(ctx->flags & PARSE_OPT_KEEP_UNKNOWN)) return PARSE_OPT_UNKNOWN; ctx->out[ctx->cpidx++] = ctx->argv[0]; @@ -622,6 +636,9 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, int parse_options_end(struct parse_opt_ctx_t *ctx) { + if (ctx->flags & PARSE_OPT_ONE_SHOT) + return ctx->total - ctx->argc; + MOVE_ARRAY(ctx->out + ctx->cpidx, ctx->argv, ctx->argc); ctx->out[ctx->cpidx + ctx->argc] = NULL; return ctx->cpidx + ctx->argc; diff --git a/parse-options.h b/parse-options.h index 1947cb27cf..043d296ea4 100644 --- a/parse-options.h +++ b/parse-options.h @@ -27,7 +27,8 @@ enum parse_opt_flags { PARSE_OPT_STOP_AT_NON_OPTION = 2, PARSE_OPT_KEEP_ARGV0 = 4, PARSE_OPT_KEEP_UNKNOWN = 8, - PARSE_OPT_NO_INTERNAL_HELP = 16 + PARSE_OPT_NO_INTERNAL_HELP = 16, + PARSE_OPT_ONE_SHOT = 32 }; enum parse_opt_option_flags { @@ -169,10 +170,18 @@ struct option { N_("no-op (backward compatibility)"), \ PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, parse_opt_noop_cb } -/* parse_options() will filter out the processed options and leave the - * non-option arguments in argv[]. usagestr strings should be marked - * for translation with N_(). +/* + * parse_options() will filter out the processed options and leave the + * non-option arguments in argv[]. argv0 is assumed program name and + * skipped. + * + * usagestr strings should be marked for translation with N_(). + * * Returns the number of arguments left in argv[]. + * + * In one-shot mode, argv0 is not a program name, argv[] is left + * untouched and parse_options() returns the number of options + * processed. */ int parse_options(int argc, const char **argv, const char *prefix, const struct option *options, From patchwork Thu Dec 27 16:25:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10743855 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 12596924 for ; Thu, 27 Dec 2018 16:25:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 036362890E for ; Thu, 27 Dec 2018 16:25:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC6272893F; Thu, 27 Dec 2018 16:25:57 +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 A6A952890E for ; Thu, 27 Dec 2018 16:25:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729378AbeL0QZz (ORCPT ); Thu, 27 Dec 2018 11:25:55 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:36888 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729311AbeL0QZv (ORCPT ); Thu, 27 Dec 2018 11:25:51 -0500 Received: by mail-lj1-f196.google.com with SMTP id t18-v6so16659400ljd.4 for ; Thu, 27 Dec 2018 08:25:49 -0800 (PST) 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=C5nPVHWSS/KtAboKd2lwXxZyhGZcEr3Tm2KFrKoNy8A=; b=TRK7LOkLKDsRS51JFu+xEg/kXT6CV30BTfscttpcD77eWjO977whp9lZ5fYnx6M01+ ng9Bgmialj18KgMTAxLLlvzZUFaFZpJk5Fbps+COESX2mVySsdXAQXRoPVDRseec+mg3 bmr7Q7N9FUmojLP94u/ucpdMxwQHbX6a3qujonlaqdz3PHy9gxbR66O61zUTWKBgNa2J jAA6PSVroAhoUu/zbdtNoJnvEhs8ArBfXD8Kf/0FNUR6an5E3U7uZL+2uxOV+GZrs1Xq /CMkNrIo0w4WhHTWmNvu4/nwWrlRCR8uMRCJRP0RjbuLhPN+Hwhfr3NdEY9lGlwvoHLL zugQ== 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=C5nPVHWSS/KtAboKd2lwXxZyhGZcEr3Tm2KFrKoNy8A=; b=mIn+YTeFIghzJwHa+GXf77VSvpJxyKf283LBoHGepSGNeQw9E82/WMS5iRdTBUmhs0 eFcAqIUq1T2VUQ63iHPlidr0VZwmwjgZ9P2l6gQYKvFlnE06HcG4D+6h3+0gZI9nRkQp PjyGFzVw8sCPmDk6b9r4Qy2iKHtPW4q3I1G65N/EMfaZEZz7ArLNNgxWApXjt6fP4bVO BjY49Mn+Ypvb2hg3NyU0FsTL3vFVERH4N6sZQjXsAV2RDqUVYbIiMuA8CStk48LkvH6T OcSTTSEdvVEBGimPB/a9aAVj7ZU+9Kb8TRuknZhsxkT+wZ51h1c48upH2rsIZ1FI2dro Td6Q== X-Gm-Message-State: AJcUukf5o/7DdgcM/dmLWDDEk4rnzax6qmm86y4WutjiHTyh/UutK8Dj D2YH74KdRfQdLJ4KSmBOh17HWCSB X-Google-Smtp-Source: ALg8bN4ydReWQnzU6/9Id29fTPy+v8SWiFfunyso4q3tXyM7ocZitwzkuW+lPC31FMi5j7hip/3ofw== X-Received: by 2002:a2e:710a:: with SMTP id m10-v6mr14198669ljc.66.1545927948740; Thu, 27 Dec 2018 08:25:48 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id a127sm7643106lfe.73.2018.12.27.08.25.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 08:25:47 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 03/75] parse-options: allow keep-unknown + stop-at-non-opt combination Date: Thu, 27 Dec 2018 17:25:24 +0100 Message-Id: <20181227162536.15895-4-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.482.g66447595a7 In-Reply-To: <20181227162536.15895-1-pclouds@gmail.com> References: <20181227162536.15895-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 These two are orthogonal. One is about unknown _option_ while the other non-option. Signed-off-by: Nguyễn Thái Ngọc Duy --- parse-options.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/parse-options.c b/parse-options.c index d47e217b07..4cbcefc262 100644 --- a/parse-options.c +++ b/parse-options.c @@ -426,9 +426,6 @@ void parse_options_start(struct parse_opt_ctx_t *ctx, ctx->prefix = prefix; ctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0); ctx->flags = flags; - if ((flags & PARSE_OPT_KEEP_UNKNOWN) && - (flags & PARSE_OPT_STOP_AT_NON_OPTION)) - die("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together"); if ((flags & PARSE_OPT_ONE_SHOT) && (flags & PARSE_OPT_KEEP_ARGV0)) BUG("Can't keep argv0 if you don't have it"); From patchwork Thu Dec 27 16:25:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10743853 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 AD15C924 for ; Thu, 27 Dec 2018 16:25:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DBCD2890E for ; Thu, 27 Dec 2018 16:25:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 924B52893F; Thu, 27 Dec 2018 16:25:56 +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 37D232890E for ; Thu, 27 Dec 2018 16:25:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729362AbeL0QZx (ORCPT ); Thu, 27 Dec 2018 11:25:53 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:36154 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727086AbeL0QZw (ORCPT ); Thu, 27 Dec 2018 11:25:52 -0500 Received: by mail-lf1-f65.google.com with SMTP id a16so13003402lfg.3 for ; Thu, 27 Dec 2018 08:25:51 -0800 (PST) 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=YFAFRg5e9ZHwBpKf9D2cHuV0LCnydBqKdfnG0tQI5FY=; b=OmdXkIeEBQbKRzdLhs08czs/K7ao0QNJR/p4b80d++oDVbg4qedoFxYqTZu/EbAUBz J6Q8Xx/ErmIw+fUJ47UYIlKVFmaPhRvT56My76r/UJVCazH3YO8pqGxT6p1b5e/ZUty5 yhxT9zrY8kdQJ56T6/YKmAHyNpBdaK7H2mpFNKJUnNRCHhHG2CzYhTw2LmwOPNVDqSMM W9gZ8iB8+u5p1eRYZo/Y4b1sUEkNbeE1MCMIi5fQNEBXwiXQuhL3dH3eLK/sJdRpNLwQ CNhBR6hfJghymsgfqUHsi//xJhNAoQ/Ou02djLOMLB7J38uIYnyLVsKcRReH6qrnPnqf HvLg== 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=YFAFRg5e9ZHwBpKf9D2cHuV0LCnydBqKdfnG0tQI5FY=; b=YUczON3yndeeoEAZaKG1RLiAv6fvgMbzqZnKNWAOo0YxBwkxbZN7DIxtB/LKYNdgEq /pCPozGf8aAd5L7H8BnP1+uP2L9Y3Qcu0i7dxQpVQ8XaaZBa3h5rGurDE3tL1Oain2if Ze5DwqrU1HpWU66lsaTeOQQM1M1pRsrb8jgltun10LmhHrGAvj3iPx3VzTfHnh0Kd9PS lw3ZaZlkg6Yg113IB/X+Nn5HWRNWnkaZ7XNV6/vBNnDKDY3kwdvzkVVwe8FEF/1EBv72 vQFmlLV9NHW0FOttou8yr4VaSpQMsXTb9oUT8CfZurRkuwdsXFFLRz5otpXnXpIiHPwi +CNg== X-Gm-Message-State: AA+aEWahBNnahNmfV/e+BFsF8PljpClq3EknnqZjlXQfV8STgM6pRz6M dfVygIbhp3HIRAxaCzes3nkVmW7R X-Google-Smtp-Source: AFSGD/WVk1M6jISDlc0Zrpbkp+98FrIcd8LC+MwfZXaRrUDVdVhpMJMl1j8LODALiFsq361HiGUjQQ== X-Received: by 2002:a19:8fce:: with SMTP id s75mr11888913lfk.151.1545927949945; Thu, 27 Dec 2018 08:25:49 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id a127sm7643106lfe.73.2018.12.27.08.25.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 08:25:49 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 04/75] parse-options: disable option abbreviation with PARSE_OPT_KEEP_UNKNOWN Date: Thu, 27 Dec 2018 17:25:25 +0100 Message-Id: <20181227162536.15895-5-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.482.g66447595a7 In-Reply-To: <20181227162536.15895-1-pclouds@gmail.com> References: <20181227162536.15895-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 parse-options can unambiguously find an abbreviation only if it sees all available options. This is usually the case when you use parse_options(). But there are other callers like blame or shortlog which uses parse_options_start() in combination with a custom option parser, like rev-list. parse-options cannot see all options in this case and will get abbrev detection wrong. Disable it. t7800 needs update because --symlink no longer expands to --symlinks and will be passed down to git-diff, which will not recognize it. I still think this is the correct thing to do. But if --symlink has been actually used in the wild, we would just add an option alias for it. Signed-off-by: Nguyễn Thái Ngọc Duy --- parse-options.c | 3 ++- t/t7800-difftool.sh | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/parse-options.c b/parse-options.c index 4cbcefc262..81e66b9374 100644 --- a/parse-options.c +++ b/parse-options.c @@ -265,7 +265,8 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg, } if (!rest) { /* abbreviated? */ - if (!strncmp(long_name, arg, arg_end - arg)) { + if (!(p->flags & PARSE_OPT_KEEP_UNKNOWN) && + !strncmp(long_name, arg, arg_end - arg)) { is_abbreviated: if (abbrev_option) { /* diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 22b9199d59..bb9a7f4ff9 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -546,7 +546,7 @@ do done >actual EOF -test_expect_success SYMLINKS 'difftool --dir-diff --symlink without unstaged changes' ' +test_expect_success SYMLINKS 'difftool --dir-diff --symlinks without unstaged changes' ' cat >expect <<-EOF && file $PWD/file @@ -555,7 +555,7 @@ test_expect_success SYMLINKS 'difftool --dir-diff --symlink without unstaged cha sub/sub $PWD/sub/sub EOF - git difftool --dir-diff --symlink \ + git difftool --dir-diff --symlinks \ --extcmd "./.git/CHECK_SYMLINKS" branch HEAD && test_cmp expect actual ' From patchwork Thu Dec 27 16:25:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10743857 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 60D8091E for ; Thu, 27 Dec 2018 16:25:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 515052890E for ; Thu, 27 Dec 2018 16:25:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4612E2893F; Thu, 27 Dec 2018 16:25:59 +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 E85AF2890E for ; Thu, 27 Dec 2018 16:25:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729410AbeL0QZ5 (ORCPT ); Thu, 27 Dec 2018 11:25:57 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:40052 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729352AbeL0QZx (ORCPT ); Thu, 27 Dec 2018 11:25:53 -0500 Received: by mail-lj1-f195.google.com with SMTP id n18-v6so16666098lji.7 for ; Thu, 27 Dec 2018 08:25:52 -0800 (PST) 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=+pkg30jNu/DUuQUOD3Fis8IRLZoYO4ztcfhZ9gpufWQ=; b=hnppQeIFuzK2srmklNsPNaZlNizpB7/20XCVA9+Q09KhHkfu9URNwE7vaD4VoRR32h NCLgrfT/bqVxP1m1MrPPeJV3RaUF5FlYwzHvpgBDwRgZL+5f49teM0oaNz9IFFOUbkVJ 9imKNLps3BJAOmeT2Q9sjnx5b8H3+aTyMO56Cc/BuHD00xCKCyIKHdLscuWEZ9gnUiBJ 2HZb2bTeaGvtx4YwPkwx9jfhpIp8I/notNN8Q/mD4QXcWMZDrIFISRsmjPLqwYnRx6PQ ZuRwfgvjo7B9X2xCVCrybKGFXie+ptyMbsGlBcmXBDK78a8cpHhxTqTTDlJdJ+pSggUw t+Cg== 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=+pkg30jNu/DUuQUOD3Fis8IRLZoYO4ztcfhZ9gpufWQ=; b=gpc1BqcYC/i/r6JbQvBO1FqBWwoaO7K1tA4u/RqGGWXONnlItwA96pqNn79SCr1zRq WZJoKR3/rNqbVJ0+fpuBc4uf7ALN2Ly3GiYFImM2odVvEwVXVdyDYifPUT5Xl+9MPfxn Fsyk04lI099ho1XfDk6Vz0cskQMNAujZVZBpJj3ua7WMkPvBWz8qLkZhb6Zz1vN5Z0Ar 18uydlDkrGiNhOOqCBDQZUqGYOq9QFQDtJoBuA/qncTFlVBZgmuFJ/2s9dNsSkNsntZ9 TzXFbQMs2Oxw/jGgloLHhQFHI3tOglKqPa/BXCwf03oFEbh9VJvMsBg1EE5Uclf32HxC z30Q== X-Gm-Message-State: AJcUukfKn0XJwUURDGKtXsrSfgo53vyHPF1+ZtFhJbmfTJBe5ro2AH6L gpNZwh4ZC89JYqhkEE6bqZcMZXfF X-Google-Smtp-Source: AFSGD/XuA6VpcqCBVFlVa2oKiXa3BokbluDsCV95RGDmGtAc+3UgUM4/QAlU5c+22vBQiFz9uTYfIg== X-Received: by 2002:a2e:a289:: with SMTP id k9-v6mr14033814lja.24.1545927951075; Thu, 27 Dec 2018 08:25:51 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id a127sm7643106lfe.73.2018.12.27.08.25.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 08:25:50 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 05/75] parse-options: add OPT_BITOP() Date: Thu, 27 Dec 2018 17:25:26 +0100 Message-Id: <20181227162536.15895-6-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.482.g66447595a7 In-Reply-To: <20181227162536.15895-1-pclouds@gmail.com> References: <20181227162536.15895-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 This is needed for diff_opt_parse() where we do value = (value & ~mask) | some_more; Signed-off-by: Nguyễn Thái Ngọc Duy --- parse-options.c | 7 +++++++ parse-options.h | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/parse-options.c b/parse-options.c index 81e66b9374..9e19d64cc9 100644 --- a/parse-options.c +++ b/parse-options.c @@ -110,6 +110,13 @@ static int get_value(struct parse_opt_ctx_t *p, *(int *)opt->value &= ~opt->defval; return 0; + case OPTION_BITOP: + if (unset) + BUG("BITOP can't have unset form"); + *(int *)opt->value &= ~opt->extra; + *(int *)opt->value |= opt->defval; + return 0; + case OPTION_COUNTUP: if (*(int *)opt->value < 0) *(int *)opt->value = 0; diff --git a/parse-options.h b/parse-options.h index 043d296ea4..69afd0bce6 100644 --- a/parse-options.h +++ b/parse-options.h @@ -10,6 +10,7 @@ enum parse_opt_type { /* options with no arguments */ OPTION_BIT, OPTION_NEGBIT, + OPTION_BITOP, OPTION_COUNTUP, OPTION_SET_INT, OPTION_CMDMODE, @@ -118,6 +119,7 @@ struct option { int flags; parse_opt_cb *callback; intptr_t defval; + intptr_t extra; }; #define OPT_BIT_F(s, l, v, h, b, f) { OPTION_BIT, (s), (l), (v), NULL, (h), \ @@ -133,6 +135,9 @@ struct option { (h), PARSE_OPT_NOARG} #define OPT_GROUP(h) { OPTION_GROUP, 0, NULL, NULL, NULL, (h) } #define OPT_BIT(s, l, v, h, b) OPT_BIT_F(s, l, v, h, b, 0) +#define OPT_BITOP(s, l, v, h, set, clear) { OPTION_BITOP, (s), (l), (v), NULL, (h), \ + PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, \ + (set), (clear) } #define OPT_NEGBIT(s, l, v, h, b) { OPTION_NEGBIT, (s), (l), (v), NULL, \ (h), PARSE_OPT_NOARG, NULL, (b) } #define OPT_COUNTUP(s, l, v, h) OPT_COUNTUP_F(s, l, v, h, 0) From patchwork Thu Dec 27 16:25:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10743861 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 21F6291E for ; Thu, 27 Dec 2018 16:26:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1257E2890E for ; Thu, 27 Dec 2018 16:26:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06DB028942; Thu, 27 Dec 2018 16:26:02 +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 5D1F628923 for ; Thu, 27 Dec 2018 16:26:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729443AbeL0Q0A (ORCPT ); Thu, 27 Dec 2018 11:26:00 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:33576 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729370AbeL0QZ4 (ORCPT ); Thu, 27 Dec 2018 11:25:56 -0500 Received: by mail-lf1-f68.google.com with SMTP id i26so13021977lfc.0 for ; Thu, 27 Dec 2018 08:25:53 -0800 (PST) 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=f2lCJLE14QkK/EbqJS9c9brG4mErfHcHvLCP0jquv+g=; b=ooOfchNiiF8Vq2f8NiA+Rl946LNAsNpYtFrKpX2PuGuBag2arUaCJ5R382LbbpRwDr q/8vSVS1mV7CW2ca78RFxulGSpFGw+GceSESA4MR2UibYM7Wt8MxNw8L6PECAS/7sWiL /riPzxWmsbbUTZWb4quwrSAywzY3A030jhFQsnpq6L3sIATJLdVK2LHz8WnhuJulq7ks DsID4oc1Qy92hwj+bWnpUlyJ3zquWdYi9s2qK7UHQPPyduuSdG4PZJcUkvFT4SBIZgiY 6MlvazjGPCHk3beustIvA4+AdgpQ3qS3TfB0I0eLOjSr2qZ2OFBEVcRl4pIhoQV+LP3z EzFw== 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=f2lCJLE14QkK/EbqJS9c9brG4mErfHcHvLCP0jquv+g=; b=THkeK66ywHRe2mzuaH8k9Oiy4osFQ9vjDoaybHxsJZGwgHyyLz6qRWZAhMhO5ENEBU MDRrzjVuoJhNdvSE2LujI93x5XphmSuHG+BU5mePOzCxhDc+6kgagm+tZELOa8IMwUqt u0j9XYozHa601Nqt3KoKg34GW72P7vH1FUze3q/b+iSxKBZuJ7OhueM5VQrMiZcOz1Bl tOBKyz4ii7Lf44ts1+NBrSbxUs/ebwi6tVUGgHvyJhEUJTidFntCbIK8xS9XpRWO3Jpc IPW/UppIYghtMvsZ+DS6CHRho52E5gaI1qoTYg+7jmNZeeunjCpnolybimm1BDlf3pBm EsKw== X-Gm-Message-State: AA+aEWYdbI/hLohmOfGdK8OrhGTejroxEoRkOCOf4aq1Ka6Oi1HvJy5O 3cQcqLWhpYYItRQznQXv50q9ME+W X-Google-Smtp-Source: AFSGD/XLpaU3tjyMBgfQ32nldW/dBeLztqiMOYH320OcAk4vKXY3SR6Cftelr5Ma7mI6QTrauKaRcg== X-Received: by 2002:a19:5601:: with SMTP id k1mr10685697lfb.99.1545927952282; Thu, 27 Dec 2018 08:25:52 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id a127sm7643106lfe.73.2018.12.27.08.25.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 08:25:51 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 06/75] parse-options: stop abusing 'callback' for lowlevel callbacks Date: Thu, 27 Dec 2018 17:25:27 +0100 Message-Id: <20181227162536.15895-7-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.482.g66447595a7 In-Reply-To: <20181227162536.15895-1-pclouds@gmail.com> References: <20181227162536.15895-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 Lowlevel callbacks have different function signatures. Add a new field in 'struct option' with the right type for lowlevel callbacks. Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/blame.c | 2 +- builtin/merge.c | 2 +- builtin/update-index.c | 11 ++++++----- parse-options-cb.c | 3 ++- parse-options.c | 15 ++++++++++++++- parse-options.h | 12 ++++++++---- 6 files changed, 32 insertions(+), 13 deletions(-) diff --git a/builtin/blame.c b/builtin/blame.c index 6d798f9939..8dcc55dffa 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -814,7 +814,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix) * and are only included here to get included in the "-h" * output: */ - { OPTION_LOWLEVEL_CALLBACK, 0, "indent-heuristic", NULL, NULL, N_("Use an experimental heuristic to improve diffs"), PARSE_OPT_NOARG, parse_opt_unknown_cb }, + { OPTION_LOWLEVEL_CALLBACK, 0, "indent-heuristic", NULL, NULL, N_("Use an experimental heuristic to improve diffs"), PARSE_OPT_NOARG, NULL, 0, parse_opt_unknown_cb }, OPT_BIT(0, "minimal", &xdl_opts, N_("Spend extra cycles to find better match"), XDF_NEED_MINIMAL), OPT_STRING('S', NULL, &revs_file, N_("file"), N_("Use revisions from instead of calling git-rev-list")), diff --git a/builtin/merge.c b/builtin/merge.c index c3c976d471..0ad0023f97 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -261,7 +261,7 @@ static struct option builtin_merge_options[] = { option_parse_message), { OPTION_LOWLEVEL_CALLBACK, 'F', "file", &merge_msg, N_("path"), N_("read message from file"), PARSE_OPT_NONEG, - (parse_opt_cb *) option_read_message }, + NULL, 0, option_read_message }, OPT__VERBOSITY(&verbosity), OPT_BOOL(0, "abort", &abort_current_merge, N_("abort the current in-progress merge")), diff --git a/builtin/update-index.c b/builtin/update-index.c index e19da77edc..727a8118b8 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -985,7 +985,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) N_("add the specified entry to the index"), PARSE_OPT_NOARG | /* disallow --cacheinfo= form */ PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP, - (parse_opt_cb *) cacheinfo_callback}, + NULL, 0, + cacheinfo_callback}, {OPTION_CALLBACK, 0, "chmod", &set_executable_bit, "(+|-)x", N_("override the executable bit of the listed files"), PARSE_OPT_NONEG, @@ -1011,19 +1012,19 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) {OPTION_LOWLEVEL_CALLBACK, 0, "stdin", &read_from_stdin, NULL, N_("read list of paths to be updated from standard input"), PARSE_OPT_NONEG | PARSE_OPT_NOARG, - (parse_opt_cb *) stdin_callback}, + NULL, 0, stdin_callback}, {OPTION_LOWLEVEL_CALLBACK, 0, "index-info", &nul_term_line, NULL, N_("add entries from standard input to the index"), PARSE_OPT_NONEG | PARSE_OPT_NOARG, - (parse_opt_cb *) stdin_cacheinfo_callback}, + NULL, 0, stdin_cacheinfo_callback}, {OPTION_LOWLEVEL_CALLBACK, 0, "unresolve", &has_errors, NULL, N_("repopulate stages #2 and #3 for the listed paths"), PARSE_OPT_NONEG | PARSE_OPT_NOARG, - (parse_opt_cb *) unresolve_callback}, + NULL, 0, unresolve_callback}, {OPTION_LOWLEVEL_CALLBACK, 'g', "again", &has_errors, NULL, N_("only update entries that differ from HEAD"), PARSE_OPT_NONEG | PARSE_OPT_NOARG, - (parse_opt_cb *) reupdate_callback}, + NULL, 0, reupdate_callback}, OPT_BIT(0, "ignore-missing", &refresh_args.flags, N_("ignore files missing from worktree"), REFRESH_IGNORE_MISSING), diff --git a/parse-options-cb.c b/parse-options-cb.c index 8c9edce52f..8d6a44a29d 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -169,7 +169,8 @@ int parse_opt_noop_cb(const struct option *opt, const char *arg, int unset) * "-h" output even if it's not being handled directly by * parse_options(). */ -int parse_opt_unknown_cb(const struct option *opt, const char *arg, int unset) +int parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx, + const struct option *opt, int unset) { return -2; } diff --git a/parse-options.c b/parse-options.c index 9e19d64cc9..5a717f219f 100644 --- a/parse-options.c +++ b/parse-options.c @@ -94,7 +94,7 @@ static int get_value(struct parse_opt_ctx_t *p, switch (opt->type) { case OPTION_LOWLEVEL_CALLBACK: - return (*(parse_opt_ll_cb *)opt->callback)(p, opt, unset); + return opt->ll_callback(p, opt, unset); case OPTION_BIT: if (unset) @@ -407,6 +407,19 @@ static void parse_options_check(const struct option *opts) if ((opts->flags & PARSE_OPT_OPTARG) || !(opts->flags & PARSE_OPT_NOARG)) err |= optbug(opts, "should not accept an argument"); + break; + case OPTION_CALLBACK: + if (!opts->callback) + BUG("OPTION_CALLBACK needs a callback"); + if (opts->ll_callback) + BUG("OPTION_CALLBACK needs no ll_callback"); + break; + case OPTION_LOWLEVEL_CALLBACK: + if (!opts->ll_callback) + BUG("OPTION_LOWLEVEL_CALLBACK needs a callback"); + if (opts->callback) + BUG("OPTION_LOWLEVEL_CALLBACK needs no high level callback"); + break; default: ; /* ok. (usually accepts an argument) */ } diff --git a/parse-options.h b/parse-options.h index 69afd0bce6..277a879c1c 100644 --- a/parse-options.h +++ b/parse-options.h @@ -100,13 +100,16 @@ typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx, * the option takes optional argument. * * `callback`:: - * pointer to the callback to use for OPTION_CALLBACK or - * OPTION_LOWLEVEL_CALLBACK. + * pointer to the callback to use for OPTION_CALLBACK * * `defval`:: * default value to fill (*->value) with for PARSE_OPT_OPTARG. * OPTION_{BIT,SET_INT} store the {mask,integer} to put in the value when met. * CALLBACKS can use it like they want. + * + * `ll_callback`:: + * pointer to the callback to use for OPTION_LOWLEVEL_CALLBACK + * */ struct option { enum parse_opt_type type; @@ -119,6 +122,7 @@ struct option { int flags; parse_opt_cb *callback; intptr_t defval; + parse_opt_ll_cb *ll_callback; intptr_t extra; }; @@ -137,7 +141,7 @@ struct option { #define OPT_BIT(s, l, v, h, b) OPT_BIT_F(s, l, v, h, b, 0) #define OPT_BITOP(s, l, v, h, set, clear) { OPTION_BITOP, (s), (l), (v), NULL, (h), \ PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, \ - (set), (clear) } + (set), NULL, (clear) } #define OPT_NEGBIT(s, l, v, h, b) { OPTION_NEGBIT, (s), (l), (v), NULL, \ (h), PARSE_OPT_NOARG, NULL, (b) } #define OPT_COUNTUP(s, l, v, h) OPT_COUNTUP_F(s, l, v, h, 0) @@ -266,7 +270,7 @@ int parse_opt_commits(const struct option *, const char *, int); int parse_opt_tertiary(const struct option *, const char *, int); int parse_opt_string_list(const struct option *, const char *, int); int parse_opt_noop_cb(const struct option *, const char *, int); -int parse_opt_unknown_cb(const struct option *, const char *, int); +int parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx, const struct option *, int); int parse_opt_passthru(const struct option *, const char *, int); int parse_opt_passthru_argv(const struct option *, const char *, int); From patchwork Thu Dec 27 16:25:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10743859 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 5B5FA91E for ; Thu, 27 Dec 2018 16:26:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A3B92890E for ; Thu, 27 Dec 2018 16:26:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E8D328942; Thu, 27 Dec 2018 16:26:01 +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 61A0B2890E for ; Thu, 27 Dec 2018 16:26:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729420AbeL0QZ6 (ORCPT ); Thu, 27 Dec 2018 11:25:58 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:41461 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729375AbeL0QZz (ORCPT ); Thu, 27 Dec 2018 11:25:55 -0500 Received: by mail-lj1-f194.google.com with SMTP id k15-v6so16653832ljc.8 for ; Thu, 27 Dec 2018 08:25:54 -0800 (PST) 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=AUakNYFU99IUce24ooYxosKKAGVCN6KsyauZ4jxBt/8=; b=GwpT53PZDQS8sOF9RBk+pyXws08B27+Upikv4EKfWivjQRmScFNP+pM+Ni9fFXYkb3 uDVEYXKVkA4HwR03yDC3TfLGRMqcgkT9nKrm06EHVtkkS31M5olOE4yzSDBwpZAkobTd yTR10Qv5QBkxvO1KV++HD5aF+b7ts6Al4o81HWOub6jnNHlGE743a+yUzQweWHRcjdrV Xy0Hs/KSBfVDaFvEUrVsxiE84z+jf2NbXMTDqdPKcGapxAIdctzdPLw6rcBN/oKl0FsS pA6gF3pYDKpGDqrwgztiplOtNy8vDZFBvCLteBtA62Q4a0edFuRh1eRosjrbDD+H3xUB gmHQ== 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=AUakNYFU99IUce24ooYxosKKAGVCN6KsyauZ4jxBt/8=; b=coQXy39C3b2QbDkbYOXyu2/bX0Rlhsd1OxwlKfkYfHsxPClgQbYdySk3BUz85EzzoA 5B+/yBB6kaqBEghWbEEFUaLQze+Tvf7FZr59PdajgGEq2Kv8CvInTQw4wiZSokkkdFN8 YbQ8TyPr0zFmZc408FKI7kPGZ3llC/pelQqJLcTe32fK0b9OO2yVBcRtM+kYYs/RqsQL f86u/Z1JeCe5DiocDWbSO3V59qu3rHJu17gOyp+c/8t6cbMGm1eER77k/1YYlFmKxAm1 DHX5BQ/m/1wFa0gNOHkU2VAaYT3B0WW1YGOOqVOoWllXI7qWnKulJYoNBDXGejQdoHK0 h5Ow== X-Gm-Message-State: AJcUukchQszelrr5++NnmFvNOmQ3eEMVFeCZfKxeXeVRRIbQdYTc+Nok YAvF0ERIhtexoQmjt+vwdlEapFjq X-Google-Smtp-Source: ALg8bN5+aw+V+NNRhj0RFEvmk/DgjNPaUC9UVXxG9TGwwVe1YWhet974n6wpAqBC3qDDHrcVl53FJA== X-Received: by 2002:a2e:9dcb:: with SMTP id x11-v6mr15561664ljj.158.1545927953255; Thu, 27 Dec 2018 08:25:53 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id a127sm7643106lfe.73.2018.12.27.08.25.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 08:25:52 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 07/75] parse-options: avoid magic return codes Date: Thu, 27 Dec 2018 17:25:28 +0100 Message-Id: <20181227162536.15895-8-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.482.g66447595a7 In-Reply-To: <20181227162536.15895-1-pclouds@gmail.com> References: <20181227162536.15895-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 Give names to these magic negative numbers. Make parse_opt_ll_cb return an enum to make clear it can actually control parse_options() with different return values (parse_opt_cb can too, but nobody needs it). Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/merge.c | 5 +-- builtin/update-index.c | 20 ++++++------ parse-options-cb.c | 6 ++-- parse-options.c | 69 +++++++++++++++++++++++++++--------------- parse-options.h | 14 ++++----- 5 files changed, 68 insertions(+), 46 deletions(-) diff --git a/builtin/merge.c b/builtin/merge.c index 0ad0023f97..1c8652e455 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -112,8 +112,9 @@ static int option_parse_message(const struct option *opt, return 0; } -static int option_read_message(struct parse_opt_ctx_t *ctx, - const struct option *opt, int unset) +static enum parse_opt_result option_read_message(struct parse_opt_ctx_t *ctx, + const struct option *opt, + int unset) { struct strbuf *buf = opt->value; const char *arg; diff --git a/builtin/update-index.c b/builtin/update-index.c index 727a8118b8..21c84e5590 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -847,8 +847,8 @@ static int parse_new_style_cacheinfo(const char *arg, return 0; } -static int cacheinfo_callback(struct parse_opt_ctx_t *ctx, - const struct option *opt, int unset) +static enum parse_opt_result cacheinfo_callback( + struct parse_opt_ctx_t *ctx, const struct option *opt, int unset) { struct object_id oid; unsigned int mode; @@ -873,8 +873,8 @@ static int cacheinfo_callback(struct parse_opt_ctx_t *ctx, return 0; } -static int stdin_cacheinfo_callback(struct parse_opt_ctx_t *ctx, - const struct option *opt, int unset) +static enum parse_opt_result stdin_cacheinfo_callback( + struct parse_opt_ctx_t *ctx, const struct option *opt, int unset) { int *nul_term_line = opt->value; @@ -887,8 +887,8 @@ static int stdin_cacheinfo_callback(struct parse_opt_ctx_t *ctx, return 0; } -static int stdin_callback(struct parse_opt_ctx_t *ctx, - const struct option *opt, int unset) +static enum parse_opt_result stdin_callback( + struct parse_opt_ctx_t *ctx, const struct option *opt, int unset) { int *read_from_stdin = opt->value; @@ -900,8 +900,8 @@ static int stdin_callback(struct parse_opt_ctx_t *ctx, return 0; } -static int unresolve_callback(struct parse_opt_ctx_t *ctx, - const struct option *opt, int unset) +static enum parse_opt_result unresolve_callback( + struct parse_opt_ctx_t *ctx, const struct option *opt, int unset) { int *has_errors = opt->value; const char *prefix = startup_info->prefix; @@ -919,8 +919,8 @@ static int unresolve_callback(struct parse_opt_ctx_t *ctx, return 0; } -static int reupdate_callback(struct parse_opt_ctx_t *ctx, - const struct option *opt, int unset) +static enum parse_opt_result reupdate_callback( + struct parse_opt_ctx_t *ctx, const struct option *opt, int unset) { int *has_errors = opt->value; const char *prefix = startup_info->prefix; diff --git a/parse-options-cb.c b/parse-options-cb.c index 8d6a44a29d..720a8663eb 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -169,10 +169,10 @@ int parse_opt_noop_cb(const struct option *opt, const char *arg, int unset) * "-h" output even if it's not being handled directly by * parse_options(). */ -int parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx, - const struct option *opt, int unset) +enum parse_opt_result parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx, + const struct option *opt, int unset) { - return -2; + return PARSE_OPT_UNKNOWN; } /** diff --git a/parse-options.c b/parse-options.c index 5a717f219f..634484d8f0 100644 --- a/parse-options.c +++ b/parse-options.c @@ -20,8 +20,9 @@ int optbug(const struct option *opt, const char *reason) return error("BUG: switch '%c' %s", opt->short_name, reason); } -static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt, - int flags, const char **arg) +static enum parse_opt_result get_arg(struct parse_opt_ctx_t *p, + const struct option *opt, + int flags, const char **arg) { if (p->opt) { *arg = p->opt; @@ -44,9 +45,10 @@ static void fix_filename(const char *prefix, const char **file) *file = prefix_filename(prefix, *file); } -static int opt_command_mode_error(const struct option *opt, - const struct option *all_opts, - int flags) +static enum parse_opt_result opt_command_mode_error( + const struct option *opt, + const struct option *all_opts, + int flags) { const struct option *that; struct strbuf message = STRBUF_INIT; @@ -71,15 +73,15 @@ static int opt_command_mode_error(const struct option *opt, strbuf_release(&that_name); opterror(opt, message.buf, flags); strbuf_release(&message); - return -1; + return PARSE_OPT_ERROR; } return opterror(opt, ": incompatible with something else", flags); } -static int get_value(struct parse_opt_ctx_t *p, - const struct option *opt, - const struct option *all_opts, - int flags) +static enum parse_opt_result get_value(struct parse_opt_ctx_t *p, + const struct option *opt, + const struct option *all_opts, + int flags) { const char *s, *arg; const int unset = flags & OPT_UNSET; @@ -208,7 +210,8 @@ static int get_value(struct parse_opt_ctx_t *p, } } -static int parse_short_opt(struct parse_opt_ctx_t *p, const struct option *options) +static enum parse_opt_result parse_short_opt(struct parse_opt_ctx_t *p, + const struct option *options) { const struct option *all_opts = options; const struct option *numopt = NULL; @@ -239,11 +242,12 @@ static int parse_short_opt(struct parse_opt_ctx_t *p, const struct option *optio free(arg); return rc; } - return -2; + return PARSE_OPT_UNKNOWN; } -static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg, - const struct option *options) +static enum parse_opt_result parse_long_opt( + struct parse_opt_ctx_t *p, const char *arg, + const struct option *options) { const struct option *all_opts = options; const char *arg_end = strchrnul(arg, '='); @@ -268,7 +272,7 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg, if (*rest) continue; p->out[p->cpidx++] = arg - 2; - return 0; + return PARSE_OPT_DONE; } if (!rest) { /* abbreviated? */ @@ -333,11 +337,11 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg, ambiguous_option->long_name, (abbrev_flags & OPT_UNSET) ? "no-" : "", abbrev_option->long_name); - return -3; + return PARSE_OPT_HELP; } if (abbrev_option) return get_value(p, abbrev_option, all_opts, abbrev_flags); - return -2; + return PARSE_OPT_UNKNOWN; } static int parse_nodash_opt(struct parse_opt_ctx_t *p, const char *arg, @@ -585,22 +589,28 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, if (arg[1] != '-') { ctx->opt = arg + 1; switch (parse_short_opt(ctx, options)) { - case -1: + case PARSE_OPT_ERROR: return PARSE_OPT_ERROR; - case -2: + case PARSE_OPT_UNKNOWN: if (ctx->opt) check_typos(arg + 1, options); if (internal_help && *ctx->opt == 'h') goto show_usage; goto unknown; + case PARSE_OPT_NON_OPTION: + case PARSE_OPT_HELP: + case PARSE_OPT_COMPLETE: + BUG("parse_short_opt() cannot return these"); + case PARSE_OPT_DONE: + break; } if (ctx->opt) check_typos(arg + 1, options); while (ctx->opt) { switch (parse_short_opt(ctx, options)) { - case -1: + case PARSE_OPT_ERROR: return PARSE_OPT_ERROR; - case -2: + case PARSE_OPT_UNKNOWN: if (internal_help && *ctx->opt == 'h') goto show_usage; @@ -612,6 +622,12 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, ctx->argv[0] = xstrdup(ctx->opt - 1); *(char *)ctx->argv[0] = '-'; goto unknown; + case PARSE_OPT_NON_OPTION: + case PARSE_OPT_COMPLETE: + case PARSE_OPT_HELP: + BUG("parse_short_opt() cannot return these"); + case PARSE_OPT_DONE: + break; } } continue; @@ -630,12 +646,17 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, if (internal_help && !strcmp(arg + 2, "help")) goto show_usage; switch (parse_long_opt(ctx, arg + 2, options)) { - case -1: + case PARSE_OPT_ERROR: return PARSE_OPT_ERROR; - case -2: + case PARSE_OPT_UNKNOWN: goto unknown; - case -3: + case PARSE_OPT_HELP: goto show_usage; + case PARSE_OPT_NON_OPTION: + case PARSE_OPT_COMPLETE: + BUG("parse_long_opt() cannot return these"); + case PARSE_OPT_DONE: + break; } continue; unknown: diff --git a/parse-options.h b/parse-options.h index 277a879c1c..617bca8efe 100644 --- a/parse-options.h +++ b/parse-options.h @@ -49,8 +49,8 @@ struct option; typedef int parse_opt_cb(const struct option *, const char *arg, int unset); struct parse_opt_ctx_t; -typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx, - const struct option *opt, int unset); +typedef enum parse_opt_result parse_opt_ll_cb(struct parse_opt_ctx_t *ctx, + const struct option *opt, int unset); /* * `type`:: @@ -225,12 +225,12 @@ int opterror(const struct option *opt, const char *reason, int flags); /*----- incremental advanced APIs -----*/ -enum { - PARSE_OPT_COMPLETE = -2, - PARSE_OPT_HELP = -1, - PARSE_OPT_DONE, +enum parse_opt_result { + PARSE_OPT_COMPLETE = -3, + PARSE_OPT_HELP = -2, + PARSE_OPT_ERROR = -1, /* must be the same as error() */ + PARSE_OPT_DONE = 0, /* fixed so that "return 0" works */ PARSE_OPT_NON_OPTION, - PARSE_OPT_ERROR, PARSE_OPT_UNKNOWN }; From patchwork Thu Dec 27 16:25:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10743863 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 232DB924 for ; Thu, 27 Dec 2018 16:26:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 121492890E for ; Thu, 27 Dec 2018 16:26:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06DA628942; Thu, 27 Dec 2018 16:26:03 +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 55A3C2890E for ; Thu, 27 Dec 2018 16:26:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729450AbeL0Q0B (ORCPT ); Thu, 27 Dec 2018 11:26:01 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:41661 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729380AbeL0QZ7 (ORCPT ); Thu, 27 Dec 2018 11:25:59 -0500 Received: by mail-lf1-f67.google.com with SMTP id c16so12992024lfj.8 for ; Thu, 27 Dec 2018 08:25:55 -0800 (PST) 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=kgeYg2Mzo+RasZEaKeGNtSEiAZsG5HFH56NEs5fU0Vk=; b=KUQv8WEd4Mfw3tUzO1Bv/ytfiLSPUQneujdeAX+pHUUVAslyT4EwhUp61izQuQj+Yg M+5Y9XluTPmeMdAtem3c+o54i4UpFsCcdAFAFAABjh3uNWVMx6o2PLvEu8qCwZGKueMr P+Ni3toz1BBoeA3STVu02D0lYav3Z4KYucK4HwW0BG8cBDxkr5vfNfl4ztI7nXQQZEf0 T0+O/Bf9G/zBdqe8mL83h0+mw9cYiRZZbaBYl/as6mLQ6RzawN9f0JXNRTFvibXDfxLd IwSoP+clUopkgxwHTSNM+bC16snSjUmgHamTzABsmmBelEZTBPNYM+vornBlG/jBdNR5 POQw== 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=kgeYg2Mzo+RasZEaKeGNtSEiAZsG5HFH56NEs5fU0Vk=; b=OdG3CGTj7NRgGUYlHKHmqj5e7FSS8OQ79aHOkD7UumIgiHvlV91xcx/jCUmfBPmVyl hjchgC2ypFOlmAtTClA/m6L3cglBNsabY8Of/x/pCAkGzPszwV5oAP7UDuRwXohB/1S1 eG9RtHDKSRlRDHNs9OqcfPoPdv9uB2I5/f/baFxDxzwImu/WR22QkHWCwLewrU6c1Z9a J56uqr7cOR1xWgbUS5zvBtrhfCk9twWHi3m7tfF0uxN3cJRfyakpOLR8Zm+Ol6yTpzqy qG9euksuaGuNyatjBttSbfMoJ5G8NrgIURFMBRKOP+t7l1K9GPQk2QRigfG7FJ539X84 1xVg== X-Gm-Message-State: AA+aEWYa1egTtKke6Bh7ZqTdCNG6NR/2y2ylDd/+A5ZqVc6Lm1fHkhVL xSLOl0y8966DzPF3GF2JdsHvVvJb X-Google-Smtp-Source: AFSGD/XI+0hvLT9mUnO9Swp1X9KT8G4z8iT9TbI86s8EPjv6bfbJAeJhAP8nEalKL/aIS3zmDymdGQ== X-Received: by 2002:a19:5349:: with SMTP id h70mr11972611lfb.50.1545927954537; Thu, 27 Dec 2018 08:25:54 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id a127sm7643106lfe.73.2018.12.27.08.25.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 08:25:53 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 08/75] parse-options: allow ll_callback with OPTION_CALLBACK Date: Thu, 27 Dec 2018 17:25:29 +0100 Message-Id: <20181227162536.15895-9-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.482.g66447595a7 In-Reply-To: <20181227162536.15895-1-pclouds@gmail.com> References: <20181227162536.15895-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 OPTION_CALLBACK is much simpler/safer to use, but parse_opt_cb does not allow access to parse_opt_ctx_t, which sometimes is useful (e.g. to obtain the prefix). Extending parse_opt_cb to take parse_opt_cb could result in a lot of changes. Instead let's just allow ll_callback to be used with OPTION_CALLBACK. The user will have to be careful, not to change anything in ctx, or return wrong result code. But that's the price for ll_callback. Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/merge.c | 2 ++ builtin/update-index.c | 20 +++++++++++++++----- parse-options-cb.c | 4 +++- parse-options.c | 42 ++++++++++++++++++++++++++++-------------- parse-options.h | 5 +++-- 5 files changed, 51 insertions(+), 22 deletions(-) diff --git a/builtin/merge.c b/builtin/merge.c index 1c8652e455..b4f4b401eb 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -114,11 +114,13 @@ static int option_parse_message(const struct option *opt, static enum parse_opt_result option_read_message(struct parse_opt_ctx_t *ctx, const struct option *opt, + const char *arg_not_used, int unset) { struct strbuf *buf = opt->value; const char *arg; + BUG_ON_OPT_ARG(arg_not_used); if (unset) BUG("-F cannot be negated"); diff --git a/builtin/update-index.c b/builtin/update-index.c index 21c84e5590..7abde20169 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -848,13 +848,15 @@ static int parse_new_style_cacheinfo(const char *arg, } static enum parse_opt_result cacheinfo_callback( - struct parse_opt_ctx_t *ctx, const struct option *opt, int unset) + struct parse_opt_ctx_t *ctx, const struct option *opt, + const char *arg, int unset) { struct object_id oid; unsigned int mode; const char *path; BUG_ON_OPT_NEG(unset); + BUG_ON_OPT_ARG(arg); if (!parse_new_style_cacheinfo(ctx->argv[1], &mode, &oid, &path)) { if (add_cacheinfo(mode, &oid, path, 0)) @@ -874,11 +876,13 @@ static enum parse_opt_result cacheinfo_callback( } static enum parse_opt_result stdin_cacheinfo_callback( - struct parse_opt_ctx_t *ctx, const struct option *opt, int unset) + struct parse_opt_ctx_t *ctx, const struct option *opt, + const char *arg, int unset) { int *nul_term_line = opt->value; BUG_ON_OPT_NEG(unset); + BUG_ON_OPT_ARG(arg); if (ctx->argc != 1) return error("option '%s' must be the last argument", opt->long_name); @@ -888,11 +892,13 @@ static enum parse_opt_result stdin_cacheinfo_callback( } static enum parse_opt_result stdin_callback( - struct parse_opt_ctx_t *ctx, const struct option *opt, int unset) + struct parse_opt_ctx_t *ctx, const struct option *opt, + const char *arg, int unset) { int *read_from_stdin = opt->value; BUG_ON_OPT_NEG(unset); + BUG_ON_OPT_ARG(arg); if (ctx->argc != 1) return error("option '%s' must be the last argument", opt->long_name); @@ -901,12 +907,14 @@ static enum parse_opt_result stdin_callback( } static enum parse_opt_result unresolve_callback( - struct parse_opt_ctx_t *ctx, const struct option *opt, int unset) + struct parse_opt_ctx_t *ctx, const struct option *opt, + const char *arg, int unset) { int *has_errors = opt->value; const char *prefix = startup_info->prefix; BUG_ON_OPT_NEG(unset); + BUG_ON_OPT_ARG(arg); /* consume remaining arguments. */ *has_errors = do_unresolve(ctx->argc, ctx->argv, @@ -920,12 +928,14 @@ static enum parse_opt_result unresolve_callback( } static enum parse_opt_result reupdate_callback( - struct parse_opt_ctx_t *ctx, const struct option *opt, int unset) + struct parse_opt_ctx_t *ctx, const struct option *opt, + const char *arg, int unset) { int *has_errors = opt->value; const char *prefix = startup_info->prefix; BUG_ON_OPT_NEG(unset); + BUG_ON_OPT_ARG(arg); /* consume remaining arguments. */ setup_work_tree(); diff --git a/parse-options-cb.c b/parse-options-cb.c index 720a8663eb..b336b4fa97 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -170,8 +170,10 @@ int parse_opt_noop_cb(const struct option *opt, const char *arg, int unset) * parse_options(). */ enum parse_opt_result parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx, - const struct option *opt, int unset) + const struct option *opt, + const char *arg, int unset) { + BUG_ON_OPT_ARG(arg); return PARSE_OPT_UNKNOWN; } diff --git a/parse-options.c b/parse-options.c index 634484d8f0..8e0aefe86b 100644 --- a/parse-options.c +++ b/parse-options.c @@ -96,7 +96,7 @@ static enum parse_opt_result get_value(struct parse_opt_ctx_t *p, switch (opt->type) { case OPTION_LOWLEVEL_CALLBACK: - return opt->ll_callback(p, opt, unset); + return opt->ll_callback(p, opt, NULL, unset); case OPTION_BIT: if (unset) @@ -162,16 +162,27 @@ static enum parse_opt_result get_value(struct parse_opt_ctx_t *p, return err; case OPTION_CALLBACK: + { + const char *p_arg = NULL; + int p_unset; + if (unset) - return (*opt->callback)(opt, NULL, 1) ? (-1) : 0; - if (opt->flags & PARSE_OPT_NOARG) - return (*opt->callback)(opt, NULL, 0) ? (-1) : 0; - if (opt->flags & PARSE_OPT_OPTARG && !p->opt) - return (*opt->callback)(opt, NULL, 0) ? (-1) : 0; - if (get_arg(p, opt, flags, &arg)) + p_unset = 1; + else if (opt->flags & PARSE_OPT_NOARG) + p_unset = 0; + else if (opt->flags & PARSE_OPT_OPTARG && !p->opt) + p_unset = 0; + else if (get_arg(p, opt, flags, &arg)) return -1; - return (*opt->callback)(opt, arg, 0) ? (-1) : 0; - + else { + p_unset = 0; + p_arg = arg; + } + if (opt->callback) + return (*opt->callback)(opt, p_arg, p_unset) ? (-1) : 0; + else + return (*opt->ll_callback)(p, opt, p_arg, p_unset); + } case OPTION_INTEGER: if (unset) { *(int *)opt->value = 0; @@ -238,7 +249,10 @@ static enum parse_opt_result parse_short_opt(struct parse_opt_ctx_t *p, len++; arg = xmemdupz(p->opt, len); p->opt = p->opt[len] ? p->opt + len : NULL; - rc = (*numopt->callback)(numopt, arg, 0) ? (-1) : 0; + if (numopt->callback) + rc = (*numopt->callback)(numopt, arg, 0) ? (-1) : 0; + else + rc = (*numopt->ll_callback)(p, numopt, arg, 0); free(arg); return rc; } @@ -413,10 +427,10 @@ static void parse_options_check(const struct option *opts) err |= optbug(opts, "should not accept an argument"); break; case OPTION_CALLBACK: - if (!opts->callback) - BUG("OPTION_CALLBACK needs a callback"); - if (opts->ll_callback) - BUG("OPTION_CALLBACK needs no ll_callback"); + if (!opts->callback && !opts->ll_callback) + BUG("OPTION_CALLBACK needs one callback"); + if (opts->callback && opts->ll_callback) + BUG("OPTION_CALLBACK can't have two callbacks"); break; case OPTION_LOWLEVEL_CALLBACK: if (!opts->ll_callback) diff --git a/parse-options.h b/parse-options.h index 617bca8efe..75c953a887 100644 --- a/parse-options.h +++ b/parse-options.h @@ -50,7 +50,8 @@ typedef int parse_opt_cb(const struct option *, const char *arg, int unset); struct parse_opt_ctx_t; typedef enum parse_opt_result parse_opt_ll_cb(struct parse_opt_ctx_t *ctx, - const struct option *opt, int unset); + const struct option *opt, + const char *arg, int unset); /* * `type`:: @@ -270,7 +271,7 @@ int parse_opt_commits(const struct option *, const char *, int); int parse_opt_tertiary(const struct option *, const char *, int); int parse_opt_string_list(const struct option *, const char *, int); int parse_opt_noop_cb(const struct option *, const char *, int); -int parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx, const struct option *, int); +int parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx, const struct option *, const char *, int); int parse_opt_passthru(const struct option *, const char *, int); int parse_opt_passthru_argv(const struct option *, const char *, int); From patchwork Thu Dec 27 16:25:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10743875 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 CC469924 for ; Thu, 27 Dec 2018 16:26:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC5902890E for ; Thu, 27 Dec 2018 16:26:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B097228971; Thu, 27 Dec 2018 16:26:12 +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 5C8742890E for ; Thu, 27 Dec 2018 16:26:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731092AbeL0Q0L (ORCPT ); Thu, 27 Dec 2018 11:26:11 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:46799 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729401AbeL0QZ6 (ORCPT ); Thu, 27 Dec 2018 11:25:58 -0500 Received: by mail-lj1-f194.google.com with SMTP id v15-v6so16652026ljh.13 for ; Thu, 27 Dec 2018 08:25:56 -0800 (PST) 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=LDenxXQFnfGA6L2wSwxdY5Z9THLD15uqhY3iNilOOXc=; b=tGQTTg6kFMYj9Ttb7q4uJQsmRx7Vq3uGon+HEkP4Jq3HxHS3M+9f8tCVGIdL4daw9h nTFDOUgVJhbV155xzEoiJm9Xtlk4hR2j8eYxLpSbrDYHgcWe6+XgNHGbJRWeJCa3wdnJ t7h3qlE05jtTInSHepG1XTi0XDEC74IDV+m+4ZiDrKVPYV/x+AMwJR4r/pm5GhYTtIbp +BaGTbxQEO2FwWM4ZYphqGybz6tqKLLrjm5XBj2FBZTwPC8dm+su94xHsN3/17yyrZxK Sa1Riq1Dm43YN/KgEHW01k0kVP1RF9cD++8QJErNA0Vv2mOzKfTL32YPecVUAB8wy67w NeUg== 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=LDenxXQFnfGA6L2wSwxdY5Z9THLD15uqhY3iNilOOXc=; b=iCZ6gUDQT0qUevtVXIzPqwBopLz3yfX4Cf32eTcv6fJChCQP2SpIBMrTXiweJ2AAe2 qmDSBHadvLnPU9+/KYh0eaOr21tP2BvIPDGDBFH0Xkn8zsAgRPkCWRlANjyZgbU7KOsQ RfK3vyIM7kyUdDvSPu0iKSCxfntmf5yxH0NKGb0C9IfmcuZJorVptD5o8MmLKil7LQsu xPhGAGpFRtcg/JZthPIijnCOA2eJHCsRHD2nHP7NQdhRKp3E3V9dipYI6gmstoPd0+WU g6tDa4+iknnb1HQduNoe/fmY8QXS5VHU9uZ5IpXgFG9o2YNR4kwDBGHjorR8n04ImQC8 LN5w== X-Gm-Message-State: AJcUukck2sQyz6E4XamjQsd1u6zPESiAcNuxApUhpoJw51X+DjlOmZ+x 7syCgYSD8Y69ZjypBn/M4jmcUtXZ X-Google-Smtp-Source: ALg8bN4eEjeAntvqh7hQvLEHpqDgkej1YNUtmuWqnwhLYdxPbzZOq/XZfis/34nNPMcibZWfgx64Hg== X-Received: by 2002:a2e:2909:: with SMTP id u9-v6mr14104840lje.28.1545927955765; Thu, 27 Dec 2018 08:25:55 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id a127sm7643106lfe.73.2018.12.27.08.25.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 08:25:54 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 09/75] diff.h: keep forward struct declarations sorted Date: Thu, 27 Dec 2018 17:25:30 +0100 Message-Id: <20181227162536.15895-10-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.482.g66447595a7 In-Reply-To: <20181227162536.15895-1-pclouds@gmail.com> References: <20181227162536.15895-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.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/diff.h b/diff.h index 9e8061ca29..4b65ff739f 100644 --- a/diff.h +++ b/diff.h @@ -9,16 +9,16 @@ #include "object.h" #include "oidset.h" -struct rev_info; +struct combine_diff_path; +struct commit; +struct diff_filespec; struct diff_options; struct diff_queue_struct; -struct strbuf; -struct diff_filespec; -struct userdiff_driver; struct oid_array; -struct commit; -struct combine_diff_path; struct repository; +struct rev_info; +struct strbuf; +struct userdiff_driver; typedef int (*pathchange_fn_t)(struct diff_options *options, struct combine_diff_path *path); From patchwork Thu Dec 27 16:25:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10743869 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 60276924 for ; Thu, 27 Dec 2018 16:26:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 505562890E for ; Thu, 27 Dec 2018 16:26:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 450E428942; Thu, 27 Dec 2018 16:26:07 +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 DC6022890E for ; Thu, 27 Dec 2018 16:26:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729487AbeL0Q0D (ORCPT ); Thu, 27 Dec 2018 11:26:03 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:35766 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729417AbeL0QZ7 (ORCPT ); Thu, 27 Dec 2018 11:25:59 -0500 Received: by mail-lf1-f67.google.com with SMTP id e26so13006938lfc.2 for ; Thu, 27 Dec 2018 08:25:57 -0800 (PST) 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=lolq631b14C8CWNv8wlwbVVhRpj2cxsgThi/9nYpKtI=; b=fcGDlYxKxDaCMNXVUY8aOqdw1Am1K0265LzPsO2ugJQh1ElmIK/j6I6sCFIy3kXHJd Ua7rLieHdDby9mseL+5KB8oIx1+TP8Xmqa2oLDGfX1DH+s7aRRFjnuUBabSmTPbXUPYQ Mvexb6dFNW8WMWED8pLGlYRmJp1Pf/4AcKs4VoUdIUr/vsf9xGHWQ6A2vtk5VNt+3Zmp PhFKcixLSh860UIJ917dyh0EqV/3+rrWR+Q19GT5n88XTzTEbRyAFdSMGYcb12gO5mpS 6xbfXqTZTphn2L9V8cZAcUeWchdP8jj9sKruBltZCxEASR/XHOTQOyfSSiRu+G55J2eu hOPQ== 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=lolq631b14C8CWNv8wlwbVVhRpj2cxsgThi/9nYpKtI=; b=PETEhUswI781aqVK4gtRFmekspYjNYPQ60Y+0d4DIUtFNqs287m2zZNrUM/KATQqUc +7eFOnzNA8LP+WYZiu6yASjtrsl8QzWzaOyisBKaJkbH1+uw9ztlOyrhz54ddSRzNI0M OzBgluaf/InieLb6kJEa4df9RqeJ3Untwibxh7cO24ZzZRYmW2vHXSBnmYm4J07HDTe+ OFhzOwCjf6SAHsM4kSCwJro4FJgBD57VO1gGPLZ3W7TZr7un6L0TrkzWlZATKeMGtzw7 UROdomyqPJfjpV8VeC093Hnlj6QgeXH7m6BkT+tcpv11WFnV2D3xalYgCGAzoj1V9vdX QQSA== X-Gm-Message-State: AA+aEWbWLLrQ/vErdcktJ9ECyjI7c70lFGeTcvjRT3+V2NU+DLQOgt/d ru/Nhbq7p+XNQvk3OcPDG0CzhOE7 X-Google-Smtp-Source: AFSGD/XPw2Lp4Ah/tj7/VFM0TUZr0ZrC/paMYq+G02J5Mpy0smTsJ4Y/bz7XIxI4I5JM3thScOSnew== X-Received: by 2002:a19:2b54:: with SMTP id r81mr12997082lfr.34.1545927956854; Thu, 27 Dec 2018 08:25:56 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id a127sm7643106lfe.73.2018.12.27.08.25.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 08:25:56 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 10/75] diff.h: avoid bit fields in struct diff_flags Date: Thu, 27 Dec 2018 17:25:31 +0100 Message-Id: <20181227162536.15895-11-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.482.g66447595a7 In-Reply-To: <20181227162536.15895-1-pclouds@gmail.com> References: <20181227162536.15895-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 Bitfield addresses cannot be passed around in a pointer. This makes it hard to use parse-options to set/unset them. Turn this struct to normal integers. This of course increases the size of this struct multiple times, but since we only have a handful of diff_options variables around, memory consumption is not at all a concern. Signed-off-by: Nguyễn Thái Ngọc Duy --- diff.h | 66 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/diff.h b/diff.h index 4b65ff739f..b71062c2d2 100644 --- a/diff.h +++ b/diff.h @@ -64,39 +64,39 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data) #define DIFF_FLAGS_INIT { 0 } struct diff_flags { - unsigned recursive:1; - unsigned tree_in_recursive:1; - unsigned binary:1; - unsigned text:1; - unsigned full_index:1; - unsigned silent_on_remove:1; - unsigned find_copies_harder:1; - unsigned follow_renames:1; - unsigned rename_empty:1; - unsigned has_changes:1; - unsigned quick:1; - unsigned no_index:1; - unsigned allow_external:1; - unsigned exit_with_status:1; - unsigned reverse_diff:1; - unsigned check_failed:1; - unsigned relative_name:1; - unsigned ignore_submodules:1; - unsigned dirstat_cumulative:1; - unsigned dirstat_by_file:1; - unsigned allow_textconv:1; - unsigned textconv_set_via_cmdline:1; - unsigned diff_from_contents:1; - unsigned dirty_submodules:1; - unsigned ignore_untracked_in_submodules:1; - unsigned ignore_dirty_submodules:1; - unsigned override_submodule_config:1; - unsigned dirstat_by_line:1; - unsigned funccontext:1; - unsigned default_follow_renames:1; - unsigned stat_with_summary:1; - unsigned suppress_diff_headers:1; - unsigned dual_color_diffed_diffs:1; + unsigned recursive; + unsigned tree_in_recursive; + unsigned binary; + unsigned text; + unsigned full_index; + unsigned silent_on_remove; + unsigned find_copies_harder; + unsigned follow_renames; + unsigned rename_empty; + unsigned has_changes; + unsigned quick; + unsigned no_index; + unsigned allow_external; + unsigned exit_with_status; + unsigned reverse_diff; + unsigned check_failed; + unsigned relative_name; + unsigned ignore_submodules; + unsigned dirstat_cumulative; + unsigned dirstat_by_file; + unsigned allow_textconv; + unsigned textconv_set_via_cmdline; + unsigned diff_from_contents; + unsigned dirty_submodules; + unsigned ignore_untracked_in_submodules; + unsigned ignore_dirty_submodules; + unsigned override_submodule_config; + unsigned dirstat_by_line; + unsigned funccontext; + unsigned default_follow_renames; + unsigned stat_with_summary; + unsigned suppress_diff_headers; + unsigned dual_color_diffed_diffs; }; static inline void diff_flags_or(struct diff_flags *a, From patchwork Thu Dec 27 16:25:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10743865 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 EBE31924 for ; Thu, 27 Dec 2018 16:26:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC0122890E for ; Thu, 27 Dec 2018 16:26:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF5CE28942; Thu, 27 Dec 2018 16:26:05 +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 B35A12890E for ; Thu, 27 Dec 2018 16:26:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729489AbeL0Q0D (ORCPT ); Thu, 27 Dec 2018 11:26:03 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:40061 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729423AbeL0Q0B (ORCPT ); Thu, 27 Dec 2018 11:26:01 -0500 Received: by mail-lj1-f195.google.com with SMTP id n18-v6so16666390lji.7 for ; Thu, 27 Dec 2018 08:25:59 -0800 (PST) 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=7lEbMDTl4QTL9yL50KZkcNvU7EmrUtLD+fiUQyKKGkU=; b=uWZSZjB5Z7rb0SyjNEcQZhosHneOoaj1ZbrgoWaEi9yCPxO08vdF3F0AT4BAfxcp5e JSIG1ZxjL4Htx1JS0L0fltA8M1lOYjK+UVVQZT1E3e37Wa+A6oC17kuKBpBc7jbMnAwM mEd6riA42JbG3cGJiSgfrYhX0AKCeT6qR6fzfof5y5b3z/8m753ysnCAtjGeZ/DHUlGT 6PARLDnyQTJzIY96CTN/EZkCq1uLpOxETOv48Z0C6yp60ZyOd4sUzkq7ObTTz+oUMxpq tE/b73dhxwsBbyGE09Y7RynJo2lSU/f6DVCYPWjk7fvR5SFAhnkWZvEpOFznEfOwZIHG GnjA== 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=7lEbMDTl4QTL9yL50KZkcNvU7EmrUtLD+fiUQyKKGkU=; b=t9wJjfni/CpsQKhHICL2MBlYfO/o4sRJg1OSnhILuGCy0gbrndoBvWX3YZZej48RV5 mU7QiQm5JTZE3BCMI70s0XeHbzUiXIMKEdJZ0XRDpDl9MqjYLmOgmI1Abc+m0W9kaL9W +ZHj+AbLdi9O7RDYmnbyN4ecME1RAW8c7W9OILipllosvomXqEJwe0hFNqrR/uFBBFNM iq5xhyuFDEJqsLzn1q9buahGIhYhPAGo/D/HSLgVfyFk12/+Lrx1LHzpmMpCk4pxrob9 kPHvz+Hblv2MuIJ3Qr9uGahYLqjkpWZgIoKDJiIpVK2z4RRA6SCD1WSy4zD3bbKD678+ UJlg== X-Gm-Message-State: AJcUukf9tLqjSbc8KKglL43Snz93wiRDC+/imdfRmG9wwbmhinlianyp 1l+duOUHdBKEafbvrGUVADIAsQPv X-Google-Smtp-Source: ALg8bN4IgInc58H0ZprqED+I4jltrFwoRNOAspZ6g0KWbRVqcCACWJqBRrF1Rg99g1xEZjKbrF1uBg== X-Received: by 2002:a2e:750a:: with SMTP id q10-v6mr8738095ljc.39.1545927957982; Thu, 27 Dec 2018 08:25:57 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id a127sm7643106lfe.73.2018.12.27.08.25.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 08:25:57 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 11/75] diff.c: prepare to use parse_options() for parsing Date: Thu, 27 Dec 2018 17:25:32 +0100 Message-Id: <20181227162536.15895-12-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.482.g66447595a7 In-Reply-To: <20181227162536.15895-1-pclouds@gmail.com> References: <20181227162536.15895-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 This is a preparation step to start using parse_options() to parse diff/revision options instead of what we have now. There are a couple of good things from using parse_options(): - better help usage - easier to add new options - better completion support - help usage generation - better integration with main command option parser. We can just concat the main command's option array and diffopt's together and parse all in one go. - detect colidding options (e.g. --reverse is used by revision code, so diff code can't use it as long name for -R) - consistent syntax, e.g. option that takes mandatory argument will now accept both "--option=value" and "--option value". The plan is migrate all diff/rev options to parse_options(). Then we could get rid of diff_opt_parse() and expose parseopts[] directly to the caller. Signed-off-by: Nguyễn Thái Ngọc Duy --- diff.c | 27 +++++++++++++++++++++++++++ diff.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/diff.c b/diff.c index 6954f4e39a..a866f13c76 100644 --- a/diff.c +++ b/diff.c @@ -23,6 +23,7 @@ #include "argv-array.h" #include "graph.h" #include "packfile.h" +#include "parse-options.h" #include "help.h" #ifdef NO_FAST_WORKING_DIRECTORY @@ -4424,6 +4425,8 @@ static void run_checkdiff(struct diff_filepair *p, struct diff_options *o) builtin_checkdiff(name, other, attr_path, p->one, p->two, o); } +static void prep_parse_options(struct diff_options *options); + void repo_diff_setup(struct repository *r, struct diff_options *options) { memcpy(options, &default_diff_options, sizeof(*options)); @@ -4465,6 +4468,8 @@ void repo_diff_setup(struct repository *r, struct diff_options *options) options->color_moved = diff_color_moved_default; options->color_moved_ws_handling = diff_color_moved_ws_default; + + prep_parse_options(options); } void diff_setup_done(struct diff_options *options) @@ -4568,6 +4573,8 @@ void diff_setup_done(struct diff_options *options) if (!options->use_color || external_diff()) options->color_moved = 0; + + FREE_AND_NULL(options->parseopts); } static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *val) @@ -4858,6 +4865,16 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg) return 1; } +static void prep_parse_options(struct diff_options *options) +{ + struct option parseopts[] = { + OPT_END() + }; + + ALLOC_ARRAY(options->parseopts, ARRAY_SIZE(parseopts)); + memcpy(options->parseopts, parseopts, sizeof(parseopts)); +} + int diff_opt_parse(struct diff_options *options, const char **av, int ac, const char *prefix) { @@ -4868,6 +4885,16 @@ int diff_opt_parse(struct diff_options *options, if (!prefix) prefix = ""; + ac = parse_options(ac, av, prefix, options->parseopts, NULL, + PARSE_OPT_KEEP_DASHDASH | + PARSE_OPT_KEEP_UNKNOWN | + PARSE_OPT_NO_INTERNAL_HELP | + PARSE_OPT_ONE_SHOT | + PARSE_OPT_STOP_AT_NON_OPTION); + + if (ac) + return ac; + /* Output format options */ if (!strcmp(arg, "-p") || !strcmp(arg, "-u") || !strcmp(arg, "--patch") || opt_arg(arg, 'U', "unified", &options->context)) diff --git a/diff.h b/diff.h index b71062c2d2..8c4748ebcf 100644 --- a/diff.h +++ b/diff.h @@ -15,6 +15,7 @@ struct diff_filespec; struct diff_options; struct diff_queue_struct; struct oid_array; +struct option; struct repository; struct rev_info; struct strbuf; @@ -229,6 +230,7 @@ struct diff_options { unsigned color_moved_ws_handling; struct repository *repo; + struct option *parseopts; }; void diff_emit_submodule_del(struct diff_options *o, const char *line); From patchwork Thu Dec 27 16:25:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10743877 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 EEFD414E2 for ; Thu, 27 Dec 2018 16:26:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFE592890E for ; Thu, 27 Dec 2018 16:26:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D49FC28971; Thu, 27 Dec 2018 16:26:12 +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 7D36A28923 for ; Thu, 27 Dec 2018 16:26:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731104AbeL0Q0L (ORCPT ); Thu, 27 Dec 2018 11:26:11 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:36163 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729448AbeL0Q0B (ORCPT ); Thu, 27 Dec 2018 11:26:01 -0500 Received: by mail-lf1-f66.google.com with SMTP id a16so13003656lfg.3 for ; Thu, 27 Dec 2018 08:26:00 -0800 (PST) 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=HnpwCGzGdUAAp1yUvgXRSiL9TZARNU+OvCtdXABJFPI=; b=JVq4fqL3ujy7L1HqyK9J+Mo6RH9t3lwuOTrh8NDZcieexjaLjC30+YTb845kNo9NHb LBI8ly3jdKzf2KdV/XJwp6hYEene5Fc+eZpJ/4IVEjrXp/uJY5KO6RiUE8twhoIr00Qk Dj3HVbC/t1ph2wDOgwMKwZbHH5Xj5ZJjDUqekbDVyQe3lnZiTc2bTS+VFmdppkeXPmqj 2gEcO0Ru6A4enfPfS5LV49X7IxJWfCvzy7w0rLEa12UEzDe9KmFiPbt1go1oeAv/H7c1 FA8sj626Fb0foUOWgGyXa3eYHJvxl++EbhKxIZe8Rpumk4xqsMYbLPqUc4SYl8iZJbCP cUHA== 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=HnpwCGzGdUAAp1yUvgXRSiL9TZARNU+OvCtdXABJFPI=; b=Nf4tBlX4nEPX2ZRgLE2IIwWhlc+pCAtVsgGdMAPoaUCF4Iu7H2rKvMxTAzrvgZgWPa MPkikhoNxJcDtkXcg+RwlX5wu+c0SBADoac6r/2f63GFh/RvzI5tpgwht+yCWx7titcT 8RPAZ4FqI/4edaYgT4+XNCFXd1JIvT0puhIMDDpbdIlTiAra3rG/k74w6cOfOATx7CaH p9ePbRrw+ylrDf6tUgeGYDkFPrKoTqV8Z3jjM26a+1kRRYsrqZ54lZLrpGUeIuV5hq80 FoMMoojem2EhiFMW90GnUUtZHa6bdo2uVqBZO9efllDl4Xa8tzYUSPX+wNnukRM7t+4W FrEQ== X-Gm-Message-State: AA+aEWax6DwejRNyCxTCsvAXXck0bpHEJdzhx0Qs03B9RaL+OJVvMl1x y6MsOFoPmfX9ccZiaPZR/HZdF2gb X-Google-Smtp-Source: AFSGD/UjJOLXGpqDDesI/QwWLwrQ3rkhtMmdy2hzQvWMa2Vt6hFd7ESakmOrbZPboiivaG1Gbqziiw== X-Received: by 2002:a19:9508:: with SMTP id x8mr12728753lfd.112.1545927959094; Thu, 27 Dec 2018 08:25:59 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id a127sm7643106lfe.73.2018.12.27.08.25.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 08:25:58 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 12/75] diff.c: convert -u|-p|--patch Date: Thu, 27 Dec 2018 17:25:33 +0100 Message-Id: <20181227162536.15895-13-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.482.g66447595a7 In-Reply-To: <20181227162536.15895-1-pclouds@gmail.com> References: <20181227162536.15895-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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/diff.c b/diff.c index a866f13c76..59132ceaff 100644 --- a/diff.c +++ b/diff.c @@ -4868,6 +4868,13 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg) static void prep_parse_options(struct diff_options *options) { struct option parseopts[] = { + OPT_GROUP(N_("Diff output format options")), + OPT_BITOP('p', "patch", &options->output_format, + N_("generate patch"), + DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT), + OPT_BITOP('u', NULL, &options->output_format, + N_("generate patch"), + DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT), OPT_END() }; @@ -4896,8 +4903,7 @@ int diff_opt_parse(struct diff_options *options, return ac; /* Output format options */ - if (!strcmp(arg, "-p") || !strcmp(arg, "-u") || !strcmp(arg, "--patch") - || opt_arg(arg, 'U', "unified", &options->context)) + if (opt_arg(arg, 'U', "unified", &options->context)) enable_patch_output(&options->output_format); else if (!strcmp(arg, "--raw")) options->output_format |= DIFF_FORMAT_RAW; From patchwork Thu Dec 27 16:25:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10743873 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 CC73791E for ; Thu, 27 Dec 2018 16:26:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC6802890E for ; Thu, 27 Dec 2018 16:26:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A782528942; Thu, 27 Dec 2018 16:26:10 +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 4EC822890E for ; Thu, 27 Dec 2018 16:26:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731080AbeL0Q0I (ORCPT ); Thu, 27 Dec 2018 11:26:08 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:39866 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729380AbeL0Q0C (ORCPT ); Thu, 27 Dec 2018 11:26:02 -0500 Received: by mail-lj1-f193.google.com with SMTP id t9-v6so16665245ljh.6 for ; Thu, 27 Dec 2018 08:26:01 -0800 (PST) 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=bZHrnM16Gvmag53Ixw50qiqI8MjHL1pNMog/JTgGrTA=; b=LJOYroXFPgvmFfIDqGHbrvMzU9BuwCtOPeeuwZXxktPrTMvQUC4ClfCv2Jtk3b6bD3 NLHMLbsJhoECJ2Z1Wq1qn/j3wnZJU8rHI1ApIlYcK6YRaP0Qx09IEW2K8TelPqbxpN9+ 2N7CEcTRcbbWjrE2UAm6Ui5ZB76CEOKVuofm9FMKb7/fhA6IzoADHKtsQwoaVK9W/lqk lXfY5+0EJo59iIe2bLWyPSsRqcBsu0mQ/uiR0UcHSM6sSRPGf95oJ65bcwuJRgL+Z6Kz 07ek7HleeaTukRdAVLgKH/YrTn4bOPKI6nSICEQ1A6ag403YWn2s/Nu13mrEy4TUTrVT DQGA== 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=bZHrnM16Gvmag53Ixw50qiqI8MjHL1pNMog/JTgGrTA=; b=MRluAU46+ejO98TLbecGGgT+UrDQGf8R/wTWVpjI2jCWNQtrFwnYaFomOUVHlEMsYj wti+5XHD+MD/VaVMTQeMXzYmqWMvYCBgHn6BjB49HkJYRDzud1ES+mR1DE3mxiVjWQSn 6ZnFMYfJ3uDrzhe0rrmzPURMXEFUfvFie8evm4XuPQK02Ev7yRpYcU27m1eGlTqaZ7uK 9T0PrhOhAq1mxLCoQse79N/eANBwWxZDXjeGtHjyktb2NsN9SvclJ3s+MwQo9o/oyISV zwsGXAzsLZOj7Ml3Cpwe67AN3e3XyKBgfxGay1hVXT2iEIQDLGIm0vb5jmvLgYQZ/Wft x2HQ== X-Gm-Message-State: AJcUukfNkorQN5dvxYH96ugafGiqfqWvpGv8mxNteEqGaEk1KXIbo2sM elRubeiYUQROQC2qOkCQIWwJTJ1U X-Google-Smtp-Source: AFSGD/WsHUk1lq+r2etzT4f3Ml8bSRpIJHxmD0ubQhRVZ0zCyp/76Od9iNyYOdF4Rooqzu2vCXe/iQ== X-Received: by 2002:a2e:7c13:: with SMTP id x19-v6mr14278674ljc.83.1545927960224; Thu, 27 Dec 2018 08:26:00 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id a127sm7643106lfe.73.2018.12.27.08.25.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 08:25:59 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 73/75] range-diff: use parse_options() instead of diff_opt_parse() Date: Thu, 27 Dec 2018 17:25:34 +0100 Message-Id: <20181227162536.15895-14-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.482.g66447595a7 In-Reply-To: <20181227162536.15895-1-pclouds@gmail.com> References: <20181227162536.15895-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 Diff's internal option parsing is now done with 'struct option', which makes it possible to combine all diff options to range-diff and parse everything all at once. Parsing code becomes simpler, and we get a looong 'git range-diff -h' Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/range-diff.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/builtin/range-diff.c b/builtin/range-diff.c index f01a0be851..784bd19321 100644 --- a/builtin/range-diff.c +++ b/builtin/range-diff.c @@ -16,42 +16,27 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix) int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT; struct diff_options diffopt = { NULL }; int simple_color = -1; - struct option options[] = { + struct option range_diff_options[] = { OPT_INTEGER(0, "creation-factor", &creation_factor, N_("Percentage by which creation is weighted")), OPT_BOOL(0, "no-dual-color", &simple_color, N_("use simple diff colors")), OPT_END() }; - int i, j, res = 0; + struct option *options; + int res = 0; struct strbuf range1 = STRBUF_INIT, range2 = STRBUF_INIT; git_config(git_diff_ui_config, NULL); repo_diff_setup(the_repository, &diffopt); + options = parse_options_concat(range_diff_options, diffopt.parseopts); argc = parse_options(argc, argv, NULL, options, - builtin_range_diff_usage, PARSE_OPT_KEEP_UNKNOWN | - PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0); - - for (i = j = 1; i < argc && strcmp("--", argv[i]); ) { - int c = diff_opt_parse(&diffopt, argv + i, argc - i, prefix); + builtin_range_diff_usage, 0); - if (!c) - argv[j++] = argv[i++]; - else - i += c; - } - while (i < argc) - argv[j++] = argv[i++]; - argc = j; diff_setup_done(&diffopt); - /* Make sure that there are no unparsed options */ - argc = parse_options(argc, argv, NULL, - options + ARRAY_SIZE(options) - 1, /* OPT_END */ - builtin_range_diff_usage, 0); - /* force color when --dual-color was used */ if (!simple_color) diffopt.use_color = 1; @@ -90,6 +75,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix) error(_("need two commit ranges")); usage_with_options(builtin_range_diff_usage, options); } + FREE_AND_NULL(options); res = show_range_diff(range1.buf, range2.buf, creation_factor, simple_color < 1, &diffopt); From patchwork Thu Dec 27 16:25:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10743867 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 99D4791E for ; Thu, 27 Dec 2018 16:26:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AA8E2890E for ; Thu, 27 Dec 2018 16:26:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F38128942; Thu, 27 Dec 2018 16:26:06 +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 020762890E for ; Thu, 27 Dec 2018 16:26:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731069AbeL0Q0F (ORCPT ); Thu, 27 Dec 2018 11:26:05 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:37103 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729458AbeL0Q0E (ORCPT ); Thu, 27 Dec 2018 11:26:04 -0500 Received: by mail-lf1-f68.google.com with SMTP id y11so12988615lfj.4 for ; Thu, 27 Dec 2018 08:26:02 -0800 (PST) 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=Cka2RIEzbXW8Mc02eXJeQ6ivYDzaQWQUK3Y2L8gBTx0=; b=BTRmcXehreIuPVR7ujPYRMYfNCVqdYrbfFkZzOlYnrshHxr5fihTfplocWWZ5GupU2 e6iJ5ci7r3waFMBaZeEcnYg9XDVpwnQuDM6JuUtPrJ9zchVLPhWRa83+n4TaZZi1RKHP uEje994MBw2hpC1kZWobsw7QVBYfRqy7EG/d6E1gf4Jy7ckckOXRZvF2UZmsbZO7xE72 exmOlpdmdYkpJpQhcxQwc4tvrbaagj1US7qVbAXftTdQux0vaR4sW5FuPViZi3fUo8Hf opmXDdgH4cNDdfKmOgN9WMnUulOpH5j5niwMZsaXPRXFCVJuJe9L3c/FFwHyBU7oVf2r BMZQ== 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=Cka2RIEzbXW8Mc02eXJeQ6ivYDzaQWQUK3Y2L8gBTx0=; b=hdh7oTSYumvpoX8HYj0f2bfnzXkZCI/hPX+xeL0QRkalDT9jhEj/F5//ek4NRptZZ8 K3+qpIN78ZdcZlkPrrCDKoPfZqLj+1QvhCJ4S37VKz62LPfpOf59di0YLUUF4wnPqIh4 aqCvzia7GIDDd0tx7QhO+5jgcUCNMqGE3ykacNmuVa/Tc7AmSW0yVb1SkgwJGdLThWFN 027q5KOABebiiHomCPLGeb53YYTPnd6PUNHyfC+QrMOfGgzZiTIzHOBpkFYNUpifL+p+ dwqvv9rAJ/qJn8HSXVZlKabWuZK15rAhrWuD5bueOZxUBn8LKCunByOCSNJyKh5+ypt8 AyeA== X-Gm-Message-State: AA+aEWYFARsOxRoNMl6nYZ56SrYArHa/7sDlKOFFuBSUHFzxX8hrH8ev VVQ9aH1EcC6wOJpzQqN8pyHeYz4k X-Google-Smtp-Source: AFSGD/VhKq9U2f1IO6F/WTHRoE/Z7XxKxaz78UaB6jO4cXdgZtwSKRYGtSKnP6xDR3Q6Ct81AmzP7Q== X-Received: by 2002:ac2:4116:: with SMTP id b22mr12987028lfi.19.1545927961590; Thu, 27 Dec 2018 08:26:01 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id a127sm7643106lfe.73.2018.12.27.08.26.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 08:26:00 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 74/75] diff --no-index: use parse_options() instead of diff_opt_parse() Date: Thu, 27 Dec 2018 17:25:35 +0100 Message-Id: <20181227162536.15895-15-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.482.g66447595a7 In-Reply-To: <20181227162536.15895-1-pclouds@gmail.com> References: <20181227162536.15895-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 While at there, move exit() back to the caller. It's easier to see the flow that way then burying it in diff-no-index.c Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/diff.c | 21 +++-------------- diff-no-index.c | 49 ++++++++++++++++++++++++---------------- diff.h | 3 ++- t/t4053-diff-no-index.sh | 3 +-- 4 files changed, 35 insertions(+), 41 deletions(-) diff --git a/builtin/diff.c b/builtin/diff.c index f0393bba23..52dc3e136f 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -320,26 +320,11 @@ int cmd_diff(int argc, const char **argv, const char *prefix) repo_init_revisions(the_repository, &rev, prefix); - if (no_index && argc != i + 2) { - if (no_index == DIFF_NO_INDEX_IMPLICIT) { - /* - * There was no --no-index and there were not two - * paths. It is possible that the user intended - * to do an inside-repository operation. - */ - fprintf(stderr, "Not a git repository\n"); - fprintf(stderr, - "To compare two paths outside a working tree:\n"); - } - /* Give the usage message for non-repository usage and exit. */ - usagef("git diff %s ", - no_index == DIFF_NO_INDEX_EXPLICIT ? - "--no-index" : "[--no-index]"); - - } if (no_index) /* If this is a no-index diff, just run it and exit there. */ - diff_no_index(the_repository, &rev, argc, argv); + exit(diff_no_index(the_repository, &rev, + no_index == DIFF_NO_INDEX_IMPLICIT, + argc, argv)); /* Otherwise, we are doing the usual "git" diff */ rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index; diff --git a/diff-no-index.c b/diff-no-index.c index 9414e922d1..a879f45862 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -14,6 +14,7 @@ #include "revision.h" #include "log-tree.h" #include "builtin.h" +#include "parse-options.h" #include "string-list.h" #include "dir.h" @@ -233,35 +234,43 @@ static void fixup_paths(const char **path, struct strbuf *replacement) } } -void diff_no_index(struct repository *r, - struct rev_info *revs, - int argc, const char **argv) +static const char * const diff_no_index_usage[] = { + N_("git diff --no-index [] "), + NULL +}; + +int diff_no_index(struct repository *r, + struct rev_info *revs, + int implicit_no_index, + int argc, const char **argv) { - int i; + int i, no_index; const char *paths[2]; struct strbuf replacement = STRBUF_INIT; const char *prefix = revs->prefix; + struct option no_index_options[] = { + OPT_BOOL_F(0, "no-index", &no_index, "", + PARSE_OPT_NONEG | PARSE_OPT_HIDDEN), + OPT_END(), + }; + struct option *options; /* * FIXME: --no-index should not look at index and we should be * able to pass NULL repo. Maybe later. */ repo_diff_setup(r, &revs->diffopt); - for (i = 1; i < argc - 2; ) { - int j; - if (!strcmp(argv[i], "--no-index")) - i++; - else if (!strcmp(argv[i], "--")) - i++; - else { - j = diff_opt_parse(&revs->diffopt, argv + i, argc - i, - revs->prefix); - if (j <= 0) - die("invalid diff option/value: %s", argv[i]); - i += j; - } + options = parse_options_concat(no_index_options, + revs->diffopt.parseopts); + argc = parse_options(argc, argv, revs->prefix, options, + diff_no_index_usage, 0); + if (argc != 2) { + if (implicit_no_index) + warning(_("Not a git repository. Use --no-index to " + "compare two paths outside a working tree")); + usage_with_options(diff_no_index_usage, options); } - + FREE_AND_NULL(options); for (i = 0; i < 2; i++) { const char *p = argv[argc - 2 + i]; if (!strcmp(p, "-")) @@ -293,7 +302,7 @@ void diff_no_index(struct repository *r, revs->diffopt.flags.exit_with_status = 1; if (queue_diff(&revs->diffopt, paths[0], paths[1])) - exit(1); + return 1; diff_set_mnemonic_prefix(&revs->diffopt, "1/", "2/"); diffcore_std(&revs->diffopt); diff_flush(&revs->diffopt); @@ -304,5 +313,5 @@ void diff_no_index(struct repository *r, * The return code for --no-index imitates diff(1): * 0 = no changes, 1 = changes, else error */ - exit(diff_result_code(&revs->diffopt, 0)); + return diff_result_code(&revs->diffopt, 0); } diff --git a/diff.h b/diff.h index 8c4748ebcf..44843d8929 100644 --- a/diff.h +++ b/diff.h @@ -437,7 +437,8 @@ int diff_flush_patch_id(struct diff_options *, struct object_id *, int); int diff_result_code(struct diff_options *, int); -void diff_no_index(struct repository *, struct rev_info *, int, const char **); +int diff_no_index(struct repository *, struct rev_info *, + int implicit_no_index, int, const char **); int index_differs_from(const char *def, const struct diff_flags *flags, int ita_invisible_in_index); diff --git a/t/t4053-diff-no-index.sh b/t/t4053-diff-no-index.sh index 6e0dd6f9e5..fb25cdb789 100755 --- a/t/t4053-diff-no-index.sh +++ b/t/t4053-diff-no-index.sh @@ -50,8 +50,7 @@ test_expect_success 'git diff --no-index executed outside repo gives correct err export GIT_CEILING_DIRECTORIES && cd non/git && test_must_fail git diff --no-index a 2>actual.err && - echo "usage: git diff --no-index " >expect.err && - test_cmp expect.err actual.err + test_i18ngrep "usage: git diff --no-index" actual.err ) ' From patchwork Thu Dec 27 16:25:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10743871 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 6D0AA924 for ; Thu, 27 Dec 2018 16:26:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E7EC2890E for ; Thu, 27 Dec 2018 16:26:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5341828942; Thu, 27 Dec 2018 16:26:08 +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 EA3F62890E for ; Thu, 27 Dec 2018 16:26:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731081AbeL0Q0G (ORCPT ); Thu, 27 Dec 2018 11:26:06 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:41669 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729490AbeL0Q0F (ORCPT ); Thu, 27 Dec 2018 11:26:05 -0500 Received: by mail-lf1-f67.google.com with SMTP id c16so12992296lfj.8 for ; Thu, 27 Dec 2018 08:26:04 -0800 (PST) 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=8+a2D0EmS2f/2kbPOXkC7EjsXKFs3wpiK0KJBISi4z0=; b=IeWAJUHzWIAdeHTi35yZ/6JCjjOv0jWXJs308g7lA05QiK9L4JqNqz4YEDzUnzXeOp ptWM3FQb8zEPp6txVdHYa5A5Zt4Pay+6P4gjiyphNDRj5X/3gewQl2o77g3xw8+u+jxK R8LocevAOnrqvC5d0+bk+NJMz5Lgkrf4hoFz5q6Qx8g1SOfRYL3KlYmW/QWOimIgCL+M EP0eN/xng0boQdpvkIeY3DBA9Tm9F4EMY95kdmwk3xvtBnUmWJwTAz/kxE8H1s0h3Yf4 deT+OMZphxPhHxBNF6mM1UXAqFZdXaV/alvcDsAVNjLbQemkZQMBpWaDRGmKE1eOSeax DVqA== 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=8+a2D0EmS2f/2kbPOXkC7EjsXKFs3wpiK0KJBISi4z0=; b=oBfyInUFsnyzguriNpA7VfNVcWt9ALZzYYpTX+9cTBlzfynOxgQuOk14M9MEpmKwgg idlQAPk7cxcs0Rbp9hr1H6EjummRvogY5SIn6QAlWhx1OhqM51yQFU9jT3KCQBjDr3Ga MqR/es5EOCH0qKb2R0LGfJPHEX83nxbKjE9qf6GYPcPo6WY+doaI7eEJeEzluxdsA6kT uo7q1tk2jGntss8Dd5V8RgEx83QdbSck3eNcQiSChhOk9bvEGc6JA/HbSnDWGdqm8snT QiG6wzpMvK+alnTqQfhewDQxNxvISI27C0wdYEiUJYYLNaU45Yk1Fr8rDulTQsmq0W7M w6/g== X-Gm-Message-State: AA+aEWa4evyOxOHgU5f5Idiz/+GgdiQjIDp4gnKMuuCuXDO61lvfGFyA 8HKAPNLyhQP8sQmZedgS2mRiK3dO X-Google-Smtp-Source: AFSGD/UntYxJRgBd2rRTCcM1jCUeuMc1Da9LukUhN1jcf5t1H/cPcCwmXFv+G+2+lyvXIjvt6ulMIw== X-Received: by 2002:a19:c650:: with SMTP id w77mr12640638lff.56.1545927963312; Thu, 27 Dec 2018 08:26:03 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id a127sm7643106lfe.73.2018.12.27.08.26.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 08:26:01 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 75/75] am: avoid diff_opt_parse() Date: Thu, 27 Dec 2018 17:25:36 +0100 Message-Id: <20181227162536.15895-16-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.482.g66447595a7 In-Reply-To: <20181227162536.15895-1-pclouds@gmail.com> References: <20181227162536.15895-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 diff_opt_parse() is a heavy hammer to just set diff filter. But it's the only way because of the diff_status_letters[] mapping. Add a new API to set diff filter and use it in git-am. diff_opt_parse()'s only remaining call site in revision.c will be gone soon and having it here just because of git-am does not make sense. Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/am.c | 4 ++-- diff.c | 6 ++++++ diff.h | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 8f27f3375b..a98e65f440 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1515,11 +1515,11 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa * review them with extra care to spot mismerges. */ struct rev_info rev_info; - const char *diff_filter_str = "--diff-filter=AM"; repo_init_revisions(the_repository, &rev_info, NULL); rev_info.diffopt.output_format = DIFF_FORMAT_NAME_STATUS; - diff_opt_parse(&rev_info.diffopt, &diff_filter_str, 1, rev_info.prefix); + rev_info.diffopt.filter |= diff_filter_bit('A'); + rev_info.diffopt.filter |= diff_filter_bit('M'); add_pending_oid(&rev_info, "HEAD", &our_tree, 0); diff_setup_done(&rev_info.diffopt); run_diff_index(&rev_info, 1); diff --git a/diff.c b/diff.c index 43ae8d4d2c..8a7011b928 100644 --- a/diff.c +++ b/diff.c @@ -4756,6 +4756,12 @@ static unsigned filter_bit_tst(char status, const struct diff_options *opt) return opt->filter & filter_bit[(int) status]; } +unsigned diff_filter_bit(char status) +{ + prepare_filter_bits(); + return filter_bit[(int) status]; +} + static int diff_opt_diff_filter(const struct option *option, const char *optarg, int unset) { diff --git a/diff.h b/diff.h index 44843d8929..48cfa3f0a6 100644 --- a/diff.h +++ b/diff.h @@ -233,6 +233,8 @@ struct diff_options { struct option *parseopts; }; +unsigned diff_filter_bit(char status); + void diff_emit_submodule_del(struct diff_options *o, const char *line); void diff_emit_submodule_add(struct diff_options *o, const char *line); void diff_emit_submodule_untracked(struct diff_options *o, const char *path);