pack-objects: refactor code into compute_layer_order()
[gitweb.git] / commit.c
index dd8c9c15b1453a999c024623b8141453732c4877..30d1af2b20660de99bed06486c11d1aef3763849 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -24,21 +24,21 @@ int save_commit_buffer = 1;
 
 const char *commit_type = "commit";
 
-struct commit *lookup_commit_reference_gently_the_repository(
+struct commit *lookup_commit_reference_gently(struct repository *r,
                const struct object_id *oid, int quiet)
 {
-       struct object *obj = deref_tag(the_repository,
-                                      parse_object(the_repository, oid),
+       struct object *obj = deref_tag(r,
+                                      parse_object(r, oid),
                                       NULL, 0);
 
        if (!obj)
                return NULL;
-       return object_as_type(the_repository, obj, OBJ_COMMIT, quiet);
+       return object_as_type(r, obj, OBJ_COMMIT, quiet);
 }
 
-struct commit *lookup_commit_reference_the_repository(const struct object_id *oid)
+struct commit *lookup_commit_reference(struct repository *r, const struct object_id *oid)
 {
-       return lookup_commit_reference_gently(the_repository, oid, 0);
+       return lookup_commit_reference_gently(r, oid, 0);
 }
 
 struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name)
@@ -283,10 +283,10 @@ void set_commit_buffer(struct repository *r, struct commit *commit, void *buffer
        v->size = size;
 }
 
-const void *get_cached_commit_buffer_the_repository(const struct commit *commit, unsigned long *sizep)
+const void *get_cached_commit_buffer(struct repository *r, const struct commit *commit, unsigned long *sizep)
 {
        struct commit_buffer *v = buffer_slab_peek(
-               the_repository->parsed_objects->buffer_slab, commit);
+               r->parsed_objects->buffer_slab, commit);
        if (!v) {
                if (sizep)
                        *sizep = 0;
@@ -342,7 +342,7 @@ struct tree *get_commit_tree(const struct commit *commit)
        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);
+       return get_commit_tree_in_graph(the_repository, commit);
 }
 
 struct object_id *get_commit_tree_oid(const struct commit *commit)
@@ -388,8 +388,8 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b
        struct object_id parent;
        struct commit_list **pptr;
        struct commit_graft *graft;
-       const int tree_entry_len = GIT_SHA1_HEXSZ + 5;
-       const int parent_entry_len = GIT_SHA1_HEXSZ + 7;
+       const int tree_entry_len = the_hash_algo->hexsz + 5;
+       const int parent_entry_len = the_hash_algo->hexsz + 7;
 
        if (item->object.parsed)
                return 0;
@@ -438,12 +438,12 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b
        item->date = parse_commit_date(bufptr, tail);
 
        if (check_graph)
-               load_commit_graph_info(item);
+               load_commit_graph_info(the_repository, item);
 
        return 0;
 }
 
-int parse_commit_gently(struct commit *item, int quiet_on_missing)
+int parse_commit_internal(struct commit *item, int quiet_on_missing, int use_commit_graph)
 {
        enum object_type type;
        void *buffer;
@@ -454,7 +454,7 @@ int parse_commit_gently(struct commit *item, int quiet_on_missing)
                return -1;
        if (item->object.parsed)
                return 0;
-       if (parse_commit_in_graph(item))
+       if (use_commit_graph && parse_commit_in_graph(the_repository, item))
                return 0;
        buffer = read_object_file(&item->object.oid, &type, &size);
        if (!buffer)
@@ -466,6 +466,7 @@ int parse_commit_gently(struct commit *item, int quiet_on_missing)
                return error("Object %s not a commit",
                             oid_to_hex(&item->object.oid));
        }
+
        ret = parse_commit_buffer(the_repository, item, buffer, size, 0);
        if (save_commit_buffer && !ret) {
                set_commit_buffer(the_repository, item, buffer, size);
@@ -475,6 +476,11 @@ int parse_commit_gently(struct commit *item, int quiet_on_missing)
        return ret;
 }
 
+int parse_commit_gently(struct commit *item, int quiet_on_missing)
+{
+       return parse_commit_internal(item, quiet_on_missing, 1);
+}
+
 void parse_commit_or_die(struct commit *item)
 {
        if (parse_commit(item))