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 <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Linus Torvalds committed
Jun 14, 2008 at 11:43 UTC
c529d75a75adf943f53dd20b8cf3e37438b4e750
1 file changed
+8
-10
sha1_file.c
+8
-10
@@ -397,21 +397,21 @@ void prepare_alt_odb(void)
397
read_info_alternates(get_object_directory(), 0);
398
}
399
400
-static char *find_sha1_file(const unsigned char *sha1, struct stat *st)
400
+static int has_loose_object(const unsigned char *sha1)
401
{
402
char *name = sha1_file_name(sha1);
403
struct alternate_object_database *alt;
404
405
- if (!stat(name, st))
406
- return name;
405
+ if (!access(name, F_OK))
406
+ return 1;
407
prepare_alt_odb();
408
for (alt = alt_odb_list; alt; alt = alt->next) {
409
name = alt->name;
410
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;
413
}
414
- return NULL;
414
+ return 0;
415
}
416
417
static unsigned int pack_used_ctr;
@@ -2232,14 +2232,13 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha
2232
2233
int force_object_loose(const unsigned char *sha1, time_t mtime)
2234
{
2235
- struct stat st;
2235
void *buf;
2236
unsigned long len;
2237
enum object_type type;
2238
char hdr[32];
2239
int hdrlen;
2240
2242
- if (find_sha1_file(sha1, &st))
2241
+ if (has_loose_object(sha1))
2242
return 0;
2243
buf = read_packed_sha1(sha1, &type, &len);
2244
if (!buf)
@@ -2272,12 +2271,11 @@ int has_sha1_pack(const unsigned char *sha1, const char **ignore_packed)
2271
2272
int has_sha1_file(const unsigned char *sha1)
2273
{
2275
- struct stat st;
2274
struct pack_entry e;
2275
2276
if (find_pack_entry(sha1, &e, NULL))
2277
return 1;
2280
- return find_sha1_file(sha1, &st) ? 1 : 0;
2278
+ return has_loose_object(sha1);
2279
}
2280
2281
int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object)