cache: convert get_graft_file to handle arbitrary repositories
[gitweb.git] / commit.c
index a0400b93a1e3dfa320040a684297f43b30a8ea78..24028fd257a661734a60d86f748517fca7fa7a94 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -104,38 +104,38 @@ static const unsigned char *commit_graft_sha1_access(size_t index, void *table)
        return commit_graft_table[index]->oid.hash;
 }
 
-#define commit_graft_pos(r, s) commit_graft_pos_##r(s)
-static int commit_graft_pos_the_repository(const unsigned char *sha1)
+static int commit_graft_pos(struct repository *r, const unsigned char *sha1)
 {
-       return sha1_pos(sha1, the_repository->parsed_objects->grafts,
-                       the_repository->parsed_objects->grafts_nr,
+       return sha1_pos(sha1, r->parsed_objects->grafts,
+                       r->parsed_objects->grafts_nr,
                        commit_graft_sha1_access);
 }
 
-int register_commit_graft_the_repository(struct commit_graft *graft, int ignore_dups)
+int register_commit_graft(struct repository *r, struct commit_graft *graft,
+                         int ignore_dups)
 {
-       int pos = commit_graft_pos(the_repository, graft->oid.hash);
+       int pos = commit_graft_pos(r, graft->oid.hash);
 
        if (0 <= pos) {
                if (ignore_dups)
                        free(graft);
                else {
-                       free(the_repository->parsed_objects->grafts[pos]);
-                       the_repository->parsed_objects->grafts[pos] = graft;
+                       free(r->parsed_objects->grafts[pos]);
+                       r->parsed_objects->grafts[pos] = graft;
                }
                return 1;
        }
        pos = -pos - 1;
-       ALLOC_GROW(the_repository->parsed_objects->grafts,
-                  the_repository->parsed_objects->grafts_nr + 1,
-                  the_repository->parsed_objects->grafts_alloc);
-       the_repository->parsed_objects->grafts_nr++;
-       if (pos < the_repository->parsed_objects->grafts_nr)
-               memmove(the_repository->parsed_objects->grafts + pos + 1,
-                       the_repository->parsed_objects->grafts + pos,
-                       (the_repository->parsed_objects->grafts_nr - pos - 1) *
-                       sizeof(*the_repository->parsed_objects->grafts));
-       the_repository->parsed_objects->grafts[pos] = graft;
+       ALLOC_GROW(r->parsed_objects->grafts,
+                  r->parsed_objects->grafts_nr + 1,
+                  r->parsed_objects->grafts_alloc);
+       r->parsed_objects->grafts_nr++;
+       if (pos < r->parsed_objects->grafts_nr)
+               memmove(r->parsed_objects->grafts + pos + 1,
+                       r->parsed_objects->grafts + pos,
+                       (r->parsed_objects->grafts_nr - pos - 1) *
+                       sizeof(*r->parsed_objects->grafts));
+       r->parsed_objects->grafts[pos] = graft;
        return 0;
 }
 
@@ -177,8 +177,7 @@ struct commit_graft *read_graft_line(struct strbuf *line)
        return NULL;
 }
 
-#define read_graft_file(r, f) read_graft_file_##r(f)
-static int read_graft_file_the_repository(const char *graft_file)
+static int read_graft_file(struct repository *r, const char *graft_file)
 {
        FILE *fp = fopen_or_warn(graft_file, "r");
        struct strbuf buf = STRBUF_INIT;
@@ -189,7 +188,7 @@ static int read_graft_file_the_repository(const char *graft_file)
                struct commit_graft *graft = read_graft_line(&buf);
                if (!graft)
                        continue;
-               if (register_commit_graft(the_repository, graft, 1))
+               if (register_commit_graft(r, graft, 1))
                        error("duplicate graft data: %s", buf.buf);
        }
        fclose(fp);
@@ -205,14 +204,14 @@ static void prepare_commit_graft_the_repository(void)
 
        if (commit_graft_prepared)
                return;
-       graft_file = get_graft_file();
+       graft_file = get_graft_file(the_repository);
        read_graft_file(the_repository, graft_file);
        /* make sure shallows are read */
-       is_repository_shallow();
+       is_repository_shallow(the_repository);
        commit_graft_prepared = 1;
 }
 
-struct commit_graft *lookup_commit_graft(const struct object_id *oid)
+struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid)
 {
        int pos;
        prepare_commit_graft(the_repository);
@@ -359,7 +358,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
        bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
        pptr = &item->parents;
 
-       graft = lookup_commit_graft(&item->object.oid);
+       graft = lookup_commit_graft(the_repository, &item->object.oid);
        while (bufptr + parent_entry_len < tail && !memcmp(bufptr, "parent ", 7)) {
                struct commit *new_parent;