Skip to content

Commit c529d75

Browse files
torvaldsgitster
authored andcommitted
Simplify and rename find_sha1_file()
Now that we've made the loose SHA1 file reading more careful and streamlined, we only use the old find_sha1_file() function for checking whether a loose object file exists at all. As such, the whole 'return stat information' part of it was just pointless (nobody cares any more), and the naming of the function is not really all that relevant either. So simplify it to not do a 'stat()', but just an existence check (which is what the callers want), and rename it to 'has_loose_object()' which matches the use. Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 44d1c19 commit c529d75

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

sha1_file.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -397,21 +397,21 @@ void prepare_alt_odb(void)
397397
read_info_alternates(get_object_directory(), 0);
398398
}
399399

400-
static char *find_sha1_file(const unsigned char *sha1, struct stat *st)
400+
static int has_loose_object(const unsigned char *sha1)
401401
{
402402
char *name = sha1_file_name(sha1);
403403
struct alternate_object_database *alt;
404404

405-
if (!stat(name, st))
406-
return name;
405+
if (!access(name, F_OK))
406+
return 1;
407407
prepare_alt_odb();
408408
for (alt = alt_odb_list; alt; alt = alt->next) {
409409
name = alt->name;
410410
fill_sha1_path(name, sha1);
411-
if (!stat(alt->base, st))
412-
return alt->base;
411+
if (!access(alt->base, F_OK))
412+
return 1;
413413
}
414-
return NULL;
414+
return 0;
415415
}
416416

417417
static unsigned int pack_used_ctr;
@@ -2232,14 +2232,13 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha
22322232

22332233
int force_object_loose(const unsigned char *sha1, time_t mtime)
22342234
{
2235-
struct stat st;
22362235
void *buf;
22372236
unsigned long len;
22382237
enum object_type type;
22392238
char hdr[32];
22402239
int hdrlen;
22412240

2242-
if (find_sha1_file(sha1, &st))
2241+
if (has_loose_object(sha1))
22432242
return 0;
22442243
buf = read_packed_sha1(sha1, &type, &len);
22452244
if (!buf)
@@ -2272,12 +2271,11 @@ int has_sha1_pack(const unsigned char *sha1, const char **ignore_packed)
22722271

22732272
int has_sha1_file(const unsigned char *sha1)
22742273
{
2275-
struct stat st;
22762274
struct pack_entry e;
22772275

22782276
if (find_pack_entry(sha1, &e, NULL))
22792277
return 1;
2280-
return find_sha1_file(sha1, &st) ? 1 : 0;
2278+
return has_loose_object(sha1);
22812279
}
22822280

22832281
int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object)

0 commit comments

Comments
 (0)