From patchwork Sun Feb 24 10:11:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koji Nakamaru via GitGitGadget X-Patchwork-Id: 10827825 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0CEFA1399 for ; Sun, 24 Feb 2019 10:11:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED7A12B9B2 for ; Sun, 24 Feb 2019 10:11:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1DA02B9B6; Sun, 24 Feb 2019 10:11:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C58312B9B2 for ; Sun, 24 Feb 2019 10:11:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728271AbfBXKLX (ORCPT ); Sun, 24 Feb 2019 05:11:23 -0500 Received: from mail-ed1-f54.google.com ([209.85.208.54]:45415 "EHLO mail-ed1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728120AbfBXKLV (ORCPT ); Sun, 24 Feb 2019 05:11:21 -0500 Received: by mail-ed1-f54.google.com with SMTP id d9so5178032edh.12 for ; Sun, 24 Feb 2019 02:11:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=UQ4CCD8hkcBwpkfRYkUR8c1ujID7gYubmdZdKWZ/jiU=; b=Phja/wg3QgjrA3yeJHv1fTjo0qQRsj0yNMLfGtO9MezMvjUw0uYxb1g9B5XObtsybV HRZaTwHFWJdRGdtmPzZoNZG5Cy8idk4xGofzdSKw29psIqrW2r10MVnHGMLlhj4Hnr6h q9nGr12HlWcah1vtYQ5XDEM4Us/Kbwyf+zwFcL4g5s1O23NEzB06dN+s9tr0hrncFOO7 qt/LzHmMx86Z8TDxnql3KIYgRtINF15gpYP25Jgf9lnksWNuCwHwy0LGrgT1rfVJjahV lN5Cf0aQRoc0PzXa0zLFuCuHmVE1A+lMvHKa1uK5VBfG0pzsBMqNXAGmSZrw3ad9+gCe dHLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=UQ4CCD8hkcBwpkfRYkUR8c1ujID7gYubmdZdKWZ/jiU=; b=nIFYgRlbh2etZ7DnHlXc/qYGCWrKC/B3kGGJPYBGMLHuPdSrMjllxH+Hr8gCbe4Ky8 I08XZLx9dAPtJLcUNLSSd8G1iClhx7+7cNfKagHVp4r8Rx4Xhj02khKBtAVGzYcGiv5Z VpFs5hn0zWJZvd8rk6Y8p+FqGPnURAe6yrc/1VAvvd/4uC0Hv6dr1nGoeUwfF+MY46ii d7kwWhR4L3Df5JUGwpeuTVeOqLx3h5H8nP2Zi8Uu8VdDJy1CVc2r4goIVZhkoxiRSlKp Yq678NWSDyK0T5couSYZEB0pZee4JbYcTkb86u+CiXwGVnWUZEuphTNXrSNnTzidbr3s UfcA== X-Gm-Message-State: AHQUAubrNchhwOQit6DjZQaV1lG6kUXZwvW3J/KDUhm31LOsUkvLwTWN voD6CeQuwuFmLovXOi08ybD4W6fX X-Google-Smtp-Source: AHgI3IY67SzmMKayjb/G063qZPdP6FPNnrNmYG9DxqML9JWb2/xnPW1Mb50SaCZp9zqE+Lw6ZMFmYw== X-Received: by 2002:a50:b613:: with SMTP id b19mr10183991ede.214.1551003079699; Sun, 24 Feb 2019 02:11:19 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n25sm1823443edd.83.2019.02.24.02.11.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Feb 2019 02:11:19 -0800 (PST) Date: Sun, 24 Feb 2019 02:11:19 -0800 (PST) X-Google-Original-Date: Sun, 24 Feb 2019 10:10:53 GMT Message-Id: <45c00ddf64982448361c461964e4ad77a328be74.1551003074.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Pranit Bauva via GitGitGadget" Subject: [PATCH 05/26] bisect.c: libify `bisect_checkout` and its dependants Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Pranit Bauva Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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()`. Handle this return in dependant methods - `check_merge_bases()`. Mentored-by: Christian Couder Mentored-by: Johannes Schindelin Signed-off-by: Pranit Bauva Signed-off-by: Tanushree Tumane --- bisect.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bisect.c b/bisect.c index bb926f09d0..1f2f3201a3 100644 --- a/bisect.c +++ b/bisect.c @@ -710,7 +710,7 @@ static int is_expected_rev(const struct object_id *oid) static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout) { char bisect_rev_hex[GIT_MAX_HEXSZ + 1]; - + int res = 0; memcpy(bisect_rev_hex, oid_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1); update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR); @@ -719,14 +719,14 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout) update_ref(NULL, "BISECT_HEAD", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR); } else { - int res; res = run_command_v_opt(argv_checkout, RUN_GIT_CMD); if (res) - exit(res); + return res > 0 ? -res : res; } argv_show_branch[1] = bisect_rev_hex; - return run_command_v_opt(argv_show_branch, RUN_GIT_CMD); + res = run_command_v_opt(argv_show_branch, RUN_GIT_CMD); + return res > 0 ? -res : res; } static struct commit *get_commit_reference(const struct object_id *oid) @@ -822,7 +822,7 @@ 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)); + exit(-bisect_checkout(mb, no_checkout)); } }