From a7c182c59414cece10c819989bce3f1247f4eacc Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Sun, 23 May 2010 04:41:31 +0200 Subject: [PATCH] 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 Signed-off-by: Andreas Ericsson --- src/revobject.c | 10 +++++++++- src/revobject.h | 3 ++- src/revwalk.c | 48 +++++++++++++++++++----------------------------- 3 files changed, 30 insertions(+), 31 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__enroot(git_revpool *pool, git_commit *commit) +{ + git_commit_node *parents; + + if (commit->seen) + return; + + if (commit->parsed == 0) + git_commit_parse_existing(commit); + + commit->seen = 1; + + for (parents = commit->parents.head; parents != NULL; parents = parents->next) + gitrp__enroot(pool, parents->commit); + + git_commit_list_append(&pool->iterator, commit); +} + void gitrp_prepare_walk(git_revpool *pool) { git_commit_node *it; for (it = pool->roots.head; it != NULL; it = it->next) - { - git_commit_list_append(&pool->iterator, it->commit); - } - - for (it = pool->iterator.head; it != NULL; it = it->next) - { - git_commit *commit; - git_commit_node *parents; - - commit = it->commit; - parents = commit->parents.head; - - while (parents) - { - git_commit *parent = parents->commit; - parents = parents->next; - - if (parent->seen) - continue; - - if (parent->parsed == 0) - git_commit_parse_existing(parent); - - parent->seen = 1; - git_commit_list_append(&pool->iterator, parent); - } - } + gitrp__enroot(pool, it->commit); // TODO: topo sort, time sort