packfile: allow find_pack_entry to handle arbitrary repositories
[gitweb.git] / sha1_file.c
index 1fa32c8a0607d2769060e1265bac05bc3342a9a0..314ff55b4769a4262a76e3fa4c639f7d9c9f4b88 100644 (file)
@@ -929,10 +929,8 @@ static int open_sha1_file(struct repository *r,
  * Map the loose object at "path" if it is not NULL, or the path found by
  * searching for a loose object named "sha1".
  */
-#define map_sha1_file_1(r, p, s, si) map_sha1_file_1_##r(p, s, si)
-static void *map_sha1_file_1_the_repository(const char *path,
-                                           const unsigned char *sha1,
-                                           unsigned long *size)
+static void *map_sha1_file_1(struct repository *r, const char *path,
+                            const unsigned char *sha1, unsigned long *size)
 {
        void *map;
        int fd;
@@ -940,7 +938,7 @@ static void *map_sha1_file_1_the_repository(const char *path,
        if (path)
                fd = git_open(path);
        else
-               fd = open_sha1_file(the_repository, sha1, &path);
+               fd = open_sha1_file(r, sha1, &path);
        map = NULL;
        if (fd >= 0) {
                struct stat st;
@@ -959,9 +957,10 @@ static void *map_sha1_file_1_the_repository(const char *path,
        return map;
 }
 
-void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned long *size)
+void *map_sha1_file(struct repository *r,
+                   const unsigned char *sha1, unsigned long *size)
 {
-       return map_sha1_file_1(the_repository, NULL, sha1, size);
+       return map_sha1_file_1(r, NULL, sha1, size);
 }
 
 static int unpack_sha1_short_header(git_zstream *stream,
@@ -1150,10 +1149,9 @@ int parse_sha1_header(const char *hdr, unsigned long *sizep)
        return parse_sha1_header_extended(hdr, &oi, 0);
 }
 
-#define sha1_loose_object_info(r, s, o, f) sha1_loose_object_info_##r(s, o, f)
-static int sha1_loose_object_info_the_repository(const unsigned char *sha1,
-                                                struct object_info *oi,
-                                                int flags)
+static int sha1_loose_object_info(struct repository *r,
+                                 const unsigned char *sha1,
+                                 struct object_info *oi, int flags)
 {
        int status = 0;
        unsigned long mapsize;
@@ -1177,14 +1175,14 @@ static int sha1_loose_object_info_the_repository(const unsigned char *sha1,
        if (!oi->typep && !oi->typename && !oi->sizep && !oi->contentp) {
                const char *path;
                struct stat st;
-               if (stat_sha1_file(the_repository, sha1, &st, &path) < 0)
+               if (stat_sha1_file(r, sha1, &st, &path) < 0)
                        return -1;
                if (oi->disk_sizep)
                        *oi->disk_sizep = st.st_size;
                return 0;
        }
 
-       map = map_sha1_file(the_repository, sha1, &mapsize);
+       map = map_sha1_file(r, sha1, &mapsize);
        if (!map)
                return -1;
 
@@ -1268,7 +1266,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
        }
 
        while (1) {
-               if (find_pack_entry(real, &e))
+               if (find_pack_entry(the_repository, real, &e))
                        break;
 
                /* Most likely it's a loose object. */
@@ -1276,8 +1274,8 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi,
                        return 0;
 
                /* Not a loose object; someone else may have just packed it. */
-               reprepare_packed_git();
-               if (find_pack_entry(real, &e))
+               reprepare_packed_git(the_repository);
+               if (find_pack_entry(the_repository, real, &e))
                        break;
 
                /* Check if it is a missing object */
@@ -1657,7 +1655,7 @@ static int freshen_loose_object(const unsigned char *sha1)
 static int freshen_packed_object(const unsigned char *sha1)
 {
        struct pack_entry e;
-       if (!find_pack_entry(sha1, &e))
+       if (!find_pack_entry(the_repository, sha1, &e))
                return 0;
        if (e.p->freshened)
                return 1;