From patchwork Tue Jan 28 14:40:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11354419 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 2EEFF92A for ; Tue, 28 Jan 2020 14:41:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0F83524685 for ; Tue, 28 Jan 2020 14:41:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bg4SKF02" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730274AbgA1OlQ (ORCPT ); Tue, 28 Jan 2020 09:41:16 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:51013 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729359AbgA1OlP (ORCPT ); Tue, 28 Jan 2020 09:41:15 -0500 Received: by mail-wm1-f67.google.com with SMTP id a5so2809059wmb.0 for ; Tue, 28 Jan 2020 06:41:13 -0800 (PST) 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=Z1w/Hc4cOkaibn8kvCOgrzsn1RxBbiqlk6Mv4m5lJ4c=; b=bg4SKF02Djm+tbt6WumL2FK+8/U6nxUz8wJ/tyldJIR+AhHggZwz4vtMkazuEaJPPp Ry7TuKN/MVZGVo2GK1b8ugpnRpJMtwfdXH0H8IzD0yQ1EH+AtbmqYvw6b2lee35hW/S0 T8uf+dMK86BhraLLVeL6xP4S2vLfoHt22qacuy4kf/7LJbgMx4PsHYSHElC7NjwgtLHz CZeQU+qPzbgzKEZcBOvfBgj1Orb+jneAd3XjALQX7gLB5mKRHsydBDFEm/l/prsUg/Tu xGyQF0ghfTlxwztOWARJFgKFXOY909UthJQwvm+xDAOXDWBbIhVK37Gd94KAhnLq0piP or6g== 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=Z1w/Hc4cOkaibn8kvCOgrzsn1RxBbiqlk6Mv4m5lJ4c=; b=YCG+Vv758BgrgU+7gfVrWPyIGYbE2bDCt51BMSEdrgSmiPhXLFNhWe9oq9CvVqh68R yoO3a67DqURQwYrvq1CxS/NiiyZ7QlK9DhqRdBWiyoMs8G1nwSqgFUPtwfHHKVrMod1D VqyxOmh/CnP49gGeGkGdr4WAeGQk18XPxd72FLJa9kRp3AO73+YuWd9w/jGaAG6S1bek K83PcEMrsaptOBhLwCsJBJqrJ3sb477BO0b2YkvbWnAOUZW1Qi9P40hUAHT2NDlK4D7y doD4qZlRVFNWMvUjJBVHhKIMKMQ6/oD3dMEbowb1IqKDTp57y1ue1uPQ1LKGQGdDYRg5 4fnw== X-Gm-Message-State: APjAAAV+NELaTU/JepgDe2UZbw1MgwUg0CHbdFmzmn8ShGl740NdFOp1 3+5tGsoLiybm0rJBYl4+2qjiKWbK X-Google-Smtp-Source: APXvYqx4uNDdzjcDfbzkZSWdHyGmRoNqJUOp2ktP4rqHoFi7oyaIG/TK9oHv02Ro4RJyXgLtTNT7Mg== X-Received: by 2002:a1c:a584:: with SMTP id o126mr5208579wme.163.1580222473026; Tue, 28 Jan 2020 06:41:13 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id g7sm25732439wrq.21.2020.01.28.06.41.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jan 2020 06:41:12 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Miriam Rubio , Christian Couder Subject: [PATCH v2 01/11] bisect--helper: convert `vocab_*` char pointers to char arrays Date: Tue, 28 Jan 2020 15:40:16 +0100 Message-Id: <20200128144026.53128-2-mirucam@gmail.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20200128144026.53128-1-mirucam@gmail.com> References: <20200128144026.53128-1-mirucam@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Instead of using a pointer that points at a constant string, just give name directly to the constant string; this way, we do not have to allocate a pointer variable in addition to the string we want to use. Let's convert `vocab_bad` and `vocab_good` char pointers to char arrays. Mentored-by: Christian Couder Signed-off-by: Miriam Rubio --- builtin/bisect--helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 1718df7f09..36c09b7238 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -52,8 +52,8 @@ static void set_terms(struct bisect_terms *terms, const char *bad, terms->term_bad = xstrdup(bad); } -static const char *vocab_bad = "bad|new"; -static const char *vocab_good = "good|old"; +static const char vocab_bad[] = "bad|new"; +static const char vocab_good[] = "good|old"; /* * Check whether the string `term` belongs to the set of strings From patchwork Tue Jan 28 14:40:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11354421 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 3FBCB92A for ; Tue, 28 Jan 2020 14:41:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 13D0824683 for ; Tue, 28 Jan 2020 14:41:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Um1hjJMS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730354AbgA1OlR (ORCPT ); Tue, 28 Jan 2020 09:41:17 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:52589 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729971AbgA1OlQ (ORCPT ); Tue, 28 Jan 2020 09:41:16 -0500 Received: by mail-wm1-f68.google.com with SMTP id p9so2797698wmc.2 for ; Tue, 28 Jan 2020 06:41:15 -0800 (PST) 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=E+ZezR0wGUOg+FjlOgC+pT3lOJ8VVLkCSBEvw6cqiKw=; b=Um1hjJMShJcFrJGqw+br4wgGzhjKfW1cxD7WR0eOKoPw8HxkO/nzBdsMW4FAzujY6h BaJDXy9GYnCDT+96ReBenFi+7IzUesAxuK1MRpLZ3RU6cEHgOWBWPkrxT80+Do+V9c7z Misk+1pwxZ2Me7TZOGqMKH4D9ydO2r0AOk4jCvqUDSJtFDhjKeDikQJKyQmhsx6b2mkb qC39ktQXfp+bpwZRp5Ht7AjfoHA2t0fWqSCGw5wqUFG1EBjRZIEEawswqkdEyzgTAtMC 7DN9x8RzueZ+slxpQ4KhkydnJ//T69aWL8bhxgFqpkRig+A0supkDtxsWcA8o9txbhKd yEaw== 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=E+ZezR0wGUOg+FjlOgC+pT3lOJ8VVLkCSBEvw6cqiKw=; b=duH+wxiNBhNUJUq2TCr234vLhjkRVaUxdt6F5ayyUQa/Njcxn4e4UMjyiNcaEUAso4 cJeGV+3B++f00MoDMTzUXRAvnUyFe9BW0LCnMNGGSF5RPz8hnuNtFEtdfvJ1GzK5FjF9 h+SizMm/+i09rSleN+lJahqxE57xiyVHUchsZi6yRWGp40gBQnFlpHMdS42wuQ7DfFzi mHJTjdGCQ+i2ppsV8Ir3EzQfQXMkwdvF6VMaRr247TnYWhsposDqoG+SKAAmos1OWbfR LMIC8+QLUEd3YDSyNKOTKOIqOX7dP2C5JPKz9Q2or80rVK9scROQ3WeiryrGTAsSDVXS OdSg== X-Gm-Message-State: APjAAAWLdZcnZm9Y87J3RB4P9VyLq9lvXsDtLyBRth9xu/VpFGObMYFg n4RyGY6Ta9SDHBef5nUglYiP2Uu0 X-Google-Smtp-Source: APXvYqwOj7/PQDJ6qfMUfFZbjpCdYW82weqmqwdevlkxXME0Xbylh8wxE86Jvpc5H+37gMS9pDifPA== X-Received: by 2002:a1c:7907:: with SMTP id l7mr5271611wme.37.1580222474416; Tue, 28 Jan 2020 06:41:14 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id g7sm25732439wrq.21.2020.01.28.06.41.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jan 2020 06:41:13 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Tanushree Tumane , Christian Couder , Miriam Rubio Subject: [PATCH v2 02/11] bisect--helper: change `retval` to `res` Date: Tue, 28 Jan 2020 15:40:17 +0100 Message-Id: <20200128144026.53128-3-mirucam@gmail.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20200128144026.53128-1-mirucam@gmail.com> References: <20200128144026.53128-1-mirucam@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Tanushree Tumane Let's rename variable retval to res, so that variable names in bisect--helper.c are more consistent. After this change, there are 110 occurrences of res in the file and zero of retval, while there were 26 instances of retval before. Mentored-by: Christian Couder Signed-off-by: Tanushree Tumane Signed-off-by: Miriam Rubio --- builtin/bisect--helper.c | 52 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 36c09b7238..21de5c096c 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -206,31 +206,31 @@ static int bisect_write(const char *state, const char *rev, struct object_id oid; struct commit *commit; FILE *fp = NULL; - int retval = 0; + int res = 0; if (!strcmp(state, terms->term_bad)) { strbuf_addf(&tag, "refs/bisect/%s", state); } else if (one_of(state, terms->term_good, "skip", NULL)) { strbuf_addf(&tag, "refs/bisect/%s-%s", state, rev); } else { - retval = error(_("Bad bisect_write argument: %s"), state); + res = error(_("Bad bisect_write argument: %s"), state); goto finish; } if (get_oid(rev, &oid)) { - retval = error(_("couldn't get the oid of the rev '%s'"), rev); + res = error(_("couldn't get the oid of the rev '%s'"), rev); goto finish; } if (update_ref(NULL, tag.buf, &oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR)) { - retval = -1; + res = -1; goto finish; } fp = fopen(git_path_bisect_log(), "a"); if (!fp) { - retval = error_errno(_("couldn't open the file '%s'"), git_path_bisect_log()); + res = error_errno(_("couldn't open the file '%s'"), git_path_bisect_log()); goto finish; } @@ -244,7 +244,7 @@ static int bisect_write(const char *state, const char *rev, if (fp) fclose(fp); strbuf_release(&tag); - return retval; + return res; } static int check_and_set_terms(struct bisect_terms *terms, const char *cmd) @@ -294,7 +294,7 @@ static const char need_bisect_start_warning[] = static int bisect_next_check(const struct bisect_terms *terms, const char *current_term) { - int missing_good = 1, missing_bad = 1, retval = 0; + int missing_good = 1, missing_bad = 1, res = 0; const char *bad_ref = xstrfmt("refs/bisect/%s", terms->term_bad); const char *good_glob = xstrfmt("%s-*", terms->term_good); @@ -308,7 +308,7 @@ static int bisect_next_check(const struct bisect_terms *terms, goto finish; if (!current_term) { - retval = -1; + res = -1; goto finish; } @@ -329,21 +329,21 @@ static int bisect_next_check(const struct bisect_terms *terms, */ yesno = git_prompt(_("Are you sure [Y/n]? "), PROMPT_ECHO); if (starts_with(yesno, "N") || starts_with(yesno, "n")) - retval = -1; + res = -1; goto finish; } if (!is_empty_or_missing_file(git_path_bisect_start())) { - retval = error(_(need_bad_and_good_revision_warning), + res = error(_(need_bad_and_good_revision_warning), vocab_bad, vocab_good, vocab_bad, vocab_good); } else { - retval = error(_(need_bisect_start_warning), + res = error(_(need_bisect_start_warning), vocab_good, vocab_bad, vocab_good, vocab_bad); } finish: free((void *) good_glob); free((void *) bad_ref); - return retval; + return res; } static int get_terms(struct bisect_terms *terms) @@ -397,7 +397,7 @@ static int bisect_terms(struct bisect_terms *terms, const char *option) static int bisect_append_log_quoted(const char **argv) { - int retval = 0; + int res = 0; FILE *fp = fopen(git_path_bisect_log(), "a"); struct strbuf orig_args = STRBUF_INIT; @@ -405,25 +405,25 @@ static int bisect_append_log_quoted(const char **argv) return -1; if (fprintf(fp, "git bisect start") < 1) { - retval = -1; + res = -1; goto finish; } sq_quote_argv(&orig_args, argv); if (fprintf(fp, "%s\n", orig_args.buf) < 1) - retval = -1; + res = -1; finish: fclose(fp); strbuf_release(&orig_args); - return retval; + return res; } static int bisect_start(struct bisect_terms *terms, int no_checkout, const char **argv, int argc) { int i, has_double_dash = 0, must_write_terms = 0, bad_seen = 0; - int flags, pathspec_pos, retval = 0; + int flags, pathspec_pos, res = 0; struct string_list revs = STRING_LIST_INIT_DUP; struct string_list states = STRING_LIST_INIT_DUP; struct strbuf start_head = STRBUF_INIT; @@ -524,7 +524,7 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout, argv_array_pushl(&argv, "checkout", start_head.buf, "--", NULL); if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) { - retval = error(_("checking out '%s' failed." + res = error(_("checking out '%s' failed." " Try 'git bisect start " "'."), start_head.buf); @@ -572,12 +572,12 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout, if (no_checkout) { if (get_oid(start_head.buf, &oid) < 0) { - retval = error(_("invalid ref: '%s'"), start_head.buf); + res = error(_("invalid ref: '%s'"), start_head.buf); goto finish; } if (update_ref(NULL, "BISECT_HEAD", &oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR)) { - retval = -1; + res = -1; goto finish; } } @@ -589,26 +589,26 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout, for (i = 0; i < states.nr; i++) if (bisect_write(states.items[i].string, revs.items[i].string, terms, 1)) { - retval = -1; + res = -1; goto finish; } if (must_write_terms && write_terms(terms->term_bad, terms->term_good)) { - retval = -1; + res = -1; goto finish; } - retval = bisect_append_log_quoted(argv); - if (retval) - retval = -1; + res = bisect_append_log_quoted(argv); + if (res) + res = -1; finish: string_list_clear(&revs, 0); string_list_clear(&states, 0); strbuf_release(&start_head); strbuf_release(&bisect_names); - return retval; + return res; } int cmd_bisect__helper(int argc, const char **argv, const char *prefix) From patchwork Tue Jan 28 14:40:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11354423 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 F064392A for ; Tue, 28 Jan 2020 14:41:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CD362207FD for ; Tue, 28 Jan 2020 14:41:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oRwgHA0D" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730396AbgA1OlS (ORCPT ); Tue, 28 Jan 2020 09:41:18 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33557 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729359AbgA1OlR (ORCPT ); Tue, 28 Jan 2020 09:41:17 -0500 Received: by mail-wr1-f68.google.com with SMTP id b6so16332176wrq.0 for ; Tue, 28 Jan 2020 06:41:16 -0800 (PST) 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=bBO/bOkGCdl6QTwKATRatKk/3LmebozvS+OJB1ptUKw=; b=oRwgHA0Ds3q1CABMFfhT04cMvOepkL0w+ogG3gcqe/EPmYArPOrk/6zRzHMqOs7ymV BbAm3cfXkTt75mgMnz6MIC6R2o8sLnFCR1TITvl5ggjjeXwlsuN0bylvtsUA7a4TP2iO FjEaeqWOMDGtHaNdkh50TQXfZRWktOb6/QIT9EPKFMSIve8JsfuusR3BYgMVt23LMJhm bplo+tYxMJF1diN0/ehQO1KS09nqO98AdK6twb/m8rO1747oJmgLsLW2MEb7MFtoJQa6 u7JLdMI0sndDPO3ej1A9FRg7EcMzV/B8BxXV62GbR+MsYC0li97JMsSWC1jv0/8mUc98 Rq9g== 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=bBO/bOkGCdl6QTwKATRatKk/3LmebozvS+OJB1ptUKw=; b=uiX3pcaZRDSA1blylCo9ogt7qNFkQyEnMp+LwzZ2pbkKrZu9jCh2B/xJkvkLVFQfHc 2itpPYF8hRx9UDBBCx7lYF3C55xxQyaM/kXjRBQmMORDcFtMEJPRuRzrXMRTL23HHpEe pGS0rXUT+7L/3XSSNP9+H9FkSGjPinVyRtjQ3kwCGIsH7jUG3XFi4Tjrey8gCHIQ5EsK KoosPgZECw2X3kqeqashIMnOR7ZVMejW10OJhKfKbmNBSC+H56PWjA1MRaXSug/3qUto HSW2erORGfSZLmKb2LZs/E8QQ8KAryaiQ00mehKX2szQUc0kLKpHaU8tC2P7BXtPoIpP NawQ== X-Gm-Message-State: APjAAAVDH8QKmJRG9Guh9yzdF3gzCkESLQAXbP0tyVvSWgaLZOPsg4dW Jy7ThN/VVGpkUP51nWX3B5Bnskf+ X-Google-Smtp-Source: APXvYqz9yvozQ0qIzY7npudFcNeHzSRxHWc2L19YjHcC6N+TH4FEYELX3RhEGVCnA+MTuTeIx6Uhhw== X-Received: by 2002:a5d:56ca:: with SMTP id m10mr30149008wrw.313.1580222475675; Tue, 28 Jan 2020 06:41:15 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id g7sm25732439wrq.21.2020.01.28.06.41.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jan 2020 06:41:15 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Miriam Rubio , Christian Couder Subject: [PATCH v2 03/11] bisect: use the standard 'if (!var)' way to check for 0 Date: Tue, 28 Jan 2020 15:40:18 +0100 Message-Id: <20200128144026.53128-4-mirucam@gmail.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20200128144026.53128-1-mirucam@gmail.com> References: <20200128144026.53128-1-mirucam@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Instead of using 'var == 0' in an if condition, let's use '!var' and make 'bisect.c' more consistent with the rest of the code. Mentored-by: Christian Couder Signed-off-by: Miriam Rubio --- bisect.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bisect.c b/bisect.c index e81c91d02c..83cb5b3a98 100644 --- a/bisect.c +++ b/bisect.c @@ -572,7 +572,7 @@ static int sqrti(int val) { float d, x = val; - if (val == 0) + if (!val) return 0; do { @@ -869,7 +869,7 @@ static void check_good_are_ancestors_of_bad(struct repository *r, goto done; /* Bisecting with no good rev is ok. */ - if (good_revs.nr == 0) + if (!good_revs.nr) goto done; /* Check if all good revs are ancestor of the bad rev. */ From patchwork Tue Jan 28 14:40:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11354425 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 515971398 for ; Tue, 28 Jan 2020 14:41:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2FB2924685 for ; Tue, 28 Jan 2020 14:41:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="K4o2YF2k" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730405AbgA1OlU (ORCPT ); Tue, 28 Jan 2020 09:41:20 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:55760 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729971AbgA1OlT (ORCPT ); Tue, 28 Jan 2020 09:41:19 -0500 Received: by mail-wm1-f67.google.com with SMTP id q9so2775916wmj.5 for ; Tue, 28 Jan 2020 06:41:17 -0800 (PST) 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=9SpYi/ohrDgazNPtmVZM0LynCsl2zU9y8ZTkc7EorDM=; b=K4o2YF2kqXQJxo1OatIApPR4NPH3qsDrtiDQU8iFFwMtDwTyLyihgadvyVge2om35K 1PSFgEJi34TjVhds0N1tZtTuUIulywLos6GSRvascc9ssg7c3FX7XzZ1NU1JY+iTmTbY uknFFs2VzcnPHTR+n4BXgMRk2/mXvmAt/sNlUKT+nVbpJLlvcYLye0VN1oaKWa0VM7+4 JIh9pd2RnYgSkChiXGni5bBmfT769QLePjvvGxe/LIGLgTzZwOn+nTGZukK3rLHaFDZo 79rw3HYtV2M2h/3wI6QJZ/6dmhVmoLnVrjSWXEN7dUfrrynJmytTvI1BJrLp0RRRv4vk ZtIw== 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=9SpYi/ohrDgazNPtmVZM0LynCsl2zU9y8ZTkc7EorDM=; b=RMYOuMmtyk4h3m/HPl0OrM0NpVNXajCyvqnFvZIFXvLUupitdYGEdNWbWtTH8Dtd9K PgKcgN9MZ47NBtRwri3hQUBM9IEVugPaBqFZpUZPNdJ+EPRcLCSQlN9Ts00oFErC5VNe fgjaWsOhbZ4ZeZRx6DEknDoZ2Q6vUzQiuxKpkDP5DuVpwWk5DpSyWXbrs3d6SI9tPr2h /TIJbqYdoTsfPJR4Azaf0PlGxKByKIauoEDE/EePh5OvMkc4svwrWHulo/0B4i+fYFjO PnfRA85gD4QC43nVFhquQkQpBWlc3WM4fr1jwHFlYbeCMGEG2yzNpD2jo4okbGT7VeKn gb0w== X-Gm-Message-State: APjAAAWJ0qfAQ4XGmLu0WkXZbgZAOQr3Fen6EsDN5Iauli820OwJ7Bfi 6iOX43VJ91rhU7p4ReeiOqXH3Ixz X-Google-Smtp-Source: APXvYqxvwsbBol6es8glKqbmbUXWM63bWWUzsKEJSTUWRugb6SMXjymnZwPeIdMU5LNYUSrVTVyIqw== X-Received: by 2002:a1c:c919:: with SMTP id f25mr5510892wmb.49.1580222476927; Tue, 28 Jan 2020 06:41:16 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id g7sm25732439wrq.21.2020.01.28.06.41.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jan 2020 06:41:16 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Tanushree Tumane , Miriam Rubio Subject: [PATCH v2 04/11] run-command: make `exists_in_PATH()` non-static Date: Tue, 28 Jan 2020 15:40:19 +0100 Message-Id: <20200128144026.53128-5-mirucam@gmail.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20200128144026.53128-1-mirucam@gmail.com> References: <20200128144026.53128-1-mirucam@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org 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. 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 | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/run-command.c b/run-command.c index f5e1149f9b..4df975178d 100644 --- a/run-command.c +++ b/run-command.c @@ -210,7 +210,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 592d9dc035..7c8e206d97 100644 --- a/run-command.h +++ b/run-command.h @@ -172,6 +172,17 @@ 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 *); + /** * Start a sub-process. Takes a pointer to a `struct child_process` * that specifies the details and returns pipe FDs (if requested). From patchwork Tue Jan 28 14:40:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11354427 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 466B692A for ; Tue, 28 Jan 2020 14:41:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 25316207FD for ; Tue, 28 Jan 2020 14:41:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gOMLqCNK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729359AbgA1OlW (ORCPT ); Tue, 28 Jan 2020 09:41:22 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:45502 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729121AbgA1OlT (ORCPT ); Tue, 28 Jan 2020 09:41:19 -0500 Received: by mail-wr1-f68.google.com with SMTP id a6so1693887wrx.12 for ; Tue, 28 Jan 2020 06:41:19 -0800 (PST) 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=z+0sLYrP58eeovRExl7dsWUvPzeYQuBQyVbe8IQ/XvY=; b=gOMLqCNK+SCd1RXm7VOlOA40j9CuTJdbpaDIDbJA8xS1/w4+49uYwRP9lTwlbraSpF eNwD3JlI9Fl2r7fblIht6+6xRM/aVEELZoI4OUbYhyjUgruBmACXaZ5R92hKsNLaBRNp s777+fmUNFzZvPLqc62nxXInbtm+xzA8g72GyjB61PejmOAHyHCqQgfEffzqcQGQAIOd mcKN88x53rRMYJ/3BlFFcNRlnUFnRXdZAN/R5qbz0VfcXYbzK3OB884sEv+1+pawbWx9 EF3Bkg4mZY1/p194kIuwrSlqONW63TNfZV83XPlkas4Xp9wS/FWVOnjvn4MS1i8//LLc jfwg== 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=z+0sLYrP58eeovRExl7dsWUvPzeYQuBQyVbe8IQ/XvY=; b=imMduORqAaOr/bRBm63s89yi8pQKYcaUtbrBvfPqH0bo8dD+WgOgYYbDYc4u9LLeZ5 NMOmWNNtWXoC1ZJ804C5THxKF3zOCq0wWY5X9LMzn5Y2Hcvn7HioSbhBwb0eD/ZVcE07 jIr6W7f4GKLetcrh3zcTnLSNERLsqtkM684Pb9tUhEoopKUJ8BTeHR0bL4dQyMMt8eCa IMp3qTRNu842c5JOqwzetuWJGTXDP7DaIUatd0YoLnmjj915v3kEZKnd+vfO0AqI7oXw bfg0aXtyAr+LNd10y89I9gNosToTXeybhRQC8uzPmEzhtQxMai6VAP827caMOIENqSk+ fTPg== X-Gm-Message-State: APjAAAV6J0VEjPzqWKBfLOfbXdWS1yJmV7CaDDPmMHZDoBckX0ygGjWq o8krcTSeFoqVE3pDLvXKf1pS6r2Q X-Google-Smtp-Source: APXvYqzveMRsjJD27jXM2Wcph/mIxQX0PozvxlJ/9VhOR48Zi1FF/xbUkKmO6UzhDNpvxknmx6loSA== X-Received: by 2002:adf:ef49:: with SMTP id c9mr30624585wrp.292.1580222478094; Tue, 28 Jan 2020 06:41:18 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id g7sm25732439wrq.21.2020.01.28.06.41.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jan 2020 06:41:17 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Tanushree Tumane , Christian Couder , Miriam Rubio Subject: [PATCH v2 05/11] bisect--helper: introduce new `decide_next()` function Date: Tue, 28 Jan 2020 15:40:20 +0100 Message-Id: <20200128144026.53128-6-mirucam@gmail.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20200128144026.53128-1-mirucam@gmail.com> References: <20200128144026.53128-1-mirucam@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Tanushree Tumane Let's refactor code from bisect_next_check() into a new decide_next() helper function. This removes some goto statements and makes the code simpler, clearer and easier to understand. Mentored-by: Christian Couder Signed-off-by: Tanushree Tumane Signed-off-by: Miriam Rubio --- builtin/bisect--helper.c | 62 +++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 21de5c096c..826fcba2ed 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -291,26 +291,14 @@ static const char need_bisect_start_warning[] = "You then need to give me at least one %s and %s revision.\n" "You can use \"git bisect %s\" and \"git bisect %s\" for that."); -static int bisect_next_check(const struct bisect_terms *terms, - const char *current_term) +static int decide_next(const struct bisect_terms *terms, + const char *current_term, int missing_good, + int missing_bad) { - int missing_good = 1, missing_bad = 1, res = 0; - const char *bad_ref = xstrfmt("refs/bisect/%s", terms->term_bad); - const char *good_glob = xstrfmt("%s-*", terms->term_good); - - if (ref_exists(bad_ref)) - missing_bad = 0; - - for_each_glob_ref_in(mark_good, good_glob, "refs/bisect/", - (void *) &missing_good); - if (!missing_good && !missing_bad) - goto finish; - - if (!current_term) { - res = -1; - goto finish; - } + return 0; + if (!current_term) + return -1; if (missing_good && !missing_bad && !strcmp(current_term, terms->term_good)) { @@ -321,7 +309,7 @@ static int bisect_next_check(const struct bisect_terms *terms, */ warning(_("bisecting only with a %s commit"), terms->term_bad); if (!isatty(0)) - goto finish; + return 0; /* * TRANSLATORS: Make sure to include [Y] and [n] in your * translation. The program will only accept English input @@ -329,21 +317,35 @@ static int bisect_next_check(const struct bisect_terms *terms, */ yesno = git_prompt(_("Are you sure [Y/n]? "), PROMPT_ECHO); if (starts_with(yesno, "N") || starts_with(yesno, "n")) - res = -1; - goto finish; - } - if (!is_empty_or_missing_file(git_path_bisect_start())) { - res = error(_(need_bad_and_good_revision_warning), - vocab_bad, vocab_good, vocab_bad, vocab_good); - } else { - res = error(_(need_bisect_start_warning), - vocab_good, vocab_bad, vocab_good, vocab_bad); + return -1; + return 0; } -finish: + if (!is_empty_or_missing_file(git_path_bisect_start())) + return error(_(need_bad_and_good_revision_warning), + vocab_bad, vocab_good, vocab_bad, vocab_good); + else + return error(_(need_bisect_start_warning), + vocab_good, vocab_bad, vocab_good, vocab_bad); +} + +static int bisect_next_check(const struct bisect_terms *terms, + const char *current_term) +{ + int missing_good = 1, missing_bad = 1; + const char *bad_ref = xstrfmt("refs/bisect/%s", terms->term_bad); + const char *good_glob = xstrfmt("%s-*", terms->term_good); + + if (ref_exists(bad_ref)) + missing_bad = 0; + + for_each_glob_ref_in(mark_good, good_glob, "refs/bisect/", + (void *) &missing_good); + free((void *) good_glob); free((void *) bad_ref); - return res; + + return decide_next(terms, current_term, missing_good, missing_bad); } static int get_terms(struct bisect_terms *terms) From patchwork Tue Jan 28 14:40:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11354429 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 4DA6292A for ; Tue, 28 Jan 2020 14:41:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2C1CC20716 for ; Tue, 28 Jan 2020 14:41:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M3ZQ80Mv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730361AbgA1OlZ (ORCPT ); Tue, 28 Jan 2020 09:41:25 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:44172 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730428AbgA1OlV (ORCPT ); Tue, 28 Jan 2020 09:41:21 -0500 Received: by mail-wr1-f65.google.com with SMTP id q10so16294116wrm.11 for ; Tue, 28 Jan 2020 06:41:20 -0800 (PST) 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=ydJB0pf8KIMaV+lmWCZ/JJIyrrUlm8Wy40gNencbC4w=; b=M3ZQ80MvByx+lkqLVzgNIbRCXsHL7JQcZuXC5D1zb7mzXUz6ZVw4332leI5ePTnvDv yDS0Si4Iek7Tv2Tz74vRUm9HxCICrnLjy4dKh45xtSaH6fYhdYmjPftsFSU0PgreWcVb cSgxfYgkRrm6MBdIbvPrIR3Aua9sgH/sC6PQWTwlBKkowdW+mbGfXcoSC20NV8zWSM3g 6kefLyNyVFcGPPzuopMxUL4ag3n7LycwuiOoVxBFImiSXXFDlpqLHMZrpn2jUstr8hS4 FNdpqgzV2PWj9C94EAwOqhmFQU5AtBvEIZUdnqGFlsPW2jMuq8uCXUaYsliTFxOqDZnA y5Ow== 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=ydJB0pf8KIMaV+lmWCZ/JJIyrrUlm8Wy40gNencbC4w=; b=Lj9u2k/c+mH12fZttBXf9/QgCZoCDJtMXECvPAc6ZFuZdpLJN7W/ne3XWQWJ7Cb4G3 Fekf0KExInIkzxTY8mrJ2VN4CFJOuVop20ibQ0OttW52I2ljiXtVr1ki50qLvJKsWoPj 3s5G9TeKtd0sDjgmTB6/KC/SQ4migp9mAImp7MYmQ8lZpwb2XgflZZylFDYZ9Z7LtFsQ vCXMFRcoyz5GNr0kHUQ4FgHHAERR3ndbDajkAcNquhT+CLd8agBVPpInHODfgW1anJoi fcx6bSf2XR9Nbsw3OwzWZ56yqXu2oBrW6jiuSaITu+45nhN6jyfwjSpWjtozthq7lBtz k5iA== X-Gm-Message-State: APjAAAVxd/FAB75W9VEiqCD+xs8NJ6mjp+VqgNY8vsrGTD92zFHzqWax Z3uQspThF2GsO36A1FkZYDVzu8lwVAY= X-Google-Smtp-Source: APXvYqy7r32zslNMP69JpjJzjWMANgebzdfZMkbNt97UQHBCygFKiRof55K8aFpld6U2/6PYilVj8g== X-Received: by 2002:adf:d183:: with SMTP id v3mr30384978wrc.180.1580222479642; Tue, 28 Jan 2020 06:41:19 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id g7sm25732439wrq.21.2020.01.28.06.41.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jan 2020 06:41:19 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Johannes Schindelin , Tanushree Tumane , Miriam Rubio Subject: [PATCH v2 06/11] bisect: libify `exit_if_skipped_commits` to `error_if_skipped*` and its dependents Date: Tue, 28 Jan 2020 15:40:21 +0100 Message-Id: <20200128144026.53128-7-mirucam@gmail.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20200128144026.53128-1-mirucam@gmail.com> References: <20200128144026.53128-1-mirucam@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Pranit Bauva Since we want to get rid of git-bisect.sh it would be necessary to convert those exit() calls to return statements so that errors can be reported. Emulate try catch in C by converting `exit()` to `return `. Follow POSIX conventions to return to indicate error. Handle this return in dependent function `bisect_next_all()`. 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 | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/bisect.c b/bisect.c index 83cb5b3a98..a7a5d158e6 100644 --- a/bisect.c +++ b/bisect.c @@ -661,11 +661,11 @@ static void bisect_common(struct rev_info *revs) mark_edges_uninteresting(revs, NULL, 0); } -static void exit_if_skipped_commits(struct commit_list *tried, +static int error_if_skipped_commits(struct commit_list *tried, const struct object_id *bad) { if (!tried) - return; + return 0; printf("There are only 'skip'ped commits left to test.\n" "The first %s commit could be any of:\n", term_bad); @@ -676,7 +676,13 @@ static void exit_if_skipped_commits(struct commit_list *tried, if (bad) printf("%s\n", oid_to_hex(bad)); printf(_("We cannot bisect more!\n")); - exit(2); + + /* + * We don't want to clean the bisection state + * as we need to get back to where we started + * by using `git bisect reset`. + */ + return -2; } static int is_expected_rev(const struct object_id *oid) @@ -949,7 +955,7 @@ int bisect_next_all(struct repository *r, const char *prefix, int no_checkout) { struct rev_info revs; struct commit_list *tried; - int reaches = 0, all = 0, nr, steps; + int reaches = 0, all = 0, nr, steps, res; struct object_id *bisect_rev; char *steps_msg; @@ -972,8 +978,9 @@ int bisect_next_all(struct repository *r, const char *prefix, int no_checkout) * We should exit here only if the "bad" * commit is also a "skip" commit. */ - exit_if_skipped_commits(tried, NULL); - + res = error_if_skipped_commits(tried, NULL); + if (res < 0) + exit(-res); printf(_("%s was both %s and %s\n"), oid_to_hex(current_bad_oid), term_good, @@ -990,7 +997,9 @@ int bisect_next_all(struct repository *r, const char *prefix, int no_checkout) bisect_rev = &revs.commits->item->object.oid; if (oideq(bisect_rev, current_bad_oid)) { - exit_if_skipped_commits(tried, current_bad_oid); + res = error_if_skipped_commits(tried, current_bad_oid); + if (res) + exit(-res); printf("%s is the first %s commit\n", oid_to_hex(bisect_rev), term_bad); show_diff_tree(r, prefix, revs.commits->item); From patchwork Tue Jan 28 14:40:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11354431 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 2F2571398 for ; Tue, 28 Jan 2020 14:41:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0D7D2207FD for ; Tue, 28 Jan 2020 14:41:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AQJZZOAn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730513AbgA1Ol0 (ORCPT ); Tue, 28 Jan 2020 09:41:26 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:42274 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730188AbgA1OlX (ORCPT ); Tue, 28 Jan 2020 09:41:23 -0500 Received: by mail-wr1-f66.google.com with SMTP id k11so1613858wrd.9 for ; Tue, 28 Jan 2020 06:41:21 -0800 (PST) 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=Tu/XeKYCFKYmJZQRo2bpb+A/ims/KDpmrlZyszF8BBc=; b=AQJZZOAn2CCnKCmAWZaszI/o22mgDSg5T+BvOyf2EBPx7DN/OhXdjhtc2EnsTH/7mj eNeHXtuXT/lrYSLLZjHdEksgsSX+Ge8pLwwaujGNs4rbh7IqyCge68jz+knRj0vkUnqv +kutg77jKdXTVG/DxDEEL1lFI7kZo/lX4K4CzAmyqALNI5W2h3Cw7KfXpj66hM8HLrLk qOCcgeozawylPkTiyRsHF2QGSP4mGf7wYcNOr/3A7NSdqcjBjcpAXC98GBznrmF482fv 13DPZIAR2JWSHizu1Tdfu8+vvH8zoboiRUGUMkACVzdjyue6sStTQS0Q6WBK31yVGeuP iTRw== 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=Tu/XeKYCFKYmJZQRo2bpb+A/ims/KDpmrlZyszF8BBc=; b=uIXCwAXwH4PbZMtROZJ5DQrtFJdiZxSWpP+9nsRZdP91y1vEPZQBOgOoMEl/uTNSzL GmYGQcwvJe9KwjxPQbFJgwSKb1HrG4ZCEKkWttCVn9rTXnklcOdC41E0ZBw0ucHP0I8b Q5a8QXs4oI5wO/qdUJSLZhg9VvAbUPtGE0ALuop8I920D837LfQPRTX22NpIBcTm2BYb lGMcmoJh5wHZsdPdn4IxXuCxP/fdLLxw824y9GYHquimoQcjqII46C8/zMPSDX3CbkkM X5jRQsBrClTxrrvuzVQge841fzX6AdrVSHnrNhCP7oXlZgQW2ZZuuS/FkTWJhn7cqu9a fF9g== X-Gm-Message-State: APjAAAU5DMSo+3vLCtbysIz3E6KcBW/XVS4VFTD7TUPOUDSu/FNp5Bu8 MbxrggupfcD9uBq5HH9qsyA+AWsu394= X-Google-Smtp-Source: APXvYqwRbmnIzJlDwGEQxf7HTFSZSN57Z6Tdb5mreZeWAQUligSjikkSOwyqajqxDVVpmNoi1i3AyA== X-Received: by 2002:adf:f3d1:: with SMTP id g17mr27654888wrp.378.1580222481031; Tue, 28 Jan 2020 06:41:21 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id g7sm25732439wrq.21.2020.01.28.06.41.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jan 2020 06:41:20 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Johannes Schindelin , Tanushree Tumane , Miriam Rubio Subject: [PATCH v2 07/11] bisect: libify `bisect_checkout` Date: Tue, 28 Jan 2020 15:40:22 +0100 Message-Id: <20200128144026.53128-8-mirucam@gmail.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20200128144026.53128-1-mirucam@gmail.com> References: <20200128144026.53128-1-mirucam@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Pranit Bauva Since we want to get rid of git-bisect.sh it would be necessary to convert those exit() calls to return statements so that errors can be reported. Emulate try catch in C by converting `exit()` to `return `. Follow POSIX conventions to return to indicate error. Turn `exit()` to `return` calls in `bisect_checkout()`. Changes related to return values have no bad side effects on the code that calls `bisect_checkout()`. 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 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bisect.c b/bisect.c index a7a5d158e6..dee8318d9b 100644 --- a/bisect.c +++ b/bisect.c @@ -713,6 +713,7 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout) { char bisect_rev_hex[GIT_MAX_HEXSZ + 1]; + int res = 0; memcpy(bisect_rev_hex, oid_to_hex(bisect_rev), the_hash_algo->hexsz + 1); update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR); @@ -721,14 +722,14 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout) update_ref(NULL, "BISECT_HEAD", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR); } else { - int res; res = run_command_v_opt(argv_checkout, RUN_GIT_CMD); if (res) - exit(res); + return res > 0 ? -res : res; } argv_show_branch[1] = bisect_rev_hex; - return run_command_v_opt(argv_show_branch, RUN_GIT_CMD); + res = run_command_v_opt(argv_show_branch, RUN_GIT_CMD); + return res > 0 ? -res : res; } static struct commit *get_commit_reference(struct repository *r, From patchwork Tue Jan 28 14:40:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11354433 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 52A5D92A for ; Tue, 28 Jan 2020 14:41:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 30B1524685 for ; Tue, 28 Jan 2020 14:41:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OYGjZFEd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730062AbgA1Ol3 (ORCPT ); Tue, 28 Jan 2020 09:41:29 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:46368 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729121AbgA1OlY (ORCPT ); Tue, 28 Jan 2020 09:41:24 -0500 Received: by mail-wr1-f67.google.com with SMTP id z7so16261868wrl.13 for ; Tue, 28 Jan 2020 06:41:23 -0800 (PST) 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=T0SyfK0NNwZIpBCHt23KPP5OREVsx0Sn8T1pAy8LCx8=; b=OYGjZFEdX6FvNaR4P6MDeBJ+1Irr+0O78pnddzDve5a6Gw5TpHi2LKPLSZxoj2GpAv GDI03ZtEue3tFLEzbahpBIvOaIajRAemncevhqzqRQ//j/5934KWWItf8nzEYGCoj6Hr Mkyx+VK1icOOg5UmWN25MNnpWi8I6bfTG5JxIf3wRl0giUZISO1m7G5cNfNZTtXtBjoc 5vyeB+rxm2YebpFldYCcOSfWxuqCc58KkQ/RN/sKY9rmzixdaUQd6fMkZUe5CPOxet1M rK7tx3gts3vtDzH4kOdCIOcIHBMAHd0ROZ/tz1gsQLpOOxPIHwpHlfUqIWsn5AVhwm4R Djvg== 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=T0SyfK0NNwZIpBCHt23KPP5OREVsx0Sn8T1pAy8LCx8=; b=CZfUSvOtTX2vRDZvMxp0ebWyVWTkeLHLcKnCVFFyTnDXeoawdjkVKrnUht07xFmCE6 gEuC+hPbYVadV7Zu89tADALlnkLKmiCxnqs2IycYeZ+B/LADJqfmRtPcd8js6v8H8t7Q oij0rSucboHHhu4PT+IakThwVae1V9mmkBgbLXK3Jl4LYnvYWaDFd2DX5ytMSI+SlGtB SbQ9qeADBPFkrlUm67MnV4nvb+Tgv0BmKDhY3syIuxisrNmHmr2lTnUqxwN4nuzVev5h fGoLBSNd8cy44vcSwrUIe84hWgdrik633uZJbJF4K0Rfj40B6Bxsg8fAMeHKGKz3ztND ky5g== X-Gm-Message-State: APjAAAXUJZ8HMj3mYOj5PmK/4KS/DRXBFAjmeRHRJ5CBINTj/DkmC48P juqxEjlwlsn4u76F/bCo+aMzhclJ X-Google-Smtp-Source: APXvYqwy2I7H6m1b80M7JCVW6osZjxNpAoWoEpFlP1tzvC4Sy9S0gxNJ+aEJRRwlTMugN44Hn/GylQ== X-Received: by 2002:a5d:6ac5:: with SMTP id u5mr30704160wrw.271.1580222482390; Tue, 28 Jan 2020 06:41:22 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id g7sm25732439wrq.21.2020.01.28.06.41.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jan 2020 06:41:21 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Tanushree Tumane , Miriam Rubio Subject: [PATCH v2 08/11] bisect: libify `check_merge_bases` and its dependents Date: Tue, 28 Jan 2020 15:40:23 +0100 Message-Id: <20200128144026.53128-9-mirucam@gmail.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20200128144026.53128-1-mirucam@gmail.com> References: <20200128144026.53128-1-mirucam@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Pranit Bauva Since we want to get rid of git-bisect.sh it would be necessary to convert those exit() calls to return statements so that errors can be reported. Emulate try catch in C by converting `exit()` to `return `. Follow POSIX conventions to return to indicate error. In `check_merge_bases()` there is an early success special case, so we have introduced special error code `-11` which indicates early success. This `-11` is converted back to `0` in `check_good_are_ancestors_of_bad()`. Handle the return value in dependent function `check_good_are_ancestors_of_bad()`. 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 | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/bisect.c b/bisect.c index dee8318d9b..2a6566d066 100644 --- a/bisect.c +++ b/bisect.c @@ -806,13 +806,16 @@ static void handle_skipped_merge_base(const struct object_id *mb) * "check_merge_bases" checks that merge bases are not "bad" (or "new"). * * - If one is "bad" (or "new"), it means the user assumed something wrong - * and we must exit with a non 0 error code. + * and we must return error with a non 0 error code. * - If one is "good" (or "old"), that's good, we have nothing to do. * - If one is "skipped", we can't know but we should warn. * - If we don't know, we should check it out and ask the user to test. + * - If a merge base must be tested, on success return -11 a special condition + * for early success, this will be converted back to 0 in check_good_are_ancestors_of_bad(). */ -static void check_merge_bases(int rev_nr, struct commit **rev, int no_checkout) +static int check_merge_bases(int rev_nr, struct commit **rev, int no_checkout) { + int res = 0; struct commit_list *result; result = get_merge_bases_many(rev[0], rev_nr - 1, rev + 1); @@ -827,11 +830,16 @@ static void check_merge_bases(int rev_nr, struct commit **rev, int no_checkout) handle_skipped_merge_base(mb); } else { printf(_("Bisecting: a merge base must be tested\n")); - exit(bisect_checkout(mb, no_checkout)); + res = bisect_checkout(mb, no_checkout); + if (!res) + /* indicate early success */ + res = -11; + break; } } free_commit_list(result); + return res; } static int check_ancestors(struct repository *r, int rev_nr, @@ -865,7 +873,7 @@ static void check_good_are_ancestors_of_bad(struct repository *r, { char *filename = git_pathdup("BISECT_ANCESTORS_OK"); struct stat st; - int fd, rev_nr; + int fd, rev_nr, res = 0; struct commit **rev; if (!current_bad_oid) @@ -880,10 +888,13 @@ static void check_good_are_ancestors_of_bad(struct repository *r, goto done; /* Check if all good revs are ancestor of the bad rev. */ + rev = get_bad_and_good_commits(r, &rev_nr); if (check_ancestors(r, rev_nr, rev, prefix)) - check_merge_bases(rev_nr, rev, no_checkout); + res = check_merge_bases(rev_nr, rev, no_checkout); free(rev); + if (res) + exit(res == -11 ? 0 : -res); /* Create file BISECT_ANCESTORS_OK. */ fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600); From patchwork Tue Jan 28 14:40:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11354439 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 C7BA71398 for ; Tue, 28 Jan 2020 14:41:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A340024683 for ; Tue, 28 Jan 2020 14:41:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c9EAmbY8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730367AbgA1Old (ORCPT ); Tue, 28 Jan 2020 09:41:33 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:40010 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730446AbgA1OlZ (ORCPT ); Tue, 28 Jan 2020 09:41:25 -0500 Received: by mail-wr1-f68.google.com with SMTP id j104so392914wrj.7 for ; Tue, 28 Jan 2020 06:41:24 -0800 (PST) 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=SQ3QmPOBX0CDWXYNnM/Q85Pl1DpTyyBNCoiFovU3mwc=; b=c9EAmbY8F1gpfiZI1VWxNJmqtX5SHU8GTOkoypek5frByIMiWwka5W4Aqw/M2IcWBM 8XtsNrCfvqmCiKRATE1B3ZmvbpurP2gdNxKO35eVZP/sgHSj5prU07LiOP1JLH4NtJkt EsjmjBnNsF7g0zIT6BkzocTvX8tWZZE+mR1AjDufl4GjJ4lRa8DPmkCVsN8UvDVl2z+Z NctXFHCneGMyzHPfx5qxulUPDMZA/SXBvDDt14UPOVBTetDGB/0kRjvV5gPHj4ft7XsW xe31qG8fKj59HYXbc8Wrd+WFRxupYITlPt+osjIwN4BO6jwRLCJji+kAMIJGxCqUDD5e eOXg== 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=SQ3QmPOBX0CDWXYNnM/Q85Pl1DpTyyBNCoiFovU3mwc=; b=GMb/KpwNwu7BD0GKzp2vvXIRCV7SRNniGOKTamrU9J4HJdWYoPdqFpWOLjlE+/3Kum BEBC9XaCS64K8vch03niCLjBJahhJUON/4XQcNRD1LONyoen4AGI44HOvix2LeI84QsD Jmb0Q34C4ZsAz11AGxlz/uytwT9OyPrlVRvSwkpI5mSdmXocyxfjoR0/gdi0ThMn8qeh svbZI4j6WtjgSdIAJAsy8U6UNxvCZJkxFh3iwMmkZQtBl0FlkF278BgBgODFpSi7cnRQ lU1KWZF0jrbSGDGy9ytcrmkLLuQw28u/aClggjEXjdLN7nVHfoVWPNNllORuac2MxIhj Bx0Q== X-Gm-Message-State: APjAAAUUfhnNG8+RjiBvfQ1lP1Ae3Hdadqgh8V0jhxgeB8Fg7aIy8Df5 +FaDSVyBFdF60otFzbtpi+TKKNnt X-Google-Smtp-Source: APXvYqx+bVS3dbgq6VGg2GakRXEs/E9ILQHITZhlzELqrjzELWafjQauVd0yM5dTRIYJ5lx7cpHZXw== X-Received: by 2002:adf:ecc7:: with SMTP id s7mr3005493wro.162.1580222483805; Tue, 28 Jan 2020 06:41:23 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id g7sm25732439wrq.21.2020.01.28.06.41.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jan 2020 06:41:23 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Tanushree Tumane , Miriam Rubio Subject: [PATCH v2 09/11] bisect: libify `check_good_are_ancestors_of_bad` and its dependents Date: Tue, 28 Jan 2020 15:40:24 +0100 Message-Id: <20200128144026.53128-10-mirucam@gmail.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20200128144026.53128-1-mirucam@gmail.com> References: <20200128144026.53128-1-mirucam@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Pranit Bauva Since we want to get rid of git-bisect.sh it would be necessary to convert those exit() calls to return statements so that errors can be reported. Emulate try catch in C by converting `exit()` to `return `. Follow POSIX conventions to return to indicate error. Code that turns -11(early success code) to 0 from `check_good_are_ancestors_of_bad()` has been moved to `cmd_bisect__helper()`. Handle the return value in dependent function `bisect_next_all()`. 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 | 40 ++++++++++++++++++++++++++-------------- builtin/bisect--helper.c | 12 ++++++++++-- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/bisect.c b/bisect.c index 2a6566d066..d519e10827 100644 --- a/bisect.c +++ b/bisect.c @@ -865,19 +865,27 @@ static int check_ancestors(struct repository *r, int rev_nr, * * If that's not the case, we need to check the merge bases. * If a merge base must be tested by the user, its source code will be - * checked out to be tested by the user and we will exit. + * checked out to be tested by the user and we will return. */ -static void check_good_are_ancestors_of_bad(struct repository *r, + +static int check_good_are_ancestors_of_bad(struct repository *r, const char *prefix, int no_checkout) { - char *filename = git_pathdup("BISECT_ANCESTORS_OK"); + char *filename; struct stat st; int fd, rev_nr, res = 0; struct commit **rev; + /* + * We don't want to clean the bisection state + * as we need to get back to where we started + * by using `git bisect reset`. + */ if (!current_bad_oid) - die(_("a %s revision is needed"), term_bad); + return error(_("a %s revision is needed"), term_bad); + + filename = git_pathdup("BISECT_ANCESTORS_OK"); /* Check if file BISECT_ANCESTORS_OK exists. */ if (!stat(filename, &st) && S_ISREG(st.st_mode)) @@ -893,18 +901,20 @@ static void check_good_are_ancestors_of_bad(struct repository *r, if (check_ancestors(r, rev_nr, rev, prefix)) res = check_merge_bases(rev_nr, rev, no_checkout); free(rev); - if (res) - exit(res == -11 ? 0 : -res); - /* Create file BISECT_ANCESTORS_OK. */ - fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600); - if (fd < 0) - warning_errno(_("could not create file '%s'"), - filename); - else - close(fd); + if (!res) + { + /* Create file BISECT_ANCESTORS_OK. */ + fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600); + if (fd < 0) + warning_errno(_("could not create file '%s'"), + filename); + else + close(fd); + } done: free(filename); + return res; } /* @@ -975,7 +985,9 @@ int bisect_next_all(struct repository *r, const char *prefix, int no_checkout) if (read_bisect_refs()) die(_("reading bisect refs failed")); - check_good_are_ancestors_of_bad(r, prefix, no_checkout); + res = check_good_are_ancestors_of_bad(r, prefix, no_checkout); + if (res) + return res; bisect_rev_setup(r, &revs, prefix, "%s", "^%s", 1); revs.limited = 1; diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 826fcba2ed..3442bfe2cb 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -666,7 +666,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) switch (cmdmode) { case NEXT_ALL: - return bisect_next_all(the_repository, prefix, no_checkout); + res = bisect_next_all(the_repository, prefix, no_checkout); + break; case WRITE_TERMS: if (argc != 2) return error(_("--write-terms requires two arguments")); @@ -713,5 +714,12 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) return error("BUG: unknown subcommand '%d'", cmdmode); } free_terms(&terms); - return !!res; + /* + * Handle early success + * From check_merge_bases > check_good_are_ancestors_of_bad > bisect_next_all + */ + if (res == -11) + res = 0; + + return res < 0 ? -res : res; } From patchwork Tue Jan 28 14:40:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11354437 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 106D01398 for ; Tue, 28 Jan 2020 14:41:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DE14120716 for ; Tue, 28 Jan 2020 14:41:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MSV4flHZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730535AbgA1Olb (ORCPT ); Tue, 28 Jan 2020 09:41:31 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:44183 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730395AbgA1Ol1 (ORCPT ); Tue, 28 Jan 2020 09:41:27 -0500 Received: by mail-wr1-f65.google.com with SMTP id q10so16294463wrm.11 for ; Tue, 28 Jan 2020 06:41:26 -0800 (PST) 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=xdOCVLhEYsS6m8fOTgnZDYNINbR6VSsTJq3b7TR1ZE8=; b=MSV4flHZBOQ48yFHHIk9c7DJ69kCSblymkSBrW0t2ikfl/gmr0Gu0Ms7falv2fuvIM nlQPcWSThfrptGo3AFa8/AOm8vPnMRhI39960/UMODxu6Z016cCKIWMH6exLAhNwFESu pYyIqLhPvlNwx95PsqBqauwnH0OMTIwPNMpL4eJZEy2UuI9z8qRuRnNa8Moq6l0vGqU5 DFx1za1C392uWnNkeMMU3P5EM+SFHsHuE16hXH9CKiI8o0LDyT0PrSeHjw11aMXlDJFC m/px0hWXvsDjxb6riZqJhXZCLwU6feTcffr6wFqr0A5GQhsGef6qs+rzTpdeCyygT6S6 JjEg== 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=xdOCVLhEYsS6m8fOTgnZDYNINbR6VSsTJq3b7TR1ZE8=; b=XIm723GTSBwsNu3AZlViGKK8ms/QkCblKPaQ+/1nroW7CRp3R7V0+puzpCcwWHtxZG 1wR6bMisl/tKImFDUhHhAXvnR3aQagJQnTM4xvPI4xkWp0KVtAQ24SDj3+lKXV6FiHCt 04ZP1twqoZXJpLR6MjiapZYyhaNTnoIgmIjbJCNz8mvpDafIue/2Gy09hD78tj52B/to CbDiRVeohFcObiQ50OFN38eCAsdph5pleU+1ZCMnY9RNj0Cpjz7NDzfl0XdkNIPIy8vO xDMyfkit/b6skXRw67JVjQ5lBcoJk8W8jUkUL8iiR8XYy/BksRgByaSfmlp89zVS3nyM /F5Q== X-Gm-Message-State: APjAAAVwwA1DQcYUSYNXB8sw6k1BnKhEXe6C9IWMQ+XmYCfKSz5Rau4R bKLxGx4k6zkTlBu4ceu/HHXLPQdH2D8= X-Google-Smtp-Source: APXvYqxx+6C7G5CL2QQlgplUHZIlBcNpAmvrKkogZxwy8xml6LqI+2C2SutRQSMBsqL9U7R1gv4o6Q== X-Received: by 2002:adf:ef49:: with SMTP id c9mr30625222wrp.292.1580222485263; Tue, 28 Jan 2020 06:41:25 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id g7sm25732439wrq.21.2020.01.28.06.41.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jan 2020 06:41:24 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Johannes Schindelin , Tanushree Tumane , Miriam Rubio Subject: [PATCH v2 10/11] bisect: libify `handle_bad_merge_base` and its dependents Date: Tue, 28 Jan 2020 15:40:25 +0100 Message-Id: <20200128144026.53128-11-mirucam@gmail.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20200128144026.53128-1-mirucam@gmail.com> References: <20200128144026.53128-1-mirucam@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Pranit Bauva Since we want to get rid of git-bisect.sh it would be necessary to convert those exit() calls to return statements so that errors can be reported. Emulate try catch in C by converting `exit()` to `return `. Follow POSIX conventions to return to indicate error. Handle the return value in dependent function check_merge_bases(). 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 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bisect.c b/bisect.c index d519e10827..43baa3df28 100644 --- a/bisect.c +++ b/bisect.c @@ -756,7 +756,7 @@ static struct commit **get_bad_and_good_commits(struct repository *r, return rev; } -static void handle_bad_merge_base(void) +static int handle_bad_merge_base(void) { if (is_expected_rev(current_bad_oid)) { char *bad_hex = oid_to_hex(current_bad_oid); @@ -777,14 +777,14 @@ static void handle_bad_merge_base(void) "between %s and [%s].\n"), bad_hex, term_bad, term_good, bad_hex, good_hex); } - exit(3); + return -3; } fprintf(stderr, _("Some %s revs are not ancestors of the %s rev.\n" "git bisect cannot work properly in this case.\n" "Maybe you mistook %s and %s revs?\n"), term_good, term_bad, term_good, term_bad); - exit(1); + return -1; } static void handle_skipped_merge_base(const struct object_id *mb) @@ -823,7 +823,8 @@ static int check_merge_bases(int rev_nr, struct commit **rev, int no_checkout) for (; result; result = result->next) { const struct object_id *mb = &result->item->object.oid; if (oideq(mb, current_bad_oid)) { - handle_bad_merge_base(); + res = handle_bad_merge_base(); + break; } else if (0 <= oid_array_lookup(&good_revs, mb)) { continue; } else if (0 <= oid_array_lookup(&skipped_revs, mb)) { From patchwork Tue Jan 28 14:40:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11354435 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 86EFC92A for ; Tue, 28 Jan 2020 14:41:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6378720716 for ; Tue, 28 Jan 2020 14:41:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gMjMkifc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730523AbgA1Ola (ORCPT ); Tue, 28 Jan 2020 09:41:30 -0500 Received: from mail-wr1-f41.google.com ([209.85.221.41]:39890 "EHLO mail-wr1-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728312AbgA1Ol3 (ORCPT ); Tue, 28 Jan 2020 09:41:29 -0500 Received: by mail-wr1-f41.google.com with SMTP id y11so16282784wrt.6 for ; Tue, 28 Jan 2020 06:41:27 -0800 (PST) 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=mN0SToNuKd1IqKAn3n7YucOPBr7uWDuDfQ3rXgbv+2U=; b=gMjMkifcl8bGYzM1GA3zMjPWzTnw7PzJUznhv6RzmUnBOQ7WqSASnrwV00+Xhydb/p cpQhwsBtIJnyLq6jJryomyMjqICr8M2roob82dsPgw1sNsc3AVo0vyW+EaDFRkClourC GJD2ttczJim24B9GlksjaU0fm800gCRpomUz2Bu5Lj0ABStSzxI8pHVvDtqj0vyCOYhP ZWZxelYKjJb1HvORHuAmEyMD4cgLE1gHSv3pn+cRPgZTQTa9rEf+NR2WTIiak7mk5a32 C3HMt0ktQQvopobmtlDJHMy2I9LPSE6tk9d/JyCugQ3pEj4QPLBj8WPdTh+wNU14pyv4 gkBQ== 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=mN0SToNuKd1IqKAn3n7YucOPBr7uWDuDfQ3rXgbv+2U=; b=jWo9yg1Y90dOucWfC0rxDvxU6UaLDD4wO66RTPNCjuQ3cZhdGBEJ768zf/G0IBzgy0 SWw8H9Xtp8/s9RpA93qlj39YmkAqYyQEPfxW1KfLICwQw+gb7G7EBzeSrDRI4gs5VU/p 2pKOl13GIxPJmnOtopn+jbIsYkbB415bGQpubltcQZoaW1f1CbiaXbNycCrfSqb0jdpG d2BMYn1LPIWZRFqfThnBBRa8XU0KLqpv/hSdZerlrf4TcK0smDyMK7HC7Z74Dr+DLZum E+eBNt6O5D3IHVvMo9E4qlfu/NayNdAR2EOlcQjVdwxHLaRFoNCF1/0r4yeTUCI8xubu xjoQ== X-Gm-Message-State: APjAAAVGvfvpf+yjAw2rY5D+lYjeTlYAYNQL6op8Lx+tEzWoheSOKDV8 pQUwvsjqBW+R6BmN3PbunEHbWMlKD5Y= X-Google-Smtp-Source: APXvYqxeZqCfkK/c9bRk41iEKDbB/Bhwyv+eT7aE9D9ENEBBIfcRA/T2Dx4kxkYlmIA7xmVDLR5qMQ== X-Received: by 2002:adf:d183:: with SMTP id v3mr30385595wrc.180.1580222486560; Tue, 28 Jan 2020 06:41:26 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id g7sm25732439wrq.21.2020.01.28.06.41.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jan 2020 06:41:26 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Johannes Schindelin , Tanushree Tumane , Miriam Rubio Subject: [PATCH v2 11/11] bisect: libify `bisect_next_all` Date: Tue, 28 Jan 2020 15:40:26 +0100 Message-Id: <20200128144026.53128-12-mirucam@gmail.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20200128144026.53128-1-mirucam@gmail.com> References: <20200128144026.53128-1-mirucam@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Pranit Bauva Since we want to get rid of git-bisect.sh it would be necessary to convert those exit() calls to return statements so that errors can be reported. Emulate try catch in C by converting `exit()` to `return `. Follow POSIX conventions to return to indicate error. All the functions calling `bisect_next_all()` are already able to handle return values from it. 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 | 40 +++++++++++++++++++++++++++++----------- bisect.h | 23 +++++++++++++++++++++++ 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/bisect.c b/bisect.c index 43baa3df28..d4b883f67d 100644 --- a/bisect.c +++ b/bisect.c @@ -967,10 +967,10 @@ void read_bisect_terms(const char **read_bad, const char **read_good) } /* - * We use the convention that exiting with an exit code 10 means that - * the bisection process finished successfully. - * In this case the calling shell script should exit 0. - * + * We use the convention that return -10 means the bisection process + * finished successfully. + * In this case the calling function or command should not turn a -10 + * 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. */ @@ -1000,23 +1000,35 @@ int bisect_next_all(struct repository *r, const char *prefix, int no_checkout) if (!revs.commits) { /* - * We should exit here only if the "bad" + * We should return error here only if the "bad" * commit is also a "skip" commit. */ res = error_if_skipped_commits(tried, NULL); if (res < 0) - exit(-res); + return res; printf(_("%s was both %s and %s\n"), oid_to_hex(current_bad_oid), term_good, term_bad); - exit(1); + + /* + * We don't want to clean the bisection state + * as we need to get back to where we started + * by using `git bisect reset`. + */ + return -1; } if (!all) { fprintf(stderr, _("No testable commit found.\n" "Maybe you started with bad path parameters?\n")); - exit(4); + + /* + * We don't want to clean the bisection state + * as we need to get back to where we started + * by using `git bisect reset`. + */ + return -4; } bisect_rev = &revs.commits->item->object.oid; @@ -1024,12 +1036,18 @@ int bisect_next_all(struct repository *r, const char *prefix, int no_checkout) if (oideq(bisect_rev, current_bad_oid)) { res = error_if_skipped_commits(tried, current_bad_oid); if (res) - exit(-res); + return res; printf("%s is the first %s commit\n", oid_to_hex(bisect_rev), term_bad); + show_diff_tree(r, prefix, revs.commits->item); - /* This means the bisection process succeeded. */ - exit(10); + /* + * This means the bisection process succeeded. + * Using -10 so that the call chain can simply check + * for negative return values for early returns up + * until the cmd_bisect__helper() caller. + */ + return -10; } nr = all - reaches - 1; diff --git a/bisect.h b/bisect.h index 4e69a11ea8..f640c4f963 100644 --- a/bisect.h +++ b/bisect.h @@ -31,6 +31,29 @@ struct rev_list_info { const char *header_prefix; }; +/* + * bisect_next_all() could return the following codes: + * 0 success code (from bisect_checkout()): a new commit to test + * has been found (and possibly checked out too). + * -1 error code (from bisect_next_all()): default error code. + * -2 error code (from error_if_skipped_commits()): only skipped + * commits left to be tested. + * -3 error code (from handle_bad_merge_base() through + * check_merge_bases() and check_good_are_ancestors_of_bad()): merge + * base check failed. + * -4 error code (from bisect_next_all()): no testable commit found. + * -10 early success code (from bisect_next_all()): first term_bad + * commit found. + * This value is checked in builtin/bisect_helper::bisect_next(). + * -11 early success code (from check_merge_bases() through + * check_good_are_ancestors_of_bad()): successfully tested + * merge base. + * Early success codes -10 and -11 should be only internal codes and + * converted to a 0 status code when the bisecting command exits. + * Different error codes might enable a bisecting script calling the + * bisect command that uses this function to do different things + * depending on the exit status of the bisect command. + */ int bisect_next_all(struct repository *r, const char *prefix, int no_checkout);