Skip to content

Commit 9b45f49

Browse files
stefanbellergitster
authored andcommitted
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>
1 parent afd69dc commit 9b45f49

File tree

3 files changed

+56
-11
lines changed

3 files changed

+56
-11
lines changed

contrib/coccinelle/the_repository.pending.cocci

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,33 @@ expression G;
1010
- read_object_file(
1111
+ repo_read_object_file(the_repository,
1212
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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,27 @@ int read_loose_object(const char *path,
212212
* object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass
213213
* nonzero flags to also set other flags.
214214
*/
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)
217219
{
218-
return has_sha1_file_with_flags(sha1, 0);
220+
return repo_has_sha1_file_with_flags(r, sha1, 0);
219221
}
220222

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+
221228
/* 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
224236

225237
/*
226238
* Return true iff an alternate object database has a loose object

sha1-file.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,24 +1768,27 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
17681768
return ret;
17691769
}
17701770

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)
17721773
{
17731774
struct object_id oid;
17741775
if (!startup_info->have_repository)
17751776
return 0;
17761777
hashcpy(oid.hash, sha1);
1777-
return oid_object_info_extended(the_repository, &oid, NULL,
1778+
return oid_object_info_extended(r, &oid, NULL,
17781779
flags | OBJECT_INFO_SKIP_CACHED) >= 0;
17791780
}
17801781

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)
17821784
{
1783-
return has_sha1_file(oid->hash);
1785+
return repo_has_sha1_file(r, oid->hash);
17841786
}
17851787

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)
17871790
{
1788-
return has_sha1_file_with_flags(oid->hash, flags);
1791+
return repo_has_sha1_file_with_flags(r, oid->hash, flags);
17891792
}
17901793

17911794
static void check_tree(const void *buf, size_t size)

0 commit comments

Comments
 (0)