sha1_file: add repository argument to stat_sha1_file

Add a repository argument to allow the stat_sha1_file caller to be more specific about which repository to act on. 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. 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 fbe33e2798fdbd7feac2d19c68e1a9c447e337c0
1 file changed +5 -4
sha1_file.c
+5 -4
@@ -867,8 +867,9 @@ int git_open_cloexec(const char *name, int flags)
867 * Note that it may point to static storage and is only valid until another
868 * call to sha1_file_name(), etc.
869 */
870 -static int stat_sha1_file(const unsigned char *sha1, struct stat *st,
871 - const char **path)
870 +#define stat_sha1_file(r, s, st, p) stat_sha1_file_##r(s, st, p)
871 +static int stat_sha1_file_the_repository(const unsigned char *sha1,
872 + struct stat *st, const char **path)
873 {
874 struct alternate_object_database *alt;
875 static struct strbuf buf = STRBUF_INIT;
@@ -1174,7 +1175,7 @@ static int sha1_loose_object_info(const unsigned char *sha1,
1175 if (!oi->typep && !oi->typename && !oi->sizep && !oi->contentp) {
1176 const char *path;
1177 struct stat st;
1177 - if (stat_sha1_file(sha1, &st, &path) < 0)
1178 + if (stat_sha1_file(the_repository, sha1, &st, &path) < 0)
1179 return -1;
1180 if (oi->disk_sizep)
1181 *oi->disk_sizep = st.st_size;
@@ -1388,7 +1389,7 @@ void *read_sha1_file_extended(const unsigned char *sha1,
1389 die("replacement %s not found for %s",
1390 sha1_to_hex(repl), sha1_to_hex(sha1));
1391
1391 - if (!stat_sha1_file(repl, &st, &path))
1392 + if (!stat_sha1_file(the_repository, repl, &st, &path))
1393 die("loose object %s (stored in %s) is corrupt",
1394 sha1_to_hex(repl), path);
1395