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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
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 */