Merge branch 'bw/remote-curl-compressed-responses'
[gitweb.git] / commit-graph.c
index 264aa6d919bc3df71d189ff5fbddfc46231499f9..4c6127088ff96282fbcdc98ef5767281e52846e9 100644 (file)
@@ -9,6 +9,7 @@
 #include "revision.h"
 #include "sha1-lookup.h"
 #include "commit-graph.h"
+#include "object-store.h"
 
 #define GRAPH_SIGNATURE 0x43475048 /* "CGPH" */
 #define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
@@ -206,8 +207,10 @@ static void prepare_commit_graph(void)
 
        obj_dir = get_object_directory();
        prepare_commit_graph_one(obj_dir);
-       prepare_alt_odb();
-       for (alt = alt_odb_list; !commit_graph && alt; alt = alt->next)
+       prepare_alt_odb(the_repository);
+       for (alt = the_repository->objects->alt_odb_list;
+            !commit_graph && alt;
+            alt = alt->next)
                prepare_commit_graph_one(alt->path);
 }
 
@@ -247,7 +250,6 @@ static struct commit_list **insert_parent_or_die(struct commit_graph *g,
 
 static int fill_commit_in_graph(struct commit *item, struct commit_graph *g, uint32_t pos)
 {
-       struct object_id oid;
        uint32_t edge_value;
        uint32_t *parent_data_ptr;
        uint64_t date_low, date_high;
@@ -257,8 +259,7 @@ static int fill_commit_in_graph(struct commit *item, struct commit_graph *g, uin
        item->object.parsed = 1;
        item->graph_pos = pos;
 
-       hashcpy(oid.hash, commit_data);
-       item->maybe_tree = lookup_tree(&oid);
+       item->maybe_tree = NULL;
 
        date_high = get_be32(commit_data + g->hash_len + 8) & 0x3;
        date_low = get_be32(commit_data + g->hash_len + 12);
@@ -317,6 +318,28 @@ int parse_commit_in_graph(struct commit *item)
        return 0;
 }
 
+static struct tree *load_tree_for_commit(struct commit_graph *g, struct commit *c)
+{
+       struct object_id oid;
+       const unsigned char *commit_data = g->chunk_commit_data +
+                                          GRAPH_DATA_WIDTH * (c->graph_pos);
+
+       hashcpy(oid.hash, commit_data);
+       c->maybe_tree = lookup_tree(&oid);
+
+       return c->maybe_tree;
+}
+
+struct tree *get_commit_tree_in_graph(const struct commit *c)
+{
+       if (c->maybe_tree)
+               return c->maybe_tree;
+       if (c->graph_pos == COMMIT_NOT_FROM_GRAPH)
+               BUG("get_commit_tree_in_graph called from non-commit-graph commit");
+
+       return load_tree_for_commit(commit_graph, (struct commit *)c);
+}
+
 static void write_graph_chunk_fanout(struct hashfile *f,
                                     struct commit **commits,
                                     int nr_commits)
@@ -492,7 +515,7 @@ static int add_packed_commits(const struct object_id *oid,
        struct object_info oi = OBJECT_INFO_INIT;
 
        oi.typep = &type;
-       if (packed_object_info(pack, offset, &oi) < 0)
+       if (packed_object_info(the_repository, pack, offset, &oi) < 0)
                die("unable to get type of object %s", oid_to_hex(oid));
 
        if (type != OBJ_COMMIT)