commit: prepare free_commit_buffer and release_commit_memory for any repo
Pass the object pool to free_commit_buffer and release_commit_memory, such that we can eliminate access to 'the_repository'. Also remove the TODO in release_commit_memory, as commit->util was removed in 9d2c97016f (commit.h: delete 'util' field in struct commit, 2018-05-19) Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Dec 14, 2018 at 16:09 UTC
6a7895fd8a3bd409f2b71ffc355d5142172cc2a0
6 files changed
+15
-12
builtin/fsck.c
+2
-1
@@ -382,7 +382,8 @@ out:
382
if (obj->type == OBJ_TREE)
383
free_tree_buffer((struct tree *)obj);
384
if (obj->type == OBJ_COMMIT)
385
- free_commit_buffer((struct commit *)obj);
385
+ free_commit_buffer(the_repository->parsed_objects,
386
+ (struct commit *)obj);
387
return err;
388
}
389
builtin/log.c
+4
-2
@@ -395,7 +395,8 @@ static int cmd_log_walk(struct rev_info *rev)
395
* We may show a given commit multiple times when
396
* walking the reflogs.
397
*/
398
- free_commit_buffer(commit);
398
+ free_commit_buffer(the_repository->parsed_objects,
399
+ commit);
400
free_commit_list(commit->parents);
401
commit->parents = NULL;
402
}
@@ -1922,7 +1923,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1923
open_next_file(rev.numbered_files ? NULL : commit, NULL, &rev, quiet))
1924
die(_("Failed to create output files"));
1925
shown = log_tree_commit(&rev, commit);
1925
- free_commit_buffer(commit);
1926
+ free_commit_buffer(the_repository->parsed_objects,
1927
+ commit);
1928
1929
/* We put one extra blank line between formatted
1930
* patches and this flag is used by log-tree code
builtin/rev-list.c
+2
-1
@@ -196,7 +196,8 @@ static void finish_commit(struct commit *commit, void *data)
196
free_commit_list(commit->parents);
197
commit->parents = NULL;
198
}
199
- free_commit_buffer(commit);
199
+ free_commit_buffer(the_repository->parsed_objects,
200
+ commit);
201
}
202
203
static inline void finish_object__ma(struct object *obj)
commit.c
+4
-5
@@ -328,10 +328,10 @@ void repo_unuse_commit_buffer(struct repository *r,
328
free((void *)buffer);
329
}
330
331
-void free_commit_buffer(struct commit *commit)
331
+void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)
332
{
333
struct commit_buffer *v = buffer_slab_peek(
334
- the_repository->parsed_objects->buffer_slab, commit);
334
+ pool->buffer_slab, commit);
335
if (v) {
336
FREE_AND_NULL(v->buffer);
337
v->size = 0;
@@ -354,13 +354,12 @@ struct object_id *get_commit_tree_oid(const struct commit *commit)
354
return &get_commit_tree(commit)->object.oid;
355
}
356
357
-void release_commit_memory(struct commit *c)
357
+void release_commit_memory(struct parsed_object_pool *pool, struct commit *c)
358
{
359
c->maybe_tree = NULL;
360
c->index = 0;
361
- free_commit_buffer(c);
361
+ free_commit_buffer(pool, c);
362
free_commit_list(c->parents);
363
- /* TODO: what about commit->util? */
363
364
c->object.parsed = 0;
365
}
commit.h
+2
-2
@@ -140,7 +140,7 @@ void repo_unuse_commit_buffer(struct repository *r,
140
/*
141
* Free any cached object buffer associated with the commit.
142
*/
143
-void free_commit_buffer(struct commit *);
143
+void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);
144
145
struct tree *get_commit_tree(const struct commit *);
146
struct object_id *get_commit_tree_oid(const struct commit *);
@@ -149,7 +149,7 @@ struct object_id *get_commit_tree_oid(const struct commit *);
149
* Release memory related to a commit, including the parent list and
150
* any cached object buffer.
151
*/
152
-void release_commit_memory(struct commit *c);
152
+void release_commit_memory(struct parsed_object_pool *pool, struct commit *c);
153
154
/*
155
* Disassociate any cached object buffer from the commit, but do not free it.
object.c
+1
-1
@@ -540,7 +540,7 @@ void parsed_object_pool_clear(struct parsed_object_pool *o)
540
if (obj->type == OBJ_TREE)
541
free_tree_buffer((struct tree*)obj);
542
else if (obj->type == OBJ_COMMIT)
543
- release_commit_memory((struct commit*)obj);
543
+ release_commit_memory(o, (struct commit*)obj);
544
else if (obj->type == OBJ_TAG)
545
release_tag_memory((struct tag*)obj);
546
}