threads / discuss / 21383

Add '--bisect' revision machinery argument

Subject: Add '--bisect' revision machinery argument

## tl;dr

5 messages between Oct 27, 2009 and Oct 31, 2009.

replies: 4people: 3as markdown or json

Linus Torvalds· Oct 27, 2009, 18:28 UTC · lore

I personally use "git bisect visualize" all the time when I bisect, but it turns out that that is not a very flexible model. Sometimes I want to do bisection based on all commits (no pathname limiting), but then visualize the current bisection tree with just a few pathnames because I _suspect_ those pathnames are involved in the problem but am not totally sure about them.

And at other times, I want to use other revision parsing logic, none of which is available with "git bisect visualize".

So this adds "--bisect" as a revision parsing argument, and as a result it just works with all the normal logging tools. So now I can just do

	gitk --bisect --simplify-by-decoration filename-here
etc.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
 builtin-rev-parse.c |   11 +++++++++++
 revision.c          |   18 +++++++++++++++++-
 2 files changed, 28 insertions(+), 1 deletions(-)
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index 45bead6..9526aaf 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -180,6 +180,12 @@ static int show_reference(const char *refname, const unsigned char *sha1, int fl
 	return 0;
 }
 
+static int anti_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
+{
+	show_rev(REVERSED, sha1, refname);
+	return 0;
+}
+
 static void show_datestring(const char *flag, const char *datestr)
 {
 	static char buffer[100];
@@ -548,6 +554,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 				for_each_ref(show_reference, NULL);
 				continue;
 			}
+			if (!strcmp(arg, "--bisect")) {
+				for_each_ref_in("refs/bisect/bad", show_reference, NULL);
+				for_each_ref_in("refs/bisect/good", anti_reference, NULL);
+				continue;
+			}
 			if (!strcmp(arg, "--branches")) {
 				for_each_branch_ref(show_reference, NULL);
 				continue;
diff --git a/revision.c b/revision.c
index 9fc4e8d..80a0528 100644
--- a/revision.c
+++ b/revision.c
@@ -994,7 +994,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 	if (!strcmp(arg, "--all") || !strcmp(arg, "--branches") ||
 	    !strcmp(arg, "--tags") || !strcmp(arg, "--remotes") ||
 	    !strcmp(arg, "--reflog") || !strcmp(arg, "--not") ||
-	    !strcmp(arg, "--no-walk") || !strcmp(arg, "--do-walk"))
+	    !strcmp(arg, "--no-walk") || !strcmp(arg, "--do-walk") ||
+	    !strcmp(arg, "--bisect"))
 	{
 		unkv[(*unkc)++] = arg;
 		return 1;
@@ -1218,6 +1219,16 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
 	ctx->argc -= n;
 }
 
+static int for_each_bad_bisect_ref(each_ref_fn fn, void *cb_data)
+{
+	return for_each_ref_in("refs/bisect/bad", fn, cb_data);
+}
+
+static int for_each_good_bisect_ref(each_ref_fn fn, void *cb_data)
+{
+	return for_each_ref_in("refs/bisect/good", fn, cb_data);
+}
+
 /*
  * Parse revision information, filling in the "rev_info" structure,
  * and removing the used arguments from the argument list.
@@ -1259,6 +1270,11 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
 				handle_refs(revs, flags, for_each_branch_ref);
 				continue;
 			}
+			if (!strcmp(arg, "--bisect")) {
+				handle_refs(revs, flags, for_each_bad_bisect_ref);
+				handle_refs(revs, flags ^ UNINTERESTING, for_each_good_bisect_ref);
+				continue;
+			}
 			if (!strcmp(arg, "--tags")) {
 				handle_refs(revs, flags, for_each_tag_ref);
 				continue;
Junio C Hamano· Oct 28, 2009, 23:07 UTC · re: Linus Torvalds · lore

Re: Add '--bisect' revision machinery argument

Linus Torvalds <torvalds@linux-foundation.org> writes:
> So this adds "--bisect" as a revision parsing argument, and as a result it 
> just works with all the normal logging tools. So now I can just do
>
> 	gitk --bisect --simplify-by-decoration filename-here

This shows a very nice direction to evolve, but your patch as-is breaks "rev-list --bisect", I think. Call to your setup_revisions() eats the command line "--bisect" option but cmd_rev_list() wants to see it to go into the "bisection" mode of traversal.

Also, the helper of "git bisect" can and probably should be taught to just ask this new behaviour from the revision machinery, instead of collecting good and bad refs itself using bisect.c::read_bisect_refs().

Here is a short-term fix that can be squashed in, in order to allow t6022 to pass again.

 builtin-rev-list.c |    2 ++
 revision.c         |    1 +
 revision.h         |    1 +
 3 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index 4ba1c12..32bf033 100644
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
@@ -319,6 +319,8 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 
 	memset(&info, 0, sizeof(info));
 	info.revs = &revs;
+	if (revs.bisect)
+		bisect_list = 1;
 
 	quiet = DIFF_OPT_TST(&revs.diffopt, QUIET);
 	for (i = 1 ; i < argc; i++) {
diff --git a/revision.c b/revision.c
index 80a0528..a36c0d9 100644
--- a/revision.c
+++ b/revision.c
@@ -1273,6 +1273,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
 			if (!strcmp(arg, "--bisect")) {
 				handle_refs(revs, flags, for_each_bad_bisect_ref);
 				handle_refs(revs, flags ^ UNINTERESTING, for_each_good_bisect_ref);
+				revs->bisect = 1;
 				continue;
 			}
 			if (!strcmp(arg, "--tags")) {
diff --git a/revision.h b/revision.h
index b6421a6..921656a 100644
--- a/revision.h
+++ b/revision.h
@@ -63,6 +63,7 @@ struct rev_info {
 			reverse:1,
 			reverse_output_stage:1,
 			cherry_pick:1,
+			bisect:1,
 			first_parent_only:1;
 
 	/* Diff flags */
Linus Torvalds· Oct 28, 2009, 23:32 UTC · re: Junio C Hamano · lore

Re: Add '--bisect' revision machinery argument

On Wed, 28 Oct 2009, Junio C Hamano wrote:
> 
> This shows a very nice direction to evolve, but your patch as-is breaks
> "rev-list --bisect", I think.

I think you're right. I tested git rev-parse, and the 'git log' machinery, but I didn't think about the fact that we already had a meaning for '--bisect' in rev-list.

> Also, the helper of "git bisect" can and probably should be taught to just
> ask this new behaviour from the revision machinery, instead of collecting
> good and bad refs itself using bisect.c::read_bisect_refs().
Yeah. And git-bisect.sh can be simplified too.
		Linus
Christian Couder· Oct 31, 2009, 20:58 UTC · re: Linus Torvalds · lore

Re: Add '--bisect' revision machinery argument

On Thursday 29 October 2009, Linus Torvalds wrote:
Show 14 quoted lines
> On Wed, 28 Oct 2009, Junio C Hamano wrote:
> > This shows a very nice direction to evolve, but your patch as-is breaks
> > "rev-list --bisect", I think.
>
> I think you're right. I tested git rev-parse, and the 'git log'
> machinery, but I didn't think about the fact that we already had a
> meaning
> for '--bisect' in rev-list.
>
> > Also, the helper of "git bisect" can and probably should be taught to
> > just ask this new behaviour from the revision machinery, instead of
> > collecting good and bad refs itself using bisect.c::read_bisect_refs().
>
> Yeah. And git-bisect.sh can be simplified too.
I will have a look at that.

Sorry for not responding earlier but I just came back today from the Linux Kongress 2009 in Dresden (http://www.linux-kongress.org/2009/).

Best regards, Christian.

← back to recent threads