sha1_file: add repository argument to map_sha1_file

Add a repository argument to allow map_sha1_file callers to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet. As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time. While at it, move the declaration to object-store.h, where it should be easier to find. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Mar 23, 2018 at 18:21 UTC e35454fa622dc5978100ad0aa5fa85dc02aa6a43
4 files changed +9 -4
cache.h
-1
@@ -1242,7 +1242,6 @@ extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned c
1242 extern int force_object_loose(const unsigned char *sha1, time_t mtime);
1243 extern int git_open_cloexec(const char *name, int flags);
1244 #define git_open(name) git_open_cloexec(name, O_RDONLY)
1245 -extern void *map_sha1_file(const unsigned char *sha1, unsigned long *size);
1245 extern int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);
1246 extern int parse_sha1_header(const char *hdr, unsigned long *sizep);
1247
object-store.h
+3
@@ -128,4 +128,7 @@ void raw_object_store_clear(struct raw_object_store *o);
128 #define sha1_file_name(r, b, s) sha1_file_name_##r(b, s)
129 void sha1_file_name_the_repository(struct strbuf *buf, const unsigned char *sha1);
130
131 +#define map_sha1_file(r, s, sz) map_sha1_file_##r(s, sz)
132 +void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned long *size);
133 +
134 #endif /* OBJECT_STORE_H */
sha1_file.c
+2 -2
@@ -961,7 +961,7 @@ static void *map_sha1_file_1_the_repository(const char *path,
961 return map;
962 }
963
964 -void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
964 +void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned long *size)
965 {
966 return map_sha1_file_1(the_repository, NULL, sha1, size);
967 }
@@ -1185,7 +1185,7 @@ static int sha1_loose_object_info(const unsigned char *sha1,
1185 return 0;
1186 }
1187
1188 - map = map_sha1_file(sha1, &mapsize);
1188 + map = map_sha1_file(the_repository, sha1, &mapsize);
1189 if (!map)
1190 return -1;
1191
streaming.c
+4 -1
@@ -3,6 +3,8 @@
3 */
4 #include "cache.h"
5 #include "streaming.h"
6 +#include "repository.h"
7 +#include "object-store.h"
8 #include "packfile.h"
9
10 enum input_source {
@@ -335,7 +337,8 @@ static struct stream_vtbl loose_vtbl = {
337
338 static open_method_decl(loose)
339 {
338 - st->u.loose.mapped = map_sha1_file(sha1, &st->u.loose.mapsize);
340 + st->u.loose.mapped = map_sha1_file(the_repository,
341 + sha1, &st->u.loose.mapsize);
342 if (!st->u.loose.mapped)
343 return -1;
344 if ((unpack_sha1_header(&st->z,