summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pqueue.c4
-rw-r--r--src/pqueue.h5
-rw-r--r--src/revwalk.c179
3 files changed, 94 insertions, 94 deletions
diff --git a/src/pqueue.c b/src/pqueue.c
index 98152cb85..6307175e3 100644
--- a/src/pqueue.c
+++ b/src/pqueue.c
@@ -50,6 +50,10 @@ void git_pqueue_free(git_pqueue *q)
q->d = NULL;
}
+void git_pqueue_clear(git_pqueue *q)
+{
+ q->size = 1;
+}
size_t git_pqueue_size(git_pqueue *q)
{
diff --git a/src/pqueue.h b/src/pqueue.h
index 6db74661d..7a1394803 100644
--- a/src/pqueue.h
+++ b/src/pqueue.h
@@ -53,6 +53,11 @@ int git_pqueue_init(git_pqueue *q, size_t n, git_pqueue_cmp cmppri);
*/
void git_pqueue_free(git_pqueue *q);
+/**
+ * clear all the elements in the queue
+ * @param q the queue
+ */
+void git_pqueue_clear(git_pqueue *q);
/**
* return the size of the queue.
diff --git a/src/revwalk.c b/src/revwalk.c
index d17b44053..a2fc092d5 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -52,7 +52,6 @@ struct git_revwalk {
git_repository *repo;
git_hashtable *commits;
- git_vector pending;
commit_list *iterator_topo;
commit_list *iterator_rand;
@@ -159,71 +158,6 @@ static commit_object **alloc_parents(commit_object *commit, size_t n_parents)
return git__malloc(n_parents * sizeof(commit_object *));
}
-int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo)
-{
- git_revwalk *walk;
-
- walk = git__malloc(sizeof(git_revwalk));
- if (walk == NULL)
- return GIT_ENOMEM;
-
- memset(walk, 0x0, sizeof(git_revwalk));
-
- walk->commits = git_hashtable_alloc(64,
- object_table_hash,
- (git_hash_keyeq_ptr)git_oid_cmp);
-
- if (walk->commits == NULL) {
- free(walk);
- return GIT_ENOMEM;
- }
-
- git_vector_init(&walk->pending, 8, NULL);
- git_vector_init(&walk->memory_alloc, 8, NULL);
- alloc_chunk(walk);
-
- walk->repo = repo;
-
- *revwalk_out = walk;
- return GIT_SUCCESS;
-}
-
-void git_revwalk_free(git_revwalk *walk)
-{
- unsigned int i;
-
- if (walk == NULL)
- return;
-
- git_revwalk_reset(walk);
- git_hashtable_free(walk->commits);
- git_vector_free(&walk->pending);
-
- for (i = 0; i < walk->memory_alloc.length; ++i) {
- free(git_vector_get(&walk->memory_alloc, i));
- }
-
- git_vector_free(&walk->memory_alloc);
- free(walk);
-}
-
-git_repository *git_revwalk_repository(git_revwalk *walk)
-{
- assert(walk);
- return walk->repo;
-}
-
-int git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode)
-{
- assert(walk);
-
- if (walk->walking)
- return GIT_EBUSY;
-
- walk->sorting = sort_mode;
- git_revwalk_reset(walk);
- return GIT_SUCCESS;
-}
static commit_object *commit_lookup(git_revwalk *walk, const git_oid *oid)
{
@@ -370,10 +304,9 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting)
if (commit == NULL)
return GIT_ENOTFOUND;
- if (uninteresting)
- mark_uninteresting(commit);
+ commit->uninteresting = uninteresting;
- return git_vector_insert(&walk->pending, commit);
+ return process_commit(walk, commit);
}
int git_revwalk_push(git_revwalk *walk, const git_oid *oid)
@@ -472,31 +405,11 @@ static int revwalk_next_reverse(commit_object **object_out, git_revwalk *walk)
static int prepare_walk(git_revwalk *walk)
{
- unsigned int i;
int error;
-
- if (walk->sorting & GIT_SORT_TIME) {
- if ((error = git_pqueue_init(&walk->iterator_time, 32, commit_time_cmp)) < GIT_SUCCESS)
- return error;
-
- walk->get_next = &revwalk_next_timesort;
- walk->enqueue = &revwalk_enqueue_timesort;
- } else {
- walk->get_next = &revwalk_next_unsorted;
- walk->enqueue = &revwalk_enqueue_unsorted;
- }
-
- for (i = 0; i < walk->pending.length; ++i) {
- commit_object *commit = walk->pending.contents[i];
- if ((error = process_commit(walk, commit)) < GIT_SUCCESS) {
- return error;
- }
- }
+ commit_object *next;
if (walk->sorting & GIT_SORT_TOPOLOGICAL) {
- commit_object *next;
unsigned short i;
- int error;
while ((error = walk->get_next(&next, walk)) == GIT_SUCCESS) {
for (i = 0; i < next->out_degree; ++i) {
@@ -514,8 +427,6 @@ static int prepare_walk(git_revwalk *walk)
}
if (walk->sorting & GIT_SORT_REVERSE) {
- commit_object *next;
- int error;
while ((error = walk->get_next(&next, walk)) == GIT_SUCCESS)
commit_list_insert(next, &walk->iterator_reverse);
@@ -531,6 +442,83 @@ static int prepare_walk(git_revwalk *walk)
}
+
+
+
+int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo)
+{
+ git_revwalk *walk;
+
+ walk = git__malloc(sizeof(git_revwalk));
+ if (walk == NULL)
+ return GIT_ENOMEM;
+
+ memset(walk, 0x0, sizeof(git_revwalk));
+
+ walk->commits = git_hashtable_alloc(64,
+ object_table_hash,
+ (git_hash_keyeq_ptr)git_oid_cmp);
+
+ if (walk->commits == NULL) {
+ free(walk);
+ return GIT_ENOMEM;
+ }
+
+ git_pqueue_init(&walk->iterator_time, 8, commit_time_cmp);
+ git_vector_init(&walk->memory_alloc, 8, NULL);
+ alloc_chunk(walk);
+
+ walk->get_next = &revwalk_next_unsorted;
+ walk->enqueue = &revwalk_enqueue_unsorted;
+
+ walk->repo = repo;
+
+ *revwalk_out = walk;
+ return GIT_SUCCESS;
+}
+
+void git_revwalk_free(git_revwalk *walk)
+{
+ unsigned int i;
+
+ if (walk == NULL)
+ return;
+
+ git_revwalk_reset(walk);
+ git_hashtable_free(walk->commits);
+ git_pqueue_free(&walk->iterator_time);
+
+ for (i = 0; i < walk->memory_alloc.length; ++i)
+ free(git_vector_get(&walk->memory_alloc, i));
+
+ git_vector_free(&walk->memory_alloc);
+ free(walk);
+}
+
+git_repository *git_revwalk_repository(git_revwalk *walk)
+{
+ assert(walk);
+ return walk->repo;
+}
+
+void git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode)
+{
+ assert(walk);
+
+ if (walk->walking)
+ git_revwalk_reset(walk);
+
+ walk->sorting = sort_mode;
+
+ if (walk->sorting & GIT_SORT_TIME) {
+ walk->get_next = &revwalk_next_timesort;
+ walk->enqueue = &revwalk_enqueue_timesort;
+ } else {
+ walk->get_next = &revwalk_next_unsorted;
+ walk->enqueue = &revwalk_enqueue_unsorted;
+ }
+}
+
int git_revwalk_next(git_oid *oid, git_revwalk *walk)
{
int error;
@@ -544,8 +532,11 @@ int git_revwalk_next(git_oid *oid, git_revwalk *walk)
}
error = walk->get_next(&next, walk);
- if (error < GIT_SUCCESS)
+ if (error < GIT_SUCCESS) {
+ if (error == GIT_EREVWALKOVER)
+ git_revwalk_reset(walk);
return error;
+ }
git_oid_cpy(oid, &next->oid);
return GIT_SUCCESS;
@@ -564,7 +555,7 @@ void git_revwalk_reset(git_revwalk *walk)
commit->topo_delay = 0;
);
- git_pqueue_free(&walk->iterator_time);
+ git_pqueue_clear(&walk->iterator_time);
commit_list_free(&walk->iterator_topo);
commit_list_free(&walk->iterator_rand);
commit_list_free(&walk->iterator_reverse);