Skip to content

Commit 6a7895f

Browse files
stefanbellergitster
authored andcommitted
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 9d2c970 (commit.h: delete 'util' field in struct commit, 2018-05-19) Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4f542b7 commit 6a7895f

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

builtin/fsck.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
382382
if (obj->type == OBJ_TREE)
383383
free_tree_buffer((struct tree *)obj);
384384
if (obj->type == OBJ_COMMIT)
385-
free_commit_buffer((struct commit *)obj);
385+
free_commit_buffer(the_repository->parsed_objects,
386+
(struct commit *)obj);
386387
return err;
387388
}
388389

builtin/log.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ static int cmd_log_walk(struct rev_info *rev)
395395
* We may show a given commit multiple times when
396396
* walking the reflogs.
397397
*/
398-
free_commit_buffer(commit);
398+
free_commit_buffer(the_repository->parsed_objects,
399+
commit);
399400
free_commit_list(commit->parents);
400401
commit->parents = NULL;
401402
}
@@ -1922,7 +1923,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
19221923
open_next_file(rev.numbered_files ? NULL : commit, NULL, &rev, quiet))
19231924
die(_("Failed to create output files"));
19241925
shown = log_tree_commit(&rev, commit);
1925-
free_commit_buffer(commit);
1926+
free_commit_buffer(the_repository->parsed_objects,
1927+
commit);
19261928

19271929
/* We put one extra blank line between formatted
19281930
* patches and this flag is used by log-tree code

builtin/rev-list.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ static void finish_commit(struct commit *commit, void *data)
196196
free_commit_list(commit->parents);
197197
commit->parents = NULL;
198198
}
199-
free_commit_buffer(commit);
199+
free_commit_buffer(the_repository->parsed_objects,
200+
commit);
200201
}
201202

202203
static inline void finish_object__ma(struct object *obj)

commit.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,10 @@ void repo_unuse_commit_buffer(struct repository *r,
328328
free((void *)buffer);
329329
}
330330

331-
void free_commit_buffer(struct commit *commit)
331+
void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)
332332
{
333333
struct commit_buffer *v = buffer_slab_peek(
334-
the_repository->parsed_objects->buffer_slab, commit);
334+
pool->buffer_slab, commit);
335335
if (v) {
336336
FREE_AND_NULL(v->buffer);
337337
v->size = 0;
@@ -354,13 +354,12 @@ struct object_id *get_commit_tree_oid(const struct commit *commit)
354354
return &get_commit_tree(commit)->object.oid;
355355
}
356356

357-
void release_commit_memory(struct commit *c)
357+
void release_commit_memory(struct parsed_object_pool *pool, struct commit *c)
358358
{
359359
c->maybe_tree = NULL;
360360
c->index = 0;
361-
free_commit_buffer(c);
361+
free_commit_buffer(pool, c);
362362
free_commit_list(c->parents);
363-
/* TODO: what about commit->util? */
364363

365364
c->object.parsed = 0;
366365
}

commit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void repo_unuse_commit_buffer(struct repository *r,
140140
/*
141141
* Free any cached object buffer associated with the commit.
142142
*/
143-
void free_commit_buffer(struct commit *);
143+
void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);
144144

145145
struct tree *get_commit_tree(const struct commit *);
146146
struct object_id *get_commit_tree_oid(const struct commit *);
@@ -149,7 +149,7 @@ struct object_id *get_commit_tree_oid(const struct commit *);
149149
* Release memory related to a commit, including the parent list and
150150
* any cached object buffer.
151151
*/
152-
void release_commit_memory(struct commit *c);
152+
void release_commit_memory(struct parsed_object_pool *pool, struct commit *c);
153153

154154
/*
155155
* Disassociate any cached object buffer from the commit, but do not free it.

object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ void parsed_object_pool_clear(struct parsed_object_pool *o)
540540
if (obj->type == OBJ_TREE)
541541
free_tree_buffer((struct tree*)obj);
542542
else if (obj->type == OBJ_COMMIT)
543-
release_commit_memory((struct commit*)obj);
543+
release_commit_memory(o, (struct commit*)obj);
544544
else if (obj->type == OBJ_TAG)
545545
release_tag_memory((struct tag*)obj);
546546
}

0 commit comments

Comments
 (0)