git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Tanushree Tumane via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Tanushree Tumane <tanushreetumane@gmail.com>
Subject: [PATCH 03/26] bisect--helper: `decide_next()` helper function.
Date: Sun, 24 Feb 2019 02:11:17 -0800 (PST)	[thread overview]
Message-ID: <cadc46442d5c960caa58227092289fa2f44fb96f.1551003074.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.117.git.gitgitgadget@gmail.com>

From: Tanushree Tumane <tanushreetumane@gmail.com>

introduce `decide_next()` helper function from `bisect_next_check()`
for better and clear understanding.

convert `*...warning` char pointers to `...warning[]`char arrays, as
char [] only creates char array while char * creates both char array
and a pointer to that char array.

Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Tanushree Tumane <tanushreetumane@gmail.com>
---
 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 5093e55273..f441ea85ff 100644
--- a/builtin/bisect--helper.c
+++ b/builtin/bisect--helper.c
@@ -282,35 +282,23 @@ static int mark_good(const char *refname, const struct object_id *oid,
 	return 1;
 }
 
-static const char *need_bad_and_good_revision_warning =
+static const char need_bad_and_good_revision_warning[] =
 	N_("You 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 const char *need_bisect_start_warning =
+static const char need_bisect_start_warning[] =
 	N_("You need to start by \"git bisect start\".\n"
 	   "You then need to give me at least one %s and %s revision.\n"
 	   "You can use \"git bisect %s\" and \"git bisect %s\" for that.");
 
-static int bisect_next_check(const struct bisect_terms *terms,
-			     const char *current_term)
+static int decide_next(const struct bisect_terms *terms,
+		       const char *current_term, int missing_good,
+		       int missing_bad)
 {
-	int missing_good = 1, missing_bad = 1, res = 0;
-	const char *bad_ref = xstrfmt("refs/bisect/%s", terms->term_bad);
-	const char *good_glob = xstrfmt("%s-*", terms->term_good);
-
-	if (ref_exists(bad_ref))
-		missing_bad = 0;
-
-	for_each_glob_ref_in(mark_good, good_glob, "refs/bisect/",
-			     (void *) &missing_good);
-
 	if (!missing_good && !missing_bad)
-		goto finish;
-
-	if (!current_term) {
-		res = -1;
-		goto finish;
-	}
+		return 0;
+	if (!current_term)
+		return -1;
 
 	if (missing_good && !missing_bad &&
 	    !strcmp(current_term, terms->term_good)) {
@@ -321,7 +309,7 @@ static int bisect_next_check(const struct bisect_terms *terms,
 		 */
 		warning(_("bisecting only with a %s commit"), terms->term_bad);
 		if (!isatty(0))
-			goto finish;
+			return 0;
 		/*
 		 * TRANSLATORS: Make sure to include [Y] and [n] in your
 		 * translation. The program will only accept English input
@@ -329,21 +317,35 @@ static int bisect_next_check(const struct bisect_terms *terms,
 		 */
 		yesno = git_prompt(_("Are you sure [Y/n]? "), PROMPT_ECHO);
 		if (starts_with(yesno, "N") || starts_with(yesno, "n"))
-			res = -1;
-		goto finish;
-	}
-	if (!is_empty_or_missing_file(git_path_bisect_start())) {
-		res = error(_(need_bad_and_good_revision_warning),
-			       vocab_bad, vocab_good, vocab_bad, vocab_good);
-	} else {
-		res = error(_(need_bisect_start_warning),
-			       vocab_good, vocab_bad, vocab_good, vocab_bad);
+			return -1;
+		return 0;
 	}
 
-finish:
+	if (!is_empty_or_missing_file(git_path_bisect_start()))
+		return error(_(need_bad_and_good_revision_warning),
+			     vocab_bad, vocab_good, vocab_bad, vocab_good);
+	else
+		return error(_(need_bisect_start_warning),
+			     vocab_good, vocab_bad, vocab_good, vocab_bad);
+}
+
+static int bisect_next_check(const struct bisect_terms *terms,
+			     const char *current_term)
+{
+	int missing_good = 1, missing_bad = 1;
+	const char *bad_ref = xstrfmt("refs/bisect/%s", terms->term_bad);
+	const char *good_glob = xstrfmt("%s-*", terms->term_good);
+
+	if (ref_exists(bad_ref))
+		missing_bad = 0;
+
+	for_each_glob_ref_in(mark_good, good_glob, "refs/bisect/",
+			     (void *) &missing_good);
+
 	free((void *) good_glob);
 	free((void *) bad_ref);
-	return res;
+
+	return decide_next(terms, current_term, missing_good, missing_bad);
 }
 
 static int get_terms(struct bisect_terms *terms)
-- 
gitgitgadget


  parent reply	other threads:[~2019-02-24 10:11 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-24 10:11 [PATCH 00/26] Git bisect part3 Tanushree Tumane via GitGitGadget
2019-02-24 10:11 ` [PATCH 01/26] bisect--helper: refer branch.buf before strbuf_release(...) Tanushree Tumane via GitGitGadget
2019-02-24 10:11 ` [PATCH 02/26] bisect--helper: change `retval` to `res` Tanushree Tumane via GitGitGadget
2019-02-24 10:11 ` Tanushree Tumane via GitGitGadget [this message]
2019-02-24 10:11 ` [PATCH 04/26] bisect.c: libify `exit_if_skipped_commits` to `error_if_skipped...` Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 05/26] bisect.c: libify `bisect_checkout` and its dependants Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 07/26] bisect.c: libify `check_good_are_ancestors_of_bad` and its dependents Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 06/26] bisect.c: libify `check_merge_bases` " Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 08/26] bisect.c: libify `handle_bad_merge_base` and its dependants Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 09/26] bisect.c: libify `bisect_next_all` " Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 11/26] bisect--helper: Finish `bisect_start()` conversion Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 10/26] bisect--helper: `bisect_next` and `bisect_auto_next` shell function in C Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 12/26] bisect--helper: dequote arguments in `bisect-start` Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 13/26] bisect--helper: retire `--bisect-clean-state` subcommand Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 14/26] bisect--helper: retire `--next-all` subcommand Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 15/26] bisect--helper: `bisect_autostart` shell function in C Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 16/26] bisect--helper: `bisect_state` & `bisect_head` " Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 17/26] bisect--helper: retire `--check-expected-revs` subcommand Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 18/26] bisect--helper: retire `--write-terms` subcommand Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 19/26] bisect--helper: `bisect_log` shell function in C Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 20/26] bisect--helper: `bisect_replay` " Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 21/26] bisect--helper: retire `--bisect-write` subcommand Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 22/26] bisect--helper: retire `--bisect-autostart` subcommand Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 23/26] bisect--helper: retire `--bisect-auto-next` subcommand Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 24/26] bisect--helper: remove the dequote in bisect_start() Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 25/26] bisect--helper: `bisect_skip` shell function in C Pranit Bauva via GitGitGadget
2019-02-24 10:11 ` [PATCH 26/26] bisect--helper: retire `--check-and-set-terms` subcommand Pranit Bauva via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cadc46442d5c960caa58227092289fa2f44fb96f.1551003074.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=tanushreetumane@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).