Stephan Beyer <s-beyer@xxxxxxx> writes: > We introduce the concept of rising and falling distances > (in addition to a halfway distance). > This will be useful in subsequent commits. > > Signed-off-by: Stephan Beyer <s-beyer@xxxxxxx> > --- > bisect.c | 33 +++++++++++++++++++++++---------- > 1 file changed, 23 insertions(+), 10 deletions(-) > > diff --git a/bisect.c b/bisect.c > index cfd406c..f737ce7 100644 > --- a/bisect.c > +++ b/bisect.c > @@ -46,6 +46,28 @@ static inline int get_distance(struct commit *commit, int total) > return distance; > } > > +/* > + * Return -1 if the distance is falling. > + * (A falling distance means that the distance of the > + * given commit is larger than the distance of its > + * child commits.) > + * Return 0 if the distance is halfway. > + * Return 1 if the distance is rising. > + */ > +static inline int distance_direction(struct commit *commit, int total) > +{ > + int doubled_diff = 2 * node_data(commit)->weight - total; > + if (doubled_diff < -1) > + return 1; > + if (doubled_diff > 1) > + return -1; > + /* > + * 2 and 3 are halfway of 5. > + * 3 is halfway of 6 but 2 and 4 are not. > + */ > + return 0; > +} Nice. This makes it clear that to arrive at a half-way point, it is pointless to dig a commit to its parents if the direction says it will only take us further away from the half-way point. > static int count_distance(struct commit *elem) > { > int nr = 0; > @@ -92,16 +114,7 @@ static inline int halfway(struct commit *commit, int nr) > */ > if (commit->object.flags & TREESAME) > return 0; > - /* > - * 2 and 3 are halfway of 5. > - * 3 is halfway of 6 but 2 and 4 are not. > - */ > - switch (2 * node_data(commit)->weight - nr) { > - case -1: case 0: case 1: > - return 1; > - default: > - return 0; > - } > + return !distance_direction(commit, nr); > } > > #if !DEBUG_BISECT -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html