From patchwork Mon Jan 10 09:01:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 12708462 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 66DFEC433FE for ; Mon, 10 Jan 2022 09:03:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242896AbiAJJDk (ORCPT ); Mon, 10 Jan 2022 04:03:40 -0500 Received: from mout.web.de ([212.227.17.11]:38293 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242277AbiAJJBc (ORCPT ); Mon, 10 Jan 2022 04:01:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1641805283; bh=KyMpleeQhCW9l+k4Fcnxc9PiHKr1q7H2DOdB7T46mcw=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=AfZrgMd82jPFIfpvr+K27WxUGBnZizF1JakO+yOvS/qh0Jbm7I1mitBeeFKQ3rPNs M58cKLJJkMDgnpuCBCW3leF8N2Ykihyym0/+OsAjlbCQa3hui0dBMHsiHaZVVDg1Up hURLM0ei1lm5Y99WuyFAc2XbL3g/NQWzz9hwuhrM= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.178.29] ([79.203.22.121]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1Mw9xG-1mGwFy44Bg-00sQr3; Mon, 10 Jan 2022 10:01:23 +0100 Message-ID: <5d8c8a72-6c4f-35e4-a6a4-4ed7d6f23c4e@web.de> Date: Mon, 10 Jan 2022 10:01:22 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.4.1 Subject: [PATCH] bisect: report actual bisect_state() argument on error Content-Language: en-US To: Ramkumar Ramachandra , Junio C Hamano Cc: Git List , Tanushree Tumane References: <1edfc6ff-4db8-447f-9eb7-85843258a286@www.fastmail.com> From: =?utf-8?q?Ren=C3=A9_Scharfe?= In-Reply-To: X-Provags-ID: V03:K1:Y0xvtqNZav5duPETsfHjim2ZuQUAD4r3i6C8YADg24VIySMgCOy bBo6V1OS1LvT1pUTvuSme9UQpHRnnyf5k79JCLK6Q+BbReS9Hx3yuj6bFDIi3SEl6DHvxE6 /177OSJ5MEkQDqFSJ4k8NGpyDRWw1bVJGWNiqVQEeCvMAXmv5aLOjMWP0O490sXuUMR5kEc c0QYWicfoX9JkmJQj/nIA== X-UI-Out-Filterresults: notjunk:1;V03:K0:MKk8OR1JLec=:kutH3Tbk4Yo92aJ+8DVHWQ l+imu8PA9LfWGkrWRO+4ELaI4QhHRDZgDy7FIauhto8ribci8KGErsK/rOC5p9aJh1htCn/A/ AB03qtc1+4TUR2jO/ezz+PgRxB4DCfajgOvQt+bm8tNRJlpOwfvZYC5U2nldDptwbsXRZVoFX RRq+c7k6euYYFB3T1K8lrB5mau3ol9+2gjZ5EooZE4qEizaqE7wU5vva6AsAXQ4lIzydhJPGm hEyz6uT0xJ7PBULGJSd2fvCA6FSCIkthqt1dw5PagtlaFRd6xYo5hlrU4zBckuicrgmLMRx7E Dcd4kzXy3W87sKMM/wQl3DDXOYg8NwqidQlAdp+wM88oJsSzY91PJvH4yLiHt9QPP9YLkHQ8Y uVerjVTtndjW6QMcYity5RuHvSxXR9REnUweI7cTNK7lU85yEt+rtjJV0nMbPEYqf6HCK9Re7 s3KoPH9DEGlCSZENmKtNG9AQFqgBYNqWEEQtEdVB+KaVMM1tbLiiON4zEs4RLFcjvKwK4wK0R bSaDkO74yb4YPovK1NQifpiOkU1nNH4HGOv7W1PiGUeLkiNSZ6JJo5Sg7FQY3GPdXrluPVT7F HRH8SdhRNnP+eKi/QqhNou7R1GdrcrB1ijOdzk0d8HG/+18y8vScaip1xdVJpjvPj/SsPlLAG p91HyJKjKDGLr4xTj98zNkklvSBi+8RTPILBbnTYaZ0eC4XVTPHO2NCd4nZVnqmFIS8+hIGLt 3gO0INV43HJII3aKqwn4Ca3o5exJ55FsQFkUlK+VTWtoHMlbe5p51gTYu9s6Rbl6CVMqNLYDm rKq3anVr5gMWp1W4k28NJ8W1KwUx/XCHVyu0qIYa4Mud1U4un3wwcTroYGDeiiqL0G1qkmuZs 8nYS1PRu1xA1lF1heUW5Djy3l/lT9pPwIOI3fmeoj4wMHvDCp2ZM/kDumHaja5nyd99Vk4sa3 3Hrz28WIIN6xWV6CkQNO0pT9mgodS90ZdZgB+L7Zvpklqy7t4QsYQNdnJoPCnYflPoic47QMc i+ML+V0l2ssHKhXPHolmGYFY5LLwym58zpWhnfkojsgf0m2e7KRla5hqCjBUtQiptw== Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The strvec "args" in bisect_run() is initialized and cleared, but never added to. Nevertheless its first member is printed when reporting a bisect_state() error. That's not useful, since it's always NULL. Before d1bbbe45df (bisect--helper: reimplement `bisect_run` shell function in C, 2021-09-13) the new state was reported if it could not been set. Reinstate that behavior and remove the unused strvec. Reported-by: Ramkumar Ramachandra Signed-off-by: René Scharfe --- This doesn't fix your problem, only replace the "(null)" in the error messages with the actual state name -- which may be useful for diagnosing its cause, though. Patch generated with --function-context for easier review. builtin/bisect--helper.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) -- 2.34.1 diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 28a2e6a575..1dbc6294ef 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -1092,80 +1092,76 @@ static int bisect_visualize(struct bisect_terms *terms, const char **argv, int a static int bisect_run(struct bisect_terms *terms, const char **argv, int argc) { int res = BISECT_OK; struct strbuf command = STRBUF_INIT; - struct strvec args = STRVEC_INIT; struct strvec run_args = STRVEC_INIT; const char *new_state; int temporary_stdout_fd, saved_stdout; if (bisect_next_check(terms, NULL)) return BISECT_FAILED; if (argc) sq_quote_argv(&command, argv); else { error(_("bisect run failed: no command provided.")); return BISECT_FAILED; } strvec_push(&run_args, command.buf); while (1) { - strvec_clear(&args); - printf(_("running %s\n"), command.buf); res = run_command_v_opt(run_args.v, RUN_USING_SHELL); if (res < 0 || 128 <= res) { error(_("bisect run failed: exit code %d from" " '%s' is < 0 or >= 128"), res, command.buf); strbuf_release(&command); return res; } if (res == 125) new_state = "skip"; else if (!res) new_state = terms->term_good; else new_state = terms->term_bad; temporary_stdout_fd = open(git_path_bisect_run(), O_CREAT | O_WRONLY | O_TRUNC, 0666); if (temporary_stdout_fd < 0) return error_errno(_("cannot open file '%s' for writing"), git_path_bisect_run()); fflush(stdout); saved_stdout = dup(1); dup2(temporary_stdout_fd, 1); res = bisect_state(terms, &new_state, 1); fflush(stdout); dup2(saved_stdout, 1); close(saved_stdout); close(temporary_stdout_fd); print_file_to_stdout(git_path_bisect_run()); if (res == BISECT_ONLY_SKIPPED_LEFT) error(_("bisect run cannot continue any more")); else if (res == BISECT_INTERNAL_SUCCESS_MERGE_BASE) { printf(_("bisect run success")); res = BISECT_OK; } else if (res == BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND) { printf(_("bisect found first bad commit")); res = BISECT_OK; } else if (res) { error(_("bisect run failed: 'git bisect--helper --bisect-state" - " %s' exited with error code %d"), args.v[0], res); + " %s' exited with error code %d"), new_state, res); } else { continue; } strbuf_release(&command); - strvec_clear(&args); strvec_clear(&run_args); return res; } } From patchwork Tue Jan 18 12:46:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 12716297 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 A88A5C433F5 for ; Tue, 18 Jan 2022 12:46:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238498AbiARMqY (ORCPT ); Tue, 18 Jan 2022 07:46:24 -0500 Received: from mout.web.de ([212.227.15.14]:44547 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236231AbiARMqX (ORCPT ); Tue, 18 Jan 2022 07:46:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1642509977; bh=s59ou5DXM40SC0/QIIAqfUk/4DCmrktlcIyrCWbGtqQ=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=LFv+ljG0wLoeCiHYZ/zcVKMhSVuK1e4ZE5fickdT3LUNtJD7e9oa1S34B472Gxr+x DdFFV0Otf9A4EBiBpsfO7TLQMfTjtz8zDYX3CjGwMJH4TTJQpr6Kd/+nsubtneJboY xX1QlPIhZMsEvjY9SzbSovoi1YXFtdoMNHDtXBpU= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.178.29] ([79.203.22.121]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1Md6tr-1maBwZ3K9T-00Zro0; Tue, 18 Jan 2022 13:46:16 +0100 Message-ID: Date: Tue, 18 Jan 2022 13:46:15 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: [PATCH v2 2/4] bisect--helper: release strbuf and strvec on run error Content-Language: en-US To: Git List Cc: Ramkumar Ramachandra , Christian Couder , "Miriam R." , Junio C Hamano References: <1edfc6ff-4db8-447f-9eb7-85843258a286@www.fastmail.com> From: =?utf-8?q?Ren=C3=A9_Scharfe?= In-Reply-To: X-Provags-ID: V03:K1:/HsZTt0OtXuRptMjGsE8CRVTbssKhSS9zja+gWPYstKNK6esheQ qWQo6sh4f7UOUU3LruyuacMeXMDxbFQmVfPz6ge7nTOBvYDS2Zv0vytPfBBResrncuQPeWx 2ft1XVXzr62yrNDMQs8/v2S8IO8L/R6+OLjki/O2lSENuQ1Lo3FFO/Yu3vH04cztPT8aQX6 P1KIkqPFVICyj/lKGVagw== X-UI-Out-Filterresults: notjunk:1;V03:K0:Wt0dxjiMel0=:+REseKHTzGY15f63C4Qhv/ XrUVcYGmgQYYApLM7vCnC2H8ALSsCDZQUDGRhMVQIKCC4L4rS7R8Gm88jo0VTrL61bAPcLfQe TJvFq506yutWTDFVnN0G2UnTLGs5dQ6vdzJxfr1EAdlNhM+ma/oydTeMtKerD19QeMvWmmi7X l4EmrUJvo42EdN5D8xMpuAOVIQRLGQT6xeTQSjel1oNiG2IKdxgq6okCbAUsK5V6GBxZWc1oU qKOabPjeo0ZBZHbM1FDAao2X3IPfveEUDD9KTL/RLMnmcbDQ/YVQSk5+2AJ69+uaElN9WLbc4 pzmcmeYKY2qcOB7+vS7b2nlRtILVeI1Tx0az46207359e9+xB8QGepdVYpFlct8mbfba1hRe9 M3Xi8lTa907TyW/inwkixP0XLdn7djImpmV7DuCd07e7QnwMy8QxEikBMzZlVWFjnEKNFbBxR BjBPxndjw+Myb/Ohd1gvFinoBzK4oZCo+AwV5ntFo+C7ju9yff2Z7XNPnPsdRsYL6z6aN8ThR Yfz4DCuaZcoKOtvKQLYqe7C5q8fdt6VHTaRbWTHVqRT45kyus9dXsZA93TBmcb+SjvGNPcSoy M8fXZR3tnttLKF7J8cYo3F2NkGavfcSTRFmFRjwVqKjbZXsX5BGgujXge2Yz9GTyxnpkIh849 GjqZERmB707PdK5fiIrnzQgvjndtHrmaArpyVDObVISJpla05k1hRFbD+M0vnj6JPQTlGcPwn XzSX2jSp42WaNByV4Fk5NsRPGKNSaxzWRow6b7JmRrofYmm3YwMKp3yh5/m0AeMjE9ZBy+zPT fG+VVYFR1bYpOzapjmhHM1BlARW3eMLJ4ABpU7nZhpWc0hqGCzxEpGyGj2yfE7PmlqDzXsg08 5u/CPuRfWAIcFWclYk/5n5sQr4J3/Fh4PM6IaphWmJb6xbciNxrqFUkQkdfnan9V8KNSL1TEW FqgqyTVWZN/aXtfXPfJr7Jv+tbitWLK0dDGpDfQtf2WQe598nRwvu5B50MfQ2pR5o53BmpKgt n+hKR9JAcvEbQVgsoD9auIoLAos2z+JpgzJAyqVBdnFZ7xUcGlfvOwo/xlH1sVtnwXmNsxA8p 1/wBd2qMq4XB4w= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the cleanup code out of the loop and make sure all execution paths pass through it to avoid leaking memory. Signed-off-by: René Scharfe --- builtin/bisect--helper.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) -- 2.34.1 diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 1dbc6294ef..e529665d9f 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -1116,8 +1116,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc) if (res < 0 || 128 <= res) { error(_("bisect run failed: exit code %d from" " '%s' is < 0 or >= 128"), res, command.buf); - strbuf_release(&command); - return res; + break; } if (res == 125) @@ -1129,8 +1128,10 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc) temporary_stdout_fd = open(git_path_bisect_run(), O_CREAT | O_WRONLY | O_TRUNC, 0666); - if (temporary_stdout_fd < 0) - return error_errno(_("cannot open file '%s' for writing"), git_path_bisect_run()); + if (temporary_stdout_fd < 0) { + res = error_errno(_("cannot open file '%s' for writing"), git_path_bisect_run()); + break; + } fflush(stdout); saved_stdout = dup(1); @@ -1159,11 +1160,12 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc) } else { continue; } - - strbuf_release(&command); - strvec_clear(&run_args); - return res; + break; } + + strbuf_release(&command); + strvec_clear(&run_args); + return res; } int cmd_bisect__helper(int argc, const char **argv, const char *prefix) From patchwork Tue Jan 18 12:46:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 12716298 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 F170FC433F5 for ; Tue, 18 Jan 2022 12:46:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238770AbiARMqc (ORCPT ); Tue, 18 Jan 2022 07:46:32 -0500 Received: from mout.web.de ([212.227.15.14]:49153 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238582AbiARMqb (ORCPT ); Tue, 18 Jan 2022 07:46:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1642509985; bh=ifA4llf293NHACfhKN6YJS9vZRyQqX1ox/EKjlCczWU=; h=X-UI-Sender-Class:Date:Subject:Cc:References:From:To:In-Reply-To; b=FKe5aE3Ug5/p164AN2ACtz+EagEF8OiHSXueXeDy6VNAxxAt6HliubZHt9V58aZ9Z ZAVZoOTKGSrN3A8mWGeIuoGVXRencZs0UlDu49XCYjUv98kcOBc5kpcsJCNS+n86CT AYfSjtypVymHBffQc6MN4ibviOkJgSRFKyZlz1P8= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.178.29] ([79.203.22.121]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1N7QUL-1mFro40tbh-017UAL; Tue, 18 Jan 2022 13:46:25 +0100 Message-ID: <97650f5a-a6c6-d3fc-010f-3d5a45c64a52@web.de> Date: Tue, 18 Jan 2022 13:46:24 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: [PATCH v2 3/4] bisect: document run behavior with exit codes 126 and 127 Content-Language: en-US Cc: Ramkumar Ramachandra , Christian Couder , "Miriam R." , Junio C Hamano References: <1edfc6ff-4db8-447f-9eb7-85843258a286@www.fastmail.com> From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List In-Reply-To: X-Provags-ID: V03:K1:vPI2kFFK6qQ4a1F8Bw8LvEPGaT22P+CubWNgPLWv654BgulvpOI SMznHmg+dZ5terFZQ/nPiZzxmMPBUxle7AKMSphqyB6JZctBJLVVbYnr573XTkTtbseoP/8 ATEeuZ0eZgdsIQPGLGN1XMe6xqmwyqw5H9yiw9jPc5MYJkTLcB6P6LeuhDxp3QEpLDm6f89 bP1GutJ7cMMyVBAvimNvQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:OLjaNsg4Svs=:h5eSMDSpm/7sdh1FeH967A V+uSKXkK6vBSwLjvPnVnz3Q68KksKyyFFrpvA15iyfk18HAVpLFDPZQXrPAlSeW7iFHrelg30 iZhmjPoXb6aNe03hMNXWjYVp6Gddwzem8Rx2wcb3mzxevIfnxbeMi9xdQX7galyQF0jA4I31f Qxtb7z3m8m8OHzlWmlV3mPx9jRROWM2JclAYxJeYq9tIVvh69wR0+XEuX//m83Rf0d5uBEh2o tuXi1NUkF8lhYDv2qgv/KPi3FnlQxdSzFZdM350OnK2WvKWiPMglxxzuwlVTvT+bkmWbtjD07 qAXaDUcjd6ShiVPbXtGpkU8C7x6ngkeGDjiWOvd1XKMQ0GCKbrDXPN99UywhQ9ZEJnav4KpkT 4OIPXyDyAVDPM8ndomkB7AeIcYcDcylDZwdHCIwcmw5nMC31xD1SOUE016fDM9c7VLViS5cEa Z0stDqi/7dSbiz1WqhPMJQyUo9wMUPSGZLtcfDmYJ/PgYZHG5a83F7HqDTL0en1NX7KhWFors egc7uArrOEcsw5nq+4xPJlMCkkQ7hXmFQldDqyC4yqcMntXT+9T/qHmUQgCd4PVetak660FhV Zx8VfEojAjLvbPTQemgIFqz8F4JAgng4t7f6iC/fj0QqVGwQ41fMRnuiV3qi8L+I85flQGhz/ LluN5oXDyEBctpCd1d6AkRSbx8Ol99NfRBCVkURbKxCD2eWm07RQaNJwjFiC4ajMoUNsTVPls X64EgQhRHP0e5huShJXsKXgxV0iJ6tTWYUKE/Yc9H2D42ca7zXnbA7U6sLZ8DQ1HbNT/95pQg 8al1P3vwxDfL5xBjAU2CndW1Nj5LrhgS2QK/yZnU116diVi4xXUXW+U+ykG70HX1MufzsmrS+ NRqJ2yCSw7gtwyqErF04eDqt3h2JvO2BQbfUN47zn1V0O0MJ/+Hy3efgmv5fJpnhti+lNxkKU OZk4sytzppWmvTBizNAfbNbSJ8CV6sude87hn4z/VZbOeB7p2oZ+sLZ8eycuuYIzUrB3XxYWy g8Ddt9pzBizH1uBuI2k8gTlfwJYc0sz4h+qpm1QW6SqWa5NmakCUIBhZVhHfsxeObBqKLjFq9 Guem4txMgu5UqY= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Shells report non-executable and missing commands with exit codes 126 and 127, respectively. For historical reasons "git bisect run" interprets them as indicating a bad commit, though. Document the current behavior by adding basic tests that cover these cases. Reported-by: Ramkumar Ramachandra Signed-off-by: René Scharfe --- t/t6030-bisect-porcelain.sh | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) -- 2.34.1 diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh index 1be85d064e..fc18796517 100755 --- a/t/t6030-bisect-porcelain.sh +++ b/t/t6030-bisect-porcelain.sh @@ -278,6 +278,51 @@ test_expect_success '"git bisect run" with more complex "git bisect start"' ' git bisect reset ' +test_expect_success 'bisect run accepts exit code 126 as bad' ' + test_when_finished "git bisect reset" && + write_script test_script.sh <<-\EOF && + ! grep Another hello || exit 126 >/dev/null + EOF + git bisect start && + git bisect good $HASH1 && + git bisect bad $HASH4 && + git bisect run ./test_script.sh >my_bisect_log.txt && + grep "$HASH3 is the first bad commit" my_bisect_log.txt +' + +test_expect_failure POSIXPERM 'bisect run fails with non-executable test script' ' + test_when_finished "git bisect reset" && + >not-executable.sh && + chmod -x not-executable.sh && + git bisect start && + git bisect good $HASH1 && + git bisect bad $HASH4 && + test_must_fail git bisect run ./not-executable.sh >my_bisect_log.txt && + ! grep "is the first bad commit" my_bisect_log.txt +' + +test_expect_success 'bisect run accepts exit code 127 as bad' ' + test_when_finished "git bisect reset" && + write_script test_script.sh <<-\EOF && + ! grep Another hello || exit 127 >/dev/null + EOF + git bisect start && + git bisect good $HASH1 && + git bisect bad $HASH4 && + git bisect run ./test_script.sh >my_bisect_log.txt && + grep "$HASH3 is the first bad commit" my_bisect_log.txt +' + +test_expect_failure 'bisect run fails with missing test script' ' + test_when_finished "git bisect reset" && + rm -f does-not-exist.sh && + git bisect start && + git bisect good $HASH1 && + git bisect bad $HASH4 && + test_must_fail git bisect run ./does-not-exist.sh >my_bisect_log.txt && + ! grep "is the first bad commit" my_bisect_log.txt +' + # $HASH1 is good, $HASH5 is bad, we skip $HASH3 # but $HASH4 is good, # so we should find $HASH5 as the first bad commit From patchwork Tue Jan 18 12:46:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 12716299 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 AE9B9C433EF for ; Tue, 18 Jan 2022 12:46:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238582AbiARMqo (ORCPT ); Tue, 18 Jan 2022 07:46:44 -0500 Received: from mout.web.de ([212.227.15.3]:58165 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238498AbiARMqn (ORCPT ); Tue, 18 Jan 2022 07:46:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1642509992; bh=6F6c5ukjterhmghzh/5R6TvZl+iw4yi2TyBF+b5uRZo=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=H+WU3UIUdUeTEHSEZ3+gzWvGG+PKqdZ6qf9K/pcNB/Lb6/XhVWXKH89s0N2JEWXcB AcQo7zUFOVXhASUZhp+1FYdhGMzhhWOnvQcyeNbRts69Ofn3t/nG60pUwql13rxxKv aKjAfm3OHpJDCBVG+KplUsb4xeg44yAcvtD1Aqxw= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.178.29] ([79.203.22.121]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1N5UkQ-1mG8v43CKA-0172mH; Tue, 18 Jan 2022 13:46:32 +0100 Message-ID: <20987dc6-e0c7-6ca2-19fd-2b323b3f6d9f@web.de> Date: Tue, 18 Jan 2022 13:46:32 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: [PATCH v2 4/4] bisect--helper: double-check run command on exit code 126 and 127 Content-Language: en-US To: Git List Cc: Ramkumar Ramachandra , Christian Couder , "Miriam R." , Junio C Hamano References: <1edfc6ff-4db8-447f-9eb7-85843258a286@www.fastmail.com> From: =?utf-8?q?Ren=C3=A9_Scharfe?= In-Reply-To: X-Provags-ID: V03:K1:t3hx6lmvO6iMt7N992LwdzB8MImHGlH5Q+w+n8UPEFOqAPN3Ilq clBLrkD6oRc3W5lraBnjiT1bceMxC/DgUbHRsEw3qrKJQzo5qQ2Xs5o4xgLn6cY8bQM70ll Bo1OYOVJ4YuD24P5eT/qhl8BVh6WAQD34ElMOinA7dUoPwt4H75T5qmmZT3FLXrsmOP/VHF KJmsTnPrhpVGUsJzQgzFQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:DdjvOl0g8gQ=:wLy9CBuIJnIxoa/BJI/PJf fIzlxfQ7H1ym/1EYM5zHWyp3bZcCw4Z4OzSkAqhIz9SeoHNHrN4K9vR2EP5UPvlu8Jj21R/xY Cgv5mU9AqKLAF9WLhMHzDcKlOVleC0EBo9wQ3ESlwRkcxRAtABj9bYoKlcMxADVDYnS9R/DtM gL8P4UgKIPyLkeA51+hMCyknMBJlqOZP4fCB+ohrZ4Mxxo7p0ql9+QtqwVJEh+6eYEqPiDqsu YHK+wzUMc5UnN7aAhAooZou3+cnz6/LVb3SuYmKJkv6TS3qMD1nPGUmOyO5KusqdvaL8PrTrP EYMjzKwn6W54jXn+A3DGUah5GRgAumKRTkai09GzlY+haaMZEtsp24pCOSh9JiyuUz47sfyw0 Y6xa5QVswmwC+Bbc1LEaiACdo0GYZ5tXm9ji5PbDXdoyMB/i035WmqfNZF8h8jtuxET5xkIRY CebuiINR4JQ08HKusj8DNT23phZ4PVE/ANT/DlZl+IcGlVLZ1aOEpJ+zsB9r+48oGZsmu5pxQ WfNdCHgT7Qfj8+zX4/Tnh1dSUrShqt/oxya+7EH0pMlsTcCMGV3bgs+VQQd6TELC++2cA6Cf/ 566NPe6QMl3JTlKhDiHOAXys8q+xxNTHwMUzISRFO8BUu8Mh+AZy7SeZekQXswtIXSnUirMAa w6GauLZL8Aqfx5TK6LvNItG0PTVs+lmXyOaDv/+k+xq2A76KXMp2ATDuM6CFmJ87DxbGYWHln tpjM4kfuEWwBOd1ZBKpZHDoJ81JdScz6uLRGvSM+7MkM4yB6AoMFnLLONiS9P7++8n+q+I/pJ Nu6E5LMSLHLfAQ+taLIoqI4uGiXXm05SSN9shHHw0tEEdmNNG6pug0QaOeacr0H6Z2RfRmG3x RZtxGFVBCgY/g9oiufDARJ+JJRtPAbq+yhumrcXnPj7bYY7yXbk9W39l6bsvJbZoa2WsO7K0G Ci6TUGqY7p3lYPOzbGA0wa2QQbTGD6AB67CORRio2A8P4AwDGIgJ/PXVZBnqGbJKMItETFxlt KVvOVB9Ve5bZxbvQkSPss9Bc8Ci06F+X2f6RybkYip3p27zPqD+DHBBJfOKGhCl24w== Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When a run command cannot be executed or found, shells return exit code 126 or 127, respectively. Valid run commands are allowed to return these codes as well to indicate bad revisions, though, for historical reasons. This means typos can cause bogus bisect runs that go over the full distance and end up reporting invalid results. The best solution would be to reserve exit codes 126 and 127, like 71b0251cdd (Bisect run: "skip" current commit if script exit code is 125., 2007-10-26) did for 125, and abort bisect run when we get them. That might be inconvenient for those who relied on the documentation stating that 126 and 127 can be used for bad revisions, though. The workaround used by this patch is to run the command on a known-good revision and abort if we still get the same error code. This adds one step to runs with scripts that use exit codes 126 and 127, but keeps them supported, with one exception: It won't work with commands that cannot recognize the (manually marked) known-good revision as such. Run commands that use low exit codes are unaffected. Typos are reported after executing the missing command twice and three checkouts (the first step, the known good revision and back to the revision of the first step). Signed-off-by: René Scharfe --- bisect.c | 3 +- bisect.h | 3 ++ builtin/bisect--helper.c | 63 +++++++++++++++++++++++++++++++++++++ t/t6030-bisect-porcelain.sh | 4 +-- 4 files changed, 70 insertions(+), 3 deletions(-) -- 2.34.1 diff --git a/bisect.c b/bisect.c index 888949fba6..9e6a2b7f20 100644 --- a/bisect.c +++ b/bisect.c @@ -724,7 +724,8 @@ static int is_expected_rev(const struct object_id *oid) return res; } -static enum bisect_error bisect_checkout(const struct object_id *bisect_rev, int no_checkout) +enum bisect_error bisect_checkout(const struct object_id *bisect_rev, + int no_checkout) { char bisect_rev_hex[GIT_MAX_HEXSZ + 1]; struct commit *commit; diff --git a/bisect.h b/bisect.h index ec24ac2d7e..748adf0cff 100644 --- a/bisect.h +++ b/bisect.h @@ -69,4 +69,7 @@ void read_bisect_terms(const char **bad, const char **good); int bisect_clean_state(void); +enum bisect_error bisect_checkout(const struct object_id *bisect_rev, + int no_checkout); + #endif diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index e529665d9f..50783a586c 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -1089,6 +1089,44 @@ static int bisect_visualize(struct bisect_terms *terms, const char **argv, int a return res; } +static int get_first_good(const char *refname, const struct object_id *oid, + int flag, void *cb_data) +{ + oidcpy(cb_data, oid); + return 1; +} + +static int verify_good(const struct bisect_terms *terms, + const char **quoted_argv) +{ + int rc; + enum bisect_error res; + struct object_id good_rev; + struct object_id current_rev; + char *good_glob = xstrfmt("%s-*", terms->term_good); + int no_checkout = ref_exists("BISECT_HEAD"); + + for_each_glob_ref_in(get_first_good, good_glob, "refs/bisect/", + &good_rev); + free(good_glob); + + if (read_ref(no_checkout ? "BISECT_HEAD" : "HEAD", ¤t_rev)) + return -1; + + res = bisect_checkout(&good_rev, no_checkout); + if (res != BISECT_OK) + return -1; + + printf(_("running %s\n"), quoted_argv[0]); + rc = run_command_v_opt(quoted_argv, RUN_USING_SHELL); + + res = bisect_checkout(¤t_rev, no_checkout); + if (res != BISECT_OK) + return -1; + + return rc; +} + static int bisect_run(struct bisect_terms *terms, const char **argv, int argc) { int res = BISECT_OK; @@ -1096,6 +1134,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc) struct strvec run_args = STRVEC_INIT; const char *new_state; int temporary_stdout_fd, saved_stdout; + int is_first_run = 1; if (bisect_next_check(terms, NULL)) return BISECT_FAILED; @@ -1113,6 +1152,30 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc) printf(_("running %s\n"), command.buf); res = run_command_v_opt(run_args.v, RUN_USING_SHELL); + /* + * Exit code 126 and 127 can either come from the shell + * if it was unable to execute or even find the script, + * or from the script itself. Check with a known-good + * revision to avoid trashing the bisect run due to a + * missing or non-executable script. + */ + if (is_first_run && (res == 126 || res == 127)) { + int rc = verify_good(terms, run_args.v); + is_first_run = 0; + if (rc < 0) { + error(_("unable to verify '%s' on good" + " revision"), command.buf); + res = BISECT_FAILED; + break; + } + if (rc == res) { + error(_("bogus exit code %d for good revision"), + rc); + res = BISECT_FAILED; + break; + } + } + if (res < 0 || 128 <= res) { error(_("bisect run failed: exit code %d from" " '%s' is < 0 or >= 128"), res, command.buf); diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh index fc18796517..5382e5d216 100755 --- a/t/t6030-bisect-porcelain.sh +++ b/t/t6030-bisect-porcelain.sh @@ -290,7 +290,7 @@ test_expect_success 'bisect run accepts exit code 126 as bad' ' grep "$HASH3 is the first bad commit" my_bisect_log.txt ' -test_expect_failure POSIXPERM 'bisect run fails with non-executable test script' ' +test_expect_success POSIXPERM 'bisect run fails with non-executable test script' ' test_when_finished "git bisect reset" && >not-executable.sh && chmod -x not-executable.sh && @@ -313,7 +313,7 @@ test_expect_success 'bisect run accepts exit code 127 as bad' ' grep "$HASH3 is the first bad commit" my_bisect_log.txt ' -test_expect_failure 'bisect run fails with missing test script' ' +test_expect_success 'bisect run fails with missing test script' ' test_when_finished "git bisect reset" && rm -f does-not-exist.sh && git bisect start &&