From patchwork Mon Feb 17 08:40:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11385791 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 4283F924 for ; Mon, 17 Feb 2020 08:41:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 232752067D for ; Mon, 17 Feb 2020 08:41:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gctrySRp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728520AbgBQIlX (ORCPT ); Mon, 17 Feb 2020 03:41:23 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:51746 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728515AbgBQIlW (ORCPT ); Mon, 17 Feb 2020 03:41:22 -0500 Received: by mail-wm1-f68.google.com with SMTP id t23so16201938wmi.1 for ; Mon, 17 Feb 2020 00: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=KnSjfJACvq4RHTwJYBCS7NlP6qBafuboKWIT7deLTUc=; b=gctrySRpckAd9KlKZzXATLcGLHmVZbOw40AkLYUnOExbGfAK69UyRk1syIXX7csoF5 GADbg4Rs4fRhKX5IcwzyKiSmqeIC3yjUYv0wAl5acObqPsLsVfjOvCw1wy6J2uJJiutH ThbpELiZIjUQycU57uTANV3CeaWarL91I9pu39RKGwM3Q43F7+RWW1jNqSfyDJa9ayOi JBOP/iSxLRKRY/hSWkva2NQP20PVVNlqBZJRKeMOXrSwHCLtMrK7CkCdL/oqO8HknZ1M E0bR9U4WWJlprOTmnoaWzkzgKjOlix3O7Q+QGyB3twuSFCvc4PLC6rvrmbtCT6qavvnw 5lmQ== 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=KnSjfJACvq4RHTwJYBCS7NlP6qBafuboKWIT7deLTUc=; b=s7JYS9MtaFcjl6K+AAyywx2Mm09GQiJNnK5sgOR1NkJooq89GEZKnQ3J4/f/1YZOzV TmPDYPbZTiWSGRuKvgNIRsPmqXf+NBCk8UnrlOZCpdnNtooMd+2hjbSMHCfcfNoxYvCM P5iPGqzwCwdpiSGhZtaDtwI9ONkai8QvU8GV8gZp1xHvkD9eb4hIx+Ar3KCD0NBtCK9p 9/BOLt/keMiHrBjwV1HRc7Wq+0K0ckOLjjXZY7jSShUu3H66h7IqtaNhLA6+e/yjPG9P HIvhf8koEufyZSCWlnUJq1RBJEmkXVCHu8Dm7ZDokEzBWNrsQPFPrmaIkxtZbUhq3lSi SlWQ== X-Gm-Message-State: APjAAAUY8pkENM5Y44R4cpEe6383Pw2nVWW7PfSJCeg6wwFPc5wei803 cKj9l18tBamrHN8kuDxHMujo4/X6 X-Google-Smtp-Source: APXvYqzQLJERPHxNX8B66igECbRTYjR9uttCEkc2sRg5EaE4cYCzHBdpL37jBKP2kIQ5/pXQITW8jQ== X-Received: by 2002:a7b:c119:: with SMTP id w25mr21297390wmi.116.1581928879422; Mon, 17 Feb 2020 00:41:19 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id s22sm19187149wmh.4.2020.02.17.00.41.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Feb 2020 00:41:18 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Miriam Rubio , Christian Couder Subject: [PATCH v4 01/12] bisect--helper: convert `vocab_*` char pointers to char arrays Date: Mon, 17 Feb 2020 09:40:28 +0100 Message-Id: <20200217084039.78215-2-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217084039.78215-1-mirucam@gmail.com> References: <20200217084039.78215-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 Mon Feb 17 08:40:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11385795 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 E0ADD1395 for ; Mon, 17 Feb 2020 08:41:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B71032064C for ; Mon, 17 Feb 2020 08:41:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Nzduef1K" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728524AbgBQIlY (ORCPT ); Mon, 17 Feb 2020 03:41:24 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:35464 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728108AbgBQIlX (ORCPT ); Mon, 17 Feb 2020 03:41:23 -0500 Received: by mail-wr1-f68.google.com with SMTP id w12so18552300wrt.2 for ; Mon, 17 Feb 2020 00: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=6rMmId46JqJEt9chXf79F4b/ZhaDCV0s6kJWTBBk17c=; b=Nzduef1KqvFljdEdMcCaF2B8g+4IMHV79PsDYDgdt+aJcA3Iwks9u4YbV89ivAzpI0 zUdjbhvYba3pykcrjJ9GE5G/q7OY0i+m8uhuD0MN4SG7KdHTD0WyNb9X3hznVDBmzITH lv7yjyq3F0Z8SJaIS72z9B4vlLx9v0FNnNSD6HMGGUPxWGc+E5QMNgKLfmMkJxucvwV3 wL4V7qJYLSxQBFbpj8wSVr2+ZxsLSmB/44DanSBmgSHyzcJMU2ZFAhCc8yaxeNUXhLun +zvh5mAgMRByFNB4y8QpFGGc6F9RNWCGOgrOf9xRHWo1Lyk8n9c9kD1Rq/qbJTlYvwiy 9S1A== 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=6rMmId46JqJEt9chXf79F4b/ZhaDCV0s6kJWTBBk17c=; b=WPQPVU86czdHDpur6AF27qRWFguY8CxXhwzlu7oFdu9MY9xlP8sb11eSvRLgVER8wz 8MdnAkwPT6z8mJofOBUyv/thBp+ePC5OOGl4t5oAuSRoMMR5gMoiQzPSJH/75cfHoqmw JN8BFMNDcNKw7Q9Ha/blr2jKrwjbMdEsOUjN04pMzT5FnbD2G4xj1Z+rQ1eJgceOTvN4 aH7A+AD40B0cabcHZTi7buzas7pyZJG5MLdPRneTCURi6nHz94lbH5t9i4KPBuKJ0tLb tphf/HCC2sAhbYXB32TRVvFW/PmzCdq6bmA+qeR73i9BriRhqVb6N4wkUvsQs1+yv9VE 4SDQ== X-Gm-Message-State: APjAAAUwAqe44K2wGCq3fQJDQZnUra6i3/o6nHNcLUPCoCiUVtV3zZOE oyxOIlKo3onWt7GhuFf9A9EKpLJt X-Google-Smtp-Source: APXvYqxQIe/XXwWC3T3UQX86WFf4gs94HzCQPLc+ydr9PqOOhQDUpG87R1k9y2BhdlPwFrRZp6PRSg== X-Received: by 2002:adf:93c1:: with SMTP id 59mr21164028wrp.399.1581928880834; Mon, 17 Feb 2020 00:41:20 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id s22sm19187149wmh.4.2020.02.17.00.41.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Feb 2020 00:41:20 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Tanushree Tumane , Christian Couder , Miriam Rubio Subject: [PATCH v4 02/12] bisect--helper: change `retval` to `res` Date: Mon, 17 Feb 2020 09:40:29 +0100 Message-Id: <20200217084039.78215-3-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217084039.78215-1-mirucam@gmail.com> References: <20200217084039.78215-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 Mon Feb 17 08:40:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11385793 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 7CDB0924 for ; Mon, 17 Feb 2020 08:41:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F03E20725 for ; Mon, 17 Feb 2020 08:41:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m0VU2xCb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728529AbgBQIlY (ORCPT ); Mon, 17 Feb 2020 03:41:24 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:34734 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728516AbgBQIlX (ORCPT ); Mon, 17 Feb 2020 03:41:23 -0500 Received: by mail-wr1-f66.google.com with SMTP id n10so16604807wrm.1 for ; Mon, 17 Feb 2020 00:41:22 -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=F/E7cK3VSiOwE85cFoKaYycycoziCZiL2QoxWjjLcEQ=; b=m0VU2xCbF1qPIXpDVUx1c9sAQ6y9orA9FAcP6obFFPVE0/kZ2FWmQ+Jw8XhOBhbSl1 n1zH0iAAPlhMsETllp+gWNRj5cR03TtQ72pOxHg/8DF8ymMIIeatlBq75KOVDMYYKI3C 41VOFD60buXf9NBk5CVqWmdo+QSeuDsOn3TrGd5aHaRB9cbbuuOuro5run0X9i4Q5WyJ yBwhXxThfJAw5OJQQYzVwLl9nGNqlQDJPUVNg2L/pSCbnNJRHVdgElugd5InsbNywMvX Z7VJ0laF86FwkLpewDIxSZ865bsN39a/xoDyiGWb2UWRifp1bC9+tmMRyuv3M6x/rQge 3ECA== 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=F/E7cK3VSiOwE85cFoKaYycycoziCZiL2QoxWjjLcEQ=; b=VGP6Ss06zm24ogA/07asT5LDBH2XBkaelCzLhycSUPTZTB/QC56ivuPSmxgBL4Dp3u DUB5aOfGMPvE8e+8DDH2a48AnI/b5fT8+Zmw+XPwothknBW5AyEc1wvcrs4MhWuXpS9D 8mssCJaERh62bh26wtdUx8zhqpqXLsWNtfldzG+uHEjdMi22PXSbRhJ7cNtABFNwOVEr FFhQfxL+lhITD6L6VbpDkEkzhFa6zXNxT4wytEkw/2ypKa0bRbajlc6eq+sqvlu5eriB C90VT9ApjqhXIVkC1KSCX0rMFDx9DJVH5FgfWMTg7idJukuhj/cfj2rjhnonlPCVWpxY +yqw== X-Gm-Message-State: APjAAAWZpvWDuNFJyv0M6PAnVtNwpb5wYes8CJS0GbFR6iVzD/K5Nh3U vJbqRGtqQ00PLftJ/QnFi2o7hvru X-Google-Smtp-Source: APXvYqyh1bw+ovjM7ymtpfK018hP+LtveKwCeW3B2evUB1cbEbJ8YuNNSg4JPQxWdRLIoxiV5dvkTg== X-Received: by 2002:adf:b605:: with SMTP id f5mr19778027wre.383.1581928881911; Mon, 17 Feb 2020 00:41:21 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id s22sm19187149wmh.4.2020.02.17.00.41.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Feb 2020 00:41:21 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Miriam Rubio , Christian Couder Subject: [PATCH v4 03/12] bisect: use the standard 'if (!var)' way to check for 0 Date: Mon, 17 Feb 2020 09:40:30 +0100 Message-Id: <20200217084039.78215-4-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217084039.78215-1-mirucam@gmail.com> References: <20200217084039.78215-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 Mon Feb 17 08:40:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11385799 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 15E6F924 for ; Mon, 17 Feb 2020 08:41:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E47CC2067D for ; Mon, 17 Feb 2020 08:41:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BxEHHbfZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728543AbgBQIl1 (ORCPT ); Mon, 17 Feb 2020 03:41:27 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41868 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728537AbgBQIl1 (ORCPT ); Mon, 17 Feb 2020 03:41:27 -0500 Received: by mail-wr1-f65.google.com with SMTP id c9so18570964wrw.8 for ; Mon, 17 Feb 2020 00: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=7cidQ2/1P7oKcKMitQp8G7KJy2dGBePySTf6krnU+sU=; b=BxEHHbfZZk4yWpcQ2Ra70Xz+xu8XYA/UAQaKTbEaBgu7yowxMEUcknmDgs+YyAhwJk ouJ2UHYCvwxOj+KkZc9ye1B2+GSnpARigFJPNrsvcZTDQYektex4qUzuCQk1UMLiQBL9 41PZ/TGpIp+Pv+mdDDe5zG9AWrHVrVZBubsY9FUEO9IgRLHGnku7Gb54dedQ67d5HNSp svyyCuk6YUlSOYLKFU6CTcpOEvdq9FZl9LJypIX7jOpMhq0aK3hp/N9yu/1fRTAvfTGV vcmElldiVfH8qDm5qM0BDyCnIQQv/zqXaIvMUbtSyggTiA8x8ZNsHz8TQ/QHegKs1BNr Q7zg== 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=7cidQ2/1P7oKcKMitQp8G7KJy2dGBePySTf6krnU+sU=; b=g9DOY7edzGoWiJPGKzCOQiOwPVfZl9PJhhbJ0dilZlEIniUjXpIXYwu9xtnzrwnhoX dxLP8/TWaD52moZn8rxyGxPtVifsnQoAi2dBSW3p++W4v7K1XQ9foKuXVpWAAatWx5NG c7d18ydLuVqsOM3fGvhbC/H3Ob0HkWx7AAhGAZuTUuYWF+mhqfc18CDl3bNxkj3yyukW rln+HkG/1oBNqoHBCyWL6UPpvlunIQm3zG8qkR/5RwAnmIHBSC2M+tQf0oibZExLUxMx ZHkxC2I9D3GopqHBDVlZvXlqIGLqQ4YqQdtriNi4IldceHfDReRdXNHdPGBV6uL3UetN SAFA== X-Gm-Message-State: APjAAAVIZmKz80wtVH39Znzbt1CtR/3r6TCmKWPHsMQ6KAp+oOfdovTx BHEhEcTu05AWLnuFvKQ+pW4tDhOr X-Google-Smtp-Source: APXvYqzy127J3FkDeoBndopOMEm5l7zeMswMAm9aTOHUz0oRc0IAZIf20Dgm5PM7xuHMvP0xiXoiig== X-Received: by 2002:adf:df03:: with SMTP id y3mr20905535wrl.260.1581928883139; Mon, 17 Feb 2020 00:41:23 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id s22sm19187149wmh.4.2020.02.17.00.41.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Feb 2020 00:41:22 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Tanushree Tumane , Christian Couder , Miriam Rubio Subject: [PATCH v4 04/12] bisect--helper: introduce new `decide_next()` function Date: Mon, 17 Feb 2020 09:40:31 +0100 Message-Id: <20200217084039.78215-5-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217084039.78215-1-mirucam@gmail.com> References: <20200217084039.78215-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. While at it `bad_ref` and `good_glob` are not const any more to void casting them inside `free()`. Mentored-by: Christian Couder Signed-off-by: Tanushree Tumane Signed-off-by: Miriam Rubio --- builtin/bisect--helper.c | 66 +++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 21de5c096c..e21d3d1a4c 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: - free((void *) good_glob); - free((void *) bad_ref); - return res; + 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; + char *bad_ref = xstrfmt("refs/bisect/%s", terms->term_bad); + 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(good_glob); + free(bad_ref); + + return decide_next(terms, current_term, missing_good, missing_bad); } static int get_terms(struct bisect_terms *terms) From patchwork Mon Feb 17 08:40:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11385797 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 016E91395 for ; Mon, 17 Feb 2020 08:41:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D66DA2067D for ; Mon, 17 Feb 2020 08:41:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="t3h228AU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728541AbgBQIl1 (ORCPT ); Mon, 17 Feb 2020 03:41:27 -0500 Received: from mail-wr1-f44.google.com ([209.85.221.44]:33845 "EHLO mail-wr1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728516AbgBQIl0 (ORCPT ); Mon, 17 Feb 2020 03:41:26 -0500 Received: by mail-wr1-f44.google.com with SMTP id n10so16604976wrm.1 for ; Mon, 17 Feb 2020 00:41:25 -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=Yo7QEzRHNTsTu/TwkDBC91rjNACXUcRl6cHU+LuRfj4=; b=t3h228AU02RsUkYCtOfcVAip+sgrZ5HXzkLhyPvVBg/amhUWexA4z0oAn9phzMv4xv hTvcwGZE6Zol+Llh3iopHScis7VElPX9idNDX3WiCR72j+nB5PW45YmLNGfK7sb9gt+X UlZrLH1OsvbKK/UfnssMpByGpa4nciuajtzdSWovCWMvULbQgQwYsFFPYkmwmxmsrmit D/iSo8CpRP32MlDgyxkq5lNhpcgm07g68Wqbw1TQtmcwAt8sDlI2HfG9jvAEjdHM4zq4 t4T6aH9bHzh983UWPmuLubz4oIJTqRS3o8mzq5bpKcq1brTFBRkDXsQGq67E5dta7WzU WR1w== 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=Yo7QEzRHNTsTu/TwkDBC91rjNACXUcRl6cHU+LuRfj4=; b=b8i5MwopG+Ii8cWajk1w2e4BoJ2fVAdEtUXZmzaMEpM8SOTJCden+/jcTojJbQAXD9 vs6JdDqD2GR9XBqj3QZdZzTUoTj3fSZ3VQiSKI6Mgs9kkXu/X6K/L1dfz/zVpJJf+Kzo 7RHnRP+nyvAG7ql+J3CaX4ARC3mPLzEPGfhGA1gyE0Iph67+zRHe5TZh3aFXhCsNPm7H V1Alt1pLESJ5feHi+ZjPtticMR5Ft3Neio21rrGkd0Gv5JXtLnl6xf+bWdvc7Q7hWxs3 vYi2alDZlRq1rPJ0fTBEAPmfM6uEJ4aY03jljj15OivprKT1z7OOG/wmmA9n8XnOjFam Gw0A== X-Gm-Message-State: APjAAAU/pLo73KzlVgPEeYWL7xsH2zMBRY/424aQ7uRrOaiwRjCyhTw0 FzQCVq1PUF4J88wEf96hOCZ5qH7n X-Google-Smtp-Source: APXvYqwSNjw+oHqLFBzthTpLlj1ZfHxbXrPYNuCzN65NwM8gtTt+n1fYoxug5fZLv4W7aFq7NK0Upw== X-Received: by 2002:adf:f3d0:: with SMTP id g16mr21567397wrp.2.1581928884353; Mon, 17 Feb 2020 00:41:24 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id s22sm19187149wmh.4.2020.02.17.00.41.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Feb 2020 00:41:23 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Miriam Rubio , Christian Couder Subject: [PATCH v4 05/12] bisect: add enum to represent bisect returning codes Date: Mon, 17 Feb 2020 09:40:32 +0100 Message-Id: <20200217084039.78215-6-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217084039.78215-1-mirucam@gmail.com> References: <20200217084039.78215-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 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. Create an enum called `bisect_error` with the bisecting return codes to use in `bisect.c` libification process. Change bisect_next_all() to make it return this enum. Mentored-by: Christian Couder Signed-off-by: Miriam Rubio --- bisect.c | 2 +- bisect.h | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/bisect.c b/bisect.c index 83cb5b3a98..e4573c7ba1 100644 --- a/bisect.c +++ b/bisect.c @@ -945,7 +945,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good) * If no_checkout is non-zero, the bisection process does not * checkout the trial commit but instead simply updates BISECT_HEAD. */ -int bisect_next_all(struct repository *r, const char *prefix, int no_checkout) +enum bisect_error bisect_next_all(struct repository *r, const char *prefix, int no_checkout) { struct rev_info revs; struct commit_list *tried; diff --git a/bisect.h b/bisect.h index 4e69a11ea8..c921ead02c 100644 --- a/bisect.h +++ b/bisect.h @@ -31,7 +31,19 @@ struct rev_list_info { const char *header_prefix; }; -int bisect_next_all(struct repository *r, +/* + * enum bisect_error represents the following return codes: + * BISECT_OK: success code. Internally, it means that next + * commit has been found (and possibly checked out) and it + * should be tested. + * BISECT_FAILED error code: default error code. + */ +enum bisect_error { + BISECT_OK = 0, + BISECT_FAILED = -1 +}; + +enum bisect_error bisect_next_all(struct repository *r, const char *prefix, int no_checkout); From patchwork Mon Feb 17 08:40:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11385801 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 9A651924 for ; Mon, 17 Feb 2020 08:41:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7D5612067D for ; Mon, 17 Feb 2020 08:41:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="vOhKdgGG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728546AbgBQIl2 (ORCPT ); Mon, 17 Feb 2020 03:41:28 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37546 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728539AbgBQIl2 (ORCPT ); Mon, 17 Feb 2020 03:41:28 -0500 Received: by mail-wr1-f68.google.com with SMTP id w15so18555271wru.4 for ; Mon, 17 Feb 2020 00: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=P7LEZGJjRIfYsumNABEw6099v9waAI03KQWY0SNTAtY=; b=vOhKdgGGvwkylXO1DYdsBPrBLPq1d4sgq9tfeAu9JGxpg2xTnQQDRjSS7A+yweHbaS 0AY9LGdZ2CExjzY/tnVnqN3kBN4ujJxvEcZ2ub8Sjuxe6JGdlPr6vWOm20iiWiamxWHI blFpnjqW+KT1ypSr9/M7QvbPHJya+qbcSV/qg3g5ftVeSoI+22dvalkN8xuPGzUxSR0t JAl2V2zjNoF3ayqg2sjj3zjuWKvC2o1YgFePK5KSgJjaRO5aEkmv+bSjAxRj27GFle20 Kgv4l8yeirXFMjiQML2zHep76OtbYwbzGivhlQ/o91whWiNi3Cud6tKZwv7OL7D1lVHU 9LnA== 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=P7LEZGJjRIfYsumNABEw6099v9waAI03KQWY0SNTAtY=; b=o3lI/mbIHI8dly7v+n/C5xncsX9fNY02I1dDdKA+Y1VKvDDZ/RijECFnY3LyKemywV rvYRHpKO9XP7k3kNQA8rXJQBguPYs/ENXCCARQpSKriLwbyDY4fJ47NRjwNNuYbAq8p1 bUNxnDDSrBCf8yS6ioPf2ZSr1Gb4olOe6Z/ZFLhVsX51EAxSLDeLzsATqxcEI2WHWBjQ JbVp6UKCdImNdqkDGjKSMzkrlu9I/IoEZ6BYD6Z21qTzyajgELys90+VNCT0bh4bBWQh kv4zvK6hah4XQlvZseclgeGo7PyPTjZwvE4e/FC897613/6Ab/9oJ89/naad1ebUklb1 jpww== X-Gm-Message-State: APjAAAUcGCPwKwOIdl5or5ORsclIzE0UjtvRU+qm9wNU8QPxNv7MncfI C8iYPLrEyxsAL8JxwsCKBH9/GDDR X-Google-Smtp-Source: APXvYqzV9HdhKkvbCisSqWygGOBDIghT8IGDi4gkSIYnoyl6+UFC1XTEqMl2H/gDp1GpVEdLpH0VSQ== X-Received: by 2002:adf:f507:: with SMTP id q7mr20417389wro.384.1581928885605; Mon, 17 Feb 2020 00:41:25 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id s22sm19187149wmh.4.2020.02.17.00.41.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Feb 2020 00:41:25 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Johannes Schindelin , Tanushree Tumane , Miriam Rubio Subject: [PATCH v4 06/12] bisect--helper: return error codes from `cmd_bisect__helper()` Date: Mon, 17 Feb 2020 09:40:33 +0100 Message-Id: <20200217084039.78215-7-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217084039.78215-1-mirucam@gmail.com> References: <20200217084039.78215-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 bisect.c exit() calls to return statements so that errors can be reported. Let's prepare for that by making it possible to return different error codes than just 0 or 1. 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. Mentored-by: Christian Couder Mentored-by: Johannes Schindelin Signed-off-by: Tanushree Tumane 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 e21d3d1a4c..e6bd4d6645 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -713,5 +713,5 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) return error("BUG: unknown subcommand '%d'", cmdmode); } free_terms(&terms); - return !!res; + return abs(res); } From patchwork Mon Feb 17 08:40:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11385805 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 119061395 for ; Mon, 17 Feb 2020 08:41:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E5BCD2067D for ; Mon, 17 Feb 2020 08:41:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Vf3X2zIJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728553AbgBQIla (ORCPT ); Mon, 17 Feb 2020 03:41:30 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:53299 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728539AbgBQIla (ORCPT ); Mon, 17 Feb 2020 03:41:30 -0500 Received: by mail-wm1-f66.google.com with SMTP id s10so16211680wmh.3 for ; Mon, 17 Feb 2020 00: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=auj2PpN7jw/nCeMzZ55W8zrFR3AQWT85aqwAv1NJUPg=; b=Vf3X2zIJLzCoLk2MaxwZIiCQi6Oo1GP312QcWznM6rMADsR3Ux9jvZtTnbXOYq5Unq ZwC5WY7QsvXtPxs9Yb1dj0ETp5PkzYHMOMp1VNH64Cbd8Nabs/tobRI15gXxq4ZhlVdl il9UQY1ubIGf+KoX22w+/zm8bIcUX4d2a+Uh/nUxuBsE/J4cTOhm3/rJj0m3fm5tufvq VoyOBaF4J1zIp+GJn8qLFtkYcBbfihVE3jTtxKjvROarKy4muFKrkhy3FGpYC4JM/P5N oFw0+QXzE6DlZ8PsL0/QHIFMU7Whmn98wulICgHdGp7mxhrpANlw2tDFSn4pIbCqwDpA /wAg== 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=auj2PpN7jw/nCeMzZ55W8zrFR3AQWT85aqwAv1NJUPg=; b=iXErm6dO1SGb2d8qlk9kwuTElnMnfvaFYRLrFM32dAu2CXlXqROW0LuMRswb/CkTNE 0cm+YYQvvoyclXVj0Ql+Af/5soMrw6VDD3/8vYa5HfK97Ht17RJbjVCEQ4ddVIlAPEpF kOp/fBYL2bPjBmR7ngwVVhv6qIJ53eZSp7Jkf4pMNlSyk98aay19y3A/w4R0XiV5f3Uy RctkNiIGLc65BSaNa3hqTTk665Lmp3eRQbtTnvKRAPU2HvlZIzQkyBbedR+IXslxGOhX xIiv3MNlUD+BtCqXd8zpcVs/SRI8kaJ/k1jclR1Z4BIpAUKzMzDb9/vPJoxfhlSlFoiQ yuUQ== X-Gm-Message-State: APjAAAWMviDyWglygd48fX+zL1iJcvHIqRfC6TnerZyMF+jg6UdJpVPA p7LT9CLWQnZ7b9geBRd/BiTHgTb1 X-Google-Smtp-Source: APXvYqyfyGnzFdi/Vcul55ktf8+pS4Q6eUrq5PrUm5EowusGn2wDbt3UwWveBRVVEuDBJeBykWYgOQ== X-Received: by 2002:a05:600c:2c53:: with SMTP id r19mr20862534wmg.39.1581928886841; Mon, 17 Feb 2020 00:41:26 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id s22sm19187149wmh.4.2020.02.17.00.41.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Feb 2020 00: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 v4 07/12] bisect: libify `exit_if_skipped_commits` to `error_if_skipped*` and its dependents Date: Mon, 17 Feb 2020 09:40:34 +0100 Message-Id: <20200217084039.78215-8-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217084039.78215-1-mirucam@gmail.com> References: <20200217084039.78215-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. Update all callers to handle the error returns. 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 | 17 +++++++++++------ bisect.h | 5 ++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/bisect.c b/bisect.c index e4573c7ba1..85bda3500b 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 enum bisect_error error_if_skipped_commits(struct commit_list *tried, const struct object_id *bad) { if (!tried) - return; + return BISECT_OK; 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,8 @@ 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); + + return BISECT_ONLY_SKIPPED_LEFT; } static int is_expected_rev(const struct object_id *oid) @@ -950,6 +951,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix, int struct rev_info revs; struct commit_list *tried; int reaches = 0, all = 0, nr, steps; + enum bisect_error res = BISECT_OK; struct object_id *bisect_rev; char *steps_msg; @@ -972,8 +974,9 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix, int * 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 +993,9 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix, int 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); diff --git a/bisect.h b/bisect.h index c921ead02c..19d90e4870 100644 --- a/bisect.h +++ b/bisect.h @@ -37,10 +37,13 @@ struct rev_list_info { * commit has been found (and possibly checked out) and it * should be tested. * BISECT_FAILED error code: default error code. + * BISECT_ONLY_SKIPPED_LEFT error code: only skipped + * commits left to be tested. */ enum bisect_error { BISECT_OK = 0, - BISECT_FAILED = -1 + BISECT_FAILED = -1, + BISECT_ONLY_SKIPPED_LEFT = -2 }; enum bisect_error bisect_next_all(struct repository *r, From patchwork Mon Feb 17 08:40: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: 11385803 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 21FC01395 for ; Mon, 17 Feb 2020 08:41:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 01D5820725 for ; Mon, 17 Feb 2020 08:41:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IS6m1lic" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728555AbgBQIlb (ORCPT ); Mon, 17 Feb 2020 03:41:31 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:33007 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728547AbgBQIla (ORCPT ); Mon, 17 Feb 2020 03:41:30 -0500 Received: by mail-wm1-f66.google.com with SMTP id m10so6833524wmc.0 for ; Mon, 17 Feb 2020 00:41:29 -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=BZA+MS84eFTTHIZpvKxlzTaC/Nse0E6Ugur+gY3o55U=; b=IS6m1liceWUttbQ6ceQMdPZO7KbzwWth2jzLLaGr3VtKQNF1+RVhXfxEE8Cd7loBwg ZQa5wbePJ1vTLIqbF0AvqHnD6lbAvdyC8e4QXAL3KiIxp+9af20KyS2FoBgFauSPrQNM iozJygKina/hDEHnxcmehD1ssk7ncNx6w/2Q+pIjF9V2OK+4R15c541nksheMerkSMIU vEKQQvX2D/knxq5+ZEtscriBV0VY3mKNSDyworvovDH0fgWlErSOuOH0oKZKJTeWSB2D g/UGRUtWWSBfCdlSPPpqte5/5J33+xFtuVrwMrqr3W54gfyGmaOsLs27RVoTX+k0cA0N 3iIw== 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=BZA+MS84eFTTHIZpvKxlzTaC/Nse0E6Ugur+gY3o55U=; b=Z5MSg/GadT2/RWJvEZzKVNcMXKJAeqVDewblgsqo/qTwAe9XbYGcNamWIXyteKxiy6 Rss0WPdE67sVtZAA5PSyyL7btHq63vdH0nzwqk9vvttc5t2ggjWvHWrUUytZWpSJ0T53 sOruQU+03h4mgWdc3iUB2cosxKn+ow4sMb7a5CAl4gEOUDjTmqfShbBi3IXdXqWLZvCE /6Ww9J3y9gOOzSaoFZEugceIb2dzcJzK41u+yR1RD6Dd8jtAsfle+OdlBtUY9IGN/b5f 5gk/2tOb0TY4dbsHa+tv3FYo+RCARdsG15WCvFelcRc1kgA3RIJ0XJzKIfA3gZWF270F HAng== X-Gm-Message-State: APjAAAXn0UG2uSEqs1Hjw+DYY5Rp59Ae90sqH5IHb20ncDfPaEkk1l6R 0eq7BIoKfHIxbN/XctE9LEFVvVPd X-Google-Smtp-Source: APXvYqyZRBkDuY3A2HqI4DJSEmT9uoUteQ8lAPoHRBgoflWKUshtSWjR1RAYIQIu6pKsdwKcy4bbFg== X-Received: by 2002:a1c:4d08:: with SMTP id o8mr21465035wmh.86.1581928888190; Mon, 17 Feb 2020 00:41:28 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id s22sm19187149wmh.4.2020.02.17.00.41.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Feb 2020 00:41:27 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Johannes Schindelin , Tanushree Tumane , Miriam Rubio Subject: [PATCH v4 08/12] bisect: libify `bisect_checkout` Date: Mon, 17 Feb 2020 09:40:35 +0100 Message-Id: <20200217084039.78215-9-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217084039.78215-1-mirucam@gmail.com> References: <20200217084039.78215-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 | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/bisect.c b/bisect.c index 85bda3500b..f6582ddfed 100644 --- a/bisect.c +++ b/bisect.c @@ -704,9 +704,10 @@ static int is_expected_rev(const struct object_id *oid) return res; } -static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout) +static enum bisect_error bisect_checkout(const struct object_id *bisect_rev, int no_checkout) { char bisect_rev_hex[GIT_MAX_HEXSZ + 1]; + enum bisect_error res = BISECT_OK; 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); @@ -716,14 +717,24 @@ 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); + /* + * Errors in `run_command()` itself, signaled by res < 0, + * and errors in the child process, signaled by res > 0 + * can both be treated as regular BISECT_FAILURE (-1). + */ + return -abs(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); + /* + * Errors in `run_command()` itself, signaled by res < 0, + * and errors in the child process, signaled by res > 0 + * can both be treated as regular BISECT_FAILURE (-1). + */ + return -abs(res); } static struct commit *get_commit_reference(struct repository *r, From patchwork Mon Feb 17 08:40: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: 11385809 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 8F92E1395 for ; Mon, 17 Feb 2020 08:41:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6FEA52067D for ; Mon, 17 Feb 2020 08:41:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FUXMb4AD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728566AbgBQIlg (ORCPT ); Mon, 17 Feb 2020 03:41:36 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:37809 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728550AbgBQIld (ORCPT ); Mon, 17 Feb 2020 03:41:33 -0500 Received: by mail-wm1-f67.google.com with SMTP id a6so17416016wme.2 for ; Mon, 17 Feb 2020 00:41:30 -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=tLSG+Q77AdLVaFVMIARi/gl7xzQBzBo857i0VLL2p5k=; b=FUXMb4ADpRoJf3qFxUGExzOjZPMyzRHuPrDtbFvy6JPfA0aERdT5gTIgikehZqs8BO ymubyr3m/jz1DyxiY9Emj/nDFQ0H/8NLCCgJb4rQwB/1rXQqf6QqRkjPR1cFzCa0vg5K jEP0u/9ROuSD5nxyneKuHukNp7G+8R8K0iHfvlHZoaRqneZ5gv1pFYLH+3fbjDl8t/PJ 5V02snKuOacOXYzObvnB9x/PtyuMC7AfB+vIdA3foO/uaehgd78gUpgDp1ZzUhaFT7ZD 1y52BVwO06v2c99a468unJ+7enVeXPl8lSMcLMVTmDvBeWRORxMXJSe4QUERuCgdrkJw EaQA== 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=tLSG+Q77AdLVaFVMIARi/gl7xzQBzBo857i0VLL2p5k=; b=DkmvQwiH87ZJr4GUxSR7zAJ8T7F70wVDb/E2HzXC4nR/DzrGr1Nrz/HT3E4aC7nhth aMYwZ1Ux9ldHP2IHlsKqUcUe8/NLqDe2wITiDV1dHMTpOFWs3uaDNIX62YMTleiXNARd K8f54/wUmL7o7CLafaoVbaKSG2ADv58S+yFkqYmjiDe/1o4g9LHOfAHDl3YUlg5rfEJx Qsy0jpzaNXLALG5wQwXIEUsSpt8h/zaDKD7qBDShSM7greWDyjI+cYbQcqdwPlkdfCvm 8A3H3HyD3c3FN3MPx/fc8k2s3SWJAZlwQHTWIk2ByeWpmki3yRw00f1RkvtIOqAICB3A cKuQ== X-Gm-Message-State: APjAAAUIp5D46qC8inh90SC5dH7BlO/kdh1qAt4LQhhvvTIwn0Lc5KiP 9wUSOKzTcNG5WBX+1XgnvtOafXk8 X-Google-Smtp-Source: APXvYqxldzjLVWYpF7QClVlrSyN7v5T/itsV5oxSmbhkK2x+D42/1dsbrzDkC6eVU+ZVWad7pRlg5Q== X-Received: by 2002:a7b:c1d0:: with SMTP id a16mr20750892wmj.175.1581928889541; Mon, 17 Feb 2020 00:41:29 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id s22sm19187149wmh.4.2020.02.17.00.41.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Feb 2020 00:41:29 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Tanushree Tumane , Miriam Rubio Subject: [PATCH v4 09/12] bisect: libify `check_merge_bases` and its dependents Date: Mon, 17 Feb 2020 09:40:36 +0100 Message-Id: <20200217084039.78215-10-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217084039.78215-1-mirucam@gmail.com> References: <20200217084039.78215-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 BISECT_INTERNAL_SUCCESS_MERGE_BASE (-11) which indicates early success. This BISECT_INTERNAL_SUCCESS_MERGE_BASE is converted back to BISECT_OK (0) in `check_good_are_ancestors_of_bad()`. Update all callers to handle the error returns. 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 | 22 ++++++++++++++++++---- bisect.h | 7 ++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/bisect.c b/bisect.c index f6582ddfed..382e0b471f 100644 --- a/bisect.c +++ b/bisect.c @@ -811,13 +811,18 @@ 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 + * BISECT_INTERNAL_SUCCESS_MERGE_BASE (-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 enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int no_checkout) { + enum bisect_error res = BISECT_OK; struct commit_list *result; result = get_merge_bases_many(rev[0], rev_nr - 1, rev + 1); @@ -832,11 +837,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 = BISECT_INTERNAL_SUCCESS_MERGE_BASE; + break; } } free_commit_list(result); + return res; } static int check_ancestors(struct repository *r, int rev_nr, @@ -871,6 +881,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; + enum bisect_error res = BISECT_OK; struct commit **rev; if (!current_bad_oid) @@ -885,10 +896,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 == BISECT_INTERNAL_SUCCESS_MERGE_BASE ? BISECT_OK : -res); /* Create file BISECT_ANCESTORS_OK. */ fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600); diff --git a/bisect.h b/bisect.h index 19d90e4870..f68ae85376 100644 --- a/bisect.h +++ b/bisect.h @@ -39,11 +39,16 @@ struct rev_list_info { * BISECT_FAILED error code: default error code. * BISECT_ONLY_SKIPPED_LEFT error code: only skipped * commits left to be tested. + * BISECT_INTERNAL_SUCCESS_MERGE_BASE early success + * code: found merge base that should be tested. + * Early success code BISECT_INTERNAL_SUCCESS_MERGE_BASE + * should be only an internal code. */ enum bisect_error { BISECT_OK = 0, BISECT_FAILED = -1, - BISECT_ONLY_SKIPPED_LEFT = -2 + BISECT_ONLY_SKIPPED_LEFT = -2, + BISECT_INTERNAL_SUCCESS_MERGE_BASE = -11 }; enum bisect_error bisect_next_all(struct repository *r, From patchwork Mon Feb 17 08:40: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: 11385807 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 3D0CD924 for ; Mon, 17 Feb 2020 08:41:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1DA172064C for ; Mon, 17 Feb 2020 08:41:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PTQzWSJw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728569AbgBQIlg (ORCPT ); Mon, 17 Feb 2020 03:41:36 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:35490 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728547AbgBQIlc (ORCPT ); Mon, 17 Feb 2020 03:41:32 -0500 Received: by mail-wr1-f68.google.com with SMTP id w12so18552984wrt.2 for ; Mon, 17 Feb 2020 00:41:31 -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=/XhzMsY+lJloLSl4b1Z/o0VZTFTA4XJ4siYO0bhm1Oc=; b=PTQzWSJwnTa++3YBkdzkU/1FmLVmCIcDy0IvS+uPFFuXuUvPaM8Ddx/Zlrg6ymsLjf Jdhu91MS9UGjMj/UrheT3PQXkLIelqf/5QU1q1n0bPtUzTVnj0x+xL50htWOeKysszUj L5wgeJtITIX2rwhmeb88yQ2aUtCBvD6nib0xjIMW47ji2UPGfequPL7FzrtMCss6sLRh y2RKr568zsSIS6seZjvLMjiryeK59TNhiZ1DJUqwh9Pdi59I9GxMF8rL/FHIYnI2jERA gBuimsNSwQRWuoADF5yrRNFu0kiIEyrhfiVrltmU6/3VKQ9/vG3CeH8EfdpLf3G5tAuB YO8Q== 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=/XhzMsY+lJloLSl4b1Z/o0VZTFTA4XJ4siYO0bhm1Oc=; b=ACB8Eg3nJWRCEBqd1Md8D8zCeTLCQeSR41kWNQPkymmq6/usZB2bEVNEa92qfUL+tK jvmIYJhIivHGkcoWObiaRLcGsKqSaJF2ToUTiT/qwIBfH6F1BkyrJU/yZqps5f0YEipv tswvD3XAP4pLsvOjuj598W0uBDR0MWix2nugv2Xu9LpH+qVid8eVLSPtnXTzt5wRQINQ S7Q31KNZkkz1g2czUUyBTcO/SYfCXcljyyUPyJ8QMxe2zVJkZLQ0MgZq5rI8/ULZ2shE y1xZ5n6TbzK0+mYLiPNuipP0gNUxGVmZO7aztaxQYDcaYeUNOQd9ya+gbzwqvTfhmKgV cQLg== X-Gm-Message-State: APjAAAUhtoKaQT0JBuedMmtz8t33tTgYXO8/vLsdxK7+RY5C+lr1yIG1 I+cIGBnHmXHPCQT8a6EZC0dwYy0h X-Google-Smtp-Source: APXvYqz/jdzZxV1RFwp9lyVtUhiT3ATgEC7xkrRhk7Je8+eNo3ZvKHYqrjsYzSkK6r8+ABGYYf5/EQ== X-Received: by 2002:adf:90cb:: with SMTP id i69mr21270818wri.205.1581928890752; Mon, 17 Feb 2020 00:41:30 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id s22sm19187149wmh.4.2020.02.17.00.41.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Feb 2020 00:41:30 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Tanushree Tumane , Miriam Rubio Subject: [PATCH v4 10/12] bisect: libify `check_good_are_ancestors_of_bad` and its dependents Date: Mon, 17 Feb 2020 09:40:37 +0100 Message-Id: <20200217084039.78215-11-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217084039.78215-1-mirucam@gmail.com> References: <20200217084039.78215-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 BISECT_INTERNAL_SUCCESS_MERGE_BASE (-11) to BISECT_OK (0) from `check_good_are_ancestors_of_bad()` has been moved to `cmd_bisect__helper()`. Update all callers to handle the error returns. 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 | 41 ++++++++++++++++++++++++++-------------- builtin/bisect--helper.c | 11 ++++++++++- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/bisect.c b/bisect.c index 382e0b471f..f5ce3a4b70 100644 --- a/bisect.c +++ b/bisect.c @@ -872,20 +872,23 @@ 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 enum bisect_error 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; enum bisect_error res = BISECT_OK; struct commit **rev; 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)) @@ -901,18 +904,26 @@ 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 == BISECT_INTERNAL_SUCCESS_MERGE_BASE ? BISECT_OK : -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) + /* + * BISECT_ANCESTORS_OK file is not absolutely necessary, + * the bisection process will continue at the next + * bisection step. + * So, just signal with a warning that something + * might be wrong. + */ + warning_errno(_("could not create file '%s'"), + filename); + else + close(fd); + } done: free(filename); + return res; } /* @@ -984,7 +995,9 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix, int 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 e6bd4d6645..c1c40b516d 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,13 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix) return error("BUG: unknown subcommand '%d'", cmdmode); } free_terms(&terms); + + /* + * Handle early success + * From check_merge_bases > check_good_are_ancestors_of_bad > bisect_next_all + */ + if (res == BISECT_INTERNAL_SUCCESS_MERGE_BASE) + res = BISECT_OK; + return abs(res); } From patchwork Mon Feb 17 08:40: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: 11385811 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 4C55B1395 for ; Mon, 17 Feb 2020 08:41:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2DF7A20725 for ; Mon, 17 Feb 2020 08:41:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="A4JRo2o7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728563AbgBQIlg (ORCPT ); Mon, 17 Feb 2020 03:41:36 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37565 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728556AbgBQIld (ORCPT ); Mon, 17 Feb 2020 03:41:33 -0500 Received: by mail-wr1-f68.google.com with SMTP id w15so18555759wru.4 for ; Mon, 17 Feb 2020 00:41:32 -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=ms8Nz34/TOFMi7UfzRyUn5hd7ezZ67aEMzjAIUfVNsE=; b=A4JRo2o7deTQrlKVMEkzYG3ANF7OlFDRkeg3wzxpvU2z273V4jDzrW7G77CTd4jnWK VixN14C3hXSvDz5fIhPQuGBLMsRXIlSAKPez5P+e1ccoBGm/5paUPQrODViThftfFvLX OZqVpYLoh3n1uwZrJ0ZeJhNN3R1JfdLtjdYqa8Gh+4EG3IEti/+QVaCxMYV+g4aQOjg9 TeZgXAwJlE55rzB7LUrK6X2TlJ9GF+TMl6tXfsfcfM5Go3ilgwfn+JZdOmWO9f5gPwz2 Wm5BHc8Wpltd/9WsKqebpxCA667+5eIVWJuUsEkeUaMqtOVfplVJ9IIfeZpqp3ZkEXL2 W3+g== 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=ms8Nz34/TOFMi7UfzRyUn5hd7ezZ67aEMzjAIUfVNsE=; b=k0l9lyhyg2U68BEMC7zX3fquGqg041lE5nVtJTv9KjW9VHm4hCN0hyfod+R4HtQb8t Q24pZMHfTO4NKiK0ze6TshtzBOqceHO23gEz02nzsOwUXcbxUrYK05hv1RCnewSX063O 7Xqj9Iw0M9kN3VYM4uG0Eucg8Hz+frWhixs5WyLLgaHgSyw9Qc96cRPR71Un4ySLrm+o 5f1rTMar2WGBSPVLwI6FIg7hGIY5j6XDkXMuexMD1OoGb6v+Lzicr1dGb0rUIJtCVmWZ 2/uDXkakdMdixTo62zKhBbczzxWchh9/1vNAVKJ4E9TvuC7sagsBSP5L/FRAnLPgKfi3 3cbg== X-Gm-Message-State: APjAAAV7fEOP2IUXPrFbCzsq2Y03T51lOFRPkfKi8uPmMsTdhtLa3Pmm 1eh1HV3UJXF40NtqiDmOs1RhgV2U X-Google-Smtp-Source: APXvYqzXJY7zpbXJoCXts+E+YB8F0uCR4jLKkAKh7SBqLK/ZpkE/WYJzZf39ohHY5c6ZB7E6JJyRmw== X-Received: by 2002:a5d:4d8d:: with SMTP id b13mr20901513wru.6.1581928891957; Mon, 17 Feb 2020 00:41:31 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id s22sm19187149wmh.4.2020.02.17.00.41.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Feb 2020 00:41:31 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Johannes Schindelin , Tanushree Tumane , Miriam Rubio Subject: [PATCH v4 11/12] bisect: libify `handle_bad_merge_base` and its dependents Date: Mon, 17 Feb 2020 09:40:38 +0100 Message-Id: <20200217084039.78215-12-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217084039.78215-1-mirucam@gmail.com> References: <20200217084039.78215-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. Update all callers to handle the error returns. 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 +++++---- bisect.h | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bisect.c b/bisect.c index f5ce3a4b70..837332a428 100644 --- a/bisect.c +++ b/bisect.c @@ -761,7 +761,7 @@ static struct commit **get_bad_and_good_commits(struct repository *r, return rev; } -static void handle_bad_merge_base(void) +static enum bisect_error handle_bad_merge_base(void) { if (is_expected_rev(current_bad_oid)) { char *bad_hex = oid_to_hex(current_bad_oid); @@ -782,14 +782,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 BISECT_MERGE_BASE_CHECK; } 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 BISECT_FAILED; } static void handle_skipped_merge_base(const struct object_id *mb) @@ -830,7 +830,8 @@ static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int 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)) { diff --git a/bisect.h b/bisect.h index f68ae85376..0d9758179f 100644 --- a/bisect.h +++ b/bisect.h @@ -48,6 +48,7 @@ enum bisect_error { BISECT_OK = 0, BISECT_FAILED = -1, BISECT_ONLY_SKIPPED_LEFT = -2, + BISECT_MERGE_BASE_CHECK = -3, BISECT_INTERNAL_SUCCESS_MERGE_BASE = -11 }; From patchwork Mon Feb 17 08:40: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: 11385813 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 9D1FF924 for ; Mon, 17 Feb 2020 08:41:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7D7B82067D for ; Mon, 17 Feb 2020 08:41:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uL43RjiF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728571AbgBQIlj (ORCPT ); Mon, 17 Feb 2020 03:41:39 -0500 Received: from mail-wm1-f50.google.com ([209.85.128.50]:52901 "EHLO mail-wm1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728433AbgBQIlg (ORCPT ); Mon, 17 Feb 2020 03:41:36 -0500 Received: by mail-wm1-f50.google.com with SMTP id p9so16207902wmc.2 for ; Mon, 17 Feb 2020 00:41:34 -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=kGh/PeU+AQvaO9QY4M69ACJAKEc+HVLem5sH/24iHkc=; b=uL43RjiFigT0HU5r2eGzrZ5af7Q4HF9oaFVcOoW3ITXFmrENNpbm7b+NwjDAsQamO4 /41HNEjgIIxCE4e1CWSQ/V5d7BbVIglj4B0/noANMmRgCV6dCU3d4jBVY3JBCNqdDW2L gQO6kaPYa0m98BxczCnCKkQSWosaPUth9UYDGK6sDkIfnVnwpNaR4xgIk7izrKcsO2+D u5ONgGUjQintZ5y81X7BgbhRwn5JoRoqeQgrr8XiUuj2BHiXv/DIXw17H4u337yh1u6l BOt+ERozFe0hkv+gh16sgUVAuoLT30gA3CeFlAu2rqwiGMe7jPdM8WrBOiX9xrCF0iWS UjQg== 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=kGh/PeU+AQvaO9QY4M69ACJAKEc+HVLem5sH/24iHkc=; b=COCMt8vgLPdSWrcCkxkHercaluZaIZDyrpJ2N/3okZtY30uVBLye2AzTxAVKmJSd8f Yy8SY56JKS6t7cqRXWzaceQK6xnvac8bNxpADawcRSxA2XXiN+LpbCGFKBvSGDxPiYCA kRSdF3qO2Ea3GbbEMksyWmQSl8JhazXTZJZueUVezvjoeHrmT5XwiAmJiqDinxL7lqYU 38d7pHB29x+/GsOuiBuZlPxnEeGmxk86Dnz/QEIMOIIic9IjmHshDMuhazRGxt/eCs3T LZHIrUFJvIMCgUnj89YM2/MFrHhKZLMC/FlRy+L+Upz3/xVJPOjShf0bmQhug8of0Lvh SmOQ== X-Gm-Message-State: APjAAAV4Ixh3nv1o+miq4hhkXRpmLh8/z+hNbzxSuDyxvr0OVjlZewjq vv3OMoJfZuqOTraswSpvXvM9nfxA X-Google-Smtp-Source: APXvYqzpecKZWjJ6odWUaoG9tSHU8FBeSkbirTupB5eEXt0sT6oWHslJrlaBwYShP9tjkmr5/2ugng== X-Received: by 2002:a05:600c:217:: with SMTP id 23mr20935254wmi.124.1581928893263; Mon, 17 Feb 2020 00:41:33 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id s22sm19187149wmh.4.2020.02.17.00.41.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Feb 2020 00:41:32 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Johannes Schindelin , Tanushree Tumane , Miriam Rubio Subject: [PATCH v4 12/12] bisect: libify `bisect_next_all` Date: Mon, 17 Feb 2020 09:40:39 +0100 Message-Id: <20200217084039.78215-13-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217084039.78215-1-mirucam@gmail.com> References: <20200217084039.78215-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 | 29 +++++++++++++++++++---------- bisect.h | 10 ++++++++-- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/bisect.c b/bisect.c index 837332a428..9154f810f7 100644 --- a/bisect.c +++ b/bisect.c @@ -976,10 +976,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 + * We use the convention that return BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND (-10) means * the bisection process finished successfully. - * In this case the calling shell script should exit 0. - * + * 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. */ @@ -1010,23 +1010,25 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix, int 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); + + return BISECT_FAILED; } if (!all) { fprintf(stderr, _("No testable commit found.\n" "Maybe you started with bad path parameters?\n")); - exit(4); + + return BISECT_NO_TESTABLE_COMMIT; } bisect_rev = &revs.commits->item->object.oid; @@ -1034,12 +1036,19 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix, int 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 BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND (-10) + * so that the call chain can simply check + * for negative return values for early returns up + * until the cmd_bisect__helper() caller. + */ + return BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND; } nr = all - reaches - 1; diff --git a/bisect.h b/bisect.h index 0d9758179f..8bad8d8391 100644 --- a/bisect.h +++ b/bisect.h @@ -39,16 +39,22 @@ struct rev_list_info { * BISECT_FAILED error code: default error code. * BISECT_ONLY_SKIPPED_LEFT error code: only skipped * commits left to be tested. + * BISECT_MERGE_BASE_CHECK error code: merge base check failed. + * BISECT_NO_TESTABLE_COMMIT error code: no testable commit found. + * BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND early success code: + * first term_bad commit found. * BISECT_INTERNAL_SUCCESS_MERGE_BASE early success * code: found merge base that should be tested. - * Early success code BISECT_INTERNAL_SUCCESS_MERGE_BASE - * should be only an internal code. + * Early success codes BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND and + * BISECT_INTERNAL_SUCCESS_MERGE_BASE should be only internal codes. */ enum bisect_error { BISECT_OK = 0, BISECT_FAILED = -1, BISECT_ONLY_SKIPPED_LEFT = -2, BISECT_MERGE_BASE_CHECK = -3, + BISECT_NO_TESTABLE_COMMIT = -4, + BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND = -10, BISECT_INTERNAL_SUCCESS_MERGE_BASE = -11 };