@@ -422,7 +422,7 @@ static const char *parse_alt_odb_entry(const char *string,
422422 return end ;
423423}
424424
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 ,
426426 const char * relative_base , int depth )
427427{
428428 struct strbuf objdirbuf = STRBUF_INIT ;
@@ -451,28 +451,18 @@ static void link_alt_odb_entries(const char *alt, int len, int sep,
451451
452452static void read_info_alternates (const char * relative_base , int depth )
453453{
454- char * map ;
455- size_t mapsz ;
456- struct stat st ;
457454 char * path ;
458- int fd ;
455+ struct strbuf buf = STRBUF_INIT ;
459456
460457 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+ free (path );
467460 return ;
468461 }
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 );
474462
475- munmap (map , mapsz );
463+ link_alt_odb_entries (buf .buf , '\n' , relative_base , depth );
464+ strbuf_release (& buf );
465+ free (path );
476466}
477467
478468struct alternate_object_database * alloc_alt_odb (const char * dir )
@@ -527,7 +517,7 @@ void add_to_alternates_file(const char *reference)
527517 if (commit_lock_file (lock ))
528518 die_errno ("unable to move new alternates file into place" );
529519 if (alt_odb_tail )
530- link_alt_odb_entries (reference , strlen ( reference ), '\n' , NULL , 0 );
520+ link_alt_odb_entries (reference , '\n' , NULL , 0 );
531521 }
532522 free (alts );
533523}
@@ -540,7 +530,7 @@ void add_to_alternates_memory(const char *reference)
540530 */
541531 prepare_alt_odb ();
542532
543- link_alt_odb_entries (reference , strlen ( reference ), '\n' , NULL , 0 );
533+ link_alt_odb_entries (reference , '\n' , NULL , 0 );
544534}
545535
546536/*
@@ -643,7 +633,7 @@ void prepare_alt_odb(void)
643633 if (!alt ) alt = "" ;
644634
645635 alt_odb_tail = & alt_odb_list ;
646- link_alt_odb_entries (alt , strlen ( alt ), PATH_SEP , NULL , 0 );
636+ link_alt_odb_entries (alt , PATH_SEP , NULL , 0 );
647637
648638 read_info_alternates (get_object_directory (), 0 );
649639}
0 commit comments