summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Beyer <s-beyer@gmx.net>2016-04-10 15:19:07 +0200
committerJunio C Hamano <gitster@pobox.com>2016-04-15 12:27:29 -0700
commit54f86dc64aa368851c2028bbf68715615dde0014 (patch)
tree2d75e9237d9097357db1eff219c4565d1a375a03
parent1f9e88de0da3a4d124c7d693b171c4e53a1fa513 (diff)
downloadgit-54f86dc64aa368851c2028bbf68715615dde0014.tar.gz
bisect: extract get_distance() function from code duplication
Signed-off-by: Stephan Beyer <s-beyer@gmx.net>
-rw-r--r--bisect.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/bisect.c b/bisect.c
index 2c1102f4df..cfd406ca69 100644
--- a/bisect.c
+++ b/bisect.c
@@ -38,6 +38,14 @@ static inline struct node_data *node_data(struct commit *elem)
return (struct node_data *)elem->util;
}
+static inline int get_distance(struct commit *commit, int total)
+{
+ int distance = node_data(commit)->weight;
+ if (total - distance < distance)
+ distance = total - distance;
+ return distance;
+}
+
static int count_distance(struct commit *elem)
{
int nr = 0;
@@ -148,9 +156,7 @@ static struct commit_list *best_bisection(struct commit_list *list, int nr)
if (flags & TREESAME)
continue;
- distance = node_data(p->item)->weight;
- if (nr - distance < distance)
- distance = nr - distance;
+ distance = get_distance(p->item, nr);
if (distance > best_distance) {
best = p;
best_distance = distance;
@@ -188,9 +194,7 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n
if (flags & TREESAME)
continue;
- distance = node_data(p->item)->weight;
- if (nr - distance < distance)
- distance = nr - distance;
+ distance = get_distance(p->item, nr);
array[cnt].commit = p->item;
array[cnt].distance = distance;
cnt++;