From patchwork Wed Apr 7 17:33:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 12189053 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35D56C433ED for ; Wed, 7 Apr 2021 17:34:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B6DC61262 for ; Wed, 7 Apr 2021 17:34:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354888AbhDGRek (ORCPT ); Wed, 7 Apr 2021 13:34:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354875AbhDGRee (ORCPT ); Wed, 7 Apr 2021 13:34:34 -0400 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 71E1FC061760 for ; Wed, 7 Apr 2021 10:34:24 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id a6so12824576wrw.8 for ; Wed, 07 Apr 2021 10:34:24 -0700 (PDT) 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=zzDdjHyE+0HmhV6Jsh0BOjFXzaLyqonGbVOaBw0ZRpE=; b=gEMgNLjhxPMLou32jgILpiG5b1XLb8RFxReAVDvD6S8ZDZr71c1tQ7uk7AXYCDKyDT griLqbqcwQKQG2QhD1aKO+VEg6cgBJv3nTIjSHh7RMl8yB4tqdaqVwywDugDKtt3Tq3P UDnf9R3YNuFQLfOg9iGqDFAM+vYoQEBs98eADRGKpS0V2s5N2ZI+2PkFm9ON1RQCI083 /KYjqKRU0/34ssM5qDktMQRtntsP0y66cVnK+09ME6MscMszxOK/GFKKBvGDdKyr43dq keZM77JJs4uUfYy1r0sJvdsT2mj/RqycgzDO2ZZoWGiH/k/3RQVjwWcjdmM8YhEXmAtz f4Bw== 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=zzDdjHyE+0HmhV6Jsh0BOjFXzaLyqonGbVOaBw0ZRpE=; b=B1okLju34Ej7Jxz1xAcBGVyt6SNKdGuxZ7DtcIHPrMuzkgLRQPbaToWH7SWFphGHO4 UQTc7TFQhTRu7DyrGlT/I4VKeAqXfqA1stQG83p+rRK0D3n3lv1UmTCq8vARTuU4pK+k Tuf8MnPvAR/qs1SVjiaHxE/gInUR9b47EsfEV4gr11c7ZiJSHzGnVEZNwNLfYIIZHBfi rZIw4u/VCxNP1boeSBuQ9FehKiqkewyTzmvFrArzsZoamVYKFQhBCL+5V1CJ+5W8xM9g 9yzKUtOppN6WcXVhpmSeRzineXud3qjGZMfKbiyU06Aw6Wu0ERfyMmQbGCMi93dZdfCk nY5g== X-Gm-Message-State: AOAM531GDsMnTekS3C4BDSzWvZzfsMRQ+DUsS+NEmjE9ic+rWTDRDnIa fiIq/BJZDxLWVw6bOMBOyWiFq7x2JXFJ2Q== X-Google-Smtp-Source: ABdhPJzfWrdqSTwAzKTXnOE25/dk/cQhO47GhRH9auBPXeuluvBQIxm8eRj1v5d90M+QpSjAudUDvQ== X-Received: by 2002:adf:c186:: with SMTP id x6mr5750554wre.253.1617816863282; Wed, 07 Apr 2021 10:34:23 -0700 (PDT) Received: from localhost.localdomain ([81.0.37.230]) by smtp.gmail.com with ESMTPSA id o7sm41657197wrs.16.2021.04.07.10.34.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Apr 2021 10:34:22 -0700 (PDT) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Tanushree Tumane , Miriam Rubio Subject: [PATCH v2 1/4] run-command: make `exists_in_PATH()` non-static Date: Wed, 7 Apr 2021 19:33:30 +0200 Message-Id: <20210407173334.68222-2-mirucam@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210407173334.68222-1-mirucam@gmail.com> References: <20210407173334.68222-1-mirucam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Pranit Bauva Removes the `static` keyword from `exists_in_PATH()` function and declares the function in `run-command.h` file. The function will be used in bisect_visualize() in a later commit. `exists_in_PATH()` and `locate_in_PATH()` functions don't depend on file-local variables. Mentored by: Christian Couder Mentored by: Johannes Schindelin Signed-off-by: Tanushree Tumane Signed-off-by: Miriam Rubio --- run-command.c | 2 +- run-command.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/run-command.c b/run-command.c index be6bc128cd..210b8858f7 100644 --- a/run-command.c +++ b/run-command.c @@ -211,7 +211,7 @@ static char *locate_in_PATH(const char *file) return NULL; } -static int exists_in_PATH(const char *file) +int exists_in_PATH(const char *file) { char *r = locate_in_PATH(file); int found = r != NULL; diff --git a/run-command.h b/run-command.h index d08414a92e..a520ad1342 100644 --- a/run-command.h +++ b/run-command.h @@ -179,6 +179,16 @@ void child_process_clear(struct child_process *); int is_executable(const char *name); +/** + * Returns if a $PATH given by parameter is found or not (it is NULL). This + * function uses locate_in_PATH() function that emulates the path search that + * execvp would perform. Memory used to store the resultant path is freed by + * the function. + * + * The caller should ensure that $PATH contains no directory separators. + */ +int exists_in_PATH(const char *file); + /** * Start a sub-process. Takes a pointer to a `struct child_process` * that specifies the details and returns pipe FDs (if requested). From patchwork Wed Apr 7 17:33:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 12189057 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E137C433B4 for ; Wed, 7 Apr 2021 17:34:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4E2D61262 for ; Wed, 7 Apr 2021 17:34:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354891AbhDGRem (ORCPT ); Wed, 7 Apr 2021 13:34:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354880AbhDGRef (ORCPT ); Wed, 7 Apr 2021 13:34:35 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46506C06175F for ; Wed, 7 Apr 2021 10:34:25 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id z24-20020a1cf4180000b029012463a9027fso1020075wma.5 for ; Wed, 07 Apr 2021 10:34:25 -0700 (PDT) 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=+9fryXH1et7HH7cUCVPfCiR4w/AEgQEVLcqt4AeGkB4=; b=U4ARIB+7pK2sqLG6s7YMJw/BPVXgey146g6VEWyyXUCn5hUbOQw/icKOnvo2LfaeTT q8jR0vZm2YwwuU0a9GFFlX1U49ZAxqdjsIECbVjSQiHyASsV9MBruy7hA2akqOH27XPc Z1uiYvTu2T9TmtXXJiBGdeUub06xayLC5+JVIJPMCP1qGbdzqQvM/saVY1Q1UvNoAtc+ xB8vNioCdtwU/DEy/q94smqjR1DsSFLFLWq3eKnptkMZyqTlCPXepKhlk76wbb+2qn65 yw99UgNhnRu7YfKWEta0/fXQVDlKiUyTeZb2HeZkMGkGjhjB2N9L1QveZgJsvMnzh1hJ TVbQ== 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=+9fryXH1et7HH7cUCVPfCiR4w/AEgQEVLcqt4AeGkB4=; b=as7mS8A0hbviW4rsUFabSPfoydRzBLGKVo8qaip/1NwA2//v7wLw5KGSJcPrPzetUC xbsq+kxFb7hX1XDzC7E/0+P7WEdzoNOjpgG0QnIStWch63akH8qPQgFTgeqFE2h8RUwq vwgPai6n+s6ExofiOL6P028So7lsdnFUpBL7taWJ61Z5fMxUu3ZIZkFf6jX/O+fpMfNK H7yU4Fnwhi47hJM2o+YPFLWpcKKOrHz5pOgxdHxdrs99RVN9MXhr67hg07TGqLk8d4pb YJG9+jhfq1EvrqIZQhHdZD6th+PsPODHxMJDdQVQZrz+PgwsZ5RA4x04h58tO9nL6LPD uwfA== X-Gm-Message-State: AOAM5334Qt/dQdylpXrxrXKcJhxrjGJLHdP6lWyEAskT8YWu/YPoTOpn vsya6xgxnpeMgm+mWMoUMyR3pIc6QN5/rw== X-Google-Smtp-Source: ABdhPJyRp7+8pBYOysoJ9l34r2fdWDmY6eJMnoOxip+sPZ0NZFYjfJM6W4OzKqdgOV8S5oDLjoTlDA== X-Received: by 2002:a1c:ed05:: with SMTP id l5mr4208909wmh.154.1617816864025; Wed, 07 Apr 2021 10:34:24 -0700 (PDT) Received: from localhost.localdomain ([81.0.37.230]) by smtp.gmail.com with ESMTPSA id o7sm41657197wrs.16.2021.04.07.10.34.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Apr 2021 10:34:23 -0700 (PDT) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Johannes Schindelin , Tanushree Tumane , Miriam Rubio Subject: [PATCH v2 2/4] bisect--helper: reimplement `bisect_visualize()`shell function in C Date: Wed, 7 Apr 2021 19:33:31 +0200 Message-Id: <20210407173334.68222-3-mirucam@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210407173334.68222-1-mirucam@gmail.com> References: <20210407173334.68222-1-mirucam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Pranit Bauva Reimplement the `bisect_visualize()` shell function in C and also add `--bisect-visualize` subcommand to `git bisect--helper` to call it from git-bisect.sh. Mentored-by: Christian Couder Mentored-by: Johannes Schindelin Signed-off-by: Tanushree Tumane Signed-off-by: Miriam Rubio --- builtin/bisect--helper.c | 48 +++++++++++++++++++++++++++++++++++++++- git-bisect.sh | 25 +-------------------- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 1fdb7d9d10..b77c4f6b29 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -30,6 +30,7 @@ static const char * const git_bisect_helper_usage[] = { N_("git bisect--helper --bisect-state (good|old) [...]"), N_("git bisect--helper --bisect-replay "), N_("git bisect--helper --bisect-skip [(|)...]"), + N_("git bisect--helper --bisect-visualize"), NULL }; @@ -1034,6 +1035,44 @@ static enum bisect_error bisect_skip(struct bisect_terms *terms, const char **ar return res; } +static int bisect_visualize(struct bisect_terms *terms, const char **argv, int argc) +{ + struct strvec args = STRVEC_INIT; + int flags = RUN_COMMAND_NO_STDIN, res = 0; + struct strbuf sb = STRBUF_INIT; + + if (bisect_next_check(terms, NULL) != 0) + return BISECT_FAILED; + + if (!argc) { + if ((getenv("DISPLAY") || getenv("SESSIONNAME") || getenv("MSYSTEM") || + getenv("SECURITYSESSIONID")) && exists_in_PATH("gitk")) + strvec_push(&args, "gitk"); + else { + strvec_pushl(&args, "log", NULL); + flags |= RUN_GIT_CMD; + } + } else { + if (argv[0][0] == '-') { + strvec_pushl(&args, "log", NULL); + flags |= RUN_GIT_CMD; + } else if (strcmp(argv[0], "tig") && !starts_with(argv[0], "git")) + flags |= RUN_GIT_CMD; + + strvec_pushv(&args, argv); + } + + strvec_pushl(&args, "--bisect", NULL); + + strbuf_read_file(&sb, git_path_bisect_names(), 0); + strvec_split(&args, sb.buf); + strbuf_release(&sb); + + res = run_command_v_opt(args.v, flags); + strvec_clear(&args); + return res; +} + int cmd_bisect__helper(int argc, const char **argv, const char *prefix) { enum { @@ -1046,7 +1085,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) BISECT_STATE, BISECT_LOG, BISECT_REPLAY, - BISECT_SKIP + BISECT_SKIP, + BISECT_VISUALIZE } cmdmode = 0; int res = 0, nolog = 0; struct option options[] = { @@ -1068,6 +1108,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) 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_BOOL(0, "no-log", &nolog, N_("no log for BISECT_WRITE")), OPT_END() @@ -1128,6 +1170,10 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) set_terms(&terms, "bad", "good"); res = bisect_skip(&terms, argv, argc); break; + case BISECT_VISUALIZE: + get_terms(&terms); + res = bisect_visualize(&terms, argv, argc); + break; default: BUG("unknown subcommand %d", cmdmode); } diff --git a/git-bisect.sh b/git-bisect.sh index 6a7afaea8d..95f7f3fb8c 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -39,29 +39,6 @@ _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40" TERM_BAD=bad TERM_GOOD=good -bisect_visualize() { - git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit - - if test $# = 0 - then - if test -n "${DISPLAY+set}${SESSIONNAME+set}${MSYSTEM+set}${SECURITYSESSIONID+set}" && - type gitk >/dev/null 2>&1 - then - set gitk - else - set git log - fi - else - case "$1" in - git*|tig) ;; - -*) set git log "$@" ;; - *) set git "$@" ;; - esac - fi - - eval '"$@"' --bisect -- $(cat "$GIT_DIR/BISECT_NAMES") -} - bisect_run () { git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit @@ -152,7 +129,7 @@ case "$#" in # Not sure we want "next" at the UI level anymore. git bisect--helper --bisect-next "$@" || exit ;; visualize|view) - bisect_visualize "$@" ;; + git bisect--helper --bisect-visualize "$@" || exit;; reset) git bisect--helper --bisect-reset "$@" ;; replay) From patchwork Wed Apr 7 17:33:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 12189055 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A956C433ED for ; Wed, 7 Apr 2021 17:34:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E782E6128D for ; Wed, 7 Apr 2021 17:34:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354894AbhDGRen (ORCPT ); Wed, 7 Apr 2021 13:34:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354881AbhDGReg (ORCPT ); Wed, 7 Apr 2021 13:34:36 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08849C061760 for ; Wed, 7 Apr 2021 10:34:26 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id f12so12852555wro.0 for ; Wed, 07 Apr 2021 10:34:25 -0700 (PDT) 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=DSUY569oHjkC1ywZQ0wdQmy4KfPUqh+cHJCfrmIfiOw=; b=KvDJkl37hdkpAvuen7PvrX+l3Uxu2xrrK9wsvB8czC7nX0hbU/dCYHUL8ToTkC0LVv WjtDCUfkZe0WQauGePNvQK+4syLTWvZjOHIkq7HehJD6lTfcFmovDhxqix8Vj9AHTel9 d6CkTlpRptDxKB0f8YAzQ3O2K0A6AooVbAnP/pXs9FKvw+VElzq3UBo4Hvt0DTSUeBFP /PtZtPn/gtlagqxcPWImqjyTf/BFTXm7euUfoMolDxcggF5btnyZglNMcc4b9UQJ4SVt 8+Qhcl3VB0WB/6iVUJurgAxO53m3iuneIZ5pXz0M7sFrrYF56Ey7EpwVfoQS8SR/EqcY wWwQ== 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=DSUY569oHjkC1ywZQ0wdQmy4KfPUqh+cHJCfrmIfiOw=; b=Tb7LMQEMAC2BDNq+OloybAxUagS1SoovqvD0j4n9Le5pJACBJR/TB5KlUqK0pcmM0p Fqd8iBYLOcmbSkO8z1z2VjKCFG2x3abMNATHIGgTFg5Nc4qPPtEJLMhewYHC7IFvc43q bec8BwZyyjYNb2omOMQXZB/uuAOH1yRj4wKURW3MDk4n+2enVdfgCq3wPVWcYCAaSkPT RRlkmIMWaO2Yya413kPUFsV7pCW12D6y6xDPw+Zb2i6s0ksexvo6z4RXm2+sBYcnJZ3O ybYidDDTudbkU5gL+Z2q8Dzy/MYRLW19CsSKFTgcLV75I0iNasW0xM8HrP9BLBK3uaXm czbA== X-Gm-Message-State: AOAM533oZQOGK8cDKKmWdd0Wwc2LBqpDYSCqL+98YzTSymz2aC4dV6en rxlKwURhidJPRsmJrNkkoUAWhJ6cWpEoHg== X-Google-Smtp-Source: ABdhPJzqkkP53P+nuH3qbPq+i1myiAusp5/aDcIdT74TxQxYH7IrlzKUysuLE0J3KdYxiRzOIgNWHg== X-Received: by 2002:a5d:5082:: with SMTP id a2mr5652722wrt.267.1617816864812; Wed, 07 Apr 2021 10:34:24 -0700 (PDT) Received: from localhost.localdomain ([81.0.37.230]) by smtp.gmail.com with ESMTPSA id o7sm41657197wrs.16.2021.04.07.10.34.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Apr 2021 10:34:24 -0700 (PDT) From: Miriam Rubio To: git@vger.kernel.org Cc: Tanushree Tumane , Christian Couder , Miriam Rubio Subject: [PATCH v2 3/4] bisect--helper: reimplement `bisect_run` shell function in C Date: Wed, 7 Apr 2021 19:33:32 +0200 Message-Id: <20210407173334.68222-4-mirucam@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210407173334.68222-1-mirucam@gmail.com> References: <20210407173334.68222-1-mirucam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Tanushree Tumane Reimplement the `bisect_run()` shell function in C and also add `--bisect-run` subcommand to `git bisect--helper` to call it from git-bisect.sh. Mentored-by: Christian Couder Signed-off-by: Tanushree Tumane Signed-off-by: Miriam Rubio --- builtin/bisect--helper.c | 71 +++++++++++++++++++++++++++++++++++++++- git-bisect.sh | 62 +---------------------------------- 2 files changed, 71 insertions(+), 62 deletions(-) diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index b77c4f6b29..31c5f99660 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -31,6 +31,7 @@ static const char * const git_bisect_helper_usage[] = { N_("git bisect--helper --bisect-replay "), N_("git bisect--helper --bisect-skip [(|)...]"), N_("git bisect--helper --bisect-visualize"), + N_("git bisect--helper --bisect-run ..."), NULL }; @@ -1073,6 +1074,65 @@ static int bisect_visualize(struct bisect_terms *terms, const char **argv, int a return res; } +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; + + if (bisect_next_check(terms, NULL)) + return BISECT_FAILED; + + if (argc) + sq_quote_argv(&command, argv); + else + return BISECT_FAILED; + + run_args.v[0] = xstrdup(command.buf); + run_args.nr = 1; + + while (1) { + strvec_clear(&args); + + printf(_("running %s"), command.buf); + res = run_command_v_opt(run_args.v, RUN_USING_SHELL); + + if (res < 0 && res >= 128) { + error(_("bisect run failed: exit code %d from" + " '%s' is < 0 or >= 128"), res, command.buf); + strbuf_release(&command); + return res; + } + + if (res == 125) + strvec_push(&args, "skip"); + else if (res > 0) + strvec_push(&args, terms->term_bad); + else + strvec_push(&args, terms->term_good); + + res = bisect_state(terms, args.v, args.nr); + + if (res == BISECT_INTERNAL_SUCCESS_MERGE_BASE) { + printf(_("bisect run success")); + res = BISECT_OK; + } else if (res == BISECT_ONLY_SKIPPED_LEFT) + error(_("bisect run cannot continue any more")); + else if (res) + error(_("bisect run failed:'git bisect--helper --bisect-state" + " %s' exited with error code %d"), args.v[0], res); + else + continue; + + strbuf_release(&command); + strvec_clear(&args); + strvec_clear(&run_args); + + return res; + } +} + int cmd_bisect__helper(int argc, const char **argv, const char *prefix) { enum { @@ -1086,7 +1146,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) BISECT_LOG, BISECT_REPLAY, BISECT_SKIP, - BISECT_VISUALIZE + BISECT_VISUALIZE, + BISECT_RUN, } cmdmode = 0; int res = 0, nolog = 0; struct option options[] = { @@ -1110,6 +1171,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) 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_BOOL(0, "no-log", &nolog, N_("no log for BISECT_WRITE")), OPT_END() @@ -1174,6 +1237,12 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) get_terms(&terms); res = bisect_visualize(&terms, argv, argc); break; + case BISECT_RUN: + if (!argc) + return error(_("bisect run failed: no command provided.")); + get_terms(&terms); + res = bisect_run(&terms, argv, argc); + break; default: BUG("unknown subcommand %d", cmdmode); } diff --git a/git-bisect.sh b/git-bisect.sh index 95f7f3fb8c..e83d011e17 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -39,66 +39,6 @@ _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40" TERM_BAD=bad TERM_GOOD=good -bisect_run () { - git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit - - test -n "$*" || die "$(gettext "bisect run failed: no command provided.")" - - while true - do - command="$@" - eval_gettextln "running \$command" - "$@" - res=$? - - # Check for really bad run error. - if [ $res -lt 0 -o $res -ge 128 ] - then - eval_gettextln "bisect run failed: -exit code \$res from '\$command' is < 0 or >= 128" >&2 - exit $res - fi - - # Find current state depending on run success or failure. - # A special exit code of 125 means cannot test. - if [ $res -eq 125 ] - then - state='skip' - elif [ $res -gt 0 ] - then - state="$TERM_BAD" - else - state="$TERM_GOOD" - fi - - git bisect--helper --bisect-state $state >"$GIT_DIR/BISECT_RUN" - res=$? - - cat "$GIT_DIR/BISECT_RUN" - - if sane_grep "first $TERM_BAD commit could be any of" "$GIT_DIR/BISECT_RUN" \ - >/dev/null - then - gettextln "bisect run cannot continue any more" >&2 - exit $res - fi - - if [ $res -ne 0 ] - then - eval_gettextln "bisect run failed: -'bisect-state \$state' exited with error code \$res" >&2 - exit $res - fi - - if sane_grep "is the first $TERM_BAD commit" "$GIT_DIR/BISECT_RUN" >/dev/null - then - gettextln "bisect run success" - exit 0; - fi - - done -} - get_terms () { if test -s "$GIT_DIR/BISECT_TERMS" then @@ -137,7 +77,7 @@ case "$#" in log) git bisect--helper --bisect-log || exit ;; run) - bisect_run "$@" ;; + git bisect--helper --bisect-run "$@" || exit;; terms) git bisect--helper --bisect-terms "$@" || exit;; *) From patchwork Wed Apr 7 17:33:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 12189059 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A76EC43460 for ; Wed, 7 Apr 2021 17:34:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0679861363 for ; Wed, 7 Apr 2021 17:34:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354885AbhDGReq (ORCPT ); Wed, 7 Apr 2021 13:34:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354886AbhDGRei (ORCPT ); Wed, 7 Apr 2021 13:34:38 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98D87C061761 for ; Wed, 7 Apr 2021 10:34:26 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id b133-20020a1c678b0000b02901231346381dso1611966wmc.0 for ; Wed, 07 Apr 2021 10:34:26 -0700 (PDT) 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=gO0AxTlSP9JgWbiUcJUymvi+2jRVcSGEQ7hJF8nhFCo=; b=NfAqWj3Gm/hvkruLk0VrGa6Pb/KZb7FXfOZOl4vygMPl8zoHx19guAA0OE7yCcR1CJ XEtGxxIb+9YSgqyTGJNW+bpZCOu1Y7bIo6legtXaNR4n5WTbCGByfRL4nXRsWVs9GxNc CBPxLEXZNvAhpZiWNJUNe3uAqhmxWj/BYdFTmDrdsa+oTU1jpWw4thxOxLSZTwVHAZP3 OB8Kv8fauT74jp7F1pntaxbRtBMVFZg+h7fOt9Wy0EWT1SajhhaBD4pu8v4b/soE/+Gb ewO30pYO8eYUjE/T+ZSQSzwSQfbnWpgWC5ozPHgd53YRUeIyxJE8XQs13gzfRxgh1WZJ zdDw== 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=gO0AxTlSP9JgWbiUcJUymvi+2jRVcSGEQ7hJF8nhFCo=; b=l06wxoJHy0qJVxcniqWjvfrwV70bIBMkb8OVx2I5qTMNtUCo5HvqynVIdnalLBQ6MI 4h5z8ai0Da8DvxRBmEiLCGkmSqm/d6HzuO21m2lBG3bhCG1GUJBVPIifZj57Ftox2TZf KRiOwuufBOV44xFX3FeSkbVhxCU2+VekOutisUzfOxMs6Pk8a2JKhm7JJpMLkAeJ6iZ0 MXiZr36sJPQHezfI3Y4e1tuUG7UaoJfexmMH4ykBCtEJ2v4NF4SNzyw9nrDf7iFQucLf a0jFQysgzIligQkW2j4hVsjH8S/Uih3M33/67NilJZuHLyYCeXLTRTupW5mqfgTqdgBp j7GQ== X-Gm-Message-State: AOAM532s/L0F6PrMMPyOIHDh2ZpWt9G/Nk6QVwybbJjJSWFZp8ljND5m 6EDJxjQV7lhsMbPoBQ9dxuoJialDZFjSow== X-Google-Smtp-Source: ABdhPJzKzgoXL8miVH9WYkjfvY3VuCwm4VtXVEB2MIG/zlmmzsRizvqCzaXwIVt2ClIS1iYulzji4w== X-Received: by 2002:a1c:f407:: with SMTP id z7mr2745553wma.20.1617816865412; Wed, 07 Apr 2021 10:34:25 -0700 (PDT) Received: from localhost.localdomain ([81.0.37.230]) by smtp.gmail.com with ESMTPSA id o7sm41657197wrs.16.2021.04.07.10.34.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Apr 2021 10:34:25 -0700 (PDT) From: Miriam Rubio To: git@vger.kernel.org Cc: Miriam Rubio Subject: [PATCH v2 4/4] bisect--helper: retire `--bisect-next-check` subcommand Date: Wed, 7 Apr 2021 19:33:33 +0200 Message-Id: <20210407173334.68222-5-mirucam@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210407173334.68222-1-mirucam@gmail.com> References: <20210407173334.68222-1-mirucam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org After reimplementation of `git bisect run` in C, `--bisect-next-check` subcommand is not needed anymore. Let's remove it from options list and code. Mentored by: Christian Couder Signed-off-by: Miriam Rubio --- builtin/bisect--helper.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 31c5f99660..c20f43c581 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -21,7 +21,6 @@ static GIT_PATH_FUNC(git_path_bisect_first_parent, "BISECT_FIRST_PARENT") static const char * const git_bisect_helper_usage[] = { N_("git bisect--helper --bisect-reset []"), - N_("git bisect--helper --bisect-next-check []"), N_("git bisect--helper --bisect-terms [--term-good | --term-old | --term-bad | --term-new]"), N_("git bisect--helper --bisect-start [--term-{new,bad}= --term-{old,good}=]" " [--no-checkout] [--first-parent] [ [...]] [--] [...]"), @@ -1192,12 +1191,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) return error(_("--bisect-reset requires either no argument or a commit")); res = bisect_reset(argc ? argv[0] : NULL); break; - case BISECT_NEXT_CHECK: - if (argc != 2 && argc != 3) - return error(_("--bisect-next-check requires 2 or 3 arguments")); - set_terms(&terms, argv[1], argv[0]); - res = bisect_next_check(&terms, argc == 3 ? argv[2] : NULL); - break; case BISECT_TERMS: if (argc > 1) return error(_("--bisect-terms requires 0 or 1 argument"));