Add object cache to the revision pool. Fixed issue when generating pending commits list during iteration. The 'git_commit_lookup' function will now check the pool's cache for commits which have been previously loaded/parsed; there can only be a single 'git_commit' structure for each commit on the same pool. Signed-off-by: Vicent Marti <tanoku@gmail.com> Signed-off-by: Andreas Ericsson <ae@op5.se>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
diff --git a/src/revobject.c b/src/revobject.c
index 2ed6345..c673654 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 8ec696a..4a59d93 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 b24cf42..088171c 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