Commit 9b5d6cea4aba38a58233a93fde2d0ffd6945f171

Carlos Martín Nieto 2014-10-08T17:14:48

revwalk: catch no-push and no-hide cases If there have been no pushes, we can immediately return ITEROVER. If there have been no hides, we must not run the uninteresting pre-mark phase, as we do not want to hide anything and this would simply cause us to spend time loading objects.

diff --git a/src/revwalk.c b/src/revwalk.c
index a1d761f..1bf9fbe 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -142,6 +142,11 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting,
 	if (commit == NULL)
 		return -1; /* error already reported by failed lookup */
 
+	if (uninteresting)
+		walk->did_hide = 1;
+	else
+		walk->did_push = 1;
+
 	commit->uninteresting = uninteresting;
 	list = walk->user_input;
 	if (git_commit_list_insert(commit, &list) == NULL) {
@@ -441,26 +446,24 @@ cleanup:
 
 static int prepare_walk(git_revwalk *walk)
 {
-	int error, interesting = 0;
+	int error;
 	git_commit_list *list;
 	git_commit_list_node *next;
 
-	if ((error = premark_uninteresting(walk)) < 0)
+	/* If there were no pushes, we know that the walk is already over */
+	if (!walk->did_push) {
+		giterr_clear();
+		return GIT_ITEROVER;
+	}
+
+	if (walk->did_hide && (error = premark_uninteresting(walk)) < 0)
 		return error;
 
 	for (list = walk->user_input; list; list = list->next) {
-		interesting += !list->item->uninteresting;
 		if (process_commit(walk, list->item, list->item->uninteresting) < 0)
 			return -1;
 	}
 
-	/*
-	 * If there were no pushes, we know that the walk is already over.
-	 */
-	if (!interesting) {
-		giterr_clear();
-		return GIT_ITEROVER;
-	}
 
 	if (walk->sorting & GIT_SORT_TOPOLOGICAL) {
 		unsigned short i;
@@ -619,6 +622,7 @@ void git_revwalk_reset(git_revwalk *walk)
 	git_commit_list_free(&walk->iterator_reverse);
 	git_commit_list_free(&walk->user_input);
 	walk->walking = 0;
+	walk->did_push = walk->did_hide = 0;
 }
 
 int git_revwalk_add_hide_cb(
diff --git a/src/revwalk.h b/src/revwalk.h
index 05a7a42..72ddedc 100644
--- a/src/revwalk.h
+++ b/src/revwalk.h
@@ -32,7 +32,9 @@ struct git_revwalk {
 	int (*enqueue)(git_revwalk *, git_commit_list_node *);
 
 	unsigned walking:1,
-		first_parent: 1;
+		first_parent: 1,
+		did_hide: 1,
+		did_push: 1;
 	unsigned int sorting;
 
 	/* the pushes and hides */