Merge branch 'sb/object-store-alloc'
authorJunio C Hamano <gitster@pobox.com>
Mon, 25 Jun 2018 20:22:38 +0000 (13:22 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 25 Jun 2018 20:22:38 +0000 (13:22 -0700)
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

1  2 
alloc.c
blame.c
cache.h
commit.c
commit.h
merge-recursive.c
object.c
object.h
repository.c
repository.h
tree.c
diff --cc alloc.c
index e8ab14f4a12bc65eb32152192af1faf719e3423c,714df633169df5a2502b27474192c59b24b336a3..c2fc5d68886bf3f74a1f013a3a36c7b5dcad2258
+++ 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 ba1b33c7f4e92c432d4cbdcb43b8d061e436f027,3a11f1ce52baebfedbd6ff11633a402eca2b2745..a5c9bd78ab09ce1d1ce40f82ccf13fcc8d973eec
+++ 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 cache.h
Simple merge
diff --cc commit.c
index 298ad747c6e0d8b1e800b5e643ab0fa6f67cd491,5eb4d2f08f8d093e871072035b0ad8024e583cba..0c3b75aeffea75956adf2190e763b0d753c848c5
+++ b/commit.c
@@@ -309,22 -297,17 +311,33 @@@ void free_commit_buffer(struct commit *
        }
  }
  
 -      c->tree = NULL;
 +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->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 cb943013d06a58f2e0427a33f5ab718df23e730f,2d764ab7d8e63536e06a83d78a13952fc8b7ebbe..3ad07c2e3d092a97e3bc20091566f4b967b6bc8c
+++ 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.
index 404f050cafe919023ec86d14230a0f6455714538,cbded673c282fd888f239202878ad452e18a3cdf..bed4a5be02404ef512ba5cfcd9bb33ac04a4ca47
@@@ -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;
  }
diff --cc object.c
Simple merge
diff --cc object.h
Simple merge
diff --cc repository.c
Simple merge
diff --cc repository.h
Simple merge
diff --cc tree.c
Simple merge