From patchwork Sun Jan 27 00:35:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10782639 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 6912B6C2 for ; Sun, 27 Jan 2019 00:36:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 572BB2C808 for ; Sun, 27 Jan 2019 00:36:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B7EC2C80B; Sun, 27 Jan 2019 00:36:11 +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 7EF7E2C808 for ; Sun, 27 Jan 2019 00:36:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726400AbfA0AgI (ORCPT ); Sat, 26 Jan 2019 19:36:08 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:34199 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726262AbfA0AgI (ORCPT ); Sat, 26 Jan 2019 19:36:08 -0500 Received: by mail-pf1-f193.google.com with SMTP id h3so6385861pfg.1 for ; Sat, 26 Jan 2019 16:36:07 -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=yxtmO7dXFX80Z9kEjqEhdw4Sy5rHHoxOw+1Cqw0ZSXo=; b=hm2QNv8Wx4WLMzJg93cefDRYiOD4s7yDuCrf4bG2fstHi8j1HCozpO9tO8taJ/VyuS 25ihsngfein5D0wZaFDwC7miUGoZMvBuX40YxNWFtS/sHp3pvW135g6Q/9ewBnCxbzWw 6sjQ0I3tb0YcitVk5J+MSfkf6tLRQTuZafUXFdPikuP613Blx2sqPxbwHbg/Y63t19zf VhDAnxcuP8F4iDTbGybr4n1ewJlTIzJ6KcrCj+C+FuG6a2GJO/SYJGY14MxGVWuFKka5 bZzdkvjPAwgJtB+VuX1gL3Pm/6Qp5UuTmdh+9P6gveys7kA8N1FR9K2kk2pITHBomjGG URPg== 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=yxtmO7dXFX80Z9kEjqEhdw4Sy5rHHoxOw+1Cqw0ZSXo=; b=YwO+n30d+xgSEh2OFXvhysHzFcpSZ3Inmx8D+XhswgTdwvbnahsJWi9DX1OQj9nbYH jcgrKSBY3oIYqypI/eHsQF85TIGVO8fSNdhQb5N9IDy7Qvy5yT63y89MSnlWAmuAu0Xs hZnhTI/5hWJ7WuzHubLr66NezdVac0f3ORxpf0pGrhns/wCE67iDtjavotFTlx9b7FbX 5rJEwDjM+7sKznfxr4tsWxoNgMSoygo2XpE3FxEKmOgqar/K1lbhHBD8MY8URvjReZuA FJT5cYU46hzb3ck3gX9pw6qQMvQi6eVxHrySkSIs87/7zwLl2Tgdyho/jiT5A7H0+p4S 8Bhg== X-Gm-Message-State: AJcUukcGnN/C9dnS+laUdmEGZ526ewTUw/LIMlVNAel/LGdODOUCVbkX o67xPs+mlcT0ZCtyccynw3M7nwEM X-Google-Smtp-Source: ALg8bN6Z53ZOjReM2j7MwKLIiW2e1TjE5+z/v+czuwD3FsrTPipTta1/Zha5jN01TmEcndn+LlB4Lw== X-Received: by 2002:a63:4948:: with SMTP id y8mr14964008pgk.32.1548549367488; Sat, 26 Jan 2019 16:36:07 -0800 (PST) Received: from ash ([115.72.21.220]) by smtp.gmail.com with ESMTPSA id h79sm45389674pfj.186.2019.01.26.16.36.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jan 2019 16:36:06 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Sun, 27 Jan 2019 07:36:02 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 01/14] parse-options.h: remove extern on function prototypes Date: Sun, 27 Jan 2019 07:35:22 +0700 Message-Id: <20190127003535.28341-2-pclouds@gmail.com> X-Mailer: git-send-email 2.20.1.560.g70ca8b83ee In-Reply-To: <20190127003535.28341-1-pclouds@gmail.com> References: <20190127003535.28341-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 Signed-off-by: Junio C Hamano --- parse-options.h | 58 ++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/parse-options.h b/parse-options.h index 14fe32428e..f5e7ec7d23 100644 --- a/parse-options.h +++ b/parse-options.h @@ -174,18 +174,18 @@ 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); +int optbug(const struct option *opt, const char *reason); const char *optname(const struct option *opt, int flags); /* @@ -227,31 +227,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 Sun Jan 27 00:35:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10782641 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 1464A13B4 for ; Sun, 27 Jan 2019 00:36:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 059A22C808 for ; Sun, 27 Jan 2019 00:36:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE4A22C80B; Sun, 27 Jan 2019 00:36:15 +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 775302C808 for ; Sun, 27 Jan 2019 00:36:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726404AbfA0AgO (ORCPT ); Sat, 26 Jan 2019 19:36:14 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:39309 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726262AbfA0AgN (ORCPT ); Sat, 26 Jan 2019 19:36:13 -0500 Received: by mail-pf1-f193.google.com with SMTP id r136so6369243pfc.6 for ; Sat, 26 Jan 2019 16:36:13 -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=Mi+TnwHoqRYCz/eHLC4xneuVI2CjzmuxZSv0E66l2O4=; b=iAX8YQY2bEL5T/EJVmWkVgZVZCiXUA8XIQBvgjnQLTv47y3g2QeO6fafOFeVtV4ewM Ty65arRA3g6UTfOVEd91oMy9Pbab7VyV+Bxm6nkKo24oQ+nkXIAcWXFROfVFq76fccwF PzgaVrRpI6ayPC7FPKLDazu6DxnIuzbPmQifjUNAkK+vLSCauYvjN02aD+StNxwkrWOP pqiuDiG34Jabe7usBp2cbS2C+d6R/ORPk1HTIASKV/zH863ULmtThFQv0Va49YoV16X6 f7K7vHIBj/3XZtI4MpPT8P+Y1reaaujGSS8Cyk7i3dSAaeA8+s7Zqe3SIAIcjRYJlTq+ yylA== 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=Mi+TnwHoqRYCz/eHLC4xneuVI2CjzmuxZSv0E66l2O4=; b=lF7jODmuoj378dF9C5FmVcVZkvu9eZYPNaJ3EJgzlq1vlt4JmFZV8LrxVMwUFIGTol 1aZ8K7DFKwiAcYj/pFpqBO5mJgGFQZEEWF0+xDZI0EbYpkHtBTdHI/XKWtA0O6lahtbF npFDA4aVvetbxWMlkzEIJSU6pmYfQnNZraIL90vj2cXQ+7x2zawviYsOeQ1B+z4jp/Pi 9venGmjMYge99IXCjmqd/uHrSVly3AnMPyTg8K65NXqUpDzNU2XdjRU96VIf/DaGt6FE AxQpQf+EdD0H5fRdoXSYUDXYH5gelES48QlfxIuKoYEbC1o6aw5w1cakJJQGOEsA7L+q s5hg== X-Gm-Message-State: AJcUukfc1t9WYSmneQ0ifzKSfsEp6KV18SvkpiHWsxsK5gFb5hyMvTK6 VTwBWb8QgFxcPLeTn3rM3wNQfkdn X-Google-Smtp-Source: ALg8bN6Vw026Hxp+EUyO8R07mQyphq8b2g9QKw3IzQpdHVHZ1peR8EDvc0ET61tYdVfDckdw1vERfA== X-Received: by 2002:a63:f34b:: with SMTP id t11mr14972545pgj.341.1548549372628; Sat, 26 Jan 2019 16:36:12 -0800 (PST) Received: from ash ([115.72.21.220]) by smtp.gmail.com with ESMTPSA id m20sm31261526pgv.93.2019.01.26.16.36.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jan 2019 16:36:12 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Sun, 27 Jan 2019 07:36:07 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 02/14] parse-options: add one-shot mode Date: Sun, 27 Jan 2019 07:35:23 +0700 Message-Id: <20190127003535.28341-3-pclouds@gmail.com> X-Mailer: git-send-email 2.20.1.560.g70ca8b83ee In-Reply-To: <20190127003535.28341-1-pclouds@gmail.com> References: <20190127003535.28341-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 | 26 ++++++++++++++++++++++---- parse-options.h | 17 +++++++++++++---- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/parse-options.c b/parse-options.c index 9f84bacce6..740ae5438f 100644 --- a/parse-options.c +++ b/parse-options.c @@ -416,15 +416,24 @@ 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)) + (flags & PARSE_OPT_STOP_AT_NON_OPTION) && + !(flags & PARSE_OPT_ONE_SHOT)) BUG("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); } @@ -536,6 +545,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; @@ -610,6 +623,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]; @@ -623,6 +638,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 f5e7ec7d23..d663b83973 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 Sun Jan 27 00:35:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10782643 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 C9DFC6C2 for ; Sun, 27 Jan 2019 00:36:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B98EB2C808 for ; Sun, 27 Jan 2019 00:36:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE1952C80B; Sun, 27 Jan 2019 00:36:20 +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 520D52C808 for ; Sun, 27 Jan 2019 00:36:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726413AbfA0AgT (ORCPT ); Sat, 26 Jan 2019 19:36:19 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:37232 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726262AbfA0AgS (ORCPT ); Sat, 26 Jan 2019 19:36:18 -0500 Received: by mail-pg1-f194.google.com with SMTP id c25so5686758pgb.4 for ; Sat, 26 Jan 2019 16:36:18 -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=f4YmLLjRKHCuoqTwvZt5Yp7fPKAB27+ZtPsKARqO0vs=; b=paVID5k+N20blHX3+zVAQC44gxMCMA0WouySM7Vb/Wy5EjpCcxltcAc8Thkno7hu8w YRGodaJaJ6tb9O2kvC7vJTn+J/Y1Kr6nh+9ZjlgB8yGIjKROt3kW5UIaL9hAJOVYzIBq pb2ZPrC1wfNq89LT4oN1QurZYEAnhznfVwH+DFNXeAFClSESJikNqAiFe/TJzX+xArmX s9JmQ9C9AbQuKrJk9Ibzhp9Ih2iscizAU1RG6VFa+i+8xyZGcGEqfBFGL9VHAplD3P4t QrRtxbPYf5JSbxXZQYj+iisEVMZeehYCWPKGLX31TFU1JOweedYJmF6vmgvCho9YkscG 68Cg== 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=f4YmLLjRKHCuoqTwvZt5Yp7fPKAB27+ZtPsKARqO0vs=; b=aNrS9rhNZdNneZvWBpgtzGkn7PquP6I3dCXRoXoRH1feVMZAt9eMwafCN/v5aorN64 p2OxWTAt0BD2/NeFexcjah30fuL4aLc6zsoib5hgGnUDpTwTbLRDHduSH42pPcllxLjX fvdfT+0NXINk9xr5Bz/mWN0DM3SKtXA3d9JB0HWJZ5JGQE3ZGV6ATmFg7EhHQzw7GsKp 1v2CH+ohCR20+gPkN11/hPsq27P5THBB0BSvtDGrYGzGapId2b5A/hB13Mj0+CnZEu6t j3+UON0e/oromNsG6UeIIMVEsBAZpJMe84zCdJmWaQfz8Ai609XMDkf44/BYBZpOFvKA smQQ== X-Gm-Message-State: AJcUukebECHm9lXZCwZSHzrMWRPY1tutb+zeNSme9k0Vl6LlsPoSOkgt Zg7f2g0PCIeyof77EUzSsDwwvaoA X-Google-Smtp-Source: ALg8bN5QOyiyB81xWTXrC5dq1apqdCdUWT/Nxf9fRpaUXyTNwMq9Q1mphJ6sW50BZCGuEliL/2LRew== X-Received: by 2002:aa7:8286:: with SMTP id s6mr16318846pfm.63.1548549377790; Sat, 26 Jan 2019 16:36:17 -0800 (PST) Received: from ash ([115.72.21.220]) by smtp.gmail.com with ESMTPSA id l11sm36963728pff.65.2019.01.26.16.36.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jan 2019 16:36:17 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Sun, 27 Jan 2019 07:36:12 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 03/14] parse-options: disable option abbreviation with PARSE_OPT_KEEP_UNKNOWN Date: Sun, 27 Jan 2019 07:35:24 +0700 Message-Id: <20190127003535.28341-4-pclouds@gmail.com> X-Mailer: git-send-email 2.20.1.560.g70ca8b83ee In-Reply-To: <20190127003535.28341-1-pclouds@gmail.com> References: <20190127003535.28341-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 Signed-off-by: Junio C Hamano --- 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 740ae5438f..779034e1fd 100644 --- a/parse-options.c +++ b/parse-options.c @@ -266,7 +266,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 Sun Jan 27 00:35:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10782645 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 D3FC413B4 for ; Sun, 27 Jan 2019 00:36:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C43B72C808 for ; Sun, 27 Jan 2019 00:36:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8DAD2C80B; Sun, 27 Jan 2019 00:36:25 +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 61D662C808 for ; Sun, 27 Jan 2019 00:36:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726423AbfA0AgY (ORCPT ); Sat, 26 Jan 2019 19:36:24 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:43038 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726262AbfA0AgY (ORCPT ); Sat, 26 Jan 2019 19:36:24 -0500 Received: by mail-pf1-f195.google.com with SMTP id w73so6351425pfk.10 for ; Sat, 26 Jan 2019 16:36:23 -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=pCkKFNZ2m4aH+e/KBCXznOvoJnfrn+1I0EYfjc2f6lw=; b=pzWBU2jqZ5WtCx08FhtPKzimqU15O1pM6PcznW7pNVWedZWhQjXUahn+PvjwfeQgzO D0T5lvuLnqLrPAcdeiYBvWSI1/Xew9+AnYUWo9B7n5brP96OKGPE6LAzdRDXfumdQfig Egnn2aucY1TZ086jyfSR5x0Yr0Rofdy5mhueSkrtkpN6MBnhGnjVJZ9aoHBFqGAYsmuu aAZFVh4TXgWaMA7pmbdWa2s4K1Elzf87TfX61dNOTQ3AsWbFNOGPLrt48ltioQJ53jiE qOO/o7qLRJAc0V0a1BlgE18ljmdkRfOSC/E6oiHxoYO0g3qGcQp1ikIY9zluzF1xgYXM AmLg== 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=pCkKFNZ2m4aH+e/KBCXznOvoJnfrn+1I0EYfjc2f6lw=; b=jkUZeUl3i3V8rT9Ho0Zxf4Qv7QVikCoEzpZhIr/dNr+4XRyGpZClbMpBaDtboVdh/J NneI3hEyP18L4To17BieR6JCduBfMI9fM2hA22Bv0HKdb4DBQ4F07BXolI+iLWWOrqHa zd4u/99tfqmSQur13FmU/v/HzhdMRLnl3NA/MxAtC5FdCIbRrU3l5zoffZmekD1W5DFr XTZVfhLgqxiBJc67OTV/b3iaCrGGJ0N8BFMl5rHhhzgxcpcfnp/zxC+Y2yU3Qbz6e5Z5 IemVcSFRaZRAtbWfIRj0m0X8J9FFhWq5FRWxIR6V4DgcoPz6qKU8hxIHcqiy1mAky1wR //4A== X-Gm-Message-State: AJcUukelMvi0ynr78kQxLkIzzEminvOWYdKy5odcNzOdn5JOIv9wl/7y +vNOykk6v1N2OnHPt8PNQCopzW8r X-Google-Smtp-Source: ALg8bN7SKXPJeqW7KEX6lToLZYV/YXL3vXVxqI/gmSJ+SwifeW1VqDeGbYq27pkLNv7iv4snsgPLzA== X-Received: by 2002:a62:37c3:: with SMTP id e186mr17017630pfa.251.1548549383184; Sat, 26 Jan 2019 16:36:23 -0800 (PST) Received: from ash ([115.72.21.220]) by smtp.gmail.com with ESMTPSA id b13sm3906455pfj.66.2019.01.26.16.36.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jan 2019 16:36:22 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Sun, 27 Jan 2019 07:36:18 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 04/14] parse-options: add OPT_BITOP() Date: Sun, 27 Jan 2019 07:35:25 +0700 Message-Id: <20190127003535.28341-5-pclouds@gmail.com> X-Mailer: git-send-email 2.20.1.560.g70ca8b83ee In-Reply-To: <20190127003535.28341-1-pclouds@gmail.com> References: <20190127003535.28341-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 Signed-off-by: Junio C Hamano --- parse-options.c | 7 +++++++ parse-options.h | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/parse-options.c b/parse-options.c index 779034e1fd..62d94ca2e0 100644 --- a/parse-options.c +++ b/parse-options.c @@ -109,6 +109,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 d663b83973..c97324f576 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 Sun Jan 27 00:35:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10782647 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 A7BAA6C2 for ; Sun, 27 Jan 2019 00:36:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94A092C808 for ; Sun, 27 Jan 2019 00:36:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 860BF2C80B; Sun, 27 Jan 2019 00:36:31 +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 D76F52C808 for ; Sun, 27 Jan 2019 00:36:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726441AbfA0Ag3 (ORCPT ); Sat, 26 Jan 2019 19:36:29 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:41887 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726262AbfA0Ag3 (ORCPT ); Sat, 26 Jan 2019 19:36:29 -0500 Received: by mail-pg1-f196.google.com with SMTP id m1so5681161pgq.8 for ; Sat, 26 Jan 2019 16:36:28 -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=1YeSH4y/rrZaM33uY2V0zkhcm8GCLbDmbmDsbun8+r0=; b=uAJTWjl+ISBJRc1yjklNjH+EmLOBpJznAAqnU4mqwgtJrOnhwVRkqhtjKvKPX54MPg K69f5qnzQb1wwe8xdpWeBEhwj/mQ3DXggn7TJ/Q2e4AOcrgphgTmhVY3iLYufgC4Twjx xnS4B1O67M2FN4cBQqk1vGeoam76SFpj/QaF/ZnUx/7T+na66QRNO4H3Qfam64+NactR C4C2NrJXCSC+5Wju6Aw19F2DmlFFb7YJfnffMPXlxLBuWfRGYvlwNFWdv9Nsbkt+jsUa LqkjbVbbDIT30pi01+p+Vq4ZxmL7DtwC6kuKYP1Y6onq8dMQEDRXU5tH3FkoXGRi6OPg BJyw== 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=1YeSH4y/rrZaM33uY2V0zkhcm8GCLbDmbmDsbun8+r0=; b=ix//WdaxkpYsf/tFXYHwWglHBfo5tT/yfncWDugqy4QJ1Fr0pCIUZtbjp7Ga0mdPaf sDltqpkw9Tj4NBN8beRQVehE4n0Hf7mA9HwM/5FSLAmo3OSbTke+3Iqq0rr0/0Itdmoh Q/4yB67pLpMKX6Bs4/DgpMmi+T9/pcNqLnfMT5JszxqykHqDol5JgeHYJRmBlJehLPdK pwvP97h4+jxFtD+YUgqhOydMcQuAYF+8NVnGSgMK0uq2mqmHUi4HfdnVRgQo82g/9yVn Qrni9R+gXB2CzwXYA4PvHNEEPwk2/7yK5EBEgZQuZi5Kb23ihXcre0Bxfd3wMIXOzbrN HK8A== X-Gm-Message-State: AJcUukebCYrSmXH89iSjkJN638zu190bRMdp2gD0N/9+vvI8oNLkgl/D jm1A+4aNx4/GYykx6wREP8bk8As8 X-Google-Smtp-Source: ALg8bN4dlY9kb3Rzk+6gebTcJ/KqTLplbOR7308+yxsK7jwhIFd/ixPzfjblwa2yTVsGGSYKnktEOg== X-Received: by 2002:a62:8add:: with SMTP id o90mr16482119pfk.210.1548549388331; Sat, 26 Jan 2019 16:36:28 -0800 (PST) Received: from ash ([115.72.21.220]) by smtp.gmail.com with ESMTPSA id e123sm47778968pgc.58.2019.01.26.16.36.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jan 2019 16:36:27 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Sun, 27 Jan 2019 07:36:23 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 05/14] parse-options: stop abusing 'callback' for lowlevel callbacks Date: Sun, 27 Jan 2019 07:35:26 +0700 Message-Id: <20190127003535.28341-6-pclouds@gmail.com> X-Mailer: git-send-email 2.20.1.560.g70ca8b83ee In-Reply-To: <20190127003535.28341-1-pclouds@gmail.com> References: <20190127003535.28341-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 Signed-off-by: Junio C Hamano --- 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 dc0b7cc521..07839b0bb8 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 e2f3eaed07..e05bcea809 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -170,7 +170,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 62d94ca2e0..37a56d079a 100644 --- a/parse-options.c +++ b/parse-options.c @@ -93,7 +93,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) @@ -408,6 +408,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 c97324f576..f1f246387c 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) @@ -263,7 +267,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 Sun Jan 27 00:35:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10782649 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 342F26C2 for ; Sun, 27 Jan 2019 00:36:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22E782C808 for ; Sun, 27 Jan 2019 00:36:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 15C602C80B; Sun, 27 Jan 2019 00:36:38 +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 53B6D2C808 for ; Sun, 27 Jan 2019 00:36:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726451AbfA0Agg (ORCPT ); Sat, 26 Jan 2019 19:36:36 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:36707 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726262AbfA0Agg (ORCPT ); Sat, 26 Jan 2019 19:36:36 -0500 Received: by mail-pf1-f193.google.com with SMTP id b85so6372419pfc.3 for ; Sat, 26 Jan 2019 16:36:35 -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=J22SqsrBnIBzBc/MowdG4uEvotFdzYR0VIbQKkBltuM=; b=jRQkrMXxH6L11gocowpgR8gldoBzo/t72NPV9RmPQpgNpTFUKRwViFfInVAShzsN8U RJ+nYYk4wDspnB7ihlkK0C0um5ES5q+ERu3tXWEH7sQPKb2mJTIKPbjA8z+yl/awS1x8 TpIIZcqmz91sGFP50z3FV2ITRoQIzCcXErTlKnR+mUUSyM0l/ZnB+5MwmgMY5wyWxpMA lRsLgJFjzrTbxHcgy5bk3V0K4Nga0evvOlJdxjJ6I+V6aMaDoLjbNvKDiS1SFwuK4s4I DVk/E0noQsCs+f2f0l4JeqgpXAhrqZIjYL4cheYSDfmjs628mBQsEDUp5fFddAfYAVh2 nZNA== 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=J22SqsrBnIBzBc/MowdG4uEvotFdzYR0VIbQKkBltuM=; b=Mqu5Sy+jKKg6mcP8Bxebpd/TYnjUAAvIetmcXwkhAuOHv/d6anqoQXkpyKG0Qnzlfr HjxWgGmp1pz6JXHQ5jQmaaQuchsAPFDJpIvDGZ87XXVzB1MXV/STQz4U/PPMwBD/+lih 6x7Ac05Cf1lxM4Z2613x83cHq9ztHz+xrBGrM1zkqyPBKbWPxE0kRIjbyzA+MVIIfGEu owTddWtYTQs3uX82Htra3v31GARGSGigA5Oe64yDxSJNkqMoIhtrgJktn077VGrKvz7T gN7FW8V2QeKut6ux3HMXotwbKmtGEMbPG22HZATp/rNPdur5lBsIE0+d14YJ05pcaB0U ODdA== X-Gm-Message-State: AJcUukfRjmOr96KyuOZ8fL5lOxyCZ5bnopePFxDL1uanW6wBJ0asgRIB vr4V/HRGXEU9ge7MZsd2/sZZMM8Z X-Google-Smtp-Source: ALg8bN5f92rARRzTANOQNglpaWJFkQXRG9JOgEoZzkb93Y+tB2bIo+fPeoxlTgWxrcduZs7lhsHtKg== X-Received: by 2002:a62:6143:: with SMTP id v64mr16629511pfb.142.1548549394667; Sat, 26 Jan 2019 16:36:34 -0800 (PST) Received: from ash ([115.72.21.220]) by smtp.gmail.com with ESMTPSA id x3sm42739901pgt.45.2019.01.26.16.36.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jan 2019 16:36:34 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Sun, 27 Jan 2019 07:36:28 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 06/14] parse-options: avoid magic return codes Date: Sun, 27 Jan 2019 07:35:27 +0700 Message-Id: <20190127003535.28341-7-pclouds@gmail.com> X-Mailer: git-send-email 2.20.1.560.g70ca8b83ee In-Reply-To: <20190127003535.28341-1-pclouds@gmail.com> References: <20190127003535.28341-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 Signed-off-by: Junio C Hamano --- 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 07839b0bb8..de64d7850e 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 e05bcea809..ec01ef722b 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -170,10 +170,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 37a56d079a..50c340474c 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 that_name = STRBUF_INIT; @@ -69,16 +71,16 @@ static int opt_command_mode_error(const struct option *opt, error(_("%s is incompatible with %s"), optname(opt, flags), that_name.buf); strbuf_release(&that_name); - return -1; + return PARSE_OPT_ERROR; } return error(_("%s : incompatible with something else"), optname(opt, 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, '='); @@ -269,7 +273,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? */ @@ -334,11 +338,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, @@ -590,22 +594,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; @@ -617,6 +627,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; @@ -635,12 +651,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 f1f246387c..4e49185027 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`:: @@ -222,12 +222,12 @@ const char *optname(const struct option *opt, 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 Sun Jan 27 00:35:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10782651 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 C7DEE6C2 for ; Sun, 27 Jan 2019 00:36:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B69E32C808 for ; Sun, 27 Jan 2019 00:36:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AAD692C80B; Sun, 27 Jan 2019 00:36:43 +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 02C2D2C808 for ; Sun, 27 Jan 2019 00:36:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726468AbfA0Agm (ORCPT ); Sat, 26 Jan 2019 19:36:42 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:41891 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726262AbfA0Agl (ORCPT ); Sat, 26 Jan 2019 19:36:41 -0500 Received: by mail-pg1-f193.google.com with SMTP id m1so5681258pgq.8 for ; Sat, 26 Jan 2019 16:36:41 -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=W8NtUzn6U8ttA/Z0NNmJcw4ThCxA2iYJCOa2CongQNI=; b=svoegjkMSl8iWjwcQvWo39NTAx256dLGhzAZSguj43ls1lK2MFPfUB7p6Am8hXPx/u 2HRX964qvx71XSQCUKrKizj79QXKduXTyPjhRO6O5zc3qXC427HPwGD0iR6Mm8XJrqwc MTSoHHFy1OD+r9ZIR/ZY/j92QvQ+44wPnO25PbtPQo1KF2xU8O60AJHnF7qB1Ri8D385 hd6P+DVptRAKdonwWjh1bULG2mS6loExx6u88aTi/W4fuSU1UE5KbYZrqB/qA0LMYLow IQ61Q7NSY6bQ1zhQORpK8IX0u66r7U+SW1VXDvsdL2Iudbgdk1Kc0yqyl/pWzXYWEbfP AokQ== 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=W8NtUzn6U8ttA/Z0NNmJcw4ThCxA2iYJCOa2CongQNI=; b=I5R/4iPAXQNDV5bBmJdLkSai5/EAFA+oN7JygJS9CvtENBMOlpllGCXTX4s7K/EprT TjEZnJjMEAMJfEVWh8pYFPv1HwfHgFkuQ1KAybpW37kaaD9LkXmzwc5lwBQyjtVmgEf6 A7kcwEu1S9tQDLLMk5fyQITWKrg24LltjwO982iYcFPB/laEzxXSRN0HgQ8acwm3x3ec 3dX55aYFvIdY67/F62pCgTT3JJOdGcA0jZ9n3VW+dBbmSo7cjUc/DtdZPzOLBODKBQwp /jynobI7RVEKgabheDvQDqnhZD74E/e+Ts/e6k6fnnRg7wbvu5/OP9j5xszTiUGVfTlo X97g== X-Gm-Message-State: AJcUukeEFuCOs3QId+yQALFqMFl7ktEGTQ8OTZ7/p4g75EizErRr8Qqc 0laXsu1+3eKAPGQqovMCHflMJ2sm X-Google-Smtp-Source: ALg8bN6VVGyAj2ybyo8DP8dBm9AiuvWmTeTTFGiZ2r71nXh2BgKeH90wr8SAUBUEXpNea/wm9ygFxg== X-Received: by 2002:a62:5f07:: with SMTP id t7mr16547426pfb.108.1548549400790; Sat, 26 Jan 2019 16:36:40 -0800 (PST) Received: from ash ([115.72.21.220]) by smtp.gmail.com with ESMTPSA id 12sm36426367pgt.33.2019.01.26.16.36.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jan 2019 16:36:39 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Sun, 27 Jan 2019 07:36:35 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 07/14] parse-options: allow ll_callback with OPTION_CALLBACK Date: Sun, 27 Jan 2019 07:35:28 +0700 Message-Id: <20190127003535.28341-8-pclouds@gmail.com> X-Mailer: git-send-email 2.20.1.560.g70ca8b83ee In-Reply-To: <20190127003535.28341-1-pclouds@gmail.com> References: <20190127003535.28341-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 Signed-off-by: Junio C Hamano --- 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 de64d7850e..563a16f38a 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 ec01ef722b..2733393546 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -171,8 +171,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 50c340474c..cec74522e5 100644 --- a/parse-options.c +++ b/parse-options.c @@ -95,7 +95,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) @@ -161,16 +161,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; } @@ -414,10 +428,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 4e49185027..ce75278804 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`:: @@ -267,7 +268,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 Sun Jan 27 00:35:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10782653 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 6672C13B4 for ; Sun, 27 Jan 2019 00:36:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 577992C808 for ; Sun, 27 Jan 2019 00:36:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BB762C80B; Sun, 27 Jan 2019 00:36:48 +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 028F02C808 for ; Sun, 27 Jan 2019 00:36:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726485AbfA0Agr (ORCPT ); Sat, 26 Jan 2019 19:36:47 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:33385 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726262AbfA0Agq (ORCPT ); Sat, 26 Jan 2019 19:36:46 -0500 Received: by mail-pg1-f193.google.com with SMTP id z11so5700504pgu.0 for ; Sat, 26 Jan 2019 16:36:46 -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=SahaEHnsnPz/zBhUk3zwfrtrsjNNSrLb4UaDduqUjJQ=; b=pp/Z5j4idr231Jn+E0oFXZbnos+F2cqEAHc8L96PW9b1/moHrDZhYe0Mgi4TUNys6/ +7JcGlkGtFTWZi4/Hl2ISr2x3XNwKRphh/OwQWzLnRctADEfA+B1nDEfCm3dqfYArrMZ wEn1+VPVfzPHJNoW9vjZuKFsAmfY2K9pPGfC+QgQ1nkFbp0aVexQ/L9B9S6wzD+iWRWL n2W0jU6FhbM2Qd3NUs+SlhyKkQqNYVC6gmqMqFOIZ/t3RUglIK6AqzweXn0PqAhgDU2N uRCoQvpoA5yV/rxwMWXndskzl+y60GfcOKaARy2DBjVWavmhH0IR0JXQ/HiIWGWLnRap jH4w== 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=SahaEHnsnPz/zBhUk3zwfrtrsjNNSrLb4UaDduqUjJQ=; b=iqlt8KeKG5RcWq9mK4Mz6u4mEyCK5CDfHzxXeqoZdO1CyJpgNiW+Q1cD9Y42rsSWnD pv6KlIfGObY04tx1Jw0KJxKLVuoZXI5GVSCUI7IRWd3GRKHPSdl52fyw3VFe9PtAvzeY UHjfZKzYgDbQViWeMWhriPsaL1Fgk+nmBWClA025HRxnNsAll0c0WxLfO7ZG20KxrIVr +tOawQmu0klz0mCwQNG7gVROM9NHJJPg+u32eaVWeo4dzjlZNjTwl53wlBc0VPEqUX46 hy4v6ThcmvQe2O2LDZ/ka2/M0nC7vCqghvawvMYRqsK87uA1//eUcI5V6hNdnOx6jtWj 2Wyw== X-Gm-Message-State: AJcUukcWLSCI6ah5CpBOTZArNz/sUYGCClJRdrZzIJwCeAh3VY0EMgNw tJOcbvqS/O/F2ox5nrd5Q8mFJ8TL X-Google-Smtp-Source: ALg8bN6aqQ2voS/Qs0OsgkvAtQnfv9veh7fHmLPW7TWYVWUJCOrBTaiY6bjfHxAHzyjRI6jWHAInQA== X-Received: by 2002:a63:cf02:: with SMTP id j2mr15194961pgg.113.1548549406019; Sat, 26 Jan 2019 16:36:46 -0800 (PST) Received: from ash ([115.72.21.220]) by smtp.gmail.com with ESMTPSA id z10sm40726233pfg.120.2019.01.26.16.36.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jan 2019 16:36:45 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Sun, 27 Jan 2019 07:36:41 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 08/14] diff.h: keep forward struct declarations sorted Date: Sun, 27 Jan 2019 07:35:29 +0700 Message-Id: <20190127003535.28341-9-pclouds@gmail.com> X-Mailer: git-send-email 2.20.1.560.g70ca8b83ee In-Reply-To: <20190127003535.28341-1-pclouds@gmail.com> References: <20190127003535.28341-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 Signed-off-by: Junio C Hamano --- diff.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/diff.h b/diff.h index b512d0477a..c872a41344 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 Sun Jan 27 00:35:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10782655 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 139A613B4 for ; Sun, 27 Jan 2019 00:36:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 042682C808 for ; Sun, 27 Jan 2019 00:36:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9C0D2C80B; Sun, 27 Jan 2019 00:36:53 +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 88E702C808 for ; Sun, 27 Jan 2019 00:36:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726511AbfA0Agw (ORCPT ); Sat, 26 Jan 2019 19:36:52 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:40691 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726262AbfA0Agw (ORCPT ); Sat, 26 Jan 2019 19:36:52 -0500 Received: by mail-pf1-f194.google.com with SMTP id i12so6362342pfo.7 for ; Sat, 26 Jan 2019 16:36: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=xrfdfKGDWIEkJ+syWQznXDqW3LBPzTMgtG17CCJwMh0=; b=dqMkdvdRQigpyvbizhc5Iw+kiEqNIj+SfkcUYprzS33qUTJ3rNCihV3DEz49iUbVIX 70j9649XBc6mfSDbZenrymWPL95QKMlFE8+cGFMvN+qt2HO8CtKmORtKxxZKkDjPL/Cs 7gAGFy5p196Y+YLT1H4gVuf01+3Llasd1+XR6nPCytaAyEUaJ9Q/be1YfjvHxnhzCc9Z wP+lQUr9x8GyH6A6M6wK0KLiqtRTuJpm9yJbnq/766aKWyBv3Ex6BaeVAbR8jNGFszTH czDoWJYT7wg1kuWmMAzdojwG7FJXKY8jI98nmY1PqXSnjt3i0zl9DINh7T+a9F58we1H uK1Q== 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=xrfdfKGDWIEkJ+syWQznXDqW3LBPzTMgtG17CCJwMh0=; b=FIQJP8grA6BZ/ZOoy+sZKxA6mCOGLoTdE7yAfsmj2QITZN8yxQ+Og5kP1pYzCZzQPw g8P9pbQPnZ+M8o17qkMHiE7wyFtWW0GNHq3dT9xMIaO2oOezF4hOwpuwKPCMCSTrxA0P vGnNe0MYwZqK5CHxUxFL4Ry/rSHpjWbk2NsEFm0GKhtPqDzZLCq2ktHeq5YUh2YOmIbz j+dMJi86uLwhdC/DIFdyI1DYZONxmkqQJ+BsbLtYfe/xVP4/J70WWZTV9EbCFq3pKRzu pxV5nOmVaNg4O2mg6Ifbc82Pv5oLskpug6d8KzkLusIMCn7RmzO/qyyFEg2QYpPKupJH IReA== X-Gm-Message-State: AJcUukekME1eCrsXKRypNLPVCtvCgQ2rGjskjs96YnZPHDh/gW2rw1yo vD9FVQsa4bAzMzrigaKZFt46l3tn X-Google-Smtp-Source: ALg8bN7/Q0CLWbRyESirFNH6GT0/HKC9Gf2NTI4qtVP2Z3AqCVleefvGwX77gi//xbucHkJ4qTwVkw== X-Received: by 2002:a63:9c1a:: with SMTP id f26mr15052005pge.381.1548549411320; Sat, 26 Jan 2019 16:36:51 -0800 (PST) Received: from ash ([115.72.21.220]) by smtp.gmail.com with ESMTPSA id u123sm40728870pfb.1.2019.01.26.16.36.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jan 2019 16:36:50 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Sun, 27 Jan 2019 07:36:46 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 09/14] diff.h: avoid bit fields in struct diff_flags Date: Sun, 27 Jan 2019 07:35:30 +0700 Message-Id: <20190127003535.28341-10-pclouds@gmail.com> X-Mailer: git-send-email 2.20.1.560.g70ca8b83ee In-Reply-To: <20190127003535.28341-1-pclouds@gmail.com> References: <20190127003535.28341-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 Signed-off-by: Junio C Hamano --- diff.h | 66 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/diff.h b/diff.h index c872a41344..8abe1649d0 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 Sun Jan 27 00:35:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10782657 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 A585E6C2 for ; Sun, 27 Jan 2019 00:36:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94E982C808 for ; Sun, 27 Jan 2019 00:36:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8867C2C80B; Sun, 27 Jan 2019 00:36: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 1C0D42C808 for ; Sun, 27 Jan 2019 00:36:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726517AbfA0Ag6 (ORCPT ); Sat, 26 Jan 2019 19:36:58 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:43559 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726262AbfA0Ag5 (ORCPT ); Sat, 26 Jan 2019 19:36:57 -0500 Received: by mail-pg1-f193.google.com with SMTP id v28so5679247pgk.10 for ; Sat, 26 Jan 2019 16:36: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=isWG9ZriEGn5qe342uz4xnWoSDM51oIhOnodE4SUTZk=; b=T6d1LUvHBW5I3KvnqcgqamEz2Q4Kb4+TwSLX4nLm35YCpajnV5C+k/XjRSW58bmchz WzwZOK65OiNO8aTaNhAGGsX97kFihfraryQfF7g3ImOzTArbrwXhpPRCvwvTm3591FR4 BgP0xBe4swMIMeoTJOY8PaTqiVA1eoEpETpcZaqkG473uRMwlFSeVo/UIFplb7S4/mth uKEcQIw0f6S3fqSzBeLRZtmCaF1bCpSSxzEeGx9rEk1jn/jOPYWIGKfJjRRT4e0SIUoq tdXuZpaWTlFt2iT9pzI2Z4qlRFqqW+tcetg7hfo6vIEWSamvmXIC8gz0Ujur8I1vq+mP 5eFQ== 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=isWG9ZriEGn5qe342uz4xnWoSDM51oIhOnodE4SUTZk=; b=FvsRfHb9q/t9kgQdjBbmCCspCruG91jeYrEHPJioAxf097Q7SNOk6aPeIbpp1L9Hf+ FqjxoD/ZWR75zXB25AsJ/ee0YR1VbwSGDJBWnhaFBG6fOG1pYHZmNnmElDPXAqwTOjZ6 v0ZQl0e7sSwr4YjLvdgNYQcluUfe+pzEurH6jZ9ao7L8QUdCLkCNO425us0HlXmN4VfT GAsa8UTLwYpOLEKWfuov/xPl47yFGLzUdsHzQTo6SNWeXNVYvvQLPOshCsU5/O6UiTBi StNT0OpA6ZIBP/4nA7e3DSTJYTBjuuT2FunCFmCFeYeWd+r2/fe5GOCsWcz3/udFhfpT MmnA== X-Gm-Message-State: AJcUukcv7jxTaYmekazO7Xi4sFqu31RlDMzydhfqIq1DmJs7gUZxCkd0 xpcL7h3LCmH/ye6MeGrNGtd6PWSx X-Google-Smtp-Source: ALg8bN7jI8kmx+HQr9ICudY1FUU7Rzn1FGInYDocg43/O8jknWfQtDsqrwMbp6vA2O295IT6jPGdcg== X-Received: by 2002:a62:5b44:: with SMTP id p65mr16444900pfb.47.1548549416577; Sat, 26 Jan 2019 16:36:56 -0800 (PST) Received: from ash ([115.72.21.220]) by smtp.gmail.com with ESMTPSA id l3sm41997904pga.92.2019.01.26.16.36.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jan 2019 16:36:55 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Sun, 27 Jan 2019 07:36:51 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 10/14] diff.c: prepare to use parse_options() for parsing Date: Sun, 27 Jan 2019 07:35:31 +0700 Message-Id: <20190127003535.28341-11-pclouds@gmail.com> X-Mailer: git-send-email 2.20.1.560.g70ca8b83ee In-Reply-To: <20190127003535.28341-1-pclouds@gmail.com> References: <20190127003535.28341-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 Signed-off-by: Junio C Hamano --- diff.c | 27 +++++++++++++++++++++++++++ diff.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/diff.c b/diff.c index 1b5f276360..80b4af23d7 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 @@ -4425,6 +4426,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)); @@ -4466,6 +4469,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) @@ -4569,6 +4574,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) @@ -4860,6 +4867,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) { @@ -4870,6 +4887,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 8abe1649d0..d9ad73f0e1 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 Sun Jan 27 00:35:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10782659 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 725FA13B4 for ; Sun, 27 Jan 2019 00:37:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 606C22C808 for ; Sun, 27 Jan 2019 00:37:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 524C62C80B; Sun, 27 Jan 2019 00:37:04 +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 EFC0B2C808 for ; Sun, 27 Jan 2019 00:37:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726523AbfA0AhD (ORCPT ); Sat, 26 Jan 2019 19:37:03 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:43067 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726262AbfA0AhC (ORCPT ); Sat, 26 Jan 2019 19:37:02 -0500 Received: by mail-pf1-f195.google.com with SMTP id w73so6351760pfk.10 for ; Sat, 26 Jan 2019 16:37: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=6P34m5nuc80QMYbxc14caHHZxpjLY+GCJR7IZrfgd7Y=; b=BhIw+eFj54KFRdzoSSp8qVQif2t9aXkDwiXKFCL1cCnUrXlY7OzNsmJ6UMXunw7iQy 2IUmsEX+UGphPaUTAvE32dTObca+7g2uZ5KtIvzS4ZlkNYBMzcD7PAi1dU8h4gDC3GnB LsEIbs4w19zMppBakjGD5d/RzFNa3OaBQWV4PdBsr9sS201fg42/gWpH6w0N0js+xPpJ l2FyHFAH0BtN/ao+qRFPgJDbxcMexm2p0gm2CxI/GAuPCgo97odKN2Y7qEfbdqd/idNA Q+sP5ovIKdUQPMQ2CozDJOF39HthWMelXtwHzaW9OTvki3dWPb/wxBhqTeR6+qY+JuTF emvQ== 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=6P34m5nuc80QMYbxc14caHHZxpjLY+GCJR7IZrfgd7Y=; b=TP+ev3EDgzj92R8i2dmEY2N/IZGGINS/UUMPBdYmp9uRIu+LdhGppsZw4V5uQJfZMC 75rpx9yEsgdjRrFLFGTVZGymCpQUelivhj+Qu/12tsKhIr9wGaC/iHVwRAfjwlFT+tot DHUiIvkq5Cd+TzIQjXicL55SzmzKlIE0pq2j/YNIisz1fb8FTLQ/gKyNWw8NguDgy+nS +yI5nGNkZcCEsMTbYQG2s95QyKKcyW5bjqycXFMNRJPTCirvdEXqrl9bL2NGJ8r3ig9s t9w9uMBuejKFHKEznE1zaBhLo5T9Asbjv49q/MlJ5ejXef+fArXlwYxxkoHO1l6C3tDS Hsuw== X-Gm-Message-State: AJcUukd4c4tezD90cq8ax/IQuXaeMzywU4085p+VVy1HLL27SUzfp8TL TJkK1yWB1eibyg5KBvn/cbSSD4kt X-Google-Smtp-Source: ALg8bN7xpnaXj8O5J5/rVv2V78HWPdV2ni918zjhhKd9X+UfDIfOgc/hqdEEvTa/WlC2tMw1f3Rgqg== X-Received: by 2002:a62:9111:: with SMTP id l17mr16628195pfe.200.1548549421750; Sat, 26 Jan 2019 16:37:01 -0800 (PST) Received: from ash ([115.72.21.220]) by smtp.gmail.com with ESMTPSA id b27sm37107025pfh.113.2019.01.26.16.36.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jan 2019 16:37:01 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Sun, 27 Jan 2019 07:36:56 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 11/14] diff.c: convert -u|-p|--patch Date: Sun, 27 Jan 2019 07:35:32 +0700 Message-Id: <20190127003535.28341-12-pclouds@gmail.com> X-Mailer: git-send-email 2.20.1.560.g70ca8b83ee In-Reply-To: <20190127003535.28341-1-pclouds@gmail.com> References: <20190127003535.28341-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 Signed-off-by: Junio C Hamano --- diff.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/diff.c b/diff.c index 80b4af23d7..a4a40e4aa8 100644 --- a/diff.c +++ b/diff.c @@ -4870,6 +4870,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() }; @@ -4898,8 +4905,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 Sun Jan 27 00:35:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10782661 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 EE79D13B4 for ; Sun, 27 Jan 2019 00:37:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF8072C13A for ; Sun, 27 Jan 2019 00:37:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D43722C80B; Sun, 27 Jan 2019 00:37:09 +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 56B412C13A for ; Sun, 27 Jan 2019 00:37:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726551AbfA0AhI (ORCPT ); Sat, 26 Jan 2019 19:37:08 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:45187 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726262AbfA0AhH (ORCPT ); Sat, 26 Jan 2019 19:37:07 -0500 Received: by mail-pf1-f193.google.com with SMTP id g62so6348811pfd.12 for ; Sat, 26 Jan 2019 16:37:07 -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=fhoF58I9lMut1AS4XvKN9biwYIqyd+/9sY10TF4bwLs=; b=DcYgxpEvWYxX0BGVxupeqW3YZIA8c4XU8+fvHPdc9emP0xTeqoyu+8b2tu/3yqwtpS 7hpxBBZM56nishqiERUFrZOU0tss239Y1gsbMJxrySse62dBWY7zRFf64Gou6hKw0Pq2 ni6itEm+DuBC+JhRRDG4EeLiiKV54HGcMsBLDRGGNIXr/vb2k2WuD5FNe9EjVZ1iKGYZ QCpHnOmmB5zXYoCkJCOnY1P5IV9myulzcmvNraFr+q84twVeS9sdoiRl1dIU147/8cA+ 6Qr4THyzrpyMRP6Bib/ew/TLk3mIERBnGCeRzefQ/w1wDQ13QZxypMLNNLy3WePHaq/s ZpMg== 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=fhoF58I9lMut1AS4XvKN9biwYIqyd+/9sY10TF4bwLs=; b=gOwp1oCX6owqtlDFiW8Z221719cbAu8XMaNzEuozxlywjXLHIfVFYyTKHM1ULIigJa qwPCDABqRbLT1elcwSXFivn6L3VFAh7y/hBZUrozPT0arPGGhuDN/iOtvq0SIwzT86b4 OoUuTwrBiAOlq57OXVGB02+zwVdp7RW45hmBNVAU0LF6HyAj1WPkkhO5ovNDeMR+FrUy 6zVPwHxqkTfeDPdOMPymx7LMbTvOqdjw769u9nIAnpfNwIJY1x8wybY7u/x0id8BCPTQ ePiqXDu6HKkdap7UonHxG1rBt4gTNfXi4OOZOQ/Wg1GVJ/R7vRR4JPmg4ArkDA2rBGf4 9xgg== X-Gm-Message-State: AJcUukfZ9cgEFNTf97pqzpf+vF/CiloqsRpVBg0um37K4i58GA3SnnWx s2iTU4TlT/MuF4yh2vxg4gX5U0s5 X-Google-Smtp-Source: ALg8bN7+h4R7/DCmuSPHFXv9d96r1BRUCEZDypdebEEzb2v1GkHFMqb6rmUbiVCthZDU54foP3N4vA== X-Received: by 2002:a65:448a:: with SMTP id l10mr15018185pgq.387.1548549426975; Sat, 26 Jan 2019 16:37:06 -0800 (PST) Received: from ash ([115.72.21.220]) by smtp.gmail.com with ESMTPSA id m65sm68163048pfg.180.2019.01.26.16.37.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jan 2019 16:37:06 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Sun, 27 Jan 2019 07:37:02 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 12/14] diff.c: convert -U|--unified Date: Sun, 27 Jan 2019 07:35:33 +0700 Message-Id: <20190127003535.28341-13-pclouds@gmail.com> X-Mailer: git-send-email 2.20.1.560.g70ca8b83ee In-Reply-To: <20190127003535.28341-1-pclouds@gmail.com> References: <20190127003535.28341-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 Signed-off-by: Junio C Hamano --- Documentation/diff-options.txt | 2 +- diff.c | 23 ++++++++++++++++++++--- parse-options.h | 5 +++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt index b94d332f71..0711734b12 100644 --- a/Documentation/diff-options.txt +++ b/Documentation/diff-options.txt @@ -36,7 +36,7 @@ endif::git-format-patch[] -U:: --unified=:: Generate diffs with lines of context instead of - the usual three. + the usual three. Implies `--patch`. ifndef::git-format-patch[] Implies `-p`. endif::git-format-patch[] diff --git a/diff.c b/diff.c index a4a40e4aa8..093158244e 100644 --- a/diff.c +++ b/diff.c @@ -4867,6 +4867,22 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg) return 1; } +static int diff_opt_unified(const struct option *opt, + const char *arg, int unset) +{ + struct diff_options *options = opt->value; + char *s; + + BUG_ON_OPT_NEG(unset); + + options->context = strtol(arg, &s, 10); + if (*s) + return error(_("%s expects a numerical value"), "--unified"); + enable_patch_output(&options->output_format); + + return 0; +} + static void prep_parse_options(struct diff_options *options) { struct option parseopts[] = { @@ -4877,6 +4893,9 @@ static void prep_parse_options(struct diff_options *options) OPT_BITOP('u', NULL, &options->output_format, N_("generate patch"), DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT), + OPT_CALLBACK_F('U', "unified", options, N_(""), + N_("generate diffs with lines context"), + PARSE_OPT_NONEG, diff_opt_unified), OPT_END() }; @@ -4905,9 +4924,7 @@ int diff_opt_parse(struct diff_options *options, return ac; /* Output format options */ - if (opt_arg(arg, 'U', "unified", &options->context)) - enable_patch_output(&options->output_format); - else if (!strcmp(arg, "--raw")) + if (!strcmp(arg, "--raw")) options->output_format |= DIFF_FORMAT_RAW; else if (!strcmp(arg, "--patch-with-raw")) { enable_patch_output(&options->output_format); diff --git a/parse-options.h b/parse-options.h index ce75278804..7d83e2971d 100644 --- a/parse-options.h +++ b/parse-options.h @@ -134,6 +134,8 @@ struct option { #define OPT_SET_INT_F(s, l, v, h, i, f) { OPTION_SET_INT, (s), (l), (v), NULL, \ (h), PARSE_OPT_NOARG | (f), NULL, (i) } #define OPT_BOOL_F(s, l, v, h, f) OPT_SET_INT_F(s, l, v, h, 1, f) +#define OPT_CALLBACK_F(s, l, v, a, h, f, cb) \ + { OPTION_CALLBACK, (s), (l), (v), (a), (h), (f), (cb) } #define OPT_END() { OPTION_END } #define OPT_ARGUMENT(l, h) { OPTION_ARGUMENT, 0, (l), NULL, NULL, \ @@ -164,8 +166,7 @@ struct option { #define OPT_EXPIRY_DATE(s, l, v, h) \ { OPTION_CALLBACK, (s), (l), (v), N_("expiry-date"),(h), 0, \ parse_opt_expiry_date_cb } -#define OPT_CALLBACK(s, l, v, a, h, f) \ - { OPTION_CALLBACK, (s), (l), (v), (a), (h), 0, (f) } +#define OPT_CALLBACK(s, l, v, a, h, f) OPT_CALLBACK_F(s, l, v, a, h, 0, f) #define OPT_NUMBER_CALLBACK(v, h, f) \ { OPTION_NUMBER, 0, NULL, (v), NULL, (h), \ PARSE_OPT_NOARG | PARSE_OPT_NONEG, (f) } From patchwork Sun Jan 27 00:35:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10782663 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 CD0CF6C2 for ; Sun, 27 Jan 2019 00:37:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE7902C13A for ; Sun, 27 Jan 2019 00:37:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2C0D2C80B; Sun, 27 Jan 2019 00:37:14 +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 603AB2C13A for ; Sun, 27 Jan 2019 00:37:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726566AbfA0AhN (ORCPT ); Sat, 26 Jan 2019 19:37:13 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:33400 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726262AbfA0AhN (ORCPT ); Sat, 26 Jan 2019 19:37:13 -0500 Received: by mail-pg1-f194.google.com with SMTP id z11so5700698pgu.0 for ; Sat, 26 Jan 2019 16:37:12 -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=Z7/yffbZEYRhL1j5hnz2u6xv+0/q5E6LNrZ0OYhcoug=; b=b+zhc68nrODG+cv5inSwWYKPEyMLIDXMQeYmSfVi1V3Wz4xF0B8G+1Kz+u7I9Kt4pS wEl4XDYfd6NX6nIahms1FnTqu9vL9EFPyD8uABubTaQFNdQcVL6rKM3QRP1ql16XPlzG ZtShaYqZsoc0/+BMf/OwRO9TnICYTgEPnGJyAhL0sOReiaKq0ofsrnltGnquZCrfS/LA W9aVZBRNakl3Wu2T0F4qfW2p35ombEd4ZRhf01d5JJ7133CppHyJuPRU/CiT19auYL9+ JUi1pvIh0qVutyyoaXfiGx+DcuhuP/H5nccbK36EHFKxOpS6o0/PiveDuZpToG2ILKbh byUg== 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=Z7/yffbZEYRhL1j5hnz2u6xv+0/q5E6LNrZ0OYhcoug=; b=VQvoNZ9UQxW1aZW62+qQxlnMhd5uHAtpq4Y/bjv1eMAsOlCHG88I0UkoXxuhSHI41C 7lVTMCv7R5ZOZgeZZVtZKQuP4ff+nkwDHCOIpWBZL4LvWWfo9urXtsKpt/ateRTR+0UK leL3QT0nRPvjY8RHq48onBtUTbkUcoAt0QUwemLOlmPleR1m/Rh9hST8vxzKSGmAkvvm 0BTiE+PGEqP0KZF6fT1sOeK8eemgoqr9ByXz9eZ0cvP8/1r8NbQlmlDBvtgFXmn5lkt7 K1054IgRtIG4x80U9eEjgSHY3PvHN69ASeWtTINMNGiUK4LbIxsFxviNbQqGw9l7EdIx s69Q== X-Gm-Message-State: AJcUukfsST4BI8O5knKWWpgEAIeVKBGAXawGby6zliVHU88UIRw+lKwZ IZFd7tfvQczOiqzLlXBYXIlXWIt0 X-Google-Smtp-Source: ALg8bN5rBUQlSnrQEC3d6PvuXGqjAqW+CLFCfU5S75H1jnwhZqYfGadS21UgyA4O6VMGF49RgclBDw== X-Received: by 2002:a63:da14:: with SMTP id c20mr14266784pgh.233.1548549432163; Sat, 26 Jan 2019 16:37:12 -0800 (PST) Received: from ash ([115.72.21.220]) by smtp.gmail.com with ESMTPSA id g136sm38121759pfb.154.2019.01.26.16.37.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jan 2019 16:37:11 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Sun, 27 Jan 2019 07:37:07 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 13/14] diff.c: convert -W|--[no-]function-context Date: Sun, 27 Jan 2019 07:35:34 +0700 Message-Id: <20190127003535.28341-14-pclouds@gmail.com> X-Mailer: git-send-email 2.20.1.560.g70ca8b83ee In-Reply-To: <20190127003535.28341-1-pclouds@gmail.com> References: <20190127003535.28341-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 Signed-off-by: Junio C Hamano --- diff.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/diff.c b/diff.c index 093158244e..8f70101362 100644 --- a/diff.c +++ b/diff.c @@ -4896,6 +4896,8 @@ static void prep_parse_options(struct diff_options *options) OPT_CALLBACK_F('U', "unified", options, N_(""), N_("generate diffs with lines context"), PARSE_OPT_NONEG, diff_opt_unified), + OPT_BOOL('W', "function-context", &options->flags.funccontext, + N_("generate diffs with lines context")), OPT_END() }; @@ -5212,12 +5214,6 @@ int diff_opt_parse(struct diff_options *options, else if (opt_arg(arg, '\0', "inter-hunk-context", &options->interhunkcontext)) ; - else if (!strcmp(arg, "-W")) - options->flags.funccontext = 1; - else if (!strcmp(arg, "--function-context")) - options->flags.funccontext = 1; - else if (!strcmp(arg, "--no-function-context")) - options->flags.funccontext = 0; else if ((argcount = parse_long_opt("output", av, &optarg))) { char *path = prefix_filename(prefix, optarg); options->file = xfopen(path, "w"); From patchwork Sun Jan 27 00:35:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10782665 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 F35036C2 for ; Sun, 27 Jan 2019 00:37:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E376D2C13A for ; Sun, 27 Jan 2019 00:37:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D80622C80B; Sun, 27 Jan 2019 00:37:19 +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 78F562C13A for ; Sun, 27 Jan 2019 00:37:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726589AbfA0AhS (ORCPT ); Sat, 26 Jan 2019 19:37:18 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:40712 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726262AbfA0AhS (ORCPT ); Sat, 26 Jan 2019 19:37:18 -0500 Received: by mail-pf1-f193.google.com with SMTP id i12so6362602pfo.7 for ; Sat, 26 Jan 2019 16:37:17 -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=sh2SzhnBPZvr+Fjr05yLP6SyI9u1WEtTh3FN2UE1lzE=; b=qekmv1Je6PhD8+rPjL3pYNw62kIRSGKrSc3D/tX67xhj/f5Hf6MIt8dmj6hNq8+S4y WBw60u50/LGR/r9Hg0E8+k76G1VTz/9EhiYBj5kKFePKoTV9a3DNWG4r08PL6GB4NEVV UGbByN6cD2IcN7A3RJffXAFEtu35kV0hCVIMcaLVBhyALbulkkGvMwUy8qUvId3IDg9C Yf5BCFCOHk+KJpr9BsmcyVj+VIdyPUrQtpGHbwq0b5tFldplna0MyUZ8/eQXyuicScrz wLjBXWqHe+GuoRhS1+AVEK1aaLVZjYcYT5o/el/2hBF3HiVOAkUsRNqYHjQdFsxwwVHL 2KTA== 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=sh2SzhnBPZvr+Fjr05yLP6SyI9u1WEtTh3FN2UE1lzE=; b=kEX9pz68MeyxRkPrgXWROeKQJ+1Crufjwc93sX8z1t2DH6ESMdxz8uquSy/XheGJWg OYpjrI8/95b0C5PS4Jv00STf2dxCEyjgWNzK2xuSRhEkdszHOwZdUqNwfztrlOz5Z19k AdlyNxR5PYodBw/2tGcLC+LzCYb6vIgYCT06PRG09fxGc4jyOg9zvIv2kW4YxMSVeM+6 lZD4Us70m6gW+fuNm50Tr8e65o8IERRhHffG7TjQgeOA/f0JlDDE6iB5xhACbwceHMIC G86VtlU0WfHykNiBhZ12IBGs9WMb2EqrTpIGBZQjjDRV0XLrlIPG7TJUymx3aWJaBArA Arww== X-Gm-Message-State: AJcUukfK9sA+1vRQXf865ibpkKJrwdPCwr/EH379tr7+1rZQt7bxktoq Bv+spw1DY2xSgVmpQ4CIGfycYrV8 X-Google-Smtp-Source: ALg8bN4fkXqKzCzI2zecAA4ecryyDi62lkE7sccF818se+Ho2U6PyQTH0NEZpE9nt/MYKu0JuQL2sg== X-Received: by 2002:a62:7dcb:: with SMTP id y194mr16743114pfc.113.1548549437419; Sat, 26 Jan 2019 16:37:17 -0800 (PST) Received: from ash ([115.72.21.220]) by smtp.gmail.com with ESMTPSA id b7sm38727273pfa.52.2019.01.26.16.37.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jan 2019 16:37:16 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Sun, 27 Jan 2019 07:37:12 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: Stefan Beller , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 14/14] diff.c: convert --raw Date: Sun, 27 Jan 2019 07:35:35 +0700 Message-Id: <20190127003535.28341-15-pclouds@gmail.com> X-Mailer: git-send-email 2.20.1.560.g70ca8b83ee In-Reply-To: <20190127003535.28341-1-pclouds@gmail.com> References: <20190127003535.28341-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 Signed-off-by: Junio C Hamano --- diff.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/diff.c b/diff.c index 8f70101362..4bc9df7362 100644 --- a/diff.c +++ b/diff.c @@ -4898,6 +4898,9 @@ static void prep_parse_options(struct diff_options *options) PARSE_OPT_NONEG, diff_opt_unified), OPT_BOOL('W', "function-context", &options->flags.funccontext, N_("generate diffs with lines context")), + OPT_BIT_F(0, "raw", &options->output_format, + N_("generate the diff in raw format"), + DIFF_FORMAT_RAW, PARSE_OPT_NONEG), OPT_END() }; @@ -4926,9 +4929,7 @@ int diff_opt_parse(struct diff_options *options, return ac; /* Output format options */ - if (!strcmp(arg, "--raw")) - options->output_format |= DIFF_FORMAT_RAW; - else if (!strcmp(arg, "--patch-with-raw")) { + if (!strcmp(arg, "--patch-with-raw")) { enable_patch_output(&options->output_format); options->output_format |= DIFF_FORMAT_RAW; } else if (!strcmp(arg, "--numstat"))