From: Junio C Hamano Date: Mon, 25 Jun 2018 20:22:38 +0000 (-0700) Subject: Merge branch 'sb/object-store-alloc' X-Git-Tag: v2.19.0-rc0~188 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=110240588d5c0ca88d3b55da52068f59d8d6367d;p=thirdparty%2Fgit.git Merge branch 'sb/object-store-alloc' The conversion to pass "the_repository" and then "a_repository" throughout the object access API continues. * sb/object-store-alloc: alloc: allow arbitrary repositories for alloc functions object: allow create_object to handle arbitrary repositories object: allow grow_object_hash to handle arbitrary repositories alloc: add repository argument to alloc_commit_index alloc: add repository argument to alloc_report alloc: add repository argument to alloc_object_node alloc: add repository argument to alloc_tag_node alloc: add repository argument to alloc_commit_node alloc: add repository argument to alloc_tree_node alloc: add repository argument to alloc_blob_node object: add repository argument to grow_object_hash object: add repository argument to create_object repository: introduce parsed objects field --- 110240588d5c0ca88d3b55da52068f59d8d6367d diff --cc alloc.c index e8ab14f4a1,714df63316..c2fc5d6888 --- a/alloc.c +++ b/alloc.c @@@ -80,21 -99,16 +99,18 @@@ void *alloc_object_node(struct reposito return obj; } - static struct alloc_state commit_state; - - unsigned int alloc_commit_index(void) + unsigned int alloc_commit_index(struct repository *r) { - static unsigned int count; - return count++; + return r->parsed_objects->commit_count++; } - void *alloc_commit_node(void) + void *alloc_commit_node(struct repository *r) { - struct commit *c = alloc_node(&commit_state, sizeof(struct commit)); + struct commit *c = alloc_node(r->parsed_objects->commit_state, sizeof(struct commit)); c->object.type = OBJ_COMMIT; - c->index = alloc_commit_index(); + c->index = alloc_commit_index(r); + c->graph_pos = COMMIT_NOT_FROM_GRAPH; + c->generation = GENERATION_NUMBER_INFINITY; return c; } diff --cc blame.c index ba1b33c7f4,3a11f1ce52..a5c9bd78ab --- a/blame.c +++ b/blame.c @@@ -6,24 -6,7 +6,25 @@@ #include "diffcore.h" #include "tag.h" #include "blame.h" + #include "alloc.h" +#include "commit-slab.h" + +define_commit_slab(blame_suspects, struct blame_origin *); +static struct blame_suspects blame_suspects; + +struct blame_origin *get_blame_suspects(struct commit *commit) +{ + struct blame_origin **result; + + result = blame_suspects_peek(&blame_suspects, commit); + + return result ? *result : NULL; +} + +static void set_blame_suspects(struct commit *commit, struct blame_origin *origin) +{ + *blame_suspects_at(&blame_suspects, commit) = origin; +} void blame_origin_decref(struct blame_origin *o) { diff --cc commit.c index 298ad747c6,5eb4d2f08f..0c3b75aeff --- a/commit.c +++ b/commit.c @@@ -309,22 -297,17 +311,33 @@@ void free_commit_buffer(struct commit * } } +struct tree *get_commit_tree(const struct commit *commit) +{ + if (commit->maybe_tree || !commit->object.parsed) + return commit->maybe_tree; + + if (commit->graph_pos == COMMIT_NOT_FROM_GRAPH) + BUG("commit has NULL tree, but was not loaded from commit-graph"); + + return get_commit_tree_in_graph(commit); +} + +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) + { - c->tree = NULL; ++ c->maybe_tree = NULL; + c->index = 0; + free_commit_buffer(c); + free_commit_list(c->parents); + /* TODO: what about commit->util? */ + + c->object.parsed = 0; + } + const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep) { struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit); diff --cc commit.h index cb943013d0,2d764ab7d8..3ad07c2e3d --- a/commit.h +++ b/commit.h @@@ -116,9 -99,12 +116,15 @@@ void unuse_commit_buffer(const struct c */ void free_commit_buffer(struct commit *); +struct tree *get_commit_tree(const struct commit *); +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); + /* * Disassociate any cached object buffer from the commit, but do not free it. * The buffer (or NULL, if none) is returned. diff --cc merge-recursive.c index 404f050caf,cbded673c2..bed4a5be02 --- a/merge-recursive.c +++ b/merge-recursive.c @@@ -160,10 -99,10 +161,10 @@@ static struct tree *shift_tree_object(s static struct commit *make_virtual_commit(struct tree *tree, const char *comment) { - struct commit *commit = alloc_commit_node(); + struct commit *commit = alloc_commit_node(the_repository); set_merge_remote_desc(commit, comment, (struct object *)commit); - commit->tree = tree; + commit->maybe_tree = tree; commit->object.parsed = 1; return commit; }