revwalk: hashmap

This commit is contained in:
Edward Thomson
2024-09-29 20:56:41 +01:00
parent 79290ba49c
commit 5d2c56d8a5
2 changed files with 15 additions and 13 deletions

View File

@@ -15,6 +15,8 @@
#include "merge.h"
#include "vector.h"
GIT_HASHMAP_FUNCTIONS(git_revwalk_oidmap, GIT_HASHMAP_INLINE, const git_oid *, git_commit_list_node *, git_oid_hash32, git_oid_equal);
static int get_revision(git_commit_list_node **out, git_revwalk *walk, git_commit_list **list);
git_commit_list_node *git_revwalk__commit_lookup(
@@ -23,7 +25,7 @@ git_commit_list_node *git_revwalk__commit_lookup(
git_commit_list_node *commit;
/* lookup and reserve space if not already present */
if ((commit = git_oidmap_get(walk->commits, oid)) != NULL)
if (git_revwalk_oidmap_get(&commit, &walk->commits, oid) == 0)
return commit;
commit = git_commit_list_alloc_node(walk);
@@ -32,7 +34,7 @@ git_commit_list_node *git_revwalk__commit_lookup(
git_oid_cpy(&commit->oid, oid);
if ((git_oidmap_set(walk->commits, &commit->oid, commit)) < 0)
if (git_revwalk_oidmap_put(&walk->commits, &commit->oid, commit) < 0)
return NULL;
return commit;
@@ -623,7 +625,7 @@ static int prepare_walk(git_revwalk *walk)
return GIT_ITEROVER;
}
/*
/*
* This is a bit convoluted, but necessary to maintain the order of
* the commits. This is especially important in situations where
* git_revwalk__push_glob is called with a git_revwalk__push_options
@@ -643,13 +645,13 @@ static int prepare_walk(git_revwalk *walk)
git_error_set_oom();
return -1;
}
commit->seen = 1;
if (commits_last == NULL)
commits = new_list;
else
commits_last->next = new_list;
commits_last = new_list;
}
}
@@ -700,8 +702,7 @@ int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo)
git_revwalk *walk = git__calloc(1, sizeof(git_revwalk));
GIT_ERROR_CHECK_ALLOC(walk);
if (git_oidmap_new(&walk->commits) < 0 ||
git_pqueue_init(&walk->iterator_time, 0, 8, git_commit_list_time_cmp) < 0 ||
if (git_pqueue_init(&walk->iterator_time, 0, 8, git_commit_list_time_cmp) < 0 ||
git_pool_init(&walk->commit_pool, COMMIT_ALLOC) < 0)
return -1;
@@ -727,7 +728,7 @@ void git_revwalk_free(git_revwalk *walk)
git_revwalk_reset(walk);
git_odb_free(walk->odb);
git_oidmap_free(walk->commits);
git_revwalk_oidmap_dispose(&walk->commits);
git_pool_clear(&walk->commit_pool);
git_pqueue_free(&walk->iterator_time);
git__free(walk);
@@ -799,17 +800,18 @@ int git_revwalk_next(git_oid *oid, git_revwalk *walk)
int git_revwalk_reset(git_revwalk *walk)
{
git_commit_list_node *commit;
git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT;
GIT_ASSERT_ARG(walk);
git_oidmap_foreach_value(walk->commits, commit, {
while (git_revwalk_oidmap_iterate(&iter, NULL, &commit, &walk->commits) == 0) {
commit->seen = 0;
commit->in_degree = 0;
commit->topo_delay = 0;
commit->uninteresting = 0;
commit->added = 0;
commit->flags = 0;
});
}
git_pqueue_clear(&walk->iterator_time);
git_commit_list_free(&walk->iterator_topo);

View File

@@ -10,19 +10,19 @@
#include "common.h"
#include "git2/revwalk.h"
#include "oidmap.h"
#include "commit_list.h"
#include "pqueue.h"
#include "pool.h"
#include "vector.h"
#include "hashmap.h"
#include "oidmap.h"
GIT_HASHMAP_STRUCT(git_revwalk_oidmap, const git_oid *, git_commit_list_node *);
struct git_revwalk {
git_repository *repo;
git_odb *odb;
git_oidmap *commits;
git_revwalk_oidmap commits;
git_pool commit_pool;
git_commit_list *iterator_topo;