git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Couder <chriscool@tuxfamily.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH 09/10] bisect: add "check_good_are_ancestors_of_bad" function
Date: Sat, 09 May 2009 17:55:46 +0200	[thread overview]
Message-ID: <20090509155548.5387.30838.chriscool@tuxfamily.org> (raw)
In-Reply-To: <20090509154419.5324.96204.chriscool@tuxfamily.org>

This is a port of the function with the same name that is in
"git-bisect.sh". The new function is not used yet but will be in
a later patch.

We also implement an helper "check_ancestors" function that use
"start_command" and "finish_command" to launch
"git rev-list $good ^$bad".

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 bisect.c |   75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 75 insertions(+), 0 deletions(-)

diff --git a/bisect.c b/bisect.c
index b24ee78..09102da 100644
--- a/bisect.c
+++ b/bisect.c
@@ -751,6 +751,81 @@ static void check_merge_bases(void)
 }
 
 /*
+ * This function runs the command "git rev-list $_good ^$_bad"
+ * and returns 1 if it produces some output, 0 otherwise.
+ */
+static int check_ancestors(void)
+{
+	struct argv_array rev_argv = { NULL, 0, 0 };
+	struct strbuf str = STRBUF_INIT;
+	int i, result = 0;
+	struct child_process rls;
+	FILE *rls_fout;
+
+	argv_array_push(&rev_argv, xstrdup("rev-list"));
+	argv_array_push_sha1(&rev_argv, current_bad_sha1, "^%s");
+	for (i = 0; i < good_revs.sha1_nr; i++)
+		argv_array_push_sha1(&rev_argv, good_revs.sha1[i], "%s");
+	argv_array_push(&rev_argv, NULL);
+
+	memset(&rls, 0, sizeof(rls));
+	rls.argv = rev_argv.argv;
+	rls.out = -1;
+	rls.git_cmd = 1;
+	if (start_command(&rls))
+		die("Could not launch 'git rev-list' command.");
+	rls_fout = fdopen(rls.out, "r");
+	while (strbuf_getline(&str, rls_fout, '\n') != EOF) {
+		strbuf_trim(&str);
+		if (*str.buf) {
+			result = 1;
+			break;
+		}
+	}
+	fclose(rls_fout);
+	finish_command(&rls);
+
+	return result;
+}
+
+/*
+ * "check_good_are_ancestors_of_bad" checks that all "good" revs are
+ * ancestor of the "bad" rev.
+ *
+ * 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.
+ */
+static void check_good_are_ancestors_of_bad(const char *prefix)
+{
+	const char *filename = git_path("BISECT_ANCESTORS_OK");
+	struct stat st;
+	int fd;
+
+	if (!current_bad_sha1)
+		die("a bad revision is needed");
+
+	/* Check if file BISECT_ANCESTORS_OK exists. */
+	if (!stat(filename, &st) && S_ISREG(st.st_mode))
+		return;
+
+	/* Bisecting with no good rev is ok. */
+	if (good_revs.sha1_nr == 0)
+		return;
+
+	if (check_ancestors())
+		check_merge_bases();
+
+	/* Create file BISECT_ANCESTORS_OK. */
+	fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);
+	if (fd < 0)
+		warning("could not create file '%s': %s",
+			filename, strerror(errno));
+	else
+		close(fd);
+}
+
+/*
  * We use the convention that exiting with an exit code 10 means that
  * the bisection process finished successfully.
  * In this case the calling shell script should exit 0.
-- 
1.6.3.rc1.112.g17e25

  parent reply	other threads:[~2009-05-09 16:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-09 15:55 [PATCH 00/10] bisect: port git bisect merge base checking to C Christian Couder
2009-05-09 15:55 ` [PATCH 01/10] bisect: use "sha1_array" to store skipped revisions Christian Couder
2009-05-09 15:55 ` [PATCH 02/10] bisect: implement "rev_argv_push" to fill an argv with revs Christian Couder
2009-05-09 15:55 ` [PATCH 03/10] bisect: store good revisions in a "sha1_array" Christian Couder
2009-05-09 15:55 ` [PATCH 04/10] bisect: use new "struct argv_array" to prepare argv for "setup_revisions" Christian Couder
2009-05-09 15:55 ` [PATCH 05/10] bisect: remove too much function nesting Christian Couder
2009-05-09 15:55 ` [PATCH 06/10] bisect: make skipped array functions more generic Christian Couder
2009-05-09 15:55 ` [PATCH 07/10] bisect: automatically sort sha1_array if needed when looking it up Christian Couder
2009-05-09 16:28   ` Jakub Narebski
2009-05-10  4:44     ` Christian Couder
2009-05-09 15:55 ` [PATCH 08/10] bisect: implement the "check_merge_bases" function Christian Couder
2009-05-09 15:55 ` Christian Couder [this message]
2009-05-09 15:55 ` [PATCH 10/10] bisect: make "git bisect" use new "--next-all" bisect-helper function Christian Couder
2009-05-11  0:44   ` Junio C Hamano

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

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

  git send-email \
    --in-reply-to=20090509155548.5387.30838.chriscool@tuxfamily.org \
    --to=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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.
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 NNTP newsgroup(s).