object-store: prepare has_{sha1, object}_file to handle any repo

Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Nov 13, 2018 at 16:12 UTC 9b45f499818f505f8f7797c6d8f63a3bdccfa95f
3 files changed +56 -11
contrib/coccinelle/the_repository.pending.cocci
+30
@@ -10,3 +10,33 @@ expression G;
10 - read_object_file(
11 + repo_read_object_file(the_repository,
12 E, F, G)
13 +
14 +@@
15 +expression E;
16 +@@
17 +- has_sha1_file(
18 ++ repo_has_sha1_file(the_repository,
19 + E)
20 +
21 +@@
22 +expression E;
23 +expression F;
24 +@@
25 +- has_sha1_file_with_flags(
26 ++ repo_has_sha1_file_with_flags(the_repository,
27 + E)
28 +
29 +@@
30 +expression E;
31 +@@
32 +- has_object_file(
33 ++ repo_has_object_file(the_repository,
34 + E)
35 +
36 +@@
37 +expression E;
38 +expression F;
39 +@@
40 +- has_object_file_with_flags(
41 ++ repo_has_object_file_with_flags(the_repository,
42 + E)
object-store.h
+17 -5
@@ -212,15 +212,27 @@ int read_loose_object(const char *path,
212 * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass
213 * nonzero flags to also set other flags.
214 */
215 -extern int has_sha1_file_with_flags(const unsigned char *sha1, int flags);
216 -static inline int has_sha1_file(const unsigned char *sha1)
215 +int repo_has_sha1_file_with_flags(struct repository *r,
216 + const unsigned char *sha1, int flags);
217 +static inline int repo_has_sha1_file(struct repository *r,
218 + const unsigned char *sha1)
219 {
218 - return has_sha1_file_with_flags(sha1, 0);
220 + return repo_has_sha1_file_with_flags(r, sha1, 0);
221 }
222
223 +#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
224 +#define has_sha1_file_with_flags(sha1, flags) repo_has_sha1_file_with_flags(the_repository, sha1, flags)
225 +#define has_sha1_file(sha1) repo_has_sha1_file(the_repository, sha1)
226 +#endif
227 +
228 /* Same as the above, except for struct object_id. */
222 -extern int has_object_file(const struct object_id *oid);
223 -extern int has_object_file_with_flags(const struct object_id *oid, int flags);
229 +int repo_has_object_file(struct repository *r, const struct object_id *oid);
230 +int repo_has_object_file_with_flags(struct repository *r,
231 + const struct object_id *oid, int flags);
232 +#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
233 +#define has_object_file(oid) repo_has_object_file(the_repository, oid)
234 +#define has_object_file_with_flags(oid, flags) repo_has_object_file_with_flags(the_repository, oid, flags)
235 +#endif
236
237 /*
238 * Return true iff an alternate object database has a loose object
sha1-file.c
+9 -6
@@ -1768,24 +1768,27 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
1768 return ret;
1769 }
1770
1771 -int has_sha1_file_with_flags(const unsigned char *sha1, int flags)
1771 +int repo_has_sha1_file_with_flags(struct repository *r,
1772 + const unsigned char *sha1, int flags)
1773 {
1774 struct object_id oid;
1775 if (!startup_info->have_repository)
1776 return 0;
1777 hashcpy(oid.hash, sha1);
1777 - return oid_object_info_extended(the_repository, &oid, NULL,
1778 + return oid_object_info_extended(r, &oid, NULL,
1779 flags | OBJECT_INFO_SKIP_CACHED) >= 0;
1780 }
1781
1781 -int has_object_file(const struct object_id *oid)
1782 +int repo_has_object_file(struct repository *r,
1783 + const struct object_id *oid)
1784 {
1783 - return has_sha1_file(oid->hash);
1785 + return repo_has_sha1_file(r, oid->hash);
1786 }
1787
1786 -int has_object_file_with_flags(const struct object_id *oid, int flags)
1788 +int repo_has_object_file_with_flags(struct repository *r,
1789 + const struct object_id *oid, int flags)
1790 {
1788 - return has_sha1_file_with_flags(oid->hash, flags);
1791 + return repo_has_sha1_file_with_flags(r, oid->hash, flags);
1792 }
1793
1794 static void check_tree(const void *buf, size_t size)