summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/revobject.c10
-rw-r--r--src/revobject.h3
-rw-r--r--src/revwalk.c42
3 files changed, 27 insertions, 28 deletions
diff --git a/src/revobject.c b/src/revobject.c
index 2ed634540..c6736542f 100644
--- a/src/revobject.c
+++ b/src/revobject.c
@@ -57,6 +57,7 @@ unsigned int git_revpool_table__hash(const git_oid *id)
git_revpool_table *git_revpool_table_create(unsigned int min_size)
{
git_revpool_table *table;
+ int i;
table = git__malloc(sizeof(table));
@@ -83,7 +84,8 @@ git_revpool_table *git_revpool_table_create(unsigned int min_size)
return NULL;
}
- memset(table->nodes, 0x0, (min_size + 1) * sizeof(git_revpool_node *));
+ for (i = 0; i <= min_size; ++i)
+ table->nodes[i] = NULL;
return table;
}
@@ -93,6 +95,9 @@ int git_revpool_table_insert(git_revpool_table *table, git_revpool_object *objec
git_revpool_node *node;
unsigned int index, hash;
+ if (table == NULL)
+ return -1;
+
if (table->count + 1 > table->max_count)
git_revpool_table_resize(table);
@@ -118,6 +123,9 @@ git_revpool_object *git_revpool_table_lookup(git_revpool_table *table, const git
git_revpool_node *node;
unsigned int index, hash;
+ if (table == NULL)
+ return NULL;
+
hash = git_revpool_table__hash(id);
index = (hash & table->size_mask);
node = table->nodes[index];
diff --git a/src/revobject.h b/src/revobject.h
index 8ec696a47..4a59d93f4 100644
--- a/src/revobject.h
+++ b/src/revobject.h
@@ -19,10 +19,11 @@ struct git_revpool_node
struct git_revpool_table
{
+ struct git_revpool_node **nodes;
+
unsigned int size_mask;
unsigned int count;
unsigned int max_count;
- struct git_revpool_node **nodes;
};
diff --git a/src/revwalk.c b/src/revwalk.c
index b24cf42e6..088171c4d 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -73,8 +73,6 @@ void gitrp_push(git_revpool *pool, git_commit *commit)
if (commit->uninteresting)
git_commit__mark_uninteresting(commit);
- commit->seen = 1;
-
git_commit_list_append(&pool->roots, commit);
}
@@ -84,38 +82,30 @@ void gitrp_hide(git_revpool *pool, git_commit *commit)
gitrp_push(pool, commit);
}
-void gitrp_prepare_walk(git_revpool *pool)
+void gitrp__enroot(git_revpool *pool, git_commit *commit)
{
- git_commit_node *it;
+ git_commit_node *parents;
- for (it = pool->roots.head; it != NULL; it = it->next)
- {
- git_commit_list_append(&pool->iterator, it->commit);
- }
+ if (commit->seen)
+ return;
- for (it = pool->iterator.head; it != NULL; it = it->next)
- {
- git_commit *commit;
- git_commit_node *parents;
+ if (commit->parsed == 0)
+ git_commit_parse_existing(commit);
- commit = it->commit;
- parents = commit->parents.head;
+ commit->seen = 1;
- while (parents)
- {
- git_commit *parent = parents->commit;
- parents = parents->next;
+ for (parents = commit->parents.head; parents != NULL; parents = parents->next)
+ gitrp__enroot(pool, parents->commit);
- if (parent->seen)
- continue;
+ git_commit_list_append(&pool->iterator, commit);
+}
- if (parent->parsed == 0)
- git_commit_parse_existing(parent);
+void gitrp_prepare_walk(git_revpool *pool)
+{
+ git_commit_node *it;
- parent->seen = 1;
- git_commit_list_append(&pool->iterator, parent);
- }
- }
+ for (it = pool->roots.head; it != NULL; it = it->next)
+ gitrp__enroot(pool, it->commit);
// TODO: topo sort, time sort