From patchwork Fri Nov 4 11:40:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= X-Patchwork-Id: 13031666 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 83D46C4332F for ; Fri, 4 Nov 2022 11:40:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231516AbiKDLkb (ORCPT ); Fri, 4 Nov 2022 07:40:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231302AbiKDLk1 (ORCPT ); Fri, 4 Nov 2022 07:40:27 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E498912760 for ; Fri, 4 Nov 2022 04:40:26 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id d20so3561990plr.10 for ; Fri, 04 Nov 2022 04:40:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=k3L8X6l6CU52qxImv/HP6JCs+2BmNeXDrnptnDdmUdE=; b=Cu4AKaypcsl+QI3WYfJxIcCYlNcC3Lh/CThYzHyAGNAkhun8Re5sXS/HXaMKLLSJRl MeM9EhF3vV9NEYwKh9EdTL8LmZkz7nAZ/SHNP5X66QPJdYmEWqIYVoj5B7Ao3/7DgpUx 6/XNJOiBZTkiMY36YuProGUrfTxJwYXSlNxRk8E4pa0ZmIqDGLWT8X2tIiwBZrFx8Raw fGE3m/TsNNCv6uVPcjC4P7ODi5K6CYM6IL3vg6LU4nxqOP6yZSoVq4SXzPPgk8/+u5yx 6CaCK9V2WRclkECAHFJQNj8UjgV3hxwig9BSnTqx+NEbvcHwvoamXpcG1AOiJgDBzl/S SYIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k3L8X6l6CU52qxImv/HP6JCs+2BmNeXDrnptnDdmUdE=; b=2W8FuJamd92MSLuibGoV5Kyj+ZLuy4FMRy+QRajJ85IUmoSRTdc7km+Yt1Ah9ffBm/ eC1oK0cRqvqjtV+XSeEtWq2mw75Kl8BWkQ2Dgz/eA4ySLhEvSSKyBwvFfchuM7tI4U1h d8OqvYvqkO+xu6BgsRIhI6uwVKXpmR+FoFmrFHFMPnNsh6xDQU/pq7Sy4/WzVshza/9O VO60rCU+sp7tCs8PHgSVMLNJOIxqzUhQGH7QiACkpl3gLy8ZJl1l5aG+AD+qXjEpRibK oFkwYS/zB3rPBuHBkE73O2+1PBY/wy0iwoc7dNU+4Mn5pa1Esu2vPTyYI+Cv0ty+/Gi7 NfcA== X-Gm-Message-State: ACrzQf2IWM3byId4CKTrlZu1oKXTKAvvukNPdgUBoYAWFzwKTYge2LfS 6d8JhZcdcKgpb7PpBegJVVHAvkv8VtA= X-Google-Smtp-Source: AMsMyM7CtqAYqRb2Jqpokozsxc9eTiZMIhbonpSVUiggWgH/nS01WOphI17C57AamiEKZn+GdDhjYQ== X-Received: by 2002:a17:902:f7d3:b0:187:ecb:20d5 with SMTP id h19-20020a170902f7d300b001870ecb20d5mr31579440plw.101.1667562026065; Fri, 04 Nov 2022 04:40:26 -0700 (PDT) Received: from localhost.localdomain ([2001:ee0:500b:6370:da47:cda5:dbd5:6e77]) by smtp.gmail.com with ESMTPSA id l24-20020a63ea58000000b0043c22e926f8sm2203133pgk.84.2022.11.04.04.40.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 04:40:25 -0700 (PDT) From: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= To: git@vger.kernel.org Cc: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , =?utf-8?b?THVrw6HFoSBEb2t0b3I=?= , Jeff King , Christian Couder Subject: [PATCH 1/3] bisect--helper: remove unused options Date: Fri, 4 Nov 2022 18:40:10 +0700 Message-Id: <489785ca45a84cffb4a2c16da15a09034829b7c6.1667561761.git.congdanhqx@gmail.com> X-Mailer: git-send-email 2.38.1.157.gedabe22e0a In-Reply-To: References: <1cb1c033-0525-7e62-8c09-81019bf26060@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Đoàn Trần Công Danh --- builtin/bisect--helper.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 1d2ce8a0e1..5ec2e67f59 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -1283,7 +1283,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) { enum { BISECT_RESET = 1, - BISECT_NEXT_CHECK, BISECT_TERMS, BISECT_START, BISECT_AUTOSTART, @@ -1295,12 +1294,10 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) BISECT_VISUALIZE, BISECT_RUN, } cmdmode = 0; - int res = 0, nolog = 0; + int res = 0; struct option options[] = { OPT_CMDMODE(0, "bisect-reset", &cmdmode, N_("reset the bisection state"), BISECT_RESET), - OPT_CMDMODE(0, "bisect-next-check", &cmdmode, - N_("check whether bad or good terms exist"), BISECT_NEXT_CHECK), OPT_CMDMODE(0, "bisect-terms", &cmdmode, N_("print out the bisect terms"), BISECT_TERMS), OPT_CMDMODE(0, "bisect-start", &cmdmode, @@ -1319,8 +1316,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) N_("visualize the bisection"), BISECT_VISUALIZE), OPT_CMDMODE(0, "bisect-run", &cmdmode, N_("use ... to automatically bisect"), BISECT_RUN), - OPT_BOOL(0, "no-log", &nolog, - N_("no log for BISECT_WRITE")), OPT_END() }; struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL }; From patchwork Fri Nov 4 11:40:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= X-Patchwork-Id: 13031667 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 002ACC433FE for ; Fri, 4 Nov 2022 11:40:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231583AbiKDLke (ORCPT ); Fri, 4 Nov 2022 07:40:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231530AbiKDLka (ORCPT ); Fri, 4 Nov 2022 07:40:30 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 795FB1EECA for ; Fri, 4 Nov 2022 04:40:29 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id c2so4608385plz.11 for ; Fri, 04 Nov 2022 04:40:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MI5nYp5YdU6JgLYQyfGXaHjanIM2cIwiIE7FmMrFOmk=; b=Z6zlpr9Gpil9cvWAcXwYoheJY2elikC+OtnWieAOBsIFBTykGwSR56UAQHIw+AcprG d2WkQBPsPsm+bT2mVXUUO2OZAfOSc/fJxqVlSblME24E+zdXDt1vAQge1Mp2pRCpYavu TbIlv4r+fN9OmxKzIn5EDakXIRuKx+ddmikjcJY6htKohomiYrgL6+BGlev13Ql23hq7 ZxzDDUPS32BoFffC03XCIZXBgW/xI/Zg5FSSsn/4KLwno4kLFUQsAPa/WychFzoH7ToQ zT/MJWb1qJ2qkbIAxvd+pXq63/xGLcos0Rf8HrpbeD8T3NjacI3YE8nB/kgRm0dtwKvh AOUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MI5nYp5YdU6JgLYQyfGXaHjanIM2cIwiIE7FmMrFOmk=; b=acSjZrybjup9jmF/cGJQXuG+bfDXSI6BcGfrMscjM49HaGA99oVWriYyCIFawovDwB MTqADpV2MsTuXyby+qAmeNPhDIwmTzQHzqYcd9OojM7VjIJnWxQiVbPkTVoq8o+zcXzu MJ6YXscNmmo3mcv1Z7tYE3UY+klchtmOJFG9yFC3JGUTYG0IBATQO/G/vwEW3fRRm/Ag RnPf2KzkcEa8JIVLpwpV8I2YzWL22KfamUWwrce7svNH2EfWxYcEWBZXvb5r+KNs391B nKV8aoDqBfQqRTLMtkbShzpLo5JzcKCtDjG+v/lyT3TC2csXRFmnOeCE2FESXLaz613D YzQQ== X-Gm-Message-State: ACrzQf1hQT/vEPmYgWLfGo1ZW+fYPg2PX3+RVlToQt8rxz9OxwDECgM/ zP+NpkVj23SqR4SuZoNpPXTeDqsalbk= X-Google-Smtp-Source: AMsMyM4Xk5IcOF5zexINBzm/M6h79K0P5KTeaE+UZncCRlflhL1z7gXX969d3adK1CS1cHoToC1aeg== X-Received: by 2002:a17:902:c1c6:b0:186:994f:6e57 with SMTP id c6-20020a170902c1c600b00186994f6e57mr34857911plc.17.1667562028578; Fri, 04 Nov 2022 04:40:28 -0700 (PDT) Received: from localhost.localdomain ([2001:ee0:500b:6370:da47:cda5:dbd5:6e77]) by smtp.gmail.com with ESMTPSA id l24-20020a63ea58000000b0043c22e926f8sm2203133pgk.84.2022.11.04.04.40.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 04:40:28 -0700 (PDT) From: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= To: git@vger.kernel.org Cc: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , =?utf-8?b?THVrw6HFoSBEb2t0b3I=?= , Jeff King , Christian Couder Subject: [PATCH 2/3] bisect--helper: move all subcommands into their own functions Date: Fri, 4 Nov 2022 18:40:11 +0700 Message-Id: <081f3f7f9501012404fb9e59ab6d94f632180b53.1667561761.git.congdanhqx@gmail.com> X-Mailer: git-send-email 2.38.1.157.gedabe22e0a In-Reply-To: References: <1cb1c033-0525-7e62-8c09-81019bf26060@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a later change, we will use OPT_SUBCOMMAND to parse sub-commands to avoid consuming non-option opts. Since OPT_SUBCOMMAND needs a function pointer to operate, let's move it now. Signed-off-by: Đoàn Trần Công Danh --- builtin/bisect--helper.c | 155 ++++++++++++++++++++++++++++++--------- 1 file changed, 121 insertions(+), 34 deletions(-) diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 5ec2e67f59..292c6fd1dd 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -1279,6 +1279,117 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc) return res; } +static int cmd_bisect__reset(int argc, const char **argv, const char *prefix UNUSED) +{ + if (argc > 1) + return error(_("--bisect-reset requires either no argument or a commit")); + return bisect_reset(argc ? argv[0] : NULL); +} + +static int cmd_bisect__terms(int argc, const char **argv, const char *prefix UNUSED) +{ + int res; + struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL }; + + if (argc > 1) + return error(_("--bisect-terms requires 0 or 1 argument")); + res = bisect_terms(&terms, argc == 1 ? argv[0] : NULL); + free_terms(&terms); + return res; +} + +static int cmd_bisect__start(int argc, const char **argv, const char *prefix UNUSED) +{ + int res; + struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL }; + + set_terms(&terms, "bad", "good"); + res = bisect_start(&terms, argv, argc); + free_terms(&terms); + return res; +} + +static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *prefix) +{ + int res; + struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL }; + + if (argc) + return error(_("--bisect-next requires 0 arguments")); + get_terms(&terms); + res = bisect_next(&terms, prefix); + free_terms(&terms); + return res; +} + +static int cmd_bisect__state(int argc, const char **argv, const char *prefix UNUSED) +{ + int res; + struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL }; + + set_terms(&terms, "bad", "good"); + get_terms(&terms); + res = bisect_state(&terms, argv, argc); + free_terms(&terms); + return res; +} + +static int cmd_bisect__log(int argc, const char **argv UNUSED, const char *prefix UNUSED) +{ + if (argc) + return error(_("--bisect-log requires 0 arguments")); + return bisect_log(); +} + +static int cmd_bisect__replay(int argc, const char **argv, const char *prefix UNUSED) +{ + int res; + struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL }; + + if (argc != 1) + return error(_("no logfile given")); + set_terms(&terms, "bad", "good"); + res = bisect_replay(&terms, argv[0]); + free_terms(&terms); + return res; +} + +static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUSED) +{ + int res; + struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL }; + + set_terms(&terms, "bad", "good"); + get_terms(&terms); + res = bisect_skip(&terms, argv, argc); + free_terms(&terms); + return res; +} + +static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix UNUSED) +{ + int res; + struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL }; + + get_terms(&terms); + res = bisect_visualize(&terms, argv, argc); + free_terms(&terms); + return res; +} + +static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSED) +{ + int res; + struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL }; + + if (!argc) + return error(_("bisect run failed: no command provided.")); + get_terms(&terms); + res = bisect_run(&terms, argv, argc); + free_terms(&terms); + return res; +} + int cmd_bisect__helper(int argc, const char **argv, const char *prefix) { enum { @@ -1318,8 +1429,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) N_("use ... to automatically bisect"), BISECT_RUN), OPT_END() }; - struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL }; - argc = parse_options(argc, argv, prefix, options, git_bisect_helper_usage, PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_UNKNOWN_OPT); @@ -1329,60 +1438,38 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) switch (cmdmode) { case BISECT_RESET: - if (argc > 1) - return error(_("--bisect-reset requires either no argument or a commit")); - res = bisect_reset(argc ? argv[0] : NULL); + res = cmd_bisect__reset(argc, argv, prefix); break; case BISECT_TERMS: - if (argc > 1) - return error(_("--bisect-terms requires 0 or 1 argument")); - res = bisect_terms(&terms, argc == 1 ? argv[0] : NULL); + res = cmd_bisect__terms(argc, argv, prefix); break; case BISECT_START: - set_terms(&terms, "bad", "good"); - res = bisect_start(&terms, argv, argc); + res = cmd_bisect__start(argc, argv, prefix); break; case BISECT_NEXT: - if (argc) - return error(_("--bisect-next requires 0 arguments")); - get_terms(&terms); - res = bisect_next(&terms, prefix); + res = cmd_bisect__next(argc, argv, prefix); break; case BISECT_STATE: - set_terms(&terms, "bad", "good"); - get_terms(&terms); - res = bisect_state(&terms, argv, argc); + res = cmd_bisect__state(argc, argv, prefix); break; case BISECT_LOG: - if (argc) - return error(_("--bisect-log requires 0 arguments")); - res = bisect_log(); + res = cmd_bisect__log(argc, argv, prefix); break; case BISECT_REPLAY: - if (argc != 1) - return error(_("no logfile given")); - set_terms(&terms, "bad", "good"); - res = bisect_replay(&terms, argv[0]); + res = cmd_bisect__replay(argc, argv, prefix); break; case BISECT_SKIP: - set_terms(&terms, "bad", "good"); - get_terms(&terms); - res = bisect_skip(&terms, argv, argc); + res = cmd_bisect__skip(argc, argv, prefix); break; case BISECT_VISUALIZE: - get_terms(&terms); - res = bisect_visualize(&terms, argv, argc); + res = cmd_bisect__visualize(argc, argv, prefix); break; case BISECT_RUN: - if (!argc) - return error(_("bisect run failed: no command provided.")); - get_terms(&terms); - res = bisect_run(&terms, argv, argc); + res = cmd_bisect__run(argc, argv, prefix); break; default: BUG("unknown subcommand %d", cmdmode); } - free_terms(&terms); /* * Handle early success From patchwork Fri Nov 4 11:40:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= X-Patchwork-Id: 13031668 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 96986C433FE for ; Fri, 4 Nov 2022 11:40:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231667AbiKDLkr (ORCPT ); Fri, 4 Nov 2022 07:40:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231302AbiKDLkd (ORCPT ); Fri, 4 Nov 2022 07:40:33 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAEC02CDE1 for ; Fri, 4 Nov 2022 04:40:31 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id k15so4299768pfg.2 for ; Fri, 04 Nov 2022 04:40:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ubtVdZipZS5W3KZeBgEFygkHS3EN6DreLxs3aSePvzw=; b=Y721tpTwh2smdJlslqFvI+oUUkv0fhWB44htUVSwK1pLnyIBwmIjAp7Pux/6+2qRwB C42BBJBm5auMcMXycv2WR4hETG9hU+/H9Le340LhCqVGpJsR6pOnDIHeueeInc1m39tK OL/YQv8SlwedD+hbEnSOVVvBGfPiUxBKifryyvTymKnmRH1orM/4wLvcOfTzJ4YI/Kup TcIaYO7C05GK4GQcjgbN+Jv+usxb//wpFJGHcZT50LU72zJOG/k0sBtPGF32IuoNREtj Qzyfs4DHsbzvyifF3jdfniB3X3pfe13uuqHSMyE/3pJr/WkDSP7ZdC5OiFFtBa9s5lLR qdIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ubtVdZipZS5W3KZeBgEFygkHS3EN6DreLxs3aSePvzw=; b=EfYSi4MnNVZN85f4tqX89mn4cKt+fg81gzY8OIJ8y1pnP/z1qyzakiTP5TNdREaMdJ 4J6CVSW+xs1+Sn/HbPDsm9ZkKFDWvcu66hBQudeTK7u5s6S3ikdro72qeCHzIjR6O26l zuM+y4W8DuPRnpBUbJUMF/xauP1vsNQw3tPti0MhfUsRA1qNOdjtXyl7v6ayfNJA2zqu jdWrJ+iH70NylIhUlEJpuMVgOh1UMdrBnsuK9FqROY4XWC6jqRsUlVjAWeNJqxVv/Bzf xrFyBE5381xryu+dPq4mbSWEfI8ko2/g3EcA+EmCNrvLGWyE718apsrHaUMXgnO9uMgl FWXw== X-Gm-Message-State: ACrzQf02cGlUBXKws/0Wx80oKww0/eoPTIV7o0V7/1fFdLBLBo8awY5S uoFjsIkbAz5grhMDbRRGbmPzyfTccsk= X-Google-Smtp-Source: AMsMyM4msjjgHD+ll7y3rxJsoO7MeHkW67jW+UopIL3ZofNTdb9CgN4nGhd5y3KWFrWstxOysymjxA== X-Received: by 2002:a05:6a00:1595:b0:56d:e04d:e0ab with SMTP id u21-20020a056a00159500b0056de04de0abmr17007885pfk.51.1667562031021; Fri, 04 Nov 2022 04:40:31 -0700 (PDT) Received: from localhost.localdomain ([2001:ee0:500b:6370:da47:cda5:dbd5:6e77]) by smtp.gmail.com with ESMTPSA id l24-20020a63ea58000000b0043c22e926f8sm2203133pgk.84.2022.11.04.04.40.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 04:40:30 -0700 (PDT) From: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= To: git@vger.kernel.org Cc: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , =?utf-8?b?THVrw6HFoSBEb2t0b3I=?= , Jeff King , Christian Couder Subject: [PATCH 3/3] bisect--helper: parse subcommand with OPT_SUBCOMMAND Date: Fri, 4 Nov 2022 18:40:12 +0700 Message-Id: <76c585d22bf415e719762fcf5decf4b71efa5bfb.1667561761.git.congdanhqx@gmail.com> X-Mailer: git-send-email 2.38.1.157.gedabe22e0a In-Reply-To: References: <1cb1c033-0525-7e62-8c09-81019bf26060@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As of it is, we're parsing subcommand with OPT_CMDMODE, which will continue to parse more options even if the command has been found. When we're running "git bisect run" with a command that expecting a "--log" or "--no-log" arguments, or one of those "--bisect-..." arguments, bisect--helper may mistakenly think those options are bisect--helper's option. We may fix those problems by passing "--" when calling from git-bisect.sh, and skip that "--" in bisect--helper. However, it may interfere with user's "--". Let's parse subcommand with OPT_SUBCOMMAND since that API was born for this specific use-case. Reported-by: Lukáš Doktor Signed-off-by: Đoàn Trần Công Danh --- builtin/bisect--helper.c | 86 +++++++------------------------------ git-bisect.sh | 20 ++++----- t/t6030-bisect-porcelain.sh | 10 +++++ 3 files changed, 36 insertions(+), 80 deletions(-) diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 292c6fd1dd..c37cb89a90 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -1392,84 +1392,30 @@ static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSE int cmd_bisect__helper(int argc, const char **argv, const char *prefix) { - enum { - BISECT_RESET = 1, - BISECT_TERMS, - BISECT_START, - BISECT_AUTOSTART, - BISECT_NEXT, - BISECT_STATE, - BISECT_LOG, - BISECT_REPLAY, - BISECT_SKIP, - BISECT_VISUALIZE, - BISECT_RUN, - } cmdmode = 0; int res = 0; + parse_opt_subcommand_fn *fn = NULL; struct option options[] = { - OPT_CMDMODE(0, "bisect-reset", &cmdmode, - N_("reset the bisection state"), BISECT_RESET), - OPT_CMDMODE(0, "bisect-terms", &cmdmode, - N_("print out the bisect terms"), BISECT_TERMS), - OPT_CMDMODE(0, "bisect-start", &cmdmode, - N_("start the bisect session"), BISECT_START), - OPT_CMDMODE(0, "bisect-next", &cmdmode, - N_("find the next bisection commit"), BISECT_NEXT), - OPT_CMDMODE(0, "bisect-state", &cmdmode, - N_("mark the state of ref (or refs)"), BISECT_STATE), - OPT_CMDMODE(0, "bisect-log", &cmdmode, - N_("list the bisection steps so far"), BISECT_LOG), - OPT_CMDMODE(0, "bisect-replay", &cmdmode, - N_("replay the bisection process from the given file"), BISECT_REPLAY), - OPT_CMDMODE(0, "bisect-skip", &cmdmode, - N_("skip some commits for checkout"), BISECT_SKIP), - OPT_CMDMODE(0, "bisect-visualize", &cmdmode, - N_("visualize the bisection"), BISECT_VISUALIZE), - OPT_CMDMODE(0, "bisect-run", &cmdmode, - N_("use ... to automatically bisect"), BISECT_RUN), + OPT_SUBCOMMAND("bisect-reset", &fn, cmd_bisect__reset), + OPT_SUBCOMMAND("bisect-terms", &fn, cmd_bisect__terms), + OPT_SUBCOMMAND("bisect-start", &fn, cmd_bisect__start), + OPT_SUBCOMMAND("bisect-next", &fn, cmd_bisect__next), + OPT_SUBCOMMAND("bisect-state", &fn, cmd_bisect__state), + OPT_SUBCOMMAND("bisect-log", &fn, cmd_bisect__log), + OPT_SUBCOMMAND("bisect-replay", &fn, cmd_bisect__replay), + OPT_SUBCOMMAND("bisect-skip", &fn, cmd_bisect__skip), + OPT_SUBCOMMAND("bisect-visualize", &fn, cmd_bisect__visualize), + OPT_SUBCOMMAND("bisect-run", &fn, cmd_bisect__run), OPT_END() }; argc = parse_options(argc, argv, prefix, options, - git_bisect_helper_usage, - PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_UNKNOWN_OPT); + git_bisect_helper_usage, 0); - if (!cmdmode) + if (!fn) usage_with_options(git_bisect_helper_usage, options); + argc--; + argv++; - switch (cmdmode) { - case BISECT_RESET: - res = cmd_bisect__reset(argc, argv, prefix); - break; - case BISECT_TERMS: - res = cmd_bisect__terms(argc, argv, prefix); - break; - case BISECT_START: - res = cmd_bisect__start(argc, argv, prefix); - break; - case BISECT_NEXT: - res = cmd_bisect__next(argc, argv, prefix); - break; - case BISECT_STATE: - res = cmd_bisect__state(argc, argv, prefix); - break; - case BISECT_LOG: - res = cmd_bisect__log(argc, argv, prefix); - break; - case BISECT_REPLAY: - res = cmd_bisect__replay(argc, argv, prefix); - break; - case BISECT_SKIP: - res = cmd_bisect__skip(argc, argv, prefix); - break; - case BISECT_VISUALIZE: - res = cmd_bisect__visualize(argc, argv, prefix); - break; - case BISECT_RUN: - res = cmd_bisect__run(argc, argv, prefix); - break; - default: - BUG("unknown subcommand %d", cmdmode); - } + res = fn(argc, argv, prefix); /* * Handle early success diff --git a/git-bisect.sh b/git-bisect.sh index 405cf76f2a..07a7257be4 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -58,26 +58,26 @@ case "$#" in help) git bisect -h ;; start) - git bisect--helper --bisect-start "$@" ;; + git bisect--helper bisect-start "$@" ;; bad|good|new|old|"$TERM_BAD"|"$TERM_GOOD") - git bisect--helper --bisect-state "$cmd" "$@" ;; + git bisect--helper bisect-state "$cmd" "$@" ;; skip) - git bisect--helper --bisect-skip "$@" || exit;; + git bisect--helper bisect-skip "$@" || exit;; next) # Not sure we want "next" at the UI level anymore. - git bisect--helper --bisect-next "$@" || exit ;; + git bisect--helper bisect-next "$@" || exit ;; visualize|view) - git bisect--helper --bisect-visualize "$@" || exit;; + git bisect--helper bisect-visualize "$@" || exit;; reset) - git bisect--helper --bisect-reset "$@" ;; + git bisect--helper bisect-reset "$@" ;; replay) - git bisect--helper --bisect-replay "$@" || exit;; + git bisect--helper bisect-replay "$@" || exit;; log) - git bisect--helper --bisect-log || exit ;; + git bisect--helper bisect-log || exit ;; run) - git bisect--helper --bisect-run "$@" || exit;; + git bisect--helper bisect-run "$@" || exit;; terms) - git bisect--helper --bisect-terms "$@" || exit;; + git bisect--helper bisect-terms "$@" || exit;; *) usage ;; esac diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh index 83931d482f..a17027d574 100755 --- a/t/t6030-bisect-porcelain.sh +++ b/t/t6030-bisect-porcelain.sh @@ -266,6 +266,16 @@ test_expect_success '"git bisect run" simple case' ' git bisect reset ' +# We want to make sure --log is not eaten +test_expect_success '"git bisect run" simple case' ' + git bisect start && + git bisect good $HASH1 && + git bisect bad $HASH4 && + git bisect run printf "%s\n" --log >my_bisect_log.txt && + grep -e --log my_bisect_log.txt && + git bisect reset +' + # We want to automatically find the commit that # added "Ciao" into hello. test_expect_success '"git bisect run" with more complex "git bisect start"' '