diff.c: add set_sign to emit_line_0
[gitweb.git] / commit.c
index 41d233520981b76c9db648e3dcb1500b88040eb4..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)
@@ -261,18 +261,32 @@ struct commit_buffer {
        unsigned long size;
 };
 define_commit_slab(buffer_slab, struct commit_buffer);
-static struct buffer_slab buffer_slab = COMMIT_SLAB_INIT(1, buffer_slab);
 
-void set_commit_buffer_the_repository(struct commit *commit, void *buffer, unsigned long size)
+struct buffer_slab *allocate_commit_buffer_slab(void)
 {
-       struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);
+       struct buffer_slab *bs = xmalloc(sizeof(*bs));
+       init_buffer_slab(bs);
+       return bs;
+}
+
+void free_commit_buffer_slab(struct buffer_slab *bs)
+{
+       clear_buffer_slab(bs);
+       free(bs);
+}
+
+void set_commit_buffer(struct repository *r, struct commit *commit, void *buffer, unsigned long size)
+{
+       struct commit_buffer *v = buffer_slab_at(
+               r->parsed_objects->buffer_slab, commit);
        v->buffer = 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(&buffer_slab, commit);
+       struct commit_buffer *v = buffer_slab_peek(
+               r->parsed_objects->buffer_slab, commit);
        if (!v) {
                if (sizep)
                        *sizep = 0;
@@ -304,14 +318,16 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)
 
 void unuse_commit_buffer(const struct commit *commit, const void *buffer)
 {
-       struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+       struct commit_buffer *v = buffer_slab_peek(
+               the_repository->parsed_objects->buffer_slab, commit);
        if (!(v && v->buffer == buffer))
                free((void *)buffer);
 }
 
 void free_commit_buffer(struct commit *commit)
 {
-       struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+       struct commit_buffer *v = buffer_slab_peek(
+               the_repository->parsed_objects->buffer_slab, commit);
        if (v) {
                FREE_AND_NULL(v->buffer);
                v->size = 0;
@@ -326,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)
@@ -347,7 +363,8 @@ void release_commit_memory(struct commit *c)
 
 const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep)
 {
-       struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+       struct commit_buffer *v = buffer_slab_peek(
+               the_repository->parsed_objects->buffer_slab, commit);
        void *ret;
 
        if (!v) {
@@ -371,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;
@@ -421,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;
@@ -437,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)
@@ -449,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);
@@ -458,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))