Commit 9bdb75947178f72df30314d66bc9bcc90df643d7

Vicent Marti 2010-05-23T17:12:28

Properly reset all commit properties when doing a gitrp_reset(). Add git_revpool_table_free() method. Signed-off-by: Vicent Marti <tanoku@gmail.com> Signed-off-by: Andreas Ericsson <ae@op5.se>

diff --git a/src/revobject.c b/src/revobject.c
index c673654..45fb973 100644
--- a/src/revobject.c
+++ b/src/revobject.c
@@ -177,5 +177,48 @@ void git_revpool_table_resize(git_revpool_table *table)
 
 void git_revpool_table_free(git_revpool_table *table)
 {
+    int index;
 
+    for (index = 0; index <= table->size_mask; ++index)
+    {
+        git_revpool_node *node, *next_node;
+
+        node = table->nodes[index];
+        while (node != NULL)
+        {
+            next_node = node->next;
+            free(node);
+            node = next_node;
+        }
+    }
+
+    free(table);
+}
+
+void git_revpool_tableit_init(git_revpool_table *table, git_revpool_tableit *it)
+{
+    memset(it, 0x0, sizeof(git_revpool_tableit));
+
+    it->nodes = table->nodes;
+    it->current_node = NULL;
+    it->current_pos = 0;
+    it->size = table->size_mask + 1;
+}
+
+git_revpool_object *git_revpool_tableit_next(git_revpool_tableit *it)
+{
+    git_revpool_node *next = NULL;
+
+    while (it->current_node == NULL)
+    {
+        if (it->current_pos >= it->size)
+            return NULL;
+
+        it->current_node = it->nodes[it->current_pos++];
+    }
+
+    next = it->current_node;
+    it->current_node = it->current_node->next;
+
+    return next->object;
 }
diff --git a/src/revobject.h b/src/revobject.h
index c073337..2876a4c 100644
--- a/src/revobject.h
+++ b/src/revobject.h
@@ -47,4 +47,8 @@ void git_revpool_table_resize(git_revpool_table *table);
 void git_revpool_table_free(git_revpool_table *table);
 
 
+git_revpool_object *git_revpool_tableit_next(git_revpool_tableit *it);
+void git_revpool_tableit_init(git_revpool_table *table, git_revpool_tableit *it);
+
+
 #endif
diff --git a/src/revwalk.c b/src/revwalk.c
index 4575d8b..60ea5e8 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -144,6 +144,18 @@ git_commit *gitrp_next(git_revpool *pool)
 
 void gitrp_reset(git_revpool *pool)
 {
+    git_commit *commit;
+    git_revpool_tableit it;
+
+    git_revpool_tableit_init(pool->commits, &it);
+
+    while ((commit = (git_commit *)git_revpool_tableit_next(&it)) != NULL)
+    {
+        commit->seen = 0;
+        commit->topo_delay = 0;
+        commit->in_degree = 0;
+    }
+
     git_commit_list_clear(&pool->iterator, 0);
     pool->walking = 0;
 }