[PATCH v2 21/21] bisect: get back halfway shortcut

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The documentation says that when the maximum possible distance
is found, the algorithm stops immediately. That feature is
reestablished by this commit.

Signed-off-by: Stephan Beyer <s-beyer@xxxxxxx>
---

Notes:
    I plugged a memory leak here.

 bisect.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/bisect.c b/bisect.c
index 9f51d73..e583852 100644
--- a/bisect.c
+++ b/bisect.c
@@ -364,8 +364,8 @@ static inline void commit_list_insert_unique(struct commit *item,
 
 /* do a traversal on the reversed DAG (starting from commits in queue),
  * but stop at merge commits */
-static void traversal_up_to_merges(struct commit_list *queue,
-				   struct commit_list **merges)
+static int traversal_up_to_merges(struct commit_list *queue,
+				  struct commit_list **merges)
 {
 	assert(queue);
 	while (queue) {
@@ -391,7 +391,13 @@ static void traversal_up_to_merges(struct commit_list *queue,
 		}
 
 		update_best_bisection(top);
+		if (distance_direction(top) == 0) { // halfway
+			assert(!(top->object.flags & TREESAME));
+			free_commit_list(queue);
+			return 1;
+		}
 	}
+	return 0;
 }
 
 static inline int all_parents_are_visited(struct commit *merge)
@@ -455,10 +461,12 @@ static inline void compute_merge_weights(struct commit_list *merges)
 static void bottom_up_traversal(struct commit_list *queue)
 {
 	struct commit_list *merges = NULL;
-	traversal_up_to_merges(queue, &merges);
-	while (find_new_queue_from_merges(&queue, &merges)) {
+	int halfway_found = traversal_up_to_merges(queue, &merges);
+
+	while (!halfway_found
+	    && find_new_queue_from_merges(&queue, &merges)) {
 		compute_merge_weights(queue);
-		traversal_up_to_merges(queue, &merges);
+		halfway_found &= traversal_up_to_merges(queue, &merges);
 	}
 
 	/* cleanup */
-- 
2.8.1.137.g522756c

--
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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]