From patchwork Sat Feb 8 09:06:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11371509 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 3676E186E for ; Sat, 8 Feb 2020 09:08:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 16159217BA for ; Sat, 8 Feb 2020 09:08:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PqLVWYK4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727255AbgBHJI1 (ORCPT ); Sat, 8 Feb 2020 04:08:27 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43717 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726920AbgBHJI1 (ORCPT ); Sat, 8 Feb 2020 04:08:27 -0500 Received: by mail-wr1-f68.google.com with SMTP id z9so1578197wrs.10 for ; Sat, 08 Feb 2020 01:08: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=KnSjfJACvq4RHTwJYBCS7NlP6qBafuboKWIT7deLTUc=; b=PqLVWYK4D6uHC4gEUoY6U+Whs/brTFL9av8NAeeevnEPujkaibDnmtTxQ7YEMhMX7O ZQHTF7nQp61IizQ6M3eHkoidXoQVxcZCnsWpe9P8l2/MBuwvoj55qWOJl3DsMetGSTlb wWL2T6EpPYCp3q2YxsWuKzJSve8SSe85qkL1ARiWyGshUHkRqyIorUuGGDVhfIuLIr04 OxrlYXMQfILLihIxJZCcEo0xGIpysSOvWqsJOXOsenNFV4VgHNJko3gVT3WPxM5uF1Nd BOf3cEGoz6dUHORXeNPbRrbzJEVstb971oyJ7tZODiTe+4r2lZ8wacK3SOslWwwGkRPm aWZw== 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=tB4Mrd/EGLxylLmMjdz6T914z6kNETTih2bumZC6HMBiiGvqwfpVsftalbuXCnHg9g aqRdSDytgHlWQxw0qM+/LCalBkmJCY9ADdDkTrM6/RYSOvDVPlgFUxWAZM0qRQMfBvg2 n2RVnWdd+l/CzZlOqhKsnH9U5MBUL79xXR/hca92KStvIp4C4DKg/g/Sp0MIYfyPFfZg wey63vy5noQHkKBCypG8RYayDg5Ci1nKdPnOr9VDRRkOUGLl2ZVpOepIv0EKqrP7JWQC 6OjRaVJF7vmm9HyFmxyv9jWdX8h6UObkF+OZEmPTRRLrw74NJfl/WYxWjJCS1zjLFETt YPVQ== X-Gm-Message-State: APjAAAVkxqKso6WN+4oZ87KjSfk/eiVC/RisHqdk20eAyAPdNVoW+Xmy XHlYBJiNiPW2LCJXHLsuA7v62MAN X-Google-Smtp-Source: APXvYqxX65eCi4c9aY3yVEruelxK8PiCRP1fM8tjSO/2Mxeyb5vw7K5xBqw8BOLYNHF9NnfDumVnWA== X-Received: by 2002:adf:de0b:: with SMTP id b11mr4297630wrm.89.1581152904959; Sat, 08 Feb 2020 01:08:24 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id e1sm6999346wrt.84.2020.02.08.01.08.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Feb 2020 01:08:24 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Miriam Rubio , Christian Couder Subject: [PATCH v3 01/13] bisect--helper: convert `vocab_*` char pointers to char arrays Date: Sat, 8 Feb 2020 10:06:52 +0100 Message-Id: <20200208090704.26506-2-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200208090704.26506-1-mirucam@gmail.com> References: <20200208090704.26506-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 Sat Feb 8 09:06:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11371511 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 60EE41398 for ; Sat, 8 Feb 2020 09:08:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 403BF217BA for ; Sat, 8 Feb 2020 09:08:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hH8+iUFG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727309AbgBHJI3 (ORCPT ); Sat, 8 Feb 2020 04:08:29 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36308 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727243AbgBHJI2 (ORCPT ); Sat, 8 Feb 2020 04:08:28 -0500 Received: by mail-wr1-f67.google.com with SMTP id z3so1626650wru.3 for ; Sat, 08 Feb 2020 01:08: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=6rMmId46JqJEt9chXf79F4b/ZhaDCV0s6kJWTBBk17c=; b=hH8+iUFGPx6oaY5DZ5ilkumNHvQoyuJK0cUpuA+RtBATJL7ojDxylDxZ2XLeZdlRv5 79M6cNHE307cWYTnC12dXXvwOfLB9U7WVKfou2PDX2WQNh453MlxYkvBvLQ2xMqxZ2SG b2MS7tCkcbqwBZK+HxSy4VsLBPCl3J7QvzXgZCUeXvvuNt+dOXdWXJ8dhW1o705ZL8Kp iGsYxt9ek63kBcGcQ9ym00y5cA9OfzUcISwGBbKtIHm36G9/LkpRRDStl5GDLVhzoJyq 4ESnx0Us6J6Ylle4JIarnLsOaoCB6Q5ulbOBFGJorVEMorx/E2fm0vl+29XW+wFyGhSj cS9A== 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=RvL/JZwsBSrb8JGhudjTjbcXlWHV8R6W+2tvfTuraJgKnEWNOmfPNLJxaYaVJFKIWr P6WdVknwc8eNJiqAw2avhJEh3MAbPmL/8s+wkkmu18Q55tKh4zVIVnyIgQJVrqkVbC/J d78cAuwrBFuK1Qk/QLoCIA8LURBIuQlSqGy4JKLENkg26gN5Uk7P99CWxbuN8q9KIa3m 86XSWGwmiQz58PypqdBX2g63qjNW70fo+FsMHx/SVsuxNPqbPeENtBIWof5cIr+enGqY G4anIU4uGLXZF1p8gjSJGDEacWV/Xmq02aB/T5ONXDCOKb/1zvRtD5WGvI8k/USotEcB 0YMQ== X-Gm-Message-State: APjAAAVINpI9SRfmu1MwsSRSCPveMMg+leT6jvBzar5nahc+s++ZWkfz RszkAW/WB6zuMKUIzuKcMTkXcm5C X-Google-Smtp-Source: APXvYqx/BPRnV5NxeDF1hbaOW0abnbTk9RlfQ004cqzFlyPXjj/+bHGVz/WiU69jGscXYJ53xocoQw== X-Received: by 2002:adf:e610:: with SMTP id p16mr4674980wrm.81.1581152906238; Sat, 08 Feb 2020 01:08:26 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id e1sm6999346wrt.84.2020.02.08.01.08.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Feb 2020 01:08:25 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Tanushree Tumane , Christian Couder , Miriam Rubio Subject: [PATCH v3 02/13] bisect--helper: change `retval` to `res` Date: Sat, 8 Feb 2020 10:06:53 +0100 Message-Id: <20200208090704.26506-3-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200208090704.26506-1-mirucam@gmail.com> References: <20200208090704.26506-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 Sat Feb 8 09:06:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11371513 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 8B37E18E8 for ; Sat, 8 Feb 2020 09:08:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6AC29217BA for ; Sat, 8 Feb 2020 09:08:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FDbHr3hq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727403AbgBHJIa (ORCPT ); Sat, 8 Feb 2020 04:08:30 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:37164 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726920AbgBHJI3 (ORCPT ); Sat, 8 Feb 2020 04:08:29 -0500 Received: by mail-wm1-f65.google.com with SMTP id f129so5251839wmf.2 for ; Sat, 08 Feb 2020 01:08:28 -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=FDbHr3hqag5akZNKfylSfOUnqOLzT4U1XQ3Bfn5VEHaEWuoqGu9QZroG979GubdEfx wV724Wwh3hJS7MrTRZaCXUgOAJ7Gtj0ZfAf7t/yiXfGs1+L6bqb4KvQ8ppWjuwC0f/4m CHcYI8ajJZnpeIXSjYBWxz9vBS2rJv3xiYgMSi5gFn+tjkH3bz4Ns1zXXqiHEoEYNmUW hhE6kK6DB7jWlEcPiMv02Z5JVuEL/0lHAtEMHUmLArS0MwHgsgdP+xxuQ5vS/993XFUm nHwFjGqXwYtHSTl4inGlaVIUqkIDxOabbyIhGJJqqM6LnbuQgwAHaGyDPdqzKMxDbpf4 r3Fg== 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=gW4j2w3WUOr7Q5O5GcuuAsd2HGXHs75G6e5xjxiiHCs3NCCu9xEFo/79PYZxLkhL0H ckhIlT3nPtHrrQRKDDQEfFGg2pwbmzBPgvHfRfaVZcmYeiNKJPlMvszoowBNdX+45YRT CtB8u/19QGEU0rqYFb6Y7N3qELTM3vFjnLhSyh8pW/6KE+sITqqJYdI9f1b7+ydLB/d/ h82C/xpPGrKSDenKofSeccoXDHZJ3cz+5GmTLj0CR59tdwJudsUql1BHXbz0xg4h8Gnt KHC71qPDGu3PdVbP852g19sMtQt7q1QcvJ+MvNSTHwtb3FIbAfsFX3y2znqxtsbTnZk2 NUqQ== X-Gm-Message-State: APjAAAU1kZUGGxLMWnnsjgKn4NF9pwa87sljiIUqHWDLjb8vt5BFRqp4 X21xAae+CezfxX5Me3XbCAMDjFSp X-Google-Smtp-Source: APXvYqxTKcYCbVrioiSh4YfUHRkMOPmMF3U6FYyx1cRTs1+AwBc3V2tmxANDXkOUwRjW2zuLZh7AQQ== X-Received: by 2002:a7b:c109:: with SMTP id w9mr3508178wmi.14.1581152907375; Sat, 08 Feb 2020 01:08:27 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id e1sm6999346wrt.84.2020.02.08.01.08.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Feb 2020 01:08:26 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Miriam Rubio , Christian Couder Subject: [PATCH v3 03/13] bisect: use the standard 'if (!var)' way to check for 0 Date: Sat, 8 Feb 2020 10:06:54 +0100 Message-Id: <20200208090704.26506-4-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200208090704.26506-1-mirucam@gmail.com> References: <20200208090704.26506-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 Sat Feb 8 09:06:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11371515 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 53F6A1398 for ; Sat, 8 Feb 2020 09:08:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 32356217BA for ; Sat, 8 Feb 2020 09:08:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YCA6UY6y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727443AbgBHJIb (ORCPT ); Sat, 8 Feb 2020 04:08:31 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:39032 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727379AbgBHJIa (ORCPT ); Sat, 8 Feb 2020 04:08:30 -0500 Received: by mail-wm1-f68.google.com with SMTP id c84so5237003wme.4 for ; Sat, 08 Feb 2020 01:08: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=+qCo2LVoN7kUc0bghjWPOu/0zLYqhaSIxCXScK4jhRc=; b=YCA6UY6yJ/TFf0j9omZy0IxcZjSISajwJT1TA889O8YPAqJdF3hEVa8K8Mll6i0cjN riZOJZxcKFO6m7H2XeZDtAy0lAcHhCrW4y1i6H+nqsMEm/lgIx77xk0EoiLtxDVWH7Ff vjDKF2xoz2w5CfOCrt5Zu9XAJU9l8u+y962UIKGEYtWee6/Nk9l83qwkm7SWseoS+ymX FPMhNuyqC4bcsWBZGY8V1R1y7HSYZSe6Lqsa6jM+ilHIwuu6iI02lLlihsy5nH+BGQuU z1KHp5hnbO5L1wXgYE7Aq412NzS8VSXSAcmy/37+u3xs0tmr0sUhR/X5Iyr6e8/w9MW+ Ai3w== 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=+qCo2LVoN7kUc0bghjWPOu/0zLYqhaSIxCXScK4jhRc=; b=HNjJZjVX5+8nAHHUnvnKZbqd7NfQ1LbtAHgx2y2Cb44fxDKlmciv1MM5wI4iSO6yga 2updH1mXpF8CH7DzREUtqrzR7gEVCRGtFqUJNaO8A+Z3Te5WAbOBNPHQH9UUk/z/Wvib g4evU5+MaStRiM5JXjjdMEhOAEdOY68/rHyGXSMHK5fZhl+AQ3MaCDaOTNun2Y4+3HB6 FkLkxNWy5IChpAjXVUFuvCLNdLaCnqxxBukCbM7r+LDp0kEnSTv3pOcbP9/p6hMqdahf ne3ZmGxA+bSzZ5o/toJizuSnxal9jlbwvbyC+x5JOw7gViNTONRy+Abz1sCM+z5CShqg hsCQ== X-Gm-Message-State: APjAAAVwxJw9iGKOJeMSXcKywYZHSolRn1QdKUgGyg1XF6p+fcIjds2j vY4hELkF/ohnYDQGw2P+CgqgmmsY X-Google-Smtp-Source: APXvYqzW+zLre+andgvnEomheb5y+JvGZIQMWBZHfFUGS7D/v4qr7dZZIwC2wyoyrzJ+IjNSBxYmTQ== X-Received: by 2002:a1c:a752:: with SMTP id q79mr3389055wme.64.1581152908502; Sat, 08 Feb 2020 01:08:28 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id e1sm6999346wrt.84.2020.02.08.01.08.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Feb 2020 01:08:28 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Tanushree Tumane , Miriam Rubio Subject: [PATCH v3 04/13] run-command: make `exists_in_PATH()` non-static Date: Sat, 8 Feb 2020 10:06:55 +0100 Message-Id: <20200208090704.26506-5-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200208090704.26506-1-mirucam@gmail.com> References: <20200208090704.26506-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. `exists_in_PATH()` and `locate_in_PATH()` functions don't depend on file-local variables. Mentored by: Christian Couder Mentored by: Johannes Schindelin Signed-off-by: Tanushree Tumane Signed-off-by: Miriam Rubio --- run-command.c | 2 +- run-command.h | 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 Sat Feb 8 09:06:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11371519 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 AA3C118C6 for ; Sat, 8 Feb 2020 09:08:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 89059217BA for ; Sat, 8 Feb 2020 09:08:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Y7i8U+1t" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727466AbgBHJIe (ORCPT ); Sat, 8 Feb 2020 04:08:34 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:54768 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727446AbgBHJIc (ORCPT ); Sat, 8 Feb 2020 04:08:32 -0500 Received: by mail-wm1-f68.google.com with SMTP id g1so4824845wmh.4 for ; Sat, 08 Feb 2020 01:08: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=7cidQ2/1P7oKcKMitQp8G7KJy2dGBePySTf6krnU+sU=; b=Y7i8U+1tj2OMRWDUAg2sL+IapXnnuj3kXd3BVkM/gDmFXG4zISVXPUG45tNTwu3pcW FlU0kHg7XbSjn3HAUzXdr8VQtjmSR4Rq+v+0U0EYcOuDqND20se8K5EzFZyi9vgyHnYz k8fyYSgGU1N9j0mK2HeT9A8gXrSkUIfUgs3LjZAwXjhksHop/1Ww3DZiAJeChPh9zlTq lADFmMZiSmc58cRG5kF8cAhfCmABBNrx3fiDQF3nvis+tZPTfN7Z96TJOu0OrVvbWTpC nFy0Qtt7b3P77BNRK/2+h4qPDackshOwjTOfwIOuFlcex9ncQMJ0b7McUGdB0bmPSXP+ d0sg== 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=CJ3Z0r5xhsCjaZZJ3ltsONkzbWqQjGIonhNfX54ai9SwVoYtCDEM5uFPg/kYSwNFGF mJsFIjOOfZHzttYqAFGhkjoSGMl8ukjeB+KEUpMnO9zsK2iLusm5KcDm67m8hAvWHYVQ M52xmBMzVYIR14rtW8//+KgSSrxH50GWBuujOg78IaG0i73xxRMxzvZQgLOkegjWvxHH CEIi0wslVRPXtOR/ANhlniOygMNqGyVO2m2uQmhoLugqxVVv7z1l2EqktHOEpCuX4lFi T7Jb3+cSLGm+9WfPeh/xjhSvYurRsNy4vxVoBMaF71wZ1rrqlWGXSBYdCkJfzzG0lNjj f63A== X-Gm-Message-State: APjAAAUTWeqDojQQiJIi5LVsV2HGisO3um8toi/LmML4UloCCMEn58zu Xx+pwYRsF8vKFPc1BVEMGsAdwscF X-Google-Smtp-Source: APXvYqxplu5gOsMPSwQf4ogr68ka7FSJ72zVA/nsaWv5AN9tZ+ydHA+fwwcUZsjy5yuPv/E0lsbcuQ== X-Received: by 2002:a7b:ce8b:: with SMTP id q11mr3608395wmj.100.1581152909620; Sat, 08 Feb 2020 01:08:29 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id e1sm6999346wrt.84.2020.02.08.01.08.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Feb 2020 01:08:29 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Tanushree Tumane , Christian Couder , Miriam Rubio Subject: [PATCH v3 05/13] bisect--helper: introduce new `decide_next()` function Date: Sat, 8 Feb 2020 10:06:56 +0100 Message-Id: <20200208090704.26506-6-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200208090704.26506-1-mirucam@gmail.com> References: <20200208090704.26506-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 Sat Feb 8 09:06:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11371517 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 7F015921 for ; Sat, 8 Feb 2020 09:08:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5DEFD217BA for ; Sat, 8 Feb 2020 09:08:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TFscMeo7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727471AbgBHJIe (ORCPT ); Sat, 8 Feb 2020 04:08:34 -0500 Received: from mail-wr1-f52.google.com ([209.85.221.52]:38906 "EHLO mail-wr1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727379AbgBHJIc (ORCPT ); Sat, 8 Feb 2020 04:08:32 -0500 Received: by mail-wr1-f52.google.com with SMTP id y17so1616059wrh.5 for ; Sat, 08 Feb 2020 01:08: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=Yo7QEzRHNTsTu/TwkDBC91rjNACXUcRl6cHU+LuRfj4=; b=TFscMeo7w+FkKT7aeixVL/ANrJ+ByBjLUWVDMrlZp09nWq+zHHMjjRHAHUALiCExDo R7/ZsytClJlDmFXvFOQI/5vtIh26FPIIalmabSCYt+KBw+5zYqorUaikad6en5SAOagc cvegJZnnvP2OE9ZtjA5cZ9J/NrL0rOY6sRXRWSJiW9XT6/hAMaYAgmhx28vYKKfCLB9l BlcMI5liLrwr1YXHHHhgaGvd/AZ7U98KGkkG47enH8Brw+NLvgdxmwEbzRzq6OvwXTK0 l6XsL6E+t+nBzZAfIvtQPkdFZ6wJBbe+4SgGIHoG/g+PcqoUpl4Ej21FVskLH3vHhQG0 uM7Q== 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=JrfyMU+DlQdHPCYxstg8ZwoO97mg39QW2+uLFi/10XHmdQXrXcGh/HTMI0uUzFVDN4 ZqAoItqLZii8QV9xNKzSjcLu8YfwJn5MCHj21idXvXdreX44HVckqvMpwyVz7jWW8SYp VylEo8m05qmlkjUwTaJlizopEAo6ThY3sA575rQmfirQ8yN1lVKfdOc1ogudJOm7aR2m 9wGwuuqLUrettDn48z8wH6t69A9xRejndoMbJRwQByZN2csLcow5yX1aAc4xPsFy2xR3 PiOVxOGjanZXoLekicEcVGDqHAxH6xJKTvZQFKjyL71bF+jChsnBHeqv5YO43O1pxGBl GzPA== X-Gm-Message-State: APjAAAVy2OBcMuZR2hSkYpp5oCtmHXgpQcNqEsC1um6uA+C5WLKGjEzF 2WxfkpxnkatUilLZH2xOGa5GayDM X-Google-Smtp-Source: APXvYqygaZwDqCGBKwVZ0Vbshpp18IJt4i7lO9cFuWKT27Yor6sHp0DCYgIhY0lsZNS7rKjsvM7A1Q== X-Received: by 2002:a5d:448c:: with SMTP id j12mr4355452wrq.125.1581152910710; Sat, 08 Feb 2020 01:08:30 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id e1sm6999346wrt.84.2020.02.08.01.08.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Feb 2020 01:08:30 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Miriam Rubio , Christian Couder Subject: [PATCH v3 06/13] bisect: add enum to represent bisect returning codes Date: Sat, 8 Feb 2020 10:06:57 +0100 Message-Id: <20200208090704.26506-7-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200208090704.26506-1-mirucam@gmail.com> References: <20200208090704.26506-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 Sat Feb 8 09:06:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11371521 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 D4F92186E for ; Sat, 8 Feb 2020 09:08:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B406C217BA for ; Sat, 8 Feb 2020 09:08:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fr2W6O+r" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727478AbgBHJIf (ORCPT ); Sat, 8 Feb 2020 04:08:35 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:50410 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727456AbgBHJIe (ORCPT ); Sat, 8 Feb 2020 04:08:34 -0500 Received: by mail-wm1-f65.google.com with SMTP id a5so4868736wmb.0 for ; Sat, 08 Feb 2020 01:08: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=P7LEZGJjRIfYsumNABEw6099v9waAI03KQWY0SNTAtY=; b=fr2W6O+rK3tpz0lKqY5Z23vkLkPSOuiRoNTCbcyFGLS+H4rc9EPIRkPESc9WarqIHt DwFc7tcBZwPfQYTQ7xzliKAY22EBKs09NMZU2LDRMi/kaPw/aRDS9pcwYezRpepv7gMR aMdYO7GThxQsh+9b7uR24X+nLmSw8UvXEAU7hPZ1T+MCjAhL3HtcEx6UTH+JWZ7SNyBG ELZEWs7ttJPzAcl3h84+fPcVaLOmhNokh5XRWunFa6owXoPUs4PCEOTTnSsnkBefYzhX sn7FjUXmNXQ3rR3DcI3alBkNcAGReQoZNqnTJ4gGJsRRBq2nnps86uFgLEzQ8z1JRZuZ Cgxw== 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=bIIGCkplwYn8/7IOWYeEsfpgeh1IsUxYaof+O76nJ0S+DExZFbmKPIS/U+06pTz7IK d8v3GBgOTwgGgh9pmLg2ehHG7sodLFG4tsRhkrIMaKhN/eV5M0JFeL/44Pd4X7pEChG4 wJQ5EYqMVLU6g3/mIQ5X3f9vUmzPWiHGW0zZ+1uKOQH/MS5TlzPS8PUt7+o66a4CzQ77 l34q1fDfOJvUZ2beY9ITQsM2FHMl4/0VxLNheSilD8LEaQCZ9cbmQvbwsSoDRpve6tDr TY5gqta4KGRorZX+BIpWWpwthaLu9gtinIrmWPITiYRxkYB1Zjzf4ybXghiQeqvJUR69 ezZQ== X-Gm-Message-State: APjAAAX/ePXSAN5Nxqb4n7UNDx7fmWyZ/6TtLa6vv5kXOA4/cC/gs6Yj QpQmhCK6j9ukkzTWjybW7LXPDDUK X-Google-Smtp-Source: APXvYqzclBXWmG+zAypPYmkHfJ38fLxEn0Yb7Ix5osKCi5FWTwTQW8gFlzTTpU8KQvAKExhkcdulZw== X-Received: by 2002:a1c:65d6:: with SMTP id z205mr3456704wmb.38.1581152912023; Sat, 08 Feb 2020 01:08:32 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id e1sm6999346wrt.84.2020.02.08.01.08.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Feb 2020 01:08:31 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Johannes Schindelin , Tanushree Tumane , Miriam Rubio Subject: [PATCH v3 07/13] bisect--helper: return error codes from `cmd_bisect__helper()` Date: Sat, 8 Feb 2020 10:06:58 +0100 Message-Id: <20200208090704.26506-8-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200208090704.26506-1-mirucam@gmail.com> References: <20200208090704.26506-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 Sat Feb 8 09:06:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11371523 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 BBA2C1398 for ; Sat, 8 Feb 2020 09:08:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9A6CC217BA for ; Sat, 8 Feb 2020 09:08:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="r80AUdch" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727492AbgBHJIh (ORCPT ); Sat, 8 Feb 2020 04:08:37 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:40722 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727465AbgBHJIf (ORCPT ); Sat, 8 Feb 2020 04:08:35 -0500 Received: by mail-wm1-f66.google.com with SMTP id t14so5218427wmi.5 for ; Sat, 08 Feb 2020 01:08: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=auj2PpN7jw/nCeMzZ55W8zrFR3AQWT85aqwAv1NJUPg=; b=r80AUdchyUZ88QiyJZksk5Ih8AfUuTgDV8Cn+6c2+IDXwDpkCm8a6zASgTs6/Oflya wecyrKXpiJ0XyCikUL2cfd1WR7mzBAAGg27OQr9OvExKiTkYd7p68cUWBBoaeeEwcryJ VxItkuSZ2X7VdT32voGNVOxeM5f7dOuN45V7zUj5dDUzO7bMs3COZo9P4ga3h74PqeO6 E65bSt7PacWpNjNTR7G3Cv9vbzP+EtDWP5r0bxFxS4g7jJwDSHqLhSHZ+jDFGwA8QrMm QmiYXeyYAOEqgKU/o5/yDZfuAnPL8SNU0XxA+Cvgm5z50zJ1nLbu83q7sahpFcsE0IPB b1Uw== 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=ln+nHaK49LULbGEQBfLDqEbmbDfx71VxB81Sn4PGvDdgDV9lObnThaGniQq6r/nbZe cUi6DRW713It1tDoWy5GEzEAvo7f6x3l8B/LTSskSZdmUr3ti7GIzNX3W5/XRvqmUwta D31cNlfEWMNwYi5SeDjWO5UOEmFLHs5CSle5v+VBjUm6tNys1NAoVYXdv93bToPsI4Cn TSUXTRQT26zonaSD7bEQ8OqNtomGde3M+zImnEwHQTOmogk/UZarOFBNDNO8z07zTjR7 qHE/XwwcAe0GwUld4BPhd3kPKEuDBNyQzve8sgd2MFr1nr0IB1OSYZ11j0VcATeuaj51 BBrQ== X-Gm-Message-State: APjAAAWu1B0md6UM6fL9JyK8RAtoW155UpQMmH5CSZXhgsTbxs4uVBM2 CLz5HTkXOAaLEOfmPMTsront3zsb X-Google-Smtp-Source: APXvYqwT2/BwTgF3qYrz3c6aTfFBnVDBgWPWDjeUFYON68op1AN+JDuq6JlSb6h81AYcMoIdLg768Q== X-Received: by 2002:a1c:1b4d:: with SMTP id b74mr3616265wmb.33.1581152913397; Sat, 08 Feb 2020 01:08:33 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id e1sm6999346wrt.84.2020.02.08.01.08.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Feb 2020 01:08:33 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Johannes Schindelin , Tanushree Tumane , Miriam Rubio Subject: [PATCH v3 08/13] bisect: libify `exit_if_skipped_commits` to `error_if_skipped*` and its dependents Date: Sat, 8 Feb 2020 10:06:59 +0100 Message-Id: <20200208090704.26506-9-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200208090704.26506-1-mirucam@gmail.com> References: <20200208090704.26506-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 Sat Feb 8 09:07:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11371525 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 EF5FE921 for ; Sat, 8 Feb 2020 09:08:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CF48D22464 for ; Sat, 8 Feb 2020 09:08:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WuliMiju" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727505AbgBHJIk (ORCPT ); Sat, 8 Feb 2020 04:08:40 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:54771 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727456AbgBHJIi (ORCPT ); Sat, 8 Feb 2020 04:08:38 -0500 Received: by mail-wm1-f67.google.com with SMTP id g1so4824970wmh.4 for ; Sat, 08 Feb 2020 01:08:35 -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=WuliMijugBPWLQzMe+JAsPUFRepjTN10gfN+clj9oggF/v+9AtQCuM+GDzBuErg+lZ entXEAw4dN1cHlYN0usWCtv45mMPzCWi7sjJApVH0C96YwlX1U2SfZCz1u+KHD2Gwr8O U2dg03zlJXBE8C64+0m+ot/g0tCq8RqGYtrc1QX4GwFM9Ajtm7qHaBu2xqM+iKUVaqie gmcmKhEbwXWiyTuT4gIlaWZQhbQIGDVT7EL2bX7ESiGHDYka/lGAqnoI92wZCc3Q8BOU tIdOqSgzmspkgo7Ia33UExmoFOqHuqLauj98s/4d0+suSnkFxULMndtl8+ErVokSb0ky /5jQ== 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=qUt4h1sEaWguboWYqXyC45UYwNwaNsLb3Y6dtFGIHdA3XvXcFP4alD2bPTZ1AlxvM1 QnKkyiWCe035RiR6ywwG/f22J96LV7CO+UdyOMjwBXTJYx1tD4uTYu4qCVTVdAdYTNno wObK/rIr9P8yJBZLIZTuGkgwW5NafxUrdGhHIuGYUDNNaIQ5MrQnBpC9SWq+ATf4Fj8F 5OBTZf1CjaaboSENGqMVV9CehQ7+v5dbLqgLjVKNbg71e/hQA1fEfcd5iVrl7tG/hj6b TEDnVfke/KDXzD1AF+BqLqfiA0N9cmRxm0nVHCndSXYGau6B3GoQ4QVCxMyZe1GamKzQ 7pXA== X-Gm-Message-State: APjAAAV9Yq0sgSt/c0CsH9LAl/Ss8pvjSlQ4qTE8wQptnOQ/ptya2F7U R0n7trYGWiBQLb2Rw0Y6uyMwZ0bo X-Google-Smtp-Source: APXvYqzJV2wjHBcfsDGod3Z9vPjULIoFvB/gpJlxvTxHxcE27EPn9cjFEeoidOdOHYcFK6Ae0Ohxgw== X-Received: by 2002:a1c:8151:: with SMTP id c78mr1681184wmd.29.1581152914682; Sat, 08 Feb 2020 01:08:34 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id e1sm6999346wrt.84.2020.02.08.01.08.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Feb 2020 01:08:34 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Johannes Schindelin , Tanushree Tumane , Miriam Rubio Subject: [PATCH v3 09/13] bisect: libify `bisect_checkout` Date: Sat, 8 Feb 2020 10:07:00 +0100 Message-Id: <20200208090704.26506-10-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200208090704.26506-1-mirucam@gmail.com> References: <20200208090704.26506-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 Sat Feb 8 09:07:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11371527 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 7C0841398 for ; Sat, 8 Feb 2020 09:08:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5B63022464 for ; Sat, 8 Feb 2020 09:08:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iv6Qr3nc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727508AbgBHJIk (ORCPT ); Sat, 8 Feb 2020 04:08:40 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:55699 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727490AbgBHJIi (ORCPT ); Sat, 8 Feb 2020 04:08:38 -0500 Received: by mail-wm1-f68.google.com with SMTP id q9so4812072wmj.5 for ; Sat, 08 Feb 2020 01:08:36 -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=iv6Qr3ncmvoJBTUowvG8yWWWretOBzxI6FkSlZqbWhSdhGZV6alem/fkmY9ps88PBp Fi1teJ43PLaji8xIa6v1B1YNWsv2dOM3OGiL/RPEtVQ3QFkwP7Xhaxl5hFdgpOsFGCPa 8ZArDyhhtlcdF77LHYVCy/yDyjZUXBKWS6N0QSAJrjX9GBcbGW05ndit5mlWVVtOjqpV Jc1+BcjpCK8Yg3Wa/lyjeBAdfSoiE+7AB/7SuAmUC+z9GZFyzvQ18nmZmzQ3d/Yp0e6r +18UfMPC4/14K6K21Zll3dmJUzdkk4219U8PAbfOWcqKs4PPuxe2HlZLLP4Td5RAF/iG NmJg== 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=dKc3CC1sQJOE3eakhoioqM5poDSYdXGuuliJfbPoqikCQpH5dSZNX03AQozoN4UESL odmYVD/txp6Y9KnClYKSd7THPvnu1La8x8gPCqXSvuWrgr/R9oLvoWbwqFb+OWbJbecd /Ffz821Qaah9vKCPkk/1RZbEeDe1+Ku7xn0dQvkK6KmWKFAaU4UbevBAy1X3PBye7DoM ii8JGtkUvJEZXYo386ohlulvaBZEsJ/mh/UquUi/fGOy7srCdzQBeHOZuEnwgzE4LH30 sTxWkjCSZYp7aspPVhSAYFKKmHhA3I1TW4mShosImJclX6/goXxsW51RAkHEscdAuKoQ FVJQ== X-Gm-Message-State: APjAAAUgq4/XBcWmrROvejUIYRoivXYz6FQ+Fg4Oonw1NhBPf6Mnubwq pkEGjow5idJHh/vd4o1J0ZO78ZUC X-Google-Smtp-Source: APXvYqwsBbUf1T3nnEkEdQe3pAIQXVdMdQC9ziI9frkMk6/SmNDBBzw4+tvttrGm4eXbezr51aFPZQ== X-Received: by 2002:a1c:6588:: with SMTP id z130mr3535571wmb.0.1581152915984; Sat, 08 Feb 2020 01:08:35 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id e1sm6999346wrt.84.2020.02.08.01.08.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Feb 2020 01:08:35 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Tanushree Tumane , Miriam Rubio Subject: [PATCH v3 10/13] bisect: libify `check_merge_bases` and its dependents Date: Sat, 8 Feb 2020 10:07:01 +0100 Message-Id: <20200208090704.26506-11-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200208090704.26506-1-mirucam@gmail.com> References: <20200208090704.26506-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 Sat Feb 8 09:07:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11371531 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 B729A921 for ; Sat, 8 Feb 2020 09:08:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 96C0522464 for ; Sat, 8 Feb 2020 09:08:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jpRyJVQT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727518AbgBHJIm (ORCPT ); Sat, 8 Feb 2020 04:08:42 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:50416 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727465AbgBHJIk (ORCPT ); Sat, 8 Feb 2020 04:08:40 -0500 Received: by mail-wm1-f66.google.com with SMTP id a5so4868856wmb.0 for ; Sat, 08 Feb 2020 01:08:38 -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=jpRyJVQTEQBBJdVklZavtE5Gj5NMnAedujtPITMSahb90DvbYMHsDrBzSOiSVuY7QE FoILbsl+DAU6ix0UMb3K/d8wQAccG+BPuj4+foOYeb7tRqh90nmIR/4HL1PemPMZXkqM vEoA8DDkEC/QPhp6RaBSlf9NdRaq16FvC/KOhWQgdlGNjg8nBoNcYHqf8svrTkhPzur8 rJw//oSAsN0RbWIYdew2GHtvAr1m2FKAsTwrKEOv4Sm3BiuPGF2zf9DSnXBrweYKWsyb kn7A4psjYOBoEllf1ok0NxXbAyuM7TJ2G4VisVcvakMyZwpOdzw+WHS/nfNciwNWVTH7 KTPA== 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=gZXqoGGDmJzpLPT9NsfuFbhGj2EetLCf03AE0C1Un02tUAczFIvIeAz0gdhFU0NoAf 5125M/Bfncoc8ZonRdkTOghwduEtQm+gzoJGHrH11xSwniY6BybXi80hxT7NYX4ZA0EE qdqp4XOlMg8FqISiMf6D7HBUL8N9dwCCQccg/37AmFqfdyKG2QSUZ4Uu+zsic7CgYE9L eTnSB5wmHPuf2euuUQNK+k3uys/dbSmm8qgPi4yK5CGelAbNQ1fDNe06Sfpty8IgqUmX Ug623Z8h0fd3RuC9w7SDaQje837zLtiAQER0eBR7150RjYge5RurDkF1yIQgDdaiTL9e gSgg== X-Gm-Message-State: APjAAAVn5auozscpL9/K6Dwoqa/gzB62S8Q5QxwkZe3l5oI42LGRwEDs hc1lubbsyhth05i+ewO2i0UJwNgO X-Google-Smtp-Source: APXvYqxoEkSGimW8qFjZHSa2FaCxS6qTnmDOFZvQTuzKeteYjeX6xlucI9l2yr+ebAurDC6fh+txkA== X-Received: by 2002:a7b:cc82:: with SMTP id p2mr3408344wma.159.1581152917161; Sat, 08 Feb 2020 01:08:37 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id e1sm6999346wrt.84.2020.02.08.01.08.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Feb 2020 01:08:36 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Tanushree Tumane , Miriam Rubio Subject: [PATCH v3 11/13] bisect: libify `check_good_are_ancestors_of_bad` and its dependents Date: Sat, 8 Feb 2020 10:07:02 +0100 Message-Id: <20200208090704.26506-12-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200208090704.26506-1-mirucam@gmail.com> References: <20200208090704.26506-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 Sat Feb 8 09:07:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11371529 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 BF1C5921 for ; Sat, 8 Feb 2020 09:08:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9DBF6217BA for ; Sat, 8 Feb 2020 09:08:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gaqGCqtQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727516AbgBHJIm (ORCPT ); Sat, 8 Feb 2020 04:08:42 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:34207 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727499AbgBHJIk (ORCPT ); Sat, 8 Feb 2020 04:08:40 -0500 Received: by mail-wm1-f68.google.com with SMTP id s144so4715771wme.1 for ; Sat, 08 Feb 2020 01:08:39 -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=gaqGCqtQewHMKxq7JvxGf4etm1Ri+bYICtpzQToVS3H5kFNpTUdM2Dnh0dw5emhglQ +S0eJrtGBpI2Hneal+40ycTgKSLJw0V63esJErh5QCiEZcKTAYMiUQ9pa28BXkTv4swp berwtOqcIMxvN1ZB0ZcpOVPv82OKxIu4a+tLJKB4OWAVWd9q8Rd6QzZCatEIx7cbUhDK X2MEp2WO2AvE80i0R2uay3lN/DffyGeHU7SO/hutmzNWpx2x92xDw7SlXGhvj4b41akU ay0XiGzb+oYNPOQ96md8NpK6KrZ5z5LhOnh+aCkd592vF/jZMyTbMNh6m+llIDqa/L8E iJqw== 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=p//H6c4sO+767FDLxBtRrpq76JkwYqTN/oUd6FZBCpMSZ/oKa9ugR1frZBMz2u7jff /AqLu9uy8mhw0F/prFY3bzLj8w1OGXtYU1xwfpxuQZvTIck056b/z10sJVZiBqCsDCx5 BCLtum8BPu+E3sBCfZkHC00WnJOrG10bRU009PXjAivrFnLyiJu6WXhyknyTn+qhhGDs HgIHZo20+JmKtvWB9m3t06bQKqYlY9uvFJMi/SKGwn9J/PlVmQM5j66ryllPgpVswEb9 pOmB7YvBULG6dJrLRW4nggqKn8tBgjx7wjTUHNaN1B8DSQX3dguje9yzdl0+XUGGzAa5 3kcw== X-Gm-Message-State: APjAAAVeydmlVaze4yE+50ryLu8kBQzHYA0Iy7WpSTCkmFxgy6qorLuM b7Qw1kwXNy5+R6Q0REc1cDAK4LKN X-Google-Smtp-Source: APXvYqyrkjdlewSXoYPJEzWH7JeGVePsFiHr2iBzroHFor50gDWp385vNFIFC6L/ug16hpXxeFhucw== X-Received: by 2002:a05:600c:2109:: with SMTP id u9mr3608906wml.183.1581152918433; Sat, 08 Feb 2020 01:08:38 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id e1sm6999346wrt.84.2020.02.08.01.08.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Feb 2020 01:08:38 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Johannes Schindelin , Tanushree Tumane , Miriam Rubio Subject: [PATCH v3 12/13] bisect: libify `handle_bad_merge_base` and its dependents Date: Sat, 8 Feb 2020 10:07:03 +0100 Message-Id: <20200208090704.26506-13-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200208090704.26506-1-mirucam@gmail.com> References: <20200208090704.26506-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 Sat Feb 8 09:07:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Miriam R." X-Patchwork-Id: 11371533 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 E58EF1398 for ; Sat, 8 Feb 2020 09:08:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C3CF422314 for ; Sat, 8 Feb 2020 09:08:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WDnvSGzZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727522AbgBHJIp (ORCPT ); Sat, 8 Feb 2020 04:08:45 -0500 Received: from mail-wm1-f46.google.com ([209.85.128.46]:51152 "EHLO mail-wm1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727509AbgBHJIm (ORCPT ); Sat, 8 Feb 2020 04:08:42 -0500 Received: by mail-wm1-f46.google.com with SMTP id a5so4868914wmb.0 for ; Sat, 08 Feb 2020 01:08:40 -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=WDnvSGzZWVqw3D62d/AY94/5JSPIUbL8FNaW/GpixUCIn0dC/MkXonP5ao2SFCylhs Up5cW4CFJ1PbZ1whaLkIlFYbBL3rSLmo9TX+G8oVF4wYNB1w6fJCNU7vWPlqFeGz5FOh zZtrr3QiaKgew3V0WCtrVdAC5kX3+d1FDHUs0j4mhYeiTCEcmSbTVYzlI8d4H2AjD8Cv VRIUakpaFQaRUzMc1UcMw2rHDocKcf6MR92qRG46fqobfkmUXp50/7EwVhSuT2mzqY1C 3Y5Nwx1ViqVAFYIyICBH5mQ2gnt0NES/vsySwnQGNPPJ2OLCT/L6xAE7XuNE30IBH1ee E/nA== 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=BKuqla422R3MLzuFVB3naQqPQrRmuYQc2KI9E9A4KKA3LgBPbxxjIZuYLFxSchFIq3 pkXn/CFQHoljVvkUh0uHd0cSXLlvfoEaYDsyWllpF+pVSVQ9HxdDMMOfogn+scZPw+S1 6fL0vTJEf7mi1xr7Z901hNHJvwfyS1zz53ASUi3zDojhDpId5m03HbGoAaHh+nuxPiiF isNhSyVRfdk23eoIEx8HbsEldKhV7nkmTVRWfFiJHWa7MY+Z3RmOAfr3b2beouGT7+CD p5c5aDq8G0Dxq7M4bsvimDoHbVJPPuOKxuN94J8jyWCIPTFQlVkaConmfJ69jGKsx3zR Y8ew== X-Gm-Message-State: APjAAAUXtTmIH+oUqBfe1HNZBfO8clAUeZCVNbCfKkkvNO6a8J/o2sLf Dc3cLqzI98ln88IZbE2uo0a/ln/1 X-Google-Smtp-Source: APXvYqwQJin/YGYucAk7zxc8snp5ZAEII5I6g2rjU8pFl+wy5Z4WsEtq7Rx5KPFMZ6DefS2WHkJEQg== X-Received: by 2002:a7b:c85a:: with SMTP id c26mr3526748wml.107.1581152919714; Sat, 08 Feb 2020 01:08:39 -0800 (PST) Received: from localhost.localdomain ([139.47.115.4]) by smtp.gmail.com with ESMTPSA id e1sm6999346wrt.84.2020.02.08.01.08.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Feb 2020 01:08:39 -0800 (PST) From: Miriam Rubio To: git@vger.kernel.org Cc: Pranit Bauva , Christian Couder , Johannes Schindelin , Tanushree Tumane , Miriam Rubio Subject: [PATCH v3 13/13] bisect: libify `bisect_next_all` Date: Sat, 8 Feb 2020 10:07:04 +0100 Message-Id: <20200208090704.26506-14-mirucam@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200208090704.26506-1-mirucam@gmail.com> References: <20200208090704.26506-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 };