@matheusbsbs / matheus-bagliano / commits / 0f4dc14ac4
Fork 0

sha1_file.c: split has_loose_object() into local and non-local counterparts

Signed-off-by: Brandon Casey <drafnel@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Casey committed Nov 9, 2008 at 23:59 UTC 0f4dc14ac4945448f7309964afeb879d20408e07
2 files changed +14 -6
cache.h
+1
@@ -565,6 +565,7 @@ extern int move_temp_to_file(const char *tmpfile, const char *filename);
565
566 extern int has_sha1_pack(const unsigned char *sha1, const char **ignore);
567 extern int has_sha1_file(const unsigned char *sha1);
568 +extern int has_loose_object_nonlocal(const unsigned char *sha1);
569
570 extern int has_pack_file(const unsigned char *sha1);
571 extern int has_pack_index(const unsigned char *sha1);
sha1_file.c
+13 -6
@@ -410,23 +410,30 @@ void prepare_alt_odb(void)
410 read_info_alternates(get_object_directory(), 0);
411 }
412
413 -static int has_loose_object(const unsigned char *sha1)
413 +static int has_loose_object_local(const unsigned char *sha1)
414 {
415 char *name = sha1_file_name(sha1);
416 - struct alternate_object_database *alt;
416 + return !access(name, F_OK);
417 +}
418
418 - if (!access(name, F_OK))
419 - return 1;
419 +int has_loose_object_nonlocal(const unsigned char *sha1)
420 +{
421 + struct alternate_object_database *alt;
422 prepare_alt_odb();
423 for (alt = alt_odb_list; alt; alt = alt->next) {
422 - name = alt->name;
423 - fill_sha1_path(name, sha1);
424 + fill_sha1_path(alt->name, sha1);
425 if (!access(alt->base, F_OK))
426 return 1;
427 }
428 return 0;
429 }
430
431 +static int has_loose_object(const unsigned char *sha1)
432 +{
433 + return has_loose_object_local(sha1) ||
434 + has_loose_object_nonlocal(sha1);
435 +}
436 +
437 static unsigned int pack_used_ctr;
438 static unsigned int pack_mmap_calls;
439 static unsigned int peak_pack_open_windows;