mirror of
https://git.proxmox.com/git/libgit2
synced 2025-07-03 08:53:13 +00:00
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>
This commit is contained in:
parent
d047b47aad
commit
a7c182c594
@ -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];
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user