Skip to content

Commit 65ea9d4

Browse files
stefanbellergitster
authored andcommitted
commit.c: migrate the commit buffer to the parsed object store
Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 95bb9d4 commit 65ea9d4

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

commit.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,18 +261,32 @@ struct commit_buffer {
261261
unsigned long size;
262262
};
263263
define_commit_slab(buffer_slab, struct commit_buffer);
264-
static struct buffer_slab buffer_slab = COMMIT_SLAB_INIT(1, buffer_slab);
264+
265+
struct buffer_slab *allocate_commit_buffer_slab(void)
266+
{
267+
struct buffer_slab *bs = xmalloc(sizeof(*bs));
268+
init_buffer_slab(bs);
269+
return bs;
270+
}
271+
272+
void free_commit_buffer_slab(struct buffer_slab *bs)
273+
{
274+
clear_buffer_slab(bs);
275+
free(bs);
276+
}
265277

266278
void set_commit_buffer_the_repository(struct commit *commit, void *buffer, unsigned long size)
267279
{
268-
struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);
280+
struct commit_buffer *v = buffer_slab_at(
281+
the_repository->parsed_objects->buffer_slab, commit);
269282
v->buffer = buffer;
270283
v->size = size;
271284
}
272285

273286
const void *get_cached_commit_buffer_the_repository(const struct commit *commit, unsigned long *sizep)
274287
{
275-
struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
288+
struct commit_buffer *v = buffer_slab_peek(
289+
the_repository->parsed_objects->buffer_slab, commit);
276290
if (!v) {
277291
if (sizep)
278292
*sizep = 0;
@@ -304,14 +318,16 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)
304318

305319
void unuse_commit_buffer(const struct commit *commit, const void *buffer)
306320
{
307-
struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
321+
struct commit_buffer *v = buffer_slab_peek(
322+
the_repository->parsed_objects->buffer_slab, commit);
308323
if (!(v && v->buffer == buffer))
309324
free((void *)buffer);
310325
}
311326

312327
void free_commit_buffer(struct commit *commit)
313328
{
314-
struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
329+
struct commit_buffer *v = buffer_slab_peek(
330+
the_repository->parsed_objects->buffer_slab, commit);
315331
if (v) {
316332
FREE_AND_NULL(v->buffer);
317333
v->size = 0;
@@ -347,7 +363,8 @@ void release_commit_memory(struct commit *c)
347363

348364
const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep)
349365
{
350-
struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
366+
struct commit_buffer *v = buffer_slab_peek(
367+
the_repository->parsed_objects->buffer_slab, commit);
351368
void *ret;
352369

353370
if (!v) {

commit.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ static inline int parse_commit(struct commit *item)
8989
}
9090
void parse_commit_or_die(struct commit *item);
9191

92+
struct buffer_slab;
93+
struct buffer_slab *allocate_commit_buffer_slab(void);
94+
void free_commit_buffer_slab(struct buffer_slab *bs);
95+
9296
/*
9397
* Associate an object buffer with the commit. The ownership of the
9498
* memory is handed over to the commit, and must be free()-able.

object.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ struct parsed_object_pool *parsed_object_pool_new(void)
467467
o->is_shallow = -1;
468468
o->shallow_stat = xcalloc(1, sizeof(*o->shallow_stat));
469469

470+
o->buffer_slab = allocate_commit_buffer_slab();
471+
470472
return o;
471473
}
472474

@@ -541,6 +543,9 @@ void parsed_object_pool_clear(struct parsed_object_pool *o)
541543
FREE_AND_NULL(o->obj_hash);
542544
o->obj_hash_size = 0;
543545

546+
free_commit_buffer_slab(o->buffer_slab);
547+
o->buffer_slab = NULL;
548+
544549
clear_alloc_state(o->blob_state);
545550
clear_alloc_state(o->tree_state);
546551
clear_alloc_state(o->commit_state);

object.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef OBJECT_H
22
#define OBJECT_H
33

4+
struct buffer_slab;
5+
46
struct parsed_object_pool {
57
struct object **obj_hash;
68
int nr_objs, obj_hash_size;
@@ -22,6 +24,8 @@ struct parsed_object_pool {
2224
char *alternate_shallow_file;
2325

2426
int commit_graft_prepared;
27+
28+
struct buffer_slab *buffer_slab;
2529
};
2630

2731
struct parsed_object_pool *parsed_object_pool_new(void);

0 commit comments

Comments
 (0)