Skip to content

Commit 0f4dc14

Browse files
drafnelgitster
authored andcommitted
sha1_file.c: split has_loose_object() into local and non-local counterparts
Signed-off-by: Brandon Casey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c3df42 commit 0f4dc14

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ extern int move_temp_to_file(const char *tmpfile, const char *filename);
565565

566566
extern int has_sha1_pack(const unsigned char *sha1, const char **ignore);
567567
extern int has_sha1_file(const unsigned char *sha1);
568+
extern int has_loose_object_nonlocal(const unsigned char *sha1);
568569

569570
extern int has_pack_file(const unsigned char *sha1);
570571
extern int has_pack_index(const unsigned char *sha1);

sha1_file.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,23 +410,30 @@ void prepare_alt_odb(void)
410410
read_info_alternates(get_object_directory(), 0);
411411
}
412412

413-
static int has_loose_object(const unsigned char *sha1)
413+
static int has_loose_object_local(const unsigned char *sha1)
414414
{
415415
char *name = sha1_file_name(sha1);
416-
struct alternate_object_database *alt;
416+
return !access(name, F_OK);
417+
}
417418

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;
420422
prepare_alt_odb();
421423
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);
424425
if (!access(alt->base, F_OK))
425426
return 1;
426427
}
427428
return 0;
428429
}
429430

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+
430437
static unsigned int pack_used_ctr;
431438
static unsigned int pack_mmap_calls;
432439
static unsigned int peak_pack_open_windows;

0 commit comments

Comments
 (0)