@@ -398,7 +398,7 @@ static const char *parse_alt_odb_entry(const char *string,
398398 return end ;
399399}
400400
401- static void link_alt_odb_entries (const char * alt , int len , int sep ,
401+ static void link_alt_odb_entries (const char * alt , int sep ,
402402 const char * relative_base , int depth )
403403{
404404 struct strbuf objdirbuf = STRBUF_INIT ;
@@ -427,28 +427,19 @@ static void link_alt_odb_entries(const char *alt, int len, int sep,
427427
428428static void read_info_alternates (const char * relative_base , int depth )
429429{
430- char * map ;
431- size_t mapsz ;
432- struct stat st ;
433430 char * path ;
434- int fd ;
431+ struct strbuf buf = STRBUF_INIT ;
435432
436433 path = xstrfmt ("%s/info/alternates" , relative_base );
437- fd = git_open (path );
438- free (path );
439- if (fd < 0 )
440- return ;
441- if (fstat (fd , & st ) || (st .st_size == 0 )) {
442- close (fd );
434+ if (strbuf_read_file (& buf , path , 1024 ) < 0 ) {
435+ warn_on_fopen_errors (path );
436+ free (path );
443437 return ;
444438 }
445- mapsz = xsize_t (st .st_size );
446- map = xmmap (NULL , mapsz , PROT_READ , MAP_PRIVATE , fd , 0 );
447- close (fd );
448-
449- link_alt_odb_entries (map , mapsz , '\n' , relative_base , depth );
450439
451- munmap (map , mapsz );
440+ link_alt_odb_entries (buf .buf , '\n' , relative_base , depth );
441+ strbuf_release (& buf );
442+ free (path );
452443}
453444
454445struct alternate_object_database * alloc_alt_odb (const char * dir )
@@ -503,7 +494,7 @@ void add_to_alternates_file(const char *reference)
503494 if (commit_lock_file (lock ))
504495 die_errno ("unable to move new alternates file into place" );
505496 if (alt_odb_tail )
506- link_alt_odb_entries (reference , strlen ( reference ), '\n' , NULL , 0 );
497+ link_alt_odb_entries (reference , '\n' , NULL , 0 );
507498 }
508499 free (alts );
509500}
@@ -516,7 +507,7 @@ void add_to_alternates_memory(const char *reference)
516507 */
517508 prepare_alt_odb ();
518509
519- link_alt_odb_entries (reference , strlen ( reference ), '\n' , NULL , 0 );
510+ link_alt_odb_entries (reference , '\n' , NULL , 0 );
520511}
521512
522513/*
@@ -619,7 +610,7 @@ void prepare_alt_odb(void)
619610 if (!alt ) alt = "" ;
620611
621612 alt_odb_tail = & alt_odb_list ;
622- link_alt_odb_entries (alt , strlen ( alt ), PATH_SEP , NULL , 0 );
613+ link_alt_odb_entries (alt , PATH_SEP , NULL , 0 );
623614
624615 read_info_alternates (get_object_directory (), 0 );
625616}
0 commit comments