@@ -422,7 +422,7 @@ static const char *parse_alt_odb_entry(const char *string,
422
422
return end ;
423
423
}
424
424
425
- static void link_alt_odb_entries (const char * alt , int len , int sep ,
425
+ static void link_alt_odb_entries (const char * alt , int sep ,
426
426
const char * relative_base , int depth )
427
427
{
428
428
struct strbuf objdirbuf = STRBUF_INIT ;
@@ -451,28 +451,19 @@ static void link_alt_odb_entries(const char *alt, int len, int sep,
451
451
452
452
static void read_info_alternates (const char * relative_base , int depth )
453
453
{
454
- char * map ;
455
- size_t mapsz ;
456
- struct stat st ;
457
454
char * path ;
458
- int fd ;
455
+ struct strbuf buf = STRBUF_INIT ;
459
456
460
457
path = xstrfmt ("%s/info/alternates" , relative_base );
461
- fd = git_open (path );
462
- free (path );
463
- if (fd < 0 )
464
- return ;
465
- if (fstat (fd , & st ) || (st .st_size == 0 )) {
466
- close (fd );
458
+ if (strbuf_read_file (& buf , path , 1024 ) < 0 ) {
459
+ warn_on_fopen_errors (path );
460
+ free (path );
467
461
return ;
468
462
}
469
- mapsz = xsize_t (st .st_size );
470
- map = xmmap (NULL , mapsz , PROT_READ , MAP_PRIVATE , fd , 0 );
471
- close (fd );
472
-
473
- link_alt_odb_entries (map , mapsz , '\n' , relative_base , depth );
474
463
475
- munmap (map , mapsz );
464
+ link_alt_odb_entries (buf .buf , '\n' , relative_base , depth );
465
+ strbuf_release (& buf );
466
+ free (path );
476
467
}
477
468
478
469
struct alternate_object_database * alloc_alt_odb (const char * dir )
@@ -527,7 +518,7 @@ void add_to_alternates_file(const char *reference)
527
518
if (commit_lock_file (lock ))
528
519
die_errno ("unable to move new alternates file into place" );
529
520
if (alt_odb_tail )
530
- link_alt_odb_entries (reference , strlen ( reference ), '\n' , NULL , 0 );
521
+ link_alt_odb_entries (reference , '\n' , NULL , 0 );
531
522
}
532
523
free (alts );
533
524
}
@@ -540,7 +531,7 @@ void add_to_alternates_memory(const char *reference)
540
531
*/
541
532
prepare_alt_odb ();
542
533
543
- link_alt_odb_entries (reference , strlen ( reference ), '\n' , NULL , 0 );
534
+ link_alt_odb_entries (reference , '\n' , NULL , 0 );
544
535
}
545
536
546
537
/*
@@ -643,7 +634,7 @@ void prepare_alt_odb(void)
643
634
if (!alt ) alt = "" ;
644
635
645
636
alt_odb_tail = & alt_odb_list ;
646
- link_alt_odb_entries (alt , strlen ( alt ), PATH_SEP , NULL , 0 );
637
+ link_alt_odb_entries (alt , PATH_SEP , NULL , 0 );
647
638
648
639
read_info_alternates (get_object_directory (), 0 );
649
640
}
0 commit comments