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
+++ 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
+++ 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
+++ 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
+++ 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.
@@@ -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