Skip to content

Commit

Permalink
commit: prepare free_commit_buffer and release_commit_memory for any …
Browse files Browse the repository at this point in the history
…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 <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
stefanbeller authored and gitster committed Dec 28, 2018
1 parent 4f542b7 commit 6a7895f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
3 changes: 2 additions & 1 deletion builtin/fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
if (obj->type == OBJ_TREE)
free_tree_buffer((struct tree *)obj);
if (obj->type == OBJ_COMMIT)
free_commit_buffer((struct commit *)obj);
free_commit_buffer(the_repository->parsed_objects,
(struct commit *)obj);
return err;
}

Expand Down
6 changes: 4 additions & 2 deletions builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ static int cmd_log_walk(struct rev_info *rev)
* We may show a given commit multiple times when
* walking the reflogs.
*/
free_commit_buffer(commit);
free_commit_buffer(the_repository->parsed_objects,
commit);
free_commit_list(commit->parents);
commit->parents = NULL;
}
Expand Down Expand Up @@ -1922,7 +1923,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
open_next_file(rev.numbered_files ? NULL : commit, NULL, &rev, quiet))
die(_("Failed to create output files"));
shown = log_tree_commit(&rev, commit);
free_commit_buffer(commit);
free_commit_buffer(the_repository->parsed_objects,
commit);

/* We put one extra blank line between formatted
* patches and this flag is used by log-tree code
Expand Down
3 changes: 2 additions & 1 deletion builtin/rev-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ static void finish_commit(struct commit *commit, void *data)
free_commit_list(commit->parents);
commit->parents = NULL;
}
free_commit_buffer(commit);
free_commit_buffer(the_repository->parsed_objects,
commit);
}

static inline void finish_object__ma(struct object *obj)
Expand Down
9 changes: 4 additions & 5 deletions commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,10 @@ void repo_unuse_commit_buffer(struct repository *r,
free((void *)buffer);
}

void free_commit_buffer(struct commit *commit)
void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)
{
struct commit_buffer *v = buffer_slab_peek(
the_repository->parsed_objects->buffer_slab, commit);
pool->buffer_slab, commit);
if (v) {
FREE_AND_NULL(v->buffer);
v->size = 0;
Expand All @@ -354,13 +354,12 @@ struct object_id *get_commit_tree_oid(const struct commit *commit)
return &get_commit_tree(commit)->object.oid;
}

void release_commit_memory(struct commit *c)
void release_commit_memory(struct parsed_object_pool *pool, struct commit *c)
{
c->maybe_tree = NULL;
c->index = 0;
free_commit_buffer(c);
free_commit_buffer(pool, c);
free_commit_list(c->parents);
/* TODO: what about commit->util? */

c->object.parsed = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void repo_unuse_commit_buffer(struct repository *r,
/*
* Free any cached object buffer associated with the commit.
*/
void free_commit_buffer(struct commit *);
void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);

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

/*
* Disassociate any cached object buffer from the commit, but do not free it.
Expand Down
2 changes: 1 addition & 1 deletion object.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ void parsed_object_pool_clear(struct parsed_object_pool *o)
if (obj->type == OBJ_TREE)
free_tree_buffer((struct tree*)obj);
else if (obj->type == OBJ_COMMIT)
release_commit_memory((struct commit*)obj);
release_commit_memory(o, (struct commit*)obj);
else if (obj->type == OBJ_TAG)
release_tag_memory((struct tag*)obj);
}
Expand Down

0 comments on commit 6a7895f

Please sign in to comment.