commit.c: migrate the commit buffer to the parsed object store
Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
95bb9d4c32
commit
65ea9d4bec
29
commit.c
29
commit.c
@ -261,18 +261,32 @@ struct commit_buffer {
|
|||||||
unsigned long size;
|
unsigned long size;
|
||||||
};
|
};
|
||||||
define_commit_slab(buffer_slab, struct commit_buffer);
|
define_commit_slab(buffer_slab, struct commit_buffer);
|
||||||
static struct buffer_slab buffer_slab = COMMIT_SLAB_INIT(1, buffer_slab);
|
|
||||||
|
struct buffer_slab *allocate_commit_buffer_slab(void)
|
||||||
|
{
|
||||||
|
struct buffer_slab *bs = xmalloc(sizeof(*bs));
|
||||||
|
init_buffer_slab(bs);
|
||||||
|
return bs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_commit_buffer_slab(struct buffer_slab *bs)
|
||||||
|
{
|
||||||
|
clear_buffer_slab(bs);
|
||||||
|
free(bs);
|
||||||
|
}
|
||||||
|
|
||||||
void set_commit_buffer_the_repository(struct commit *commit, void *buffer, unsigned long size)
|
void set_commit_buffer_the_repository(struct commit *commit, void *buffer, unsigned long size)
|
||||||
{
|
{
|
||||||
struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);
|
struct commit_buffer *v = buffer_slab_at(
|
||||||
|
the_repository->parsed_objects->buffer_slab, commit);
|
||||||
v->buffer = buffer;
|
v->buffer = buffer;
|
||||||
v->size = size;
|
v->size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *get_cached_commit_buffer_the_repository(const struct commit *commit, unsigned long *sizep)
|
const void *get_cached_commit_buffer_the_repository(const struct commit *commit, unsigned long *sizep)
|
||||||
{
|
{
|
||||||
struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
|
struct commit_buffer *v = buffer_slab_peek(
|
||||||
|
the_repository->parsed_objects->buffer_slab, commit);
|
||||||
if (!v) {
|
if (!v) {
|
||||||
if (sizep)
|
if (sizep)
|
||||||
*sizep = 0;
|
*sizep = 0;
|
||||||
@ -304,14 +318,16 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)
|
|||||||
|
|
||||||
void unuse_commit_buffer(const struct commit *commit, const void *buffer)
|
void unuse_commit_buffer(const struct commit *commit, const void *buffer)
|
||||||
{
|
{
|
||||||
struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
|
struct commit_buffer *v = buffer_slab_peek(
|
||||||
|
the_repository->parsed_objects->buffer_slab, commit);
|
||||||
if (!(v && v->buffer == buffer))
|
if (!(v && v->buffer == buffer))
|
||||||
free((void *)buffer);
|
free((void *)buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_commit_buffer(struct commit *commit)
|
void free_commit_buffer(struct commit *commit)
|
||||||
{
|
{
|
||||||
struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
|
struct commit_buffer *v = buffer_slab_peek(
|
||||||
|
the_repository->parsed_objects->buffer_slab, commit);
|
||||||
if (v) {
|
if (v) {
|
||||||
FREE_AND_NULL(v->buffer);
|
FREE_AND_NULL(v->buffer);
|
||||||
v->size = 0;
|
v->size = 0;
|
||||||
@ -347,7 +363,8 @@ void release_commit_memory(struct commit *c)
|
|||||||
|
|
||||||
const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep)
|
const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep)
|
||||||
{
|
{
|
||||||
struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
|
struct commit_buffer *v = buffer_slab_peek(
|
||||||
|
the_repository->parsed_objects->buffer_slab, commit);
|
||||||
void *ret;
|
void *ret;
|
||||||
|
|
||||||
if (!v) {
|
if (!v) {
|
||||||
|
4
commit.h
4
commit.h
@ -89,6 +89,10 @@ static inline int parse_commit(struct commit *item)
|
|||||||
}
|
}
|
||||||
void parse_commit_or_die(struct commit *item);
|
void parse_commit_or_die(struct commit *item);
|
||||||
|
|
||||||
|
struct buffer_slab;
|
||||||
|
struct buffer_slab *allocate_commit_buffer_slab(void);
|
||||||
|
void free_commit_buffer_slab(struct buffer_slab *bs);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Associate an object buffer with the commit. The ownership of the
|
* Associate an object buffer with the commit. The ownership of the
|
||||||
* memory is handed over to the commit, and must be free()-able.
|
* memory is handed over to the commit, and must be free()-able.
|
||||||
|
5
object.c
5
object.c
@ -467,6 +467,8 @@ struct parsed_object_pool *parsed_object_pool_new(void)
|
|||||||
o->is_shallow = -1;
|
o->is_shallow = -1;
|
||||||
o->shallow_stat = xcalloc(1, sizeof(*o->shallow_stat));
|
o->shallow_stat = xcalloc(1, sizeof(*o->shallow_stat));
|
||||||
|
|
||||||
|
o->buffer_slab = allocate_commit_buffer_slab();
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,6 +543,9 @@ void parsed_object_pool_clear(struct parsed_object_pool *o)
|
|||||||
FREE_AND_NULL(o->obj_hash);
|
FREE_AND_NULL(o->obj_hash);
|
||||||
o->obj_hash_size = 0;
|
o->obj_hash_size = 0;
|
||||||
|
|
||||||
|
free_commit_buffer_slab(o->buffer_slab);
|
||||||
|
o->buffer_slab = NULL;
|
||||||
|
|
||||||
clear_alloc_state(o->blob_state);
|
clear_alloc_state(o->blob_state);
|
||||||
clear_alloc_state(o->tree_state);
|
clear_alloc_state(o->tree_state);
|
||||||
clear_alloc_state(o->commit_state);
|
clear_alloc_state(o->commit_state);
|
||||||
|
4
object.h
4
object.h
@ -1,6 +1,8 @@
|
|||||||
#ifndef OBJECT_H
|
#ifndef OBJECT_H
|
||||||
#define OBJECT_H
|
#define OBJECT_H
|
||||||
|
|
||||||
|
struct buffer_slab;
|
||||||
|
|
||||||
struct parsed_object_pool {
|
struct parsed_object_pool {
|
||||||
struct object **obj_hash;
|
struct object **obj_hash;
|
||||||
int nr_objs, obj_hash_size;
|
int nr_objs, obj_hash_size;
|
||||||
@ -22,6 +24,8 @@ struct parsed_object_pool {
|
|||||||
char *alternate_shallow_file;
|
char *alternate_shallow_file;
|
||||||
|
|
||||||
int commit_graft_prepared;
|
int commit_graft_prepared;
|
||||||
|
|
||||||
|
struct buffer_slab *buffer_slab;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct parsed_object_pool *parsed_object_pool_new(void);
|
struct parsed_object_pool *parsed_object_pool_new(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user