From patchwork Wed Sep 23 07:27:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11794153 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D22FA6CA for ; Wed, 23 Sep 2020 07:28:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B38A6235FC for ; Wed, 23 Sep 2020 07:28:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b4w7NJhx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726758AbgIWH2G (ORCPT ); Wed, 23 Sep 2020 03:28:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726557AbgIWH2D (ORCPT ); Wed, 23 Sep 2020 03:28:03 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DD6EC061755 for ; Wed, 23 Sep 2020 00:28:03 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id s13so5978636wmh.4 for ; Wed, 23 Sep 2020 00:28:03 -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=M+JmQMk+e2m4npZedAl84xsb23PB90uGmu0PhUZk5L0=; b=b4w7NJhxEbIFOHB7my3zrwDsuS2nFfFDguYJdqIyDLnjYWXAEX7hhkLH7rGkZ6wq1r 1TwbuugMt+kKVlHK6Tp5gsvfkRTC9pbUUpEAqj4tGny2dPdGy885ws9fNwcEzFEy2UHb gwY0xmLTUEFvPHaCFLnvKEQxhO+M9owh3g3KtBNqYF4BaDETfL5pJqs/G8LShKiVRmDL 21SxK5QHA0Gzgmlfarh181fdtK26RaOXUO32fj2lQ7B0Hi3V5KcnVhnhUpSXG8CN12Td 0Kdnh//vAm3Mey4WkppzXiMjxMZRa5X3jdG7beDg/opKM7qUs0v5geuHm6toVY8hFtcf ICDg== 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=M+JmQMk+e2m4npZedAl84xsb23PB90uGmu0PhUZk5L0=; b=keqkgvAmpNrmC/W/lzPcaUBCoZUq1qGB0LxJRP1nlHtyHjy8lWvfK/rsz/wI9nkKiS Tzbsj50J2cP4yiOxDmlSBakKrrSUSXoExBCC4ber8J7c3cdo9mXUiG3d42E5vwDyTU7k +vp2NFSjUl3X/F0s9HymXBbCY1VSTeuetOno7Glt2cRxJ/qFGlRTlP15Gio6tXwi0JDM 0i1rGCWKZbVVqg0gTk3yLiDY7gMFetIvFWtrFvDo+OMfiR4BLme5yj0zo4Q6IW99B5SN TPNf3SZbnTz7TRm8h/fAQYhn6++JjZcxu6fRbUIaU+VTr1tsW3+hX1iT2woDmN4FXypS crFQ== X-Gm-Message-State: AOAM530G9HzT7dSR1o12+tAXqGyZg6J9fuj68qTy51qez6H2mPr/KmF/ ro2VbLMkb4PyEu3gzXVAYdkUHWauVik= X-Google-Smtp-Source: ABdhPJzMMxew31yEGz55UwxpteZzpIAkmaGPbfJIuiY8qBP+CNZI2iu8VNIsNsa9prN0MtMYYaOQhQ== X-Received: by 2002:a1c:cc0a:: with SMTP id h10mr4660949wmb.80.1600846081635; Wed, 23 Sep 2020 00:28:01 -0700 (PDT) Received: from localhost.localdomain ([178.237.235.60]) by smtp.gmail.com with ESMTPSA id j14sm30046838wrr.66.2020.09.23.00.28.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Sep 2020 00:28:01 -0700 (PDT) From: Miriam Rubio To: git@vger.kernel.org Cc: Miriam Rubio , Christian Couder , Johannes Schindelin Subject: [PATCH v8 1/6] bisect--helper: BUG() in cmd_*() on invalid subcommand Date: Wed, 23 Sep 2020 09:27:35 +0200 Message-Id: <20200923072740.20772-2-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200923072740.20772-1-mirucam@gmail.com> References: <20200923072740.20772-1-mirucam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In cmd_bisect__helper() function, if an invalid or no subcommand is passed there is a BUG. BUG() out instead of returning an error. Mentored-by: Christian Couder Mentored-by: Johannes Schindelin Signed-off-by: Miriam Rubio --- builtin/bisect--helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 7dcc1b5188..23a9f00035 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -720,7 +720,7 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) res = bisect_start(&terms, argv, argc); break; default: - return error("BUG: unknown subcommand '%d'", cmdmode); + BUG("unknown subcommand %d", cmdmode); } free_terms(&terms); From patchwork Wed Sep 23 07:27:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11794155 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9F3A36CA for ; Wed, 23 Sep 2020 07:28:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F5B52223E for ; Wed, 23 Sep 2020 07:28:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N3AYN0JK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726748AbgIWH2F (ORCPT ); Wed, 23 Sep 2020 03:28:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726738AbgIWH2E (ORCPT ); Wed, 23 Sep 2020 03:28:04 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C028C0613D1 for ; Wed, 23 Sep 2020 00:28:04 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id a17so19772928wrn.6 for ; Wed, 23 Sep 2020 00:28:04 -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=c9Y7TvxvEafAn9PpUMsqnYYW+Mm5hIL2kR7H/olF6XM=; b=N3AYN0JKwgc5XGVyjS0PVypMLdUcRmPHQqrKSCidrS4cPH5IvCoPWeH4MF93/oDZpd XnBYCKgqODo1/K7QXemk1zJSe59gxlXv9Zmng61Q6YO42Vj8cALCXa8JLf3/PubQ53lT 4jDt1GZfpn+fcrYyOwlZI/Xx9r3gHN6AaGAsq/io2aV6nmUGPkSXIY0Byhcm6iC3RfHw TafAa3l711+kka39fmx6A92i4om5Z4GnzGWfiv+x3YdxQOyWTxGElr2EP2Fe9AmF6i22 rfWr54oxGdivKNJ/Dxt+lHanXYmwvXmf9V1JtnpCLdJOrmV+7VEMiapffjItV87TxmSz l3Nw== 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=c9Y7TvxvEafAn9PpUMsqnYYW+Mm5hIL2kR7H/olF6XM=; b=F71FVzAx8HpKDIq4N+3RrFe1DWsDTAyG8Nn3ydM60cj+Pd1Jdr7lRDpx4lOkHVFcSU G3nj2kpyG6qW/n2+rZyr4tLujZLN+nM+aC9C/BA/B6t9AKpIWwLpuol1orKacSatuJPf UwtWvCCK6xC0fFawIsbXPNRgqpYsVLlXbZy4KwVqJeCEr5XRhLRNBAtFTRsQQwsAnYr/ eJtTXoZqjDPxMY4ZO/9Cq6ziqkc2SI2oWjfnLoLCEoT7K8GKfl0YgPxxBru42yaM8Oaq HLFb2soFYzi46UrwMZ+ZpD0Fcv2MRTNbfWpnYTY7+GkCzAN/0fFvV54QRhKYVxKBOhuQ adyg== X-Gm-Message-State: AOAM530LrbTFjGaIQOe6B0zPWfqmts/qnWYaAajwEClZypHQSql3wKt6 gQRSpDv1lgeC4dcl0fkqEgcmzbW68SU= X-Google-Smtp-Source: ABdhPJwtosypFVn3Hlkn13oO2ZlG/k+cFIK8mNRUuI2FkqP2eLaYVZx78F/X2t0qIfHbjEa5adS9AQ== X-Received: by 2002:a5d:5306:: with SMTP id e6mr9837887wrv.156.1600846082942; Wed, 23 Sep 2020 00:28:02 -0700 (PDT) Received: from localhost.localdomain ([178.237.235.60]) by smtp.gmail.com with ESMTPSA id j14sm30046838wrr.66.2020.09.23.00.28.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Sep 2020 00:28:02 -0700 (PDT) From: Miriam Rubio To: git@vger.kernel.org Cc: Miriam Rubio , Christian Couder , Junio C Hamano Subject: [PATCH v8 2/6] bisect--helper: use '-res' in 'cmd_bisect__helper' return Date: Wed, 23 Sep 2020 09:27:36 +0200 Message-Id: <20200923072740.20772-3-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200923072740.20772-1-mirucam@gmail.com> References: <20200923072740.20772-1-mirucam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Following 'enum bisect_error' vocabulary, return variable 'res' is always non-positive. Let's use '-res' instead of 'abs(res)' to make the code clearer. Mentored-by: Christian Couder Helped-by: Junio C Hamano Signed-off-by: Miriam Rubio --- builtin/bisect--helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 23a9f00035..8037888ae2 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -731,5 +731,5 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) if (res == BISECT_INTERNAL_SUCCESS_MERGE_BASE) res = BISECT_OK; - return abs(res); + return -res; } From patchwork Wed Sep 23 07:27:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11794159 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7743E6CA for ; Wed, 23 Sep 2020 07:28:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5878A235FC for ; Wed, 23 Sep 2020 07:28:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="s41U09dN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726770AbgIWH2J (ORCPT ); Wed, 23 Sep 2020 03:28:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726557AbgIWH2G (ORCPT ); Wed, 23 Sep 2020 03:28:06 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C044C061755 for ; Wed, 23 Sep 2020 00:28:06 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id x14so19770720wrl.12 for ; Wed, 23 Sep 2020 00:28:06 -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=6RIDM9yzJVsduW37sLu4RYCMYtjNJRoj3YnsK67/z0s=; b=s41U09dNJwyprGTb4vOq7X5WlhP6Hm3siGpJRjvJTn/9goqGiESRMLpz+oDGb/L86V a2NwPM5TZxs/z6Ek4J0VvawPORiK3TNSl2X1TsYrHNr2QRTEOr1TE68mtOPUJFpyN90x 99PqYoTXoPjBZ+5HqsNskvI+cuQO3lRWGIcl58lnxMpbb/LgAwZAbujGsIU7NiVplh7j 7Dy1Ba7NP15Fs34X2vgd5UhsVTXLo/0ChA53yEhnpaJIFg3SYn4SyuABUjVpTqtIfn7e TYFF8ioF1Vg5m6CNZ15d4Ilsc6jYG4ZzBxlVJTvaHevAatdCV+oDJPqmt8WUv2PU2RPG 3yvA== 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=6RIDM9yzJVsduW37sLu4RYCMYtjNJRoj3YnsK67/z0s=; b=nnOOJ0cszvLTwKlGN+IxMYUQN8C5OOY1Dx8WzqkSMp1BUGbJ7/eIzQ8FAnPZYUX701 CbedT/EcrCUBBQK+uXi/JL1UPzrF3EAUEW/Lbl+fG354Ghiyl9vcoqVmk7PDSBolv1jZ EZdRILGgy7tWEYwMEJ6deYfRQzvXrJTl4l1/1F0d/G0NjtWBkhnu/fXhsHrjQcYYjRHR LndBNBmJhHcNJHu81nKQu7ULnUgegexVuPcc4LAEpWENWsIhqG2UjjZgceDzEzjZvRGJ jqLLLC3LRMfgn3r8BzkzUf3g+tvyfp7eIVNj8BzqP+ZojE8+Qv1BB8v0UPut0Diy1EL3 5xKA== X-Gm-Message-State: AOAM532mpa3BME8vXUkniurc82DJidkbdrsS8BsrUn7HWdk4EDkBwhsC V87DHhCYE40e+Z4ym/1HTsW27gStY98= X-Google-Smtp-Source: ABdhPJx/qOr6JBSti/BKowlojkWchu4KBPk1aIYFnCPRIB+5hCpxwNnxEJK2xcj4m5jP75Ihqa1lAw== X-Received: by 2002:a5d:4d51:: with SMTP id a17mr9474185wru.248.1600846084704; Wed, 23 Sep 2020 00:28:04 -0700 (PDT) Received: from localhost.localdomain ([178.237.235.60]) by smtp.gmail.com with ESMTPSA id j14sm30046838wrr.66.2020.09.23.00.28.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Sep 2020 00:28:03 -0700 (PDT) From: Miriam Rubio To: git@vger.kernel.org Cc: Miriam Rubio , Christian Couder , Johannes Schindelin Subject: [PATCH v8 3/6] bisect--helper: introduce new `write_in_file()` function Date: Wed, 23 Sep 2020 09:27:37 +0200 Message-Id: <20200923072740.20772-4-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200923072740.20772-1-mirucam@gmail.com> References: <20200923072740.20772-1-mirucam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Let's refactor code adding a new `write_in_file()` function that opens a file for writing a message and closes it and a wrapper for writing mode. This helper will be used in later steps and makes the code simpler and easier to understand. Mentored-by: Christian Couder Mentored-by: Johannes Schindelin Signed-off-by: Miriam Rubio --- builtin/bisect--helper.c | 43 +++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 8037888ae2..46d2abb36f 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -74,6 +74,40 @@ static int one_of(const char *term, ...) return res; } +static int write_in_file(const char *path, const char *mode, const char *format, va_list args) +{ + FILE *fp = NULL; + int res = 0; + + if (strcmp(mode, "w")) + BUG("write-in-file does not support '%s' mode", mode); + fp = fopen(path, mode); + if (!fp) + return error_errno(_("cannot open file '%s' in mode '%s'"), path, mode); + res = vfprintf(fp, format, args); + + if (res < 0) { + int saved_errno = errno; + fclose(fp); + errno = saved_errno; + return error_errno(_("could not write to file '%s'"), path); + } + + return fclose(fp); +} + +static int write_to_file(const char *path, const char *format, ...) +{ + int res; + va_list args; + + va_start(args, format); + res = write_in_file(path, "w", format, args); + va_end(args); + + return res; +} + static int check_term_format(const char *term, const char *orig_term) { int res; @@ -104,7 +138,6 @@ static int check_term_format(const char *term, const char *orig_term) static int write_terms(const char *bad, const char *good) { - FILE *fp = NULL; int res; if (!strcmp(bad, good)) @@ -113,13 +146,9 @@ static int write_terms(const char *bad, const char *good) if (check_term_format(bad, "bad") || check_term_format(good, "good")) return -1; - fp = fopen(git_path_bisect_terms(), "w"); - if (!fp) - return error_errno(_("could not open the file BISECT_TERMS")); + res = write_to_file(git_path_bisect_terms(), "%s\n%s\n", bad, good); - res = fprintf(fp, "%s\n%s\n", bad, good); - res |= fclose(fp); - return (res < 0) ? -1 : 0; + return res; } static int is_expected_rev(const char *expected_hex) From patchwork Wed Sep 23 07:27:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11794157 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2AFC66CB for ; Wed, 23 Sep 2020 07:28:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 081C6235FC for ; Wed, 23 Sep 2020 07:28:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nU+dmDUE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726779AbgIWH2J (ORCPT ); Wed, 23 Sep 2020 03:28:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726716AbgIWH2I (ORCPT ); Wed, 23 Sep 2020 03:28:08 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3E27C0613D1 for ; Wed, 23 Sep 2020 00:28:07 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id z4so19802887wrr.4 for ; Wed, 23 Sep 2020 00:28:07 -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=V3XoLAkZ22MkSetPvCkGEfSe9qUnUEj3czdfFAaQXE4=; b=nU+dmDUEYiENpTNSpcUmokuPDZi9Bz3ToDwwMYqdDbDL6QG6vYJ3j5U89x6sFaUJIp s48uWxVRLuL26ZG/IofuzT0TcB2GgbeT5dWoZeS2AOHwNnscV0S7qWLyPvgDy8EfXjfH q1l9L1nJDaYIf8LWe1zimv/BdLPizxrbbQi0lBZFZAid5WJinD6SvkYTdZTLDxdH9HbZ 1fAkG/wOqMfniEFdXB5nYfTXUxtiO4pKpuU0wyTFfXFRmVoCNdDExw+zok65aqyv5aym ZoqqY8VkuDHFaA7s651Yp3BIxII1XFRTYbk79VCCpi27CiKywtlB7CkiaNhorP6xnIe6 w6Cg== 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=V3XoLAkZ22MkSetPvCkGEfSe9qUnUEj3czdfFAaQXE4=; b=NYS6HuNThCwB2zX2S9nqtQuKr+mXJG5UH2XRRKj4X8q9bQTQD7JHvGbV271rkq9AFh J+rMgkD/vn/c0XfX+CGlsYUGU1SObpYde/LKnz3eDIYwBAGRnIl0ZvVX/QL4Leh5wxnJ Z6d93xQ13i2dMDGzw4KykFLZyAKMk6ZUNHJRiiZkWyWFVimpJ9n65m3zC7X6jp1bAGVY lYutdoSNibrYsV648G96ZBTgyQbPWr01BagcMyk1dIaax8q2Yn6x+cJsnOvbrcv8hOJx 9/t9Mqfr+FtgtZPFP5XWinwwGcZ5pvJAJIZVQwWb16DpxVooGLGM/ZyaAN/N4KhW0gsx T3lw== X-Gm-Message-State: AOAM533/erKJ46AqGRqvjk5VjtUcY+CH06R9HXtL5kwCTbd7EonzmgGX Vwz+wrzCVbrWUm20PRAaoiOVSlIoSRk= X-Google-Smtp-Source: ABdhPJyDZvCJlD2eAkzamrNpKC7Gf9dyWocODIwkP3SLJnapV7p7Id7lG/xTaTDqqgsj+tyAO1st6w== X-Received: by 2002:adf:a3db:: with SMTP id m27mr8133887wrb.277.1600846086144; Wed, 23 Sep 2020 00:28:06 -0700 (PDT) Received: from localhost.localdomain ([178.237.235.60]) by smtp.gmail.com with ESMTPSA id j14sm30046838wrr.66.2020.09.23.00.28.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Sep 2020 00:28:05 -0700 (PDT) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Lars Schneider , Christian Couder , Johannes Schindelin , Tanushree Tumane , Miriam Rubio Subject: [PATCH v8 4/6] bisect--helper: reimplement `bisect_autostart` shell function in C Date: Wed, 23 Sep 2020 09:27:38 +0200 Message-Id: <20200923072740.20772-5-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200923072740.20772-1-mirucam@gmail.com> References: <20200923072740.20772-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_autostart()` shell function in C and add the C implementation from `bisect_next()` which was previously left uncovered. Add `--bisect-autostart` subcommand to be called from git-bisect.sh. Using `--bisect-autostart` subcommand is a temporary measure to port the shell function to C so as to use the existing test suite. As more functions are ported, this subcommand will be retired and bisect_autostart() will be called directly by `bisect_state()`. Change behavior of shell script that returned success when user aborted the bisection. Mentored-by: Lars Schneider Mentored-by: Christian Couder Mentored-by: Johannes Schindelin Signed-off-by: Pranit Bauva Signed-off-by: Tanushree Tumane Signed-off-by: Miriam Rubio --- builtin/bisect--helper.c | 44 +++++++++++++++++++++++++++++++++++++++- git-bisect.sh | 25 ++--------------------- 2 files changed, 45 insertions(+), 24 deletions(-) diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 46d2abb36f..ab27a8dff6 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -29,6 +29,7 @@ static const char * const git_bisect_helper_usage[] = { 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] [ [...]] [--] [...]"), + N_("git bisect--helper --bisect-autostart"), NULL }; @@ -653,6 +654,38 @@ static int bisect_start(struct bisect_terms *terms, const char **argv, int argc) return res; } +static inline int file_is_not_empty(const char *path) +{ + return !is_empty_or_missing_file(path); +} + +static int bisect_autostart(struct bisect_terms *terms) +{ + int res; + const char *yesno; + + if (file_is_not_empty(git_path_bisect_start())) + return 0; + + fprintf_ln(stderr, _("You need to start by \"git bisect " + "start\"\n")); + + if (!isatty(STDIN_FILENO)) + return -1; + + /* + * TRANSLATORS: Make sure to include [Y] and [n] in your + * translation. The program will only accept English input + * at this point. + */ + yesno = git_prompt(_("Do you want me to do it for you " + "[Y/n]? "), PROMPT_ECHO); + res = tolower(*yesno) == 'n' ? + -1 : bisect_start(terms, empty_strvec, 0); + + return res; +} + int cmd_bisect__helper(int argc, const char **argv, const char *prefix) { enum { @@ -665,7 +698,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) CHECK_AND_SET_TERMS, BISECT_NEXT_CHECK, BISECT_TERMS, - BISECT_START + BISECT_START, + BISECT_AUTOSTART, } cmdmode = 0; int res = 0, nolog = 0; struct option options[] = { @@ -689,6 +723,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) 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-autostart", &cmdmode, + N_("start the bisection if it has not yet been started"), BISECT_AUTOSTART), OPT_BOOL(0, "no-log", &nolog, N_("no log for BISECT_WRITE")), OPT_END() @@ -748,6 +784,12 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) set_terms(&terms, "bad", "good"); res = bisect_start(&terms, argv, argc); break; + case BISECT_AUTOSTART: + if (argc) + return error(_("--bisect-autostart does not accept arguments")); + set_terms(&terms, "bad", "good"); + res = bisect_autostart(&terms); + break; default: BUG("unknown subcommand %d", cmdmode); } diff --git a/git-bisect.sh b/git-bisect.sh index 2f60fefcfa..4e9b2d36cb 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -49,27 +49,6 @@ bisect_head() fi } -bisect_autostart() { - test -s "$GIT_DIR/BISECT_START" || { - gettextln "You need to start by \"git bisect start\"" >&2 - if test -t 0 - then - # TRANSLATORS: Make sure to include [Y] and [n] in your - # translation. The program will only accept English input - # at this point. - gettext "Do you want me to do it for you [Y/n]? " >&2 - read yesno - case "$yesno" in - [Nn]*) - exit ;; - esac - bisect_start - else - exit 1 - fi - } -} - bisect_start() { git bisect--helper --bisect-start $@ || exit @@ -108,7 +87,7 @@ bisect_skip() { } bisect_state() { - bisect_autostart + git bisect--helper --bisect-autostart || exit state=$1 git bisect--helper --check-and-set-terms $state $TERM_GOOD $TERM_BAD || exit get_terms @@ -149,7 +128,7 @@ bisect_auto_next() { bisect_next() { case "$#" in 0) ;; *) usage ;; esac - bisect_autostart + git bisect--helper --bisect-autostart git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD $TERM_GOOD|| exit # Perform all bisection computation, display and checkout From patchwork Wed Sep 23 07:27:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11794161 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5C9B66CA for ; Wed, 23 Sep 2020 07:28:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F72B235FC for ; Wed, 23 Sep 2020 07:28:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sLz0nCsP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726652AbgIWH2L (ORCPT ); Wed, 23 Sep 2020 03:28:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726557AbgIWH2J (ORCPT ); Wed, 23 Sep 2020 03:28:09 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3A5AC0613D2 for ; Wed, 23 Sep 2020 00:28:08 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id q9so5996536wmj.2 for ; Wed, 23 Sep 2020 00:28:08 -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=2I9Y2hRuXgRqT6FgB1KECR88tDHWd7i0V/IscrZ+zbo=; b=sLz0nCsPem/YCBhwUd2QgL+uKuK21ZaXjB9xRqVg2qoQIUNoqbdeqqvihvpcsXSuTA Bm+qgTg3eryNfNcII3YPwbujMI2zYmZHHixabBXFYeuRHZYXCGG8U0udxnb4YWxiZUy1 ZswMxlHTjYyUEWXHxF4DzKiSwgUp/yFBgdz7RMe6BokTe22RJpEbCZI/4oq4XhQHRExY j0sU6FIzcdFq2cMzOjsXeiuPOhart8GSu+VQkSLWGzjUcx/SYVv+R3RAUkO59wbFTbQB Ojw8LX1GkF1vP6WJ2gHooeVXo+kFhDqRPrhV8OIALbZlz01vV624K3GUS///0Qkltxrx sxQg== 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=2I9Y2hRuXgRqT6FgB1KECR88tDHWd7i0V/IscrZ+zbo=; b=uQK+pA2W+WPh2Iu4DreB827xC1TmNf+96VPW6/XTDgvvcKLtTUAw90NMYVWa6eeZY+ N4c+EACtK3IeOOg54iUwGl8CjOrouyBwisEDN5yDV3f66pzqq4MEICG5rjiygzT/BQiX PA3OFInfvnY6JwNhMnYRBs5By9X8txiepIF9NVWHfVB4mn2/L2q51ENmkGectH9up26H 0bQLe88kiam/qHU5q3UbriA7yfSf7ElIATVgxt6VEB6ecxrJ06ROMPnJY39Pw4LSkPJ7 JS1uR7kNcMx9LTkvElciFH44DQzVhKhLwLPPT7PBbZbO5Q7+F80Z7M3RklvGFpZLeLeo wByw== X-Gm-Message-State: AOAM531byRGeZCv7RnNPidBr5XQNsZ5B/R2xA1H3V5rBFJCBGvSVQaEP 09AHVd8afw2OMLsPdyaGgkcfd0wC1C4= X-Google-Smtp-Source: ABdhPJwjQH/0c75LVir/TlVcpjrdvkJFhHSco2V5b3LCPukwJso6lJVJjsn7oRu+uxEMraWEEN1tng== X-Received: by 2002:a1c:2d86:: with SMTP id t128mr5135410wmt.189.1600846087354; Wed, 23 Sep 2020 00:28:07 -0700 (PDT) Received: from localhost.localdomain ([178.237.235.60]) by smtp.gmail.com with ESMTPSA id j14sm30046838wrr.66.2020.09.23.00.28.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Sep 2020 00:28:06 -0700 (PDT) From: Miriam Rubio To: git@vger.kernel.org Cc: Miriam Rubio , Christian Couder Subject: [PATCH v8 5/6] bisect: call 'clear_commit_marks_all()' in 'bisect_next_all()' Date: Wed, 23 Sep 2020 09:27:39 +0200 Message-Id: <20200923072740.20772-6-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200923072740.20772-1-mirucam@gmail.com> References: <20200923072740.20772-1-mirucam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As there can be other revision walks after bisect_next_all(), let's add a call to a function to clear all the marks at the end of bisect_next_all(). Mentored-by: Christian Couder Signed-off-by: Miriam Rubio --- bisect.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bisect.c b/bisect.c index d42a3a3767..c6aba2b9f2 100644 --- a/bisect.c +++ b/bisect.c @@ -1082,6 +1082,8 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix) "Bisecting: %d revisions left to test after this %s\n", nr), nr, steps_msg); free(steps_msg); + /* Clean up objects used, as they will be reused. */ + clear_commit_marks_all(ALL_REV_FLAGS); return bisect_checkout(bisect_rev, no_checkout); } From patchwork Wed Sep 23 07:27:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11794163 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 764746CA for ; Wed, 23 Sep 2020 07:28:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4CE7A235FC for ; Wed, 23 Sep 2020 07:28:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="roGXDTjN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726784AbgIWH2O (ORCPT ); Wed, 23 Sep 2020 03:28:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726780AbgIWH2L (ORCPT ); Wed, 23 Sep 2020 03:28:11 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F580C061755 for ; Wed, 23 Sep 2020 00:28:10 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id k15so19780585wrn.10 for ; Wed, 23 Sep 2020 00:28:10 -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=OPvHuI4I9ltG2U+CejGb+eCqCwUop1dC5eFjfi65CIw=; b=roGXDTjNwzd3qu8O+00W9MPbsxEHjnsUNcH60DFaitKc2aa/2QpEVoFfjWF7oKGMp4 /8KA7N+EbVJpo7y72cy49hApyufGbtrVEaxml3j9je/Imb2oZwKxUrrqqbsw/4TNCQGq We7fX4FNvPiiBT723GByoslVjWAdXuY5Cvd7hkw8XmgLunDq9DIf0XkuTx89aS6Te3W1 pLuQMsrQ+d8+bGzn2s5fFAycamX04ISII24sSqAs8TM7d8RntqQwJzg5QKS5qwv/kpTq IwEe+JVhMyj4O3rsPomfGHJU/F5BP7bmlngy4ZX32rdZ7Rm6EASSdHBtK9VSpPLKfXDV pZ2A== 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=OPvHuI4I9ltG2U+CejGb+eCqCwUop1dC5eFjfi65CIw=; b=QW4anH3DfQJgM/xU0N0rR4gdnwQkRWpT+7jFYISV9/hpWEBZn42Dqrdg2nyMho+h/G jGOvRRSpcoyGi4fsteyx7/Vaewn+kIzWbxDfYpDkMCq+wgwFStCV29GTydZr4UT5BIvv 3IdPFCZUCxsDwafT3WwdTp2cobR55dPLTEmsQ0hjcRmAxW+rEmzfQbrfdTE7t3Ny9Cy6 Ss+7i6TR+qInIBz0B92wVoHQvvF8eLbh2/3NvppovaR83mc9YONObFF9gf5ksLuTnBPB yv0KT1wne1AzTNhfsTZswig3dNzWAzBV7xGudZLo5oErJy3HaJHfBJ42Ws04O4L0zkZM KNCw== X-Gm-Message-State: AOAM532yQASBipoGGV/gvttkT5RUZyhz+WYPNRTS75fzL+M+f1YtmX7J NJZzs/NSOmZCtNWHbvtKZDB96TiSd5A= X-Google-Smtp-Source: ABdhPJzL6TzjDnk4uncFSZaC/HO2NQCIC7wczXTzwKJj5Yq73WwiOUMVrHxkI7byEVzK3HwHWjSJrw== X-Received: by 2002:adf:e601:: with SMTP id p1mr10218062wrm.172.1600846088868; Wed, 23 Sep 2020 00:28:08 -0700 (PDT) Received: from localhost.localdomain ([178.237.235.60]) by smtp.gmail.com with ESMTPSA id j14sm30046838wrr.66.2020.09.23.00.28.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Sep 2020 00:28:08 -0700 (PDT) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Lars Schneider , Christian Couder , Johannes Schindelin , Tanushree Tumane , Miriam Rubio Subject: [PATCH v8 6/6] bisect--helper: reimplement `bisect_next` and `bisect_auto_next` shell functions in C Date: Wed, 23 Sep 2020 09:27:40 +0200 Message-Id: <20200923072740.20772-7-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200923072740.20772-1-mirucam@gmail.com> References: <20200923072740.20772-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_next()` and the `bisect_auto_next()` shell functions in C and add the subcommands to `git bisect--helper` to call them from git-bisect.sh . bisect_auto_next() function returns an enum bisect_error type as whole `git bisect` can exit with an error code when bisect_next() does. Return an error when `bisect_next()` fails, that fix a bug on shell script version. Using `--bisect-next` and `--bisect-auto-next` subcommands is a temporary measure to port shell function to C so as to use the existing test suite. As more functions are ported, `--bisect-auto-next` subcommand will be retired and will be called by some other methods. Mentored-by: Lars Schneider Mentored-by: Christian Couder Mentored-by: Johannes Schindelin Signed-off-by: Pranit Bauva Signed-off-by: Tanushree Tumane Signed-off-by: Miriam Rubio --- bisect.c | 11 ++- builtin/bisect--helper.c | 180 ++++++++++++++++++++++++++++++++++++++- git-bisect.sh | 47 +--------- 3 files changed, 191 insertions(+), 47 deletions(-) diff --git a/bisect.c b/bisect.c index c6aba2b9f2..f5b1368128 100644 --- a/bisect.c +++ b/bisect.c @@ -988,8 +988,11 @@ void read_bisect_terms(const char **read_bad, const char **read_good) * the bisection process finished successfully. * In this case the calling function or command should not turn a * BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND return code into an error or a non zero exit code. - * If no_checkout is non-zero, the bisection process does not - * checkout the trial commit but instead simply updates BISECT_HEAD. + * + * Checking BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND + * in bisect_helper::bisect_next() and only transforming it to 0 at + * the end of bisect_helper::cmd_bisect__helper() helps bypassing + * all the code related to finding a commit to test. */ enum bisect_error bisect_next_all(struct repository *r, const char *prefix) { @@ -999,6 +1002,10 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix) enum bisect_error res = BISECT_OK; struct object_id *bisect_rev; char *steps_msg; + /* + * If no_checkout is non-zero, the bisection process does not + * checkout the trial commit but instead simply updates BISECT_HEAD. + */ int no_checkout = ref_exists("BISECT_HEAD"); unsigned bisect_flags = 0; diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index ab27a8dff6..3a5bf99257 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -8,6 +8,7 @@ #include "run-command.h" #include "prompt.h" #include "quote.h" +#include "revision.h" static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS") static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV") @@ -29,10 +30,17 @@ static const char * const git_bisect_helper_usage[] = { 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] [ [...]] [--] [...]"), + N_("git bisect--helper --bisect-next"), + N_("git bisect--helper --bisect-auto-next"), N_("git bisect--helper --bisect-autostart"), NULL }; +struct add_bisect_ref_data { + struct rev_info *revs; + unsigned int object_flags; +}; + struct bisect_terms { char *term_good; char *term_bad; @@ -56,6 +64,8 @@ static void set_terms(struct bisect_terms *terms, const char *bad, static const char vocab_bad[] = "bad|new"; static const char vocab_good[] = "good|old"; +static int bisect_autostart(struct bisect_terms *terms); + /* * Check whether the string `term` belongs to the set of strings * included in the variable arguments. @@ -80,7 +90,7 @@ static int write_in_file(const char *path, const char *mode, const char *format, FILE *fp = NULL; int res = 0; - if (strcmp(mode, "w")) + if (strcmp(mode, "w") && strcmp(mode, "a")) BUG("write-in-file does not support '%s' mode", mode); fp = fopen(path, mode); if (!fp) @@ -109,6 +119,18 @@ static int write_to_file(const char *path, const char *format, ...) return res; } +static int append_to_file(const char *path, const char *format, ...) +{ + int res; + va_list args; + + va_start(args, format); + res = write_in_file(path, "a", format, args); + va_end(args); + + return res; +} + static int check_term_format(const char *term, const char *orig_term) { int res; @@ -451,6 +473,142 @@ static int bisect_append_log_quoted(const char **argv) return res; } +static int add_bisect_ref(const char *refname, const struct object_id *oid, + int flags, void *cb) +{ + struct add_bisect_ref_data *data = cb; + + add_pending_oid(data->revs, refname, oid, data->object_flags); + + return 0; +} + +static int prepare_revs(struct bisect_terms *terms, struct rev_info *revs) +{ + int res = 0; + struct add_bisect_ref_data cb = { revs }; + char *good = xstrfmt("%s-*", terms->term_good); + + /* + * We cannot use terms->term_bad directly in + * for_each_glob_ref_in() and we have to append a '*' to it, + * otherwise for_each_glob_ref_in() will append '/' and '*'. + */ + char *bad = xstrfmt("%s*", terms->term_bad); + + /* + * It is important to reset the flags used by revision walks + * as the previous call to bisect_next_all() in turn + * sets up a revision walk. + */ + reset_revision_walk(); + init_revisions(revs, NULL); + setup_revisions(0, NULL, revs, NULL); + for_each_glob_ref_in(add_bisect_ref, bad, "refs/bisect/", &cb); + cb.object_flags = UNINTERESTING; + for_each_glob_ref_in(add_bisect_ref, good, "refs/bisect/", &cb); + if (prepare_revision_walk(revs)) + res = error(_("revision walk setup failed\n")); + + free(good); + free(bad); + return res; +} + +static int bisect_skipped_commits(struct bisect_terms *terms) +{ + int res; + FILE *fp = NULL; + struct rev_info revs; + struct commit *commit; + struct pretty_print_context pp = {0}; + struct strbuf commit_name = STRBUF_INIT; + + res = prepare_revs(terms, &revs); + if (res) + return res; + + fp = fopen(git_path_bisect_log(), "a"); + if (!fp) + return error_errno(_("could not open '%s' for appending"), + git_path_bisect_log()); + + if (fprintf(fp, "# only skipped commits left to test\n") < 0) + return error_errno(_("failed to write to '%s'"), git_path_bisect_log()); + + while ((commit = get_revision(&revs)) != NULL) { + strbuf_reset(&commit_name); + format_commit_message(commit, "%s", + &commit_name, &pp); + fprintf(fp, "# possible first %s commit: [%s] %s\n", + terms->term_bad, oid_to_hex(&commit->object.oid), + commit_name.buf); + } + + /* + * Reset the flags used by revision walks in case + * there is another revision walk after this one. + */ + reset_revision_walk(); + + strbuf_release(&commit_name); + fclose(fp); + return 0; +} + +static int bisect_successful(struct bisect_terms *terms) +{ + struct object_id oid; + struct commit *commit; + struct pretty_print_context pp = {0}; + struct strbuf commit_name = STRBUF_INIT; + char *bad_ref = xstrfmt("refs/bisect/%s",terms->term_bad); + int res; + + read_ref(bad_ref, &oid); + commit = lookup_commit_reference_by_name(bad_ref); + format_commit_message(commit, "%s", &commit_name, &pp); + + res = append_to_file(git_path_bisect_log(), "# first %s commit: [%s] %s\n", + terms->term_bad, oid_to_hex(&commit->object.oid), + commit_name.buf); + + strbuf_release(&commit_name); + free(bad_ref); + return res; +} + +static enum bisect_error bisect_next(struct bisect_terms *terms, const char *prefix) +{ + enum bisect_error res; + + if (bisect_autostart(terms)) + return BISECT_FAILED; + + if (bisect_next_check(terms, terms->term_good)) + return BISECT_FAILED; + + /* Perform all bisection computation */ + res = bisect_next_all(the_repository, prefix); + + if (res == BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND) { + res = bisect_successful(terms); + return res ? res : BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND; + } else if (res == BISECT_ONLY_SKIPPED_LEFT) { + res = bisect_skipped_commits(terms); + return res ? res : BISECT_ONLY_SKIPPED_LEFT; + } + return res; +} + +static enum bisect_error bisect_auto_next(struct bisect_terms *terms, const char *prefix) +{ + if (bisect_next_check(terms, NULL)) + return BISECT_OK; + + return bisect_next(terms, prefix); +} + static int bisect_start(struct bisect_terms *terms, const char **argv, int argc) { int no_checkout = 0; @@ -700,6 +858,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) BISECT_TERMS, BISECT_START, BISECT_AUTOSTART, + BISECT_NEXT, + BISECT_AUTO_NEXT } cmdmode = 0; int res = 0, nolog = 0; struct option options[] = { @@ -723,6 +883,10 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) 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-auto-next", &cmdmode, + N_("verify the next bisection state then checkout the next bisection commit"), BISECT_AUTO_NEXT), OPT_CMDMODE(0, "bisect-autostart", &cmdmode, N_("start the bisection if it has not yet been started"), BISECT_AUTOSTART), OPT_BOOL(0, "no-log", &nolog, @@ -784,6 +948,18 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) set_terms(&terms, "bad", "good"); res = bisect_start(&terms, argv, argc); break; + case BISECT_NEXT: + if (argc) + return error(_("--bisect-next requires 0 arguments")); + get_terms(&terms); + res = bisect_next(&terms, prefix); + break; + case BISECT_AUTO_NEXT: + if (argc) + return error(_("--bisect-auto-next requires 0 arguments")); + get_terms(&terms); + res = bisect_auto_next(&terms, prefix); + break; case BISECT_AUTOSTART: if (argc) return error(_("--bisect-autostart does not accept arguments")); @@ -799,7 +975,7 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) * Handle early success * From check_merge_bases > check_good_are_ancestors_of_bad > bisect_next_all */ - if (res == BISECT_INTERNAL_SUCCESS_MERGE_BASE) + if ((res == BISECT_INTERNAL_SUCCESS_MERGE_BASE) || (res == BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND)) res = BISECT_OK; return -res; diff --git a/git-bisect.sh b/git-bisect.sh index 4e9b2d36cb..ea7e684ebb 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -65,8 +65,7 @@ bisect_start() { # # Check if we can proceed to the next bisect state. # - get_terms - bisect_auto_next + git bisect--helper --bisect-auto-next || exit trap '-' 0 } @@ -119,45 +118,7 @@ bisect_state() { *) usage ;; esac - bisect_auto_next -} - -bisect_auto_next() { - git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD && bisect_next || : -} - -bisect_next() { - case "$#" in 0) ;; *) usage ;; esac - git bisect--helper --bisect-autostart - git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD $TERM_GOOD|| exit - - # Perform all bisection computation, display and checkout - git bisect--helper --next-all - res=$? - - # Check if we should exit because bisection is finished - if test $res -eq 10 - then - bad_rev=$(git show-ref --hash --verify refs/bisect/$TERM_BAD) - bad_commit=$(git show-branch $bad_rev) - echo "# first $TERM_BAD commit: $bad_commit" >>"$GIT_DIR/BISECT_LOG" - exit 0 - elif test $res -eq 2 - then - echo "# only skipped commits left to test" >>"$GIT_DIR/BISECT_LOG" - good_revs=$(git for-each-ref --format="%(objectname)" "refs/bisect/$TERM_GOOD-*") - for skipped in $(git rev-list refs/bisect/$TERM_BAD --not $good_revs) - do - skipped_commit=$(git show-branch $skipped) - echo "# possible first $TERM_BAD commit: $skipped_commit" >>"$GIT_DIR/BISECT_LOG" - done - exit $res - fi - - # Check for an error in the bisection process - test $res -ne 0 && exit $res - - return 0 + git bisect--helper --bisect-auto-next } bisect_visualize() { @@ -213,7 +174,7 @@ bisect_replay () { esac done <"$file" IFS="$oIFS" - bisect_auto_next + git bisect--helper --bisect-auto-next || exit } bisect_run () { @@ -310,7 +271,7 @@ case "$#" in bisect_skip "$@" ;; next) # Not sure we want "next" at the UI level anymore. - bisect_next "$@" ;; + git bisect--helper --bisect-next "$@" || exit ;; visualize|view) bisect_visualize "$@" ;; reset)