summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2016-08-31 15:04:41 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2016-08-31 15:04:41 +0200
commit872ee9d81069e116ed07e7994c4f13ad2dc05b7a (patch)
treee219c35e14bfd4207dfcca3ba876d7816ba72ce1
parentee0c8b595fb70c5e156529f0e3def1f0aa184f9e (diff)
downloadlibgit2-ethomson/revwalk_hide_old.tar.gz
revwalk: refactor the initial mark-unintersting loopethomson/revwalk_hide_old
We're now close to the way git itself does it, and most of the logic goes into mark_parents_uninteresting so we can remove our own loop from premark_uninteresting. This function then becomes so simple we should extract its loop and make it part of loop we're running over the same input in its caller.
-rw-r--r--src/revwalk.c57
1 files changed, 6 insertions, 51 deletions
diff --git a/src/revwalk.c b/src/revwalk.c
index 5bccb5c3a..6a1033009 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -457,53 +457,6 @@ static void mark_parents_uninteresting(git_commit_list_node *commit)
}
}
-static int premark_uninteresting(git_revwalk *walk)
-{
- int error = 0;
- unsigned short i;
- git_pqueue q;
- git_commit_list *list;
- git_commit_list_node *commit, *parent;
-
- if ((error = git_pqueue_init(&q, 0, 8, git_commit_list_time_cmp)) < 0)
- return error;
-
- for (list = walk->user_input; list; list = list->next) {
- if ((error = git_commit_list_parse(walk, list->item)) < 0)
- goto cleanup;
-
- if (list->item->uninteresting)
- mark_parents_uninteresting(list->item);
-
- if ((error = git_pqueue_insert(&q, list->item)) < 0)
- goto cleanup;
- }
-
- while (interesting(&q)) {
- commit = git_pqueue_pop(&q);
-
- for (i = 0; i < commit->out_degree; i++) {
- parent = commit->parents[i];
-
- if ((error = git_commit_list_parse(walk, parent)) < 0)
- goto cleanup;
-
- if (commit->uninteresting)
- parent->uninteresting = 1;
-
- if (contains(&q, parent))
- continue;
-
- if ((error = git_pqueue_insert(&q, parent)) < 0)
- goto cleanup;
- }
- }
-
-cleanup:
- git_pqueue_free(&q);
- return error;
-}
-
static int prepare_walk(git_revwalk *walk)
{
int error;
@@ -516,15 +469,17 @@ static int prepare_walk(git_revwalk *walk)
return GIT_ITEROVER;
}
- if (walk->did_hide && (error = premark_uninteresting(walk)) < 0)
- return error;
-
for (list = walk->user_input; list; list = list->next) {
+ if ((error = git_commit_list_parse(walk, list->item)) < 0)
+ return error;
+
+ if (list->item->uninteresting)
+ mark_parents_uninteresting(list->item);
+
if (process_commit(walk, list->item, list->item->uninteresting) < 0)
return -1;
}
-
if (walk->sorting & GIT_SORT_TOPOLOGICAL) {
unsigned short i;