From patchwork Thu Feb 23 20:55:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13150761 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A9EBC677F1 for ; Thu, 23 Feb 2023 20:55:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229632AbjBWUzJ (ORCPT ); Thu, 23 Feb 2023 15:55:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229504AbjBWUzH (ORCPT ); Thu, 23 Feb 2023 15:55:07 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B37514EBD for ; Thu, 23 Feb 2023 12:55:05 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id r7so11657311wrz.6 for ; Thu, 23 Feb 2023 12:55:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=WNw93lSd/GN1jkFYpBRUhEcbTdpObtt4fiCmOmMjZ/c=; b=LD3MgQSMi5SGP1L3agt7Q6AtN2EDExyuM54DB/j1hxoZi65dXJkjiS3FV/ymL7PhZd 0niVgrhKZ6eVaGxIRNowy/zzIpaly4k4CSTW/s6hVc8wP1ZmfUFQPHyA2yxFtXOzGeR/ RXy2i975KepEZUwIVHLstH0lS59PL0Ihix1ca03Mzq8rCSxJzWfWUNMY0CMj57bHW21W sYYUQzleeITgrpCqlkKmbizpsdKTikGq8/48q6eTjdQXXOBFhGhu+nPVm1ILqpTGGhS2 p4oDydLMyLT+Xp3C+Tgpka4EanwVEnLb5syQy23sLDvlYcSFFvijXPfmou+K1H7Nkj/B pdlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WNw93lSd/GN1jkFYpBRUhEcbTdpObtt4fiCmOmMjZ/c=; b=7lN9B2yrjWUVkXf7lHy5jEVx5655f0tlrIa0/GQNSpTpvdeVaSQLEeswrXo/iaUKOd zX78YNe1JJzrwEjpXdeMXdyCa5KfyL+ofsMV7R9g6LrxiVd570ZJYfQM+cZJbE5yIGcf ZhYPoQ6VtemH1OvyMyomt5b1MSkuV7lxzA74IL9IkVY30V0r+TXSTfYC4m1TKOda/c8z dVAtZkBittDHoe0Q4OlnSdNMFpxrMuqIWGHLs8qndmc8gnCDjnDjiABUxYA2LHnmLJpc iwp2uFbwl+A2C7RmWbH3gKl+XA6zt0ol83PCMlP439eNd1ds9g03Vw/ZcL/1bfGJIozz efpQ== X-Gm-Message-State: AO0yUKX/+tw9IxzMW1QVJvK5dJJF4oTefAyK7UUoSSBX/TupyfbexXoD DEPBCa/oAOQAD5IUFx7+2lyBD8G6wzE= X-Google-Smtp-Source: AK7set8VQHRxcRMujPDELBpWLoySf8qpZcp/aZhYXNmuezz75PHhIFX0FCMORz7GQsTJJ9km8UIonw== X-Received: by 2002:adf:efca:0:b0:2bf:b92b:8a8a with SMTP id i10-20020adfefca000000b002bfb92b8a8amr12895493wrp.7.1677185703747; Thu, 23 Feb 2023 12:55:03 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c4-20020adffb04000000b002c54241b4fesm1771130wrr.80.2023.02.23.12.55.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 12:55:03 -0800 (PST) Message-Id: In-Reply-To: References: Date: Thu, 23 Feb 2023 20:55:00 +0000 Subject: [PATCH 1/2] rebase -i: match whole word in is_command() Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood When matching an unabbreviated command is_command() only does a prefix match which means it parses "pickled" as TODO_PICK. parse_insn_line() does error out because is_command() only advances as far as the end of "pick" so it looks like the command name is not followed by a space but the error message is "missing arguments for pick" rather than telling the user that the "pickled" is not a valid command. Fix this by ensuring the match is follow by whitespace or the end of the string as we already do for abbreviated commands. The (*bol = p) at the end of the condition is a bit cute for my taste but I decided to leave it be for now. Rather than add new tests the existing tests for bad commands are adapted to use a bad command name that triggers the prefix matching bug. Signed-off-by: Phillip Wood --- sequencer.c | 12 ++++++------ t/lib-rebase.sh | 2 +- t/t3404-rebase-interactive.sh | 12 +++++++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/sequencer.c b/sequencer.c index 65a34f9676c..d19ee189b57 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2479,12 +2479,11 @@ static int is_command(enum todo_command command, const char **bol) { const char *str = todo_command_info[command].str; const char nick = todo_command_info[command].c; - const char *p = *bol + 1; + const char *p = *bol; - return skip_prefix(*bol, str, bol) || - ((nick && **bol == nick) && - (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || !*p) && - (*bol = p)); + return (skip_prefix(p, str, &p) || (nick && *p++ == nick)) && + (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || !*p) && + (*bol = p); } static int parse_insn_line(struct repository *r, struct todo_item *item, @@ -2513,7 +2512,8 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, break; } if (i >= TODO_COMMENT) - return -1; + return error(_("invalid command '%.*s'"), + (int)strcspn(bol, " \t\r\n"), bol); /* Eat up extra spaces/ tabs before object name */ padding = strspn(bol, " \t"); diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh index b57541356bd..1d2f0429aea 100644 --- a/t/lib-rebase.sh +++ b/t/lib-rebase.sh @@ -60,7 +60,7 @@ set_fake_editor () { ">") echo >> "$1";; bad) - action="badcmd";; + action="pickled";; fakesha) test \& != "$action" || action=pick echo "$action XXXXXXX False commit" >> "$1" diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 462cefd25df..3862a4301a6 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -1449,14 +1449,15 @@ test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = ig test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = warn' ' cat >expect <<-EOF && - error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4) + error: invalid command '\''pickled'\'' + error: invalid line 1: pickled $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4) Warning: some commits may have been dropped accidentally. Dropped commits (newer to older): - $(git rev-list --pretty=oneline --abbrev-commit -1 primary) - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4) To avoid this message, use "drop" to explicitly remove a commit. EOF - head -n4 expect >expect.2 && + head -n5 expect >expect.2 && tail -n1 expect >>expect.2 && tail -n4 expect.2 >expect.3 && test_config rebase.missingCommitsCheck warn && @@ -1467,7 +1468,7 @@ test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = wa git rebase -i --root && cp .git/rebase-merge/git-rebase-todo.backup orig && FAKE_LINES="2 3 4" git rebase --edit-todo 2>actual.2 && - head -n6 actual.2 >actual && + head -n7 actual.2 >actual && test_cmp expect actual && cp orig .git/rebase-merge/git-rebase-todo && FAKE_LINES="1 2 3 4" git rebase --edit-todo 2>actual.2 && @@ -1483,7 +1484,8 @@ test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = wa test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = error' ' cat >expect <<-EOF && - error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4) + error: invalid command '\''pickled'\'' + error: invalid line 1: pickled $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4) Warning: some commits may have been dropped accidentally. Dropped commits (newer to older): - $(git rev-list --pretty=oneline --abbrev-commit -1 primary) @@ -1583,7 +1585,7 @@ test_expect_success 'static check of bad command' ' set_fake_editor && test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \ git rebase -i --root 2>actual && - test_i18ngrep "badcmd $(git rev-list --oneline -1 primary~1)" \ + test_i18ngrep "pickled $(git rev-list --oneline -1 primary~1)" \ actual && test_i18ngrep "You can fix this with .git rebase --edit-todo.." \ actual && From patchwork Thu Feb 23 20:55:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13150762 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6397AC64ED8 for ; Thu, 23 Feb 2023 20:55:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229515AbjBWUzK (ORCPT ); Thu, 23 Feb 2023 15:55:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229618AbjBWUzI (ORCPT ); Thu, 23 Feb 2023 15:55:08 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67E0615CB7 for ; Thu, 23 Feb 2023 12:55:06 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id l7-20020a05600c4f0700b003e79fa98ce1so367326wmq.2 for ; Thu, 23 Feb 2023 12:55:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=JHo6iV4PFZ9rA8j/z0NTlhby/vMcGwgJWrgvJGvMzGA=; b=OvK8/YWO03R7bTzaOVMOer7ObCS+tyvfBHukGHrjDgV4mPultbIw5NTSDaQPvXzAx2 BBG+0K8Q3fG5T+VevvCCv2AZJbX1Rm4JKxX4V+7pEsH52Fc1eGirbkceW3+goYkTmAP4 qDRQ6fIeBssvjo0FHplHXtdsy4GqoLMAqhtK3Xh3uMTzyEkKuly9jHUt2Rbgu1SZY5Pi XsBWSgksMntlX4OEhA/cWuQmQoX3Mx9MUIXAbIfWZ6Y3oPEiOaz94Nph5HXKKJEro/3+ cH1baGaf7nLJhS1BnpiapMA7+qEX+0R7H3FJOuxe/8uQCUPDFbrWEQkm8RiVN3YC/tKx UCvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JHo6iV4PFZ9rA8j/z0NTlhby/vMcGwgJWrgvJGvMzGA=; b=m+NH/MSToV9kTljqjw/FoFD8M/MlGteUghhUVcECEWQxlU6K892JPUqVK5BHWLD0im I8DFill9KEMFCKF3e23e8xk/3bdxfISv9dnjL0VUJxf7CA4/U/zvfffF/3q3FhvqJYgt zA6atta7BQu3uc2SfU29fI3kmDf0P59MU8FiAvfT88W5heegRaEc+SoIQXASGoALIpgb tbuPdHz9+BgdxtsevvnxwA0LoBUuhGGL7ssCALGCB1FYeRXI9vzya6FBX9zR2eXmDqRG 7j081bvsljqg4+vzCkoSW+05HNB94CuEEagIaCbXrBFcp+UkV/Nk36VXa/Uvs0uRPn+D owMQ== X-Gm-Message-State: AO0yUKWhKLgUNTRwhCjWvZAfd3xxlocSAYDQBaeR5slcTFCVbpf13HQB ocEJACJpYqrkg3NAkzHrvVc7md3/loQ= X-Google-Smtp-Source: AK7set84c+c5PrmxeRM1Fg7oxtb6EzLKDm2Ww4KVYRYGmGt7/rM/sTYB0Uyu2y0xgKEPxurpF6OeBQ== X-Received: by 2002:a05:600c:43c8:b0:3e2:1d1e:78d0 with SMTP id f8-20020a05600c43c800b003e21d1e78d0mr6879535wmn.22.1677185704609; Thu, 23 Feb 2023 12:55:04 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m26-20020a05600c3b1a00b003e21ba8684dsm507468wms.26.2023.02.23.12.55.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 12:55:04 -0800 (PST) Message-Id: In-Reply-To: References: Date: Thu, 23 Feb 2023 20:55:01 +0000 Subject: [PATCH 2/2] rebase -i: fix parsing of "fixup -C" Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood If the user omits the space between "-C" and the commit in a fixup command then it is parsed as an ordinary fixup and the commit message is not updated as it should be. Fix this by making the space between "-C" and "" optional as it is for the "merge" command. Note that set_replace_editor() is changed to set $GIT_SEQUENCE_EDITOR instead of $EDITOR in order to be able to replace the todo list and reword commits with $FAKE_COMMIT_MESSAGE. This is safe as all the existing users are using set_replace_editor() to replace the todo list. Signed-off-by: Phillip Wood --- sequencer.c | 6 ++---- t/lib-rebase.sh | 8 ++++++-- t/t3437-rebase-fixup-options.sh | 26 ++++++++++++++++++++++++++ t/test-lib-functions.sh | 8 ++++++++ 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/sequencer.c b/sequencer.c index d19ee189b57..9ddae1ce944 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2542,12 +2542,10 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, } if (item->command == TODO_FIXUP) { - if (skip_prefix(bol, "-C", &bol) && - (*bol == ' ' || *bol == '\t')) { + if (skip_prefix(bol, "-C", &bol)) { bol += strspn(bol, " \t"); item->flags |= TODO_REPLACE_FIXUP_MSG; - } else if (skip_prefix(bol, "-c", &bol) && - (*bol == ' ' || *bol == '\t')) { + } else if (skip_prefix(bol, "-c", &bol)) { bol += strspn(bol, " \t"); item->flags |= TODO_EDIT_FIXUP_MSG; } diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh index 1d2f0429aea..7ca5b918f04 100644 --- a/t/lib-rebase.sh +++ b/t/lib-rebase.sh @@ -211,6 +211,9 @@ check_reworded_commits () { # usage: set_replace_editor # # Replace the todo file with the exact contents of the given file. +# N.B. sets GIT_SEQUENCE_EDITOR rather than EDITOR so it can be +# combined with set_fake_editor to reword commits and replace the +# todo list set_replace_editor () { cat >script <<-\EOF && cat FILENAME >"$1" @@ -219,6 +222,7 @@ set_replace_editor () { cat "$1" EOF - sed -e "s/FILENAME/$1/g"