* [PATCH 2/4] Move finding bisection into do_find_bisection.
[not found] <20070731143602.a5ed0a04.chriscool@tuxfamily.org>
@ 2007-07-31 12:48 ` Christian Couder
2007-07-31 12:48 ` [PATCH 3/4] Move some bisection code into best_bisection Christian Couder
2007-07-31 12:48 ` [PATCH 4/4] Bisection "distance" clean up Christian Couder
2 siblings, 0 replies; 3+ messages in thread
From: Christian Couder @ 2007-07-31 12:48 UTC (permalink / raw)
To: Junio Hamano; +Cc: git
This factorises some code and make a big function smaller.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
builtin-rev-list.c | 40 +++++++++++++++++++++++++---------------
1 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index 5bcafe4..4e2524a 100644
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
@@ -255,6 +255,9 @@ static void show_list(const char *debug, int counted, int nr,
}
#endif /* DEBUG_BISECT */
+static struct commit_list *do_find_bisection(struct commit_list *list,
+ int nr, int *weights);
+
/*
* zero or positive weight is the number of interesting commits it can
* reach, including itself. Especially, weight = 0 means it does not
@@ -272,7 +275,7 @@ static void show_list(const char *debug, int counted, int nr,
static struct commit_list *find_bisection(struct commit_list *list,
int *reaches, int *all)
{
- int n, nr, on_list, counted, distance;
+ int nr, on_list;
struct commit_list *p, *best, *next, *last;
int *weights;
@@ -301,6 +304,25 @@ static struct commit_list *find_bisection(struct commit_list *list,
*all = nr;
weights = xcalloc(on_list, sizeof(int));
+
+ /* Do the real work of finding bisection commit. */
+ best = do_find_bisection(list, nr, weights);
+
+ if (best)
+ best->next = NULL;
+
+ *reaches = weight(best);
+ free(weights);
+
+ return best;
+}
+
+static struct commit_list *do_find_bisection(struct commit_list *list,
+ int nr, int *weights)
+{
+ int n, counted, distance;
+ struct commit_list *p, *best;
+
counted = 0;
for (n = 0, p = list; p; p = p->next) {
@@ -357,12 +379,8 @@ static struct commit_list *find_bisection(struct commit_list *list,
weight_set(p, distance);
/* Does it happen to be at exactly half-way? */
- if (halfway(p, distance, nr)) {
- p->next = NULL;
- *reaches = distance;
- free(weights);
+ if (halfway(p, distance, nr))
return p;
- }
counted++;
}
@@ -400,12 +418,8 @@ static struct commit_list *find_bisection(struct commit_list *list,
/* Does it happen to be at exactly half-way? */
distance = weight(p);
- if (halfway(p, distance, nr)) {
- p->next = NULL;
- *reaches = distance;
- free(weights);
+ if (halfway(p, distance, nr))
return p;
- }
}
}
@@ -425,12 +439,8 @@ static struct commit_list *find_bisection(struct commit_list *list,
if (distance > counted) {
best = p;
counted = distance;
- *reaches = weight(p);
}
}
- if (best)
- best->next = NULL;
- free(weights);
return best;
}
--
1.5.2.1.144.gabc40
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 3/4] Move some bisection code into best_bisection.
[not found] <20070731143602.a5ed0a04.chriscool@tuxfamily.org>
2007-07-31 12:48 ` [PATCH 2/4] Move finding bisection into do_find_bisection Christian Couder
@ 2007-07-31 12:48 ` Christian Couder
2007-07-31 12:48 ` [PATCH 4/4] Bisection "distance" clean up Christian Couder
2 siblings, 0 replies; 3+ messages in thread
From: Christian Couder @ 2007-07-31 12:48 UTC (permalink / raw)
To: Junio Hamano; +Cc: git
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
builtin-rev-list.c | 19 +++++++++++++++----
1 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index 4e2524a..e5e8011 100644
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
@@ -258,6 +258,8 @@ static void show_list(const char *debug, int counted, int nr,
static struct commit_list *do_find_bisection(struct commit_list *list,
int nr, int *weights);
+static struct commit_list *best_bisection(struct commit_list *list, int nr);
+
/*
* zero or positive weight is the number of interesting commits it can
* reach, including itself. Especially, weight = 0 means it does not
@@ -321,7 +323,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
int nr, int *weights)
{
int n, counted, distance;
- struct commit_list *p, *best;
+ struct commit_list *p;
counted = 0;
@@ -426,9 +428,17 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
show_list("bisection 2 counted all", counted, nr, list);
/* Then find the best one */
- counted = -1;
+ return best_bisection(list, nr);
+}
+
+static struct commit_list *best_bisection(struct commit_list *list, int nr)
+{
+ struct commit_list *p, *best;
+ int best_distance = -1;
+
best = list;
for (p = list; p; p = p->next) {
+ int distance;
unsigned flags = p->item->object.flags;
if (revs.prune_fn && !(flags & TREECHANGE))
@@ -436,11 +446,12 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
distance = weight(p);
if (nr - distance < distance)
distance = nr - distance;
- if (distance > counted) {
+ if (distance > best_distance) {
best = p;
- counted = distance;
+ best_distance = distance;
}
}
+
return best;
}
--
1.5.2.1.144.gabc40
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 4/4] Bisection "distance" clean up.
[not found] <20070731143602.a5ed0a04.chriscool@tuxfamily.org>
2007-07-31 12:48 ` [PATCH 2/4] Move finding bisection into do_find_bisection Christian Couder
2007-07-31 12:48 ` [PATCH 3/4] Move some bisection code into best_bisection Christian Couder
@ 2007-07-31 12:48 ` Christian Couder
2 siblings, 0 replies; 3+ messages in thread
From: Christian Couder @ 2007-07-31 12:48 UTC (permalink / raw)
To: Junio Hamano; +Cc: git
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
builtin-rev-list.c | 18 +++++++-----------
1 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index e5e8011..38d7069 100644
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
@@ -189,7 +189,7 @@ static int count_interesting_parents(struct commit *commit)
return count;
}
-static inline int halfway(struct commit_list *p, int distance, int nr)
+static inline int halfway(struct commit_list *p, int nr)
{
/*
* Don't short-cut something we are not going to return!
@@ -202,8 +202,7 @@ static inline int halfway(struct commit_list *p, int distance, int nr)
* 2 and 3 are halfway of 5.
* 3 is halfway of 6 but 2 and 4 are not.
*/
- distance *= 2;
- switch (distance - nr) {
+ switch (2 * weight(p) - nr) {
case -1: case 0: case 1:
return 1;
default:
@@ -322,7 +321,7 @@ static struct commit_list *find_bisection(struct commit_list *list,
static struct commit_list *do_find_bisection(struct commit_list *list,
int nr, int *weights)
{
- int n, counted, distance;
+ int n, counted;
struct commit_list *p;
counted = 0;
@@ -373,15 +372,13 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
for (p = list; p; p = p->next) {
if (p->item->object.flags & UNINTERESTING)
continue;
- n = weight(p);
- if (n != -2)
+ if (weight(p) != -2)
continue;
- distance = count_distance(p);
+ weight_set(p, count_distance(p));
clear_distance(list);
- weight_set(p, distance);
/* Does it happen to be at exactly half-way? */
- if (halfway(p, distance, nr))
+ if (halfway(p, nr))
return p;
counted++;
}
@@ -419,8 +416,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
weight_set(p, weight(q));
/* Does it happen to be at exactly half-way? */
- distance = weight(p);
- if (halfway(p, distance, nr))
+ if (halfway(p, nr))
return p;
}
}
--
1.5.2.1.144.gabc40
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-07-31 12:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20070731143602.a5ed0a04.chriscool@tuxfamily.org>
2007-07-31 12:48 ` [PATCH 2/4] Move finding bisection into do_find_bisection Christian Couder
2007-07-31 12:48 ` [PATCH 3/4] Move some bisection code into best_bisection Christian Couder
2007-07-31 12:48 ` [PATCH 4/4] Bisection "distance" clean up Christian Couder
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).