Browse Source

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>
maint
Stefan Beller 6 years ago committed by Junio C Hamano
parent
commit
6a7895fd8a
  1. 3
      builtin/fsck.c
  2. 6
      builtin/log.c
  3. 3
      builtin/rev-list.c
  4. 9
      commit.c
  5. 4
      commit.h
  6. 2
      object.c

3
builtin/fsck.c

@ -382,7 +382,8 @@ out: @@ -382,7 +382,8 @@ out:
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;
}


6
builtin/log.c

@ -395,7 +395,8 @@ static int cmd_log_walk(struct rev_info *rev) @@ -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;
}
@ -1922,7 +1923,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) @@ -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

3
builtin/rev-list.c

@ -196,7 +196,8 @@ static void finish_commit(struct commit *commit, void *data) @@ -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)

9
commit.c

@ -328,10 +328,10 @@ void repo_unuse_commit_buffer(struct repository *r, @@ -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;
@ -354,13 +354,12 @@ struct object_id *get_commit_tree_oid(const struct commit *commit) @@ -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;
}

4
commit.h

@ -140,7 +140,7 @@ void repo_unuse_commit_buffer(struct repository *r, @@ -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 *);
@ -149,7 +149,7 @@ struct object_id *get_commit_tree_oid(const struct commit *); @@ -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.

2
object.c

@ -540,7 +540,7 @@ void parsed_object_pool_clear(struct parsed_object_pool *o) @@ -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);
}

Loading…
Cancel
Save