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>

Stefan Beller committed Jun 28, 2018 at 18:22 UTC 65ea9d4bec141295d34955b286c32725fe3b422d
4 files changed +36 -6
commit.c
+23 -6
@@ -261,18 +261,32 @@ struct commit_buffer {
261 unsigned long size;
262 };
263 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 +}
277
278 void set_commit_buffer_the_repository(struct commit *commit, void *buffer, unsigned long size)
279 {
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);
282 v->buffer = buffer;
283 v->size = size;
284 }
285
286 const void *get_cached_commit_buffer_the_repository(const struct commit *commit, unsigned long *sizep)
287 {
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);
290 if (!v) {
291 if (sizep)
292 *sizep = 0;
@@ -304,14 +318,16 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)
318
319 void unuse_commit_buffer(const struct commit *commit, const void *buffer)
320 {
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);
323 if (!(v && v->buffer == buffer))
324 free((void *)buffer);
325 }
326
327 void free_commit_buffer(struct commit *commit)
328 {
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);
331 if (v) {
332 FREE_AND_NULL(v->buffer);
333 v->size = 0;
@@ -347,7 +363,8 @@ void release_commit_memory(struct commit *c)
363
364 const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep)
365 {
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);
368 void *ret;
369
370 if (!v) {
commit.h
+4
@@ -89,6 +89,10 @@ static inline int parse_commit(struct commit *item)
89 }
90 void parse_commit_or_die(struct commit *item);
91
92 +struct buffer_slab;
93 +struct buffer_slab *allocate_commit_buffer_slab(void);
94 +void free_commit_buffer_slab(struct buffer_slab *bs);
95 +
96 /*
97 * Associate an object buffer with the commit. The ownership of the
98 * memory is handed over to the commit, and must be free()-able.
object.c
+5
@@ -467,6 +467,8 @@ struct parsed_object_pool *parsed_object_pool_new(void)
467 o->is_shallow = -1;
468 o->shallow_stat = xcalloc(1, sizeof(*o->shallow_stat));
469
470 + o->buffer_slab = allocate_commit_buffer_slab();
471 +
472 return o;
473 }
474
@@ -541,6 +543,9 @@ void parsed_object_pool_clear(struct parsed_object_pool *o)
543 FREE_AND_NULL(o->obj_hash);
544 o->obj_hash_size = 0;
545
546 + free_commit_buffer_slab(o->buffer_slab);
547 + o->buffer_slab = NULL;
548 +
549 clear_alloc_state(o->blob_state);
550 clear_alloc_state(o->tree_state);
551 clear_alloc_state(o->commit_state);
object.h
+4
@@ -1,6 +1,8 @@
1 #ifndef OBJECT_H
2 #define OBJECT_H
3
4 +struct buffer_slab;
5 +
6 struct parsed_object_pool {
7 struct object **obj_hash;
8 int nr_objs, obj_hash_size;
@@ -22,6 +24,8 @@ struct parsed_object_pool {
24 char *alternate_shallow_file;
25
26 int commit_graft_prepared;
27 +
28 + struct buffer_slab *buffer_slab;
29 };
30
31 struct parsed_object_pool *parsed_object_pool_new(void);