mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 18:38:58 +00:00
Changed revpool's object table to support arbitrary objects
git_revpool_object now has a type identifier for each object type in a revpool (commits, trees, blobs, etc). Trees can now be stored in the revision pool. git_revpool_tableit now supports filtering objects by their type when iterating through the object table. Signed-off-by: Vicent Marti <tanoku@gmail.com>
This commit is contained in:
parent
b231ef3acd
commit
40721f6b12
11
src/commit.c
11
src/commit.c
@ -34,6 +34,12 @@
|
|||||||
printf("Oid: %s | In degree: %d | Time: %u\n", oid, commit->in_degree, commit->commit_time);\
|
printf("Oid: %s | In degree: %d | Time: %u\n", oid, commit->in_degree, commit->commit_time);\
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void git_commit__free(git_commit *commit)
|
||||||
|
{
|
||||||
|
git_commit_list_clear(&commit->parents, 0);
|
||||||
|
free(commit);
|
||||||
|
}
|
||||||
|
|
||||||
const git_oid *git_commit_id(git_commit *c)
|
const git_oid *git_commit_id(git_commit *c)
|
||||||
{
|
{
|
||||||
return &c->object.id;
|
return &c->object.id;
|
||||||
@ -104,7 +110,7 @@ git_commit *git_commit_lookup(git_revpool *pool, const git_oid *id)
|
|||||||
if (pool == NULL)
|
if (pool == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
commit = (git_commit *)git_revpool_table_lookup(pool->commits, id);
|
commit = (git_commit *)git_revpool_table_lookup(pool->objects, id);
|
||||||
if (commit != NULL)
|
if (commit != NULL)
|
||||||
return commit;
|
return commit;
|
||||||
|
|
||||||
@ -118,8 +124,9 @@ git_commit *git_commit_lookup(git_revpool *pool, const git_oid *id)
|
|||||||
/* Initialize parent object */
|
/* Initialize parent object */
|
||||||
git_oid_cpy(&commit->object.id, id);
|
git_oid_cpy(&commit->object.id, id);
|
||||||
commit->object.pool = pool;
|
commit->object.pool = pool;
|
||||||
|
commit->object.type = GIT_OBJ_COMMIT;
|
||||||
|
|
||||||
git_revpool_table_insert(pool->commits, (git_revpool_object *)commit);
|
git_revpool_table_insert(pool->objects, (git_revpool_object *)commit);
|
||||||
|
|
||||||
return commit;
|
return commit;
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ struct git_commit {
|
|||||||
flags:26;
|
flags:26;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void git_commit__free(git_commit *c);
|
||||||
int git_commit__parse_oid(git_oid *oid, char **buffer_out, const char *buffer_end, const char *header);
|
int git_commit__parse_oid(git_oid *oid, char **buffer_out, const char *buffer_end, const char *header);
|
||||||
int git_commit__parse_buffer(git_commit *commit, void *data, size_t len);
|
int git_commit__parse_buffer(git_commit *commit, void *data, size_t len);
|
||||||
int git_commit__parse_time(time_t *commit_time, char *buffer, const char *buffer_end);
|
int git_commit__parse_time(time_t *commit_time, char *buffer, const char *buffer_end);
|
||||||
|
@ -197,3 +197,14 @@ git_revpool_object *git_revpool_tableit_next(git_revpool_tableit *it)
|
|||||||
|
|
||||||
return next->object;
|
return next->object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
git_revpool_object *git_revpool_tableit_nextfilter(git_revpool_tableit *it, git_otype type)
|
||||||
|
{
|
||||||
|
git_revpool_object *obj;
|
||||||
|
|
||||||
|
do {
|
||||||
|
obj = git_revpool_tableit_next(it);
|
||||||
|
} while (obj != NULL && obj->type != type);
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
@ -3,10 +3,12 @@
|
|||||||
|
|
||||||
#include "git/common.h"
|
#include "git/common.h"
|
||||||
#include "git/oid.h"
|
#include "git/oid.h"
|
||||||
|
#include "git/odb.h"
|
||||||
|
|
||||||
struct git_revpool_object {
|
struct git_revpool_object {
|
||||||
git_oid id;
|
git_oid id;
|
||||||
git_revpool *pool;
|
git_revpool *pool;
|
||||||
|
git_otype type;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct git_revpool_node {
|
struct git_revpool_node {
|
||||||
@ -44,6 +46,7 @@ void git_revpool_table_free(git_revpool_table *table);
|
|||||||
|
|
||||||
|
|
||||||
git_revpool_object *git_revpool_tableit_next(git_revpool_tableit *it);
|
git_revpool_object *git_revpool_tableit_next(git_revpool_tableit *it);
|
||||||
|
git_revpool_object *git_revpool_tableit_nextfilter(git_revpool_tableit *it, git_otype type);
|
||||||
void git_revpool_tableit_init(git_revpool_table *table, git_revpool_tableit *it);
|
void git_revpool_tableit_init(git_revpool_table *table, git_revpool_tableit *it);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -37,7 +37,7 @@ git_revpool *gitrp_alloc(git_odb *db)
|
|||||||
|
|
||||||
memset(walk, 0x0, sizeof(git_revpool));
|
memset(walk, 0x0, sizeof(git_revpool));
|
||||||
|
|
||||||
walk->commits = git_revpool_table_create(default_table_size);
|
walk->objects = git_revpool_table_create(default_table_size);
|
||||||
|
|
||||||
walk->db = db;
|
walk->db = db;
|
||||||
return walk;
|
return walk;
|
||||||
@ -45,20 +45,29 @@ git_revpool *gitrp_alloc(git_odb *db)
|
|||||||
|
|
||||||
void gitrp_free(git_revpool *walk)
|
void gitrp_free(git_revpool *walk)
|
||||||
{
|
{
|
||||||
git_commit *commit;
|
git_revpool_object *obj;
|
||||||
git_revpool_tableit it;
|
git_revpool_tableit it;
|
||||||
|
|
||||||
git_commit_list_clear(&(walk->iterator), 0);
|
git_commit_list_clear(&(walk->iterator), 0);
|
||||||
git_commit_list_clear(&(walk->roots), 0);
|
git_commit_list_clear(&(walk->roots), 0);
|
||||||
|
|
||||||
git_revpool_tableit_init(walk->commits, &it);
|
git_revpool_tableit_init(walk->objects, &it);
|
||||||
|
|
||||||
while ((commit = (git_commit *)git_revpool_tableit_next(&it)) != NULL) {
|
while ((obj = git_revpool_tableit_next(&it)) != NULL) {
|
||||||
git_commit_list_clear(&commit->parents, 0);
|
switch (obj->type) {
|
||||||
free(commit);
|
|
||||||
|
case GIT_OBJ_COMMIT:
|
||||||
|
git_commit__free((git_commit *)obj);
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
free(obj);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
git_revpool_table_free(walk->commits);
|
git_revpool_table_free(walk->objects);
|
||||||
|
|
||||||
free(walk);
|
free(walk);
|
||||||
}
|
}
|
||||||
@ -182,9 +191,12 @@ void gitrp_reset(git_revpool *pool)
|
|||||||
git_commit *commit;
|
git_commit *commit;
|
||||||
git_revpool_tableit it;
|
git_revpool_tableit it;
|
||||||
|
|
||||||
git_revpool_tableit_init(pool->commits, &it);
|
git_revpool_tableit_init(pool->objects, &it);
|
||||||
|
|
||||||
|
while ((commit =
|
||||||
|
(git_commit *)git_revpool_tableit_nextfilter(
|
||||||
|
&it, GIT_OBJ_COMMIT)) != NULL) {
|
||||||
|
|
||||||
while ((commit = (git_commit *)git_revpool_tableit_next(&it)) != NULL) {
|
|
||||||
commit->seen = 0;
|
commit->seen = 0;
|
||||||
commit->topo_delay = 0;
|
commit->topo_delay = 0;
|
||||||
commit->in_degree = 0;
|
commit->in_degree = 0;
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "git/common.h"
|
#include "git/common.h"
|
||||||
#include "git/revwalk.h"
|
#include "git/revwalk.h"
|
||||||
|
|
||||||
|
#include "commit.h"
|
||||||
|
|
||||||
struct git_revpool {
|
struct git_revpool {
|
||||||
git_odb *db;
|
git_odb *db;
|
||||||
|
|
||||||
@ -11,7 +13,7 @@ struct git_revpool {
|
|||||||
git_commit *(*next_commit)(git_commit_list *);
|
git_commit *(*next_commit)(git_commit_list *);
|
||||||
|
|
||||||
git_commit_list roots;
|
git_commit_list roots;
|
||||||
git_revpool_table *commits;
|
git_revpool_table *objects;
|
||||||
|
|
||||||
unsigned walking:1;
|
unsigned walking:1;
|
||||||
unsigned int sorting;
|
unsigned int sorting;
|
||||||
|
Loading…
Reference in New Issue
Block a user