threads / patch / 19642

patch, 4 partsbisect: use the skip ratio to choose a commit away from a skipped commit

Subject: [PATCH 2/4] bisect: use the skip ratio to choose a commit away from a skipped commit

## tl;dr

10 messages between Jun 2, 2009 and Jun 3, 2009. Diffs are folded; open one to read it.

replies: 9people: 3as markdown or json

Christian Couder· Jun 2, 2009, 20:16 UTC · lore

[PATCH 0/4] make it possible to skip away from broken commits

This patch series adds a "--ratio=x/y" option to "git bisect skip" so that it is possible to skip away from an area were the commits cannot be tested.

Note that in this series "--ratio=4" means the same as "--ratio=1/4". But I am not sure if this shortcut is worth it.

After this series I plan to implement a similar "--skip-ratio" option that can be passed to "git bisect start" and to add some documentation.

  bisect: add parameters to "filter_skipped"
  bisect: use the skip ratio to choose a commit away from a skipped
    commit
  bisect: add "--ratio=<ratio>" option to "git bisect skip"
  t6030: add test case for "git bisect skip --ratio=x/y"
 bisect.c                    |   74 ++++++++++++++++++++++++++++++++++++++++--
 bisect.h                    |    4 ++-
 builtin-rev-list.c          |    4 ++-
 git-bisect.sh               |   37 ++++++++++++++-------
 t/t6030-bisect-porcelain.sh |   12 +++++++
 5 files changed, 112 insertions(+), 19 deletions(-)
Christian Couder· Jun 2, 2009, 20:16 UTC · re: Christian Couder · lore

[PATCH 1/4] bisect: add parameters to "filter_skipped"

because we will need to get more information from this function in some later patches.

The new "int *count" parameter gives the number of commits left after the skipped commit have been filtered out.

The new "int *skipped_first" parameter tells us if the first commit in the list has been skipped. Note that using this parameter also changes the behavior of the function if the first commit is indeed skipped. Because we assume that in this case we will want all the filtered commits, not just the first one, even if "show_all" is not set.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 bisect.c           |   26 ++++++++++++++++++++++----
 bisect.h           |    4 +++-
 builtin-rev-list.c |    4 +++-
 3 files changed, 28 insertions(+), 6 deletions(-)
Show changes to 3 files +28 −6

bisect.c, bisect.h, builtin-rev-list.c

diff --git a/bisect.c b/bisect.c
index 2a273f3..5e5a248 100644
--- a/bisect.c
+++ b/bisect.c
@@ -523,12 +523,19 @@ static char *join_sha1_array_hex(struct sha1_array *array, char delim)
 
 struct commit_list *filter_skipped(struct commit_list *list,
 				   struct commit_list **tried,
-				   int show_all)
+				   int show_all,
+				   int *count,
+				   int *skipped_first)
 {
 	struct commit_list *filtered = NULL, **f = &filtered;
 
 	*tried = NULL;
 
+	if (skipped_first)
+		*skipped_first = 0;
+	if (count)
+		*count = 0;
+
 	if (!skipped_revs.sha1_nr)
 		return list;
 
@@ -537,19 +544,30 @@ struct commit_list *filter_skipped(struct commit_list *list,
 		list->next = NULL;
 		if (0 <= lookup_sha1_array(&skipped_revs,
 					   list->item->object.sha1)) {
+			if (skipped_first && !*skipped_first)
+				*skipped_first = 1;
 			/* Move current to tried list */
 			*tried = list;
 			tried = &list->next;
 		} else {
-			if (!show_all)
-				return list;
+			if (!show_all) {
+				if (!skipped_first || !*skipped_first)
+					return list;
+			} else if (skipped_first && !*skipped_first) {
+				*skipped_first = -1;
+			}
 			/* Move current to filtered list */
 			*f = list;
 			f = &list->next;
+			if (count)
+				(*count)++;
 		}
 		list = next;
 	}
 
+	if (skipped_first && *skipped_first == -1)
+		*skipped_first = 0;
+
 	return filtered;
 }
 
@@ -909,7 +927,7 @@ int bisect_next_all(const char *prefix, const char *skip_ratio)
 
 	revs.commits = find_bisection(revs.commits, &reaches, &all,
 				       !!skipped_revs.sha1_nr);
-	revs.commits = filter_skipped(revs.commits, &tried, 0);
+	revs.commits = filter_skipped(revs.commits, &tried, 0, NULL, NULL);
 
 	if (!revs.commits) {
 		/*
diff --git a/bisect.h b/bisect.h
index 6808389..6ac0ff5 100644
--- a/bisect.h
+++ b/bisect.h
@@ -7,7 +7,9 @@ extern struct commit_list *find_bisection(struct commit_list *list,
 
 extern struct commit_list *filter_skipped(struct commit_list *list,
 					  struct commit_list **tried,
-					  int show_all);
+					  int show_all,
+					  int *count,
+					  int *skipped_first);
 
 extern void print_commit_list(struct commit_list *list,
 			      const char *format_cur,
diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index 73bff84..69753dc 100644
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
@@ -262,7 +262,9 @@ int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
 	if (!revs->commits && !(flags & BISECT_SHOW_TRIED))
 		return 1;
 
-	revs->commits = filter_skipped(revs->commits, &tried, flags & BISECT_SHOW_ALL);
+	revs->commits = filter_skipped(revs->commits, &tried,
+				       flags & BISECT_SHOW_ALL,
+				       NULL, NULL);
 
 	/*
 	 * revs->commits can reach "reaches" commits among
-- 
1.6.3.GIT
Christian Couder· Jun 2, 2009, 20:16 UTC · re: Christian Couder · lore

To do that a new function "apply_skip_ratio" is added and another function "managed_skipped" is created to wrap both "filter_skipped" and the previous one.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 bisect.c |   50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 49 insertions(+), 1 deletions(-)
Show changes to bisect.c +49 −1
diff --git a/bisect.c b/bisect.c
index 5e5a248..0a50cba 100644
--- a/bisect.c
+++ b/bisect.c
@@ -571,6 +571,53 @@ struct commit_list *filter_skipped(struct commit_list *list,
 	return filtered;
 }
 
+static struct commit_list *apply_skip_ratio(struct commit_list *list,
+					    int count,
+					    int skip_num, int skip_denum)
+{
+	int index, i;
+	struct commit_list *cur, *previous;
+
+	cur = list;
+	previous = NULL;
+	index = count * skip_num / skip_denum;
+
+	for (i = 0; cur; cur = cur->next, i++) {
+		if (i == index) {
+			if (hashcmp(cur->item->object.sha1, current_bad_sha1))
+				return cur;
+			if (previous)
+				return previous;
+			return list;
+		}
+		previous = cur;
+	}
+
+	return list;
+}
+
+static struct commit_list *managed_skipped(struct commit_list *list,
+					   struct commit_list **tried,
+					   int skip_num, int skip_denum)
+{
+	int count, skipped_first;
+
+	*tried = NULL;
+
+	if (!skipped_revs.sha1_nr)
+		return list;
+
+	if (!skip_num)
+		return filter_skipped(list, tried, 0, NULL, NULL);
+
+	list = filter_skipped(list, tried, 0, &count, &skipped_first);
+
+	if (!skipped_first)
+		return list;
+
+	return apply_skip_ratio(list, count, skip_num, skip_denum);
+}
+
 static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
 			     const char *bad_format, const char *good_format,
 			     int read_paths)
@@ -927,7 +974,8 @@ int bisect_next_all(const char *prefix, const char *skip_ratio)
 
 	revs.commits = find_bisection(revs.commits, &reaches, &all,
 				       !!skipped_revs.sha1_nr);
-	revs.commits = filter_skipped(revs.commits, &tried, 0, NULL, NULL);
+	revs.commits = managed_skipped(revs.commits, &tried,
+				       skip_num, skip_denum);
 
 	if (!revs.commits) {
 		/*
-- 
1.6.3.GIT
Christian Couder· Jun 2, 2009, 20:16 UTC · re: Christian Couder · lore

[PATCH 3/4] bisect: add "--ratio=<ratio>" option to "git bisect skip"

This option will be passed to "git bisect--helper" using its "--skip-ratio" option.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 git-bisect.sh |   37 ++++++++++++++++++++++++-------------
 1 files changed, 24 insertions(+), 13 deletions(-)
Show changes to git-bisect.sh +24 −13
diff --git a/git-bisect.sh b/git-bisect.sh
index 8969553..176b21d 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -9,7 +9,7 @@ git bisect bad [<rev>]
         mark <rev> a known-bad revision.
 git bisect good [<rev>...]
         mark <rev>... known-good revisions.
-git bisect skip [(<rev>|<range>)...]
+git bisect skip [--ratio=<ratio>] [(<rev>|<range>)...]
         mark <rev>... untestable revisions.
 git bisect next
         find next bisection to test and check it out.
@@ -178,18 +178,27 @@ check_expected_revs() {
 }
 
 bisect_skip() {
-        all=''
-	for arg in "$@"
+	all=''
+	unset BISECT_SKIP_RATIO
+	while [ $# -gt 0 ]
 	do
-	    case "$arg" in
-            *..*)
-                revs=$(git rev-list "$arg") || die "Bad rev input: $arg" ;;
-            *)
-                revs=$(git rev-parse --sq-quote "$arg") ;;
-	    esac
-            all="$all $revs"
-        done
-        eval bisect_state 'skip' $all
+		arg="$1"
+		case "$arg" in
+		--ratio)
+			shift; BISECT_SKIP_RATIO="$1" ;;
+		--ratio=*)
+			BISECT_SKIP_RATIO=$(expr "$arg" : '--ratio=\(.*\)') ;;
+		*..*)
+			revs=$(git rev-list "$arg") ||
+			die "Bad rev input: $arg"
+			all="$all $revs" ;;
+		*)
+			revs=$(git rev-parse --sq-quote "$arg")
+			all="$all $revs" ;;
+		esac
+		shift
+	done
+	eval bisect_state 'skip' $all
 }
 
 bisect_state() {
@@ -270,8 +279,10 @@ bisect_next() {
 	bisect_autostart
 	bisect_next_check good
 
+	skip_ratio="${BISECT_SKIP_RATIO+--skip-ratio=$BISECT_SKIP_RATIO}"
+
 	# Perform all bisection computation, display and checkout
-	git bisect--helper --next-all
+	git bisect--helper --next-all $skip_ratio
 	res=$?
 
         # Check if we should exit because bisection is finished
-- 
1.6.3.GIT
Christian Couder· Jun 2, 2009, 20:16 UTC · re: Christian Couder · lore

[PATCH 4/4] t6030: add test case for "git bisect skip --ratio=x/y"

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 t/t6030-bisect-porcelain.sh |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
Show changes to t/t6030-bisect-porcelain.sh +12 −0
diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh
index 5254b23..79956e5 100755
--- a/t/t6030-bisect-porcelain.sh
+++ b/t/t6030-bisect-porcelain.sh
@@ -555,6 +555,18 @@ test_expect_success 'restricting bisection on one dir and a file' '
 	grep "$PARA_HASH4 is first bad commit" my_bisect_log.txt
 '
 
+test_expect_success 'skipping with skip ratio' '
+	git bisect start $PARA_HASH7 $HASH1 &&
+	para4=$(git rev-parse --verify HEAD) &&
+	test "$para4" = "$PARA_HASH4" &&
+        git bisect skip --ratio=1/2 &&
+	hash7=$(git rev-parse --verify HEAD) &&
+	test "$hash7" = "$HASH7" &&
+        git bisect skip --ratio=3 &&
+	para6=$(git rev-parse --verify HEAD) &&
+	test "$para6" = "$PARA_HASH6"
+'
+
 #
 #
 test_done
-- 
1.6.3.GIT
Junio C Hamano· Jun 2, 2009, 20:53 UTC · re: Christian Couder · lore

Re: [PATCH 0/4] make it possible to skip away from broken commits

Christian Couder <chriscool@tuxfamily.org> writes:
Show 6 quoted lines
> This patch series adds a "--ratio=x/y" option to "git bisect skip" so
> that it is possible to skip away from an area were the commits cannot
> be tested.
>
> Note that in this series "--ratio=4" means the same as "--ratio=1/4".
> But I am not sure if this shortcut is worth it.

Actually my gut feeling is that a tweakable knob itself is worth it, because the user can never tell what the right value should be.

Especially without any documentation updates that explains what this ratio refers to ;-), but I suspect, unless the user is very familiar with how the revision graph bisection internally works, such an explanation would not help him find a skip ratio that is closer to the optimum than a random guess. Why not use a constant ratio (or perhaps a pair of alternating ratios) on "bisect skip" without any new options?

H. Peter Anvin· Jun 3, 2009, 03:14 UTC · re: Junio C Hamano · lore

Re: [PATCH 0/4] make it possible to skip away from broken commits

Junio C Hamano wrote:
Show 19 quoted lines
> Christian Couder <chriscool@tuxfamily.org> writes:
> 
>> This patch series adds a "--ratio=x/y" option to "git bisect skip" so
>> that it is possible to skip away from an area were the commits cannot
>> be tested.
>>
>> Note that in this series "--ratio=4" means the same as "--ratio=1/4".
>> But I am not sure if this shortcut is worth it.
> 
> Actually my gut feeling is that a tweakable knob itself is worth it,
> because the user can never tell what the right value should be.
> 
> Especially without any documentation updates that explains what this ratio
> refers to ;-), but I suspect, unless the user is very familiar with how
> the revision graph bisection internally works, such an explanation would
> not help him find a skip ratio that is closer to the optimum than a random
> guess.  Why not use a constant ratio (or perhaps a pair of alternating
> ratios) on "bisect skip" without any new options?
> 

I would agree with this assessment. It's hard enough to teach a user how to use "git bisect" as it is... and being able to have a *user* bisect a problem is worth its weight in gold.

If the algorithm I proposed earlier is too complex, here is a very simple approximation:

start:
	num = 1
	den = 2
again:
	run test (num/den)
	if (!skip)
		goto start
	num = num + 2
	if (num > den)	
		num = 1
		den = den * 2
	goto again
This creates test ratios in the following sequence:
1/2 1/4 3/4 1/8 3/8 5/8 7/8 1/16 3/16 ...
When one gets down to a small number of points this could get weird, but
as long as skip points are filtered (which looks like it's already being
 done) it should converge.

This is almost certainly suboptimal, because there are at least two possibilities as to which is better, and this isn't either:

a) one should seek points closer to the periphery, because the likelihood of a contiguous skip region goes down.

1/2 1/4 3/4 1/8 7/8 1/16 15/16 ...

b) one should seek points closer to the center in the hope of getting more information; this is better on the assumption that skip points are generally scattered:

1/2 1/4 3/4 3/8 5/8 1/8 7/8 7/16 9/16 5/16 11/16 ...

However, as before, I think there is every reason to believe something like that should be plenty good enough.

	-hpa
-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
Christian Couder· Jun 3, 2009, 06:32 UTC · re: H. Peter Anvin · lore

Re: [PATCH 0/4] make it possible to skip away from broken commits

Le Wednesday 03 June 2009, H. Peter Anvin a écrit :
Show 50 quoted lines
> Junio C Hamano wrote:
> > Christian Couder <chriscool@tuxfamily.org> writes:
> >> This patch series adds a "--ratio=x/y" option to "git bisect skip" so
> >> that it is possible to skip away from an area were the commits cannot
> >> be tested.
> >>
> >> Note that in this series "--ratio=4" means the same as "--ratio=1/4".
> >> But I am not sure if this shortcut is worth it.
> >
> > Actually my gut feeling is that a tweakable knob itself is worth it,
> > because the user can never tell what the right value should be.
> >
> > Especially without any documentation updates that explains what this
> > ratio refers to ;-), but I suspect, unless the user is very familiar
> > with how the revision graph bisection internally works, such an
> > explanation would not help him find a skip ratio that is closer to the
> > optimum than a random guess.  Why not use a constant ratio (or perhaps
> > a pair of alternating ratios) on "bisect skip" without any new options?
>
> I would agree with this assessment.  It's hard enough to teach a user
> how to use "git bisect" as it is... and being able to have a *user*
> bisect a problem is worth its weight in gold.
>
> If the algorithm I proposed earlier is too complex, here is a very
> simple approximation:
>
> start:
> 	num = 1
> 	den = 2
>
> again:
> 	run test (num/den)
> 	if (!skip)
> 		goto start
>
> 	num = num + 2
> 	if (num > den)
> 		num = 1
> 		den = den * 2
>
> 	goto again
>
>
> This creates test ratios in the following sequence:
>
> 1/2 1/4 3/4 1/8 3/8 5/8 7/8 1/16 3/16 ...
>
> When one gets down to a small number of points this could get weird, but
> as long as skip points are filtered (which looks like it's already being
>  done) it should converge.
I agree. I will have a look.

Thanks, Christian.

Junio C Hamano· Jun 3, 2009, 07:10 UTC · re: H. Peter Anvin · lore

Re: [PATCH 0/4] make it possible to skip away from broken commits

"H. Peter Anvin" <hpa@zytor.com> writes:
Show 11 quoted lines
> Junio C Hamano wrote:
>> Christian Couder <chriscool@tuxfamily.org> writes:
>> 
>>> This patch series adds a "--ratio=x/y" option to "git bisect skip" so
>>> that it is possible to skip away from an area were the commits cannot
>>> be tested.
>>>
>>> Note that in this series "--ratio=4" means the same as "--ratio=1/4".
>>> But I am not sure if this shortcut is worth it.
>> 
>> Actually my gut feeling is that a tweakable knob itself is worth it,
I meant "is not" worth it.
Show 6 quoted lines
>> because the user can never tell what the right value should be.
>> 
>> ...  Why not use a constant ratio (or perhaps a pair of alternating
>> ratios) on "bisect skip" without any new options?
>
> I would agree with this assessment....

Thanks for reading what I meant to say, even though I said quite opposite to what I meant to say ;-)

> When one gets down to a small number of points this could get weird, but
> as long as skip points are filtered (which looks like it's already being
> done) it should converge.

Yes; I think "the next point" selection after "skip" is (or at least can be handled as) a local thing. As long as the next point selection is not too close to the known-to-be-untestable commit we will have a reasonable coverage over the remainder of the history. Also I suspect that trying to be too clever will not help us very much and the end result would be affected more heavily by the distribution of untestable commits than how well these next points are chosen.

Christian Couder· Jun 3, 2009, 06:29 UTC · re: Junio C Hamano · lore

Re: [PATCH 0/4] make it possible to skip away from broken commits

Le Tuesday 02 June 2009, Junio C Hamano a écrit :
Show 10 quoted lines
> Christian Couder <chriscool@tuxfamily.org> writes:
> > This patch series adds a "--ratio=x/y" option to "git bisect skip" so
> > that it is possible to skip away from an area were the commits cannot
> > be tested.
> >
> > Note that in this series "--ratio=4" means the same as "--ratio=1/4".
> > But I am not sure if this shortcut is worth it.
>
> Actually my gut feeling is that a tweakable knob itself is worth it,
> because the user can never tell what the right value should be.

You mean a boolean configuration variable like "bisect.skip_away" or a "--skip_away" switch to "git bisect start" or both?

Show 6 quoted lines
> Especially without any documentation updates that explains what this
> ratio refers to ;-), but I suspect, unless the user is very familiar with
> how the revision graph bisection internally works, such an explanation
> would not help him find a skip ratio that is closer to the optimum than a
> random guess.  Why not use a constant ratio (or perhaps a pair of
> alternating ratios) on "bisect skip" without any new options?
Ok, I will have a look at that too.

Thanks, Christian.

← back to recent threads