Re: [PATCH v2 15/21] bisect: introduce distance_direction()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 15, 2016, 22:10 UTC
- Message-ID
- <xmqqbn5a8qw0.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <1460294354-7031-16-git-send-email-s-beyer@gmx.net>
Stephan Beyer <s-beyer@gmx.net> writes:
Show 38 quoted lines
> 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@gmx.net>
> ---
> 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.
Show 21 quoted lines
> 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