From patchwork Thu Mar 7 09:58:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10842533 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 4C8161575 for ; Thu, 7 Mar 2019 09:58:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38E262E6AC for ; Thu, 7 Mar 2019 09:58:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D4BC2E7EE; Thu, 7 Mar 2019 09:58:41 +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 AB36F2E6AC for ; Thu, 7 Mar 2019 09:58:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726254AbfCGJ6j (ORCPT ); Thu, 7 Mar 2019 04:58:39 -0500 Received: from mail-pf1-f181.google.com ([209.85.210.181]:37630 "EHLO mail-pf1-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725795AbfCGJ6i (ORCPT ); Thu, 7 Mar 2019 04:58:38 -0500 Received: by mail-pf1-f181.google.com with SMTP id s22so11037218pfh.4 for ; Thu, 07 Mar 2019 01:58:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=g3dlSD/5UcPU+iH3xviy5+63lSKvMmzaL/HXMiUyTz0=; b=FgXMp2yjdBGaZz49SF8SfVgq/C9GV9VTPLmzQrT76GFdA/O877m2T5L6EX5/ucnQa2 Qtffrlgzb+Zpq7McCEdnWYQfs0a7zKI977oHsJWg6jzKwqeYq63eLJ1dPsYgWbFsN/r8 Fot3mfJsR8+Hidp2baJoYR8E4WXzJXSBn4hmWtgqUFiudj2sIe8nU19NnPKQdgKkFe1I 4WypS+bBaQUSh1WokLHmWLFrYVlK2mC2sF2Heirl3GtKYXVb8uaJeR2SCrnUaQ0DjKDZ jn+Pb1vPS5a2RGA1FbP0HFO7PoWUnHcl3Phm3u32Di6BYVzaYReOfmSqeDKy0/UC0i0D RWFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=g3dlSD/5UcPU+iH3xviy5+63lSKvMmzaL/HXMiUyTz0=; b=f2t7/8XTiBZKQsHTP/5wvm72O9g68H7Al17gxrJhUxi3hO8HV8QPMpwliLJ66OjZfB mKi39MLeK4bVj35Gwo+EZl3Yk2VOMQatcKa+olN0yP47aRZe40iPTMyeNVcDAxdocSgJ AEO0uCdEyWk3Q5IsLqijCqG6MSHFOwCa8pCSeQodlzyMHHwtAjVZYzL36k5bE8dNMq8y D9NkulehYkx2Q9eUI/5IfNXNJe5zqfxBhOcteobNFbipGmQ+fjWwl7DXufE0muPGUZrd CgMwgZwEzTtRm9drp2rV+ZGmz7JTOjYdLCe3WsxdLugYvGFOFYRyujoeLcLOY1z6e7Fd 44EA== X-Gm-Message-State: APjAAAVM+dMFNS6luN72sz9apd2s4/9FkS5i5mT2p5XoS16O7jBSReqc fXP/GGK8q3o8txC0uUXnLHYFV9cj X-Google-Smtp-Source: APXvYqw9Ea1+zZzBTmMBdR7mn65sFa25yGsfmy+C0aeCrMIR6km5UdVHaGTOdakMsFAC2lFb9V/IIg== X-Received: by 2002:a62:1bd4:: with SMTP id b203mr11825704pfb.144.1551952717388; Thu, 07 Mar 2019 01:58:37 -0800 (PST) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id k7sm1931402pgo.60.2019.03.07.01.58.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Mar 2019 01:58:36 -0800 (PST) Date: Thu, 7 Mar 2019 01:58:35 -0800 From: Denton Liu To: Git Mailing List Cc: Phillip Wood , Junio C Hamano Subject: [PATCH v3 4/4] sequencer.c: don't die on invalid cleanup_arg Message-ID: <68ec2b7cd7457e9bcd3f6f211774457c73ef8646.1551951770.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When get_cleanup_mode was provided with an invalid cleanup_arg, it used to die. Warn user and fallback to default behaviour if an invalid cleanup_arg is given. Signed-off-by: Denton Liu --- builtin/commit.c | 2 +- builtin/merge.c | 4 ++-- builtin/revert.c | 2 +- sequencer.c | 10 +++++++--- sequencer.h | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 43291d79bd..0072a5817a 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1167,7 +1167,7 @@ static int parse_and_validate_options(int argc, const char *argv[], die(_("Only one of --include/--only/--all/--interactive/--patch can be used.")); if (argc == 0 && (also || (only && !amend && !allow_empty))) die(_("No paths with --include/--only does not make sense.")); - cleanup_mode = get_cleanup_mode(cleanup_arg, use_editor); + cleanup_mode = get_cleanup_mode(cleanup_arg, use_editor, 1); handle_untracked_files_arg(s); diff --git a/builtin/merge.c b/builtin/merge.c index d4217ebcf5..3b597ec540 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -916,7 +916,7 @@ static int suggest_conflicts(void) * Thus, we will get the cleanup mode which is returned when we _are_ using * an editor. */ - append_conflicts_hint(&msgbuf, get_cleanup_mode(cleanup_arg, 1)); + append_conflicts_hint(&msgbuf, get_cleanup_mode(cleanup_arg, 1, 1)); fputs(msgbuf.buf, fp); strbuf_release(&msgbuf); fclose(fp); @@ -1424,7 +1424,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) if (option_edit < 0) option_edit = default_edit_option(); - cleanup_mode = get_cleanup_mode(cleanup_arg, 0 < option_edit); + cleanup_mode = get_cleanup_mode(cleanup_arg, 0 < option_edit, 1); if (!use_strategies) { if (!remoteheads) diff --git a/builtin/revert.c b/builtin/revert.c index fe18036be7..a96f2ecd8a 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -139,7 +139,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) opts->allow_empty = 1; if (cleanup_arg) - opts->default_msg_cleanup = get_cleanup_mode(cleanup_arg, 1); + opts->default_msg_cleanup = get_cleanup_mode(cleanup_arg, 1, 1); /* Check for incompatible command line arguments */ if (cmd) { diff --git a/sequencer.c b/sequencer.c index 5c04bae7ac..7d18c55223 100644 --- a/sequencer.c +++ b/sequencer.c @@ -170,7 +170,7 @@ static int git_sequencer_config(const char *k, const char *v, void *cb) if (status) return status; - opts->default_msg_cleanup = get_cleanup_mode(s, !is_rebase_i(opts)); + opts->default_msg_cleanup = get_cleanup_mode(s, !is_rebase_i(opts), 0); free((char *)s); return status; @@ -488,7 +488,7 @@ static int fast_forward_to(const struct object_id *to, const struct object_id *f } enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg, - int use_editor) + int use_editor, int die_on_error) { if (!cleanup_arg || !strcmp(cleanup_arg, "default")) return use_editor ? COMMIT_MSG_CLEANUP_ALL : @@ -502,7 +502,11 @@ enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg, else if (!strcmp(cleanup_arg, "scissors")) return use_editor ? COMMIT_MSG_CLEANUP_SCISSORS : COMMIT_MSG_CLEANUP_SPACE; - else + else if (!die_on_error) { + warning(_("Invalid cleanup mode %s, falling back to default"), cleanup_arg); + return use_editor ? COMMIT_MSG_CLEANUP_ALL : + COMMIT_MSG_CLEANUP_SPACE; + } else die(_("Invalid cleanup mode %s"), cleanup_arg); } diff --git a/sequencer.h b/sequencer.h index aa99503dd7..c4c80051ea 100644 --- a/sequencer.h +++ b/sequencer.h @@ -94,7 +94,7 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag); void append_conflicts_hint(struct strbuf *msgbuf, enum commit_msg_cleanup_mode cleanup_mode); enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg, - int use_editor); + int use_editor, int die_on_error); void cleanup_message(struct strbuf *msgbuf, enum commit_msg_cleanup_mode cleanup_mode, int verbose);