From 9b5d6cea4aba38a58233a93fde2d0ffd6945f171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 8 Oct 2014 17:14:48 +0200 Subject: [PATCH] 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. --- src/revwalk.c | 24 ++++++++++++++---------- src/revwalk.h | 4 +++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/revwalk.c b/src/revwalk.c index a1d761f1b..1bf9fbe5c 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 05a7a4223..72ddedc75 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 */