@@ -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,18 @@ 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
+ free (path );
467
460
return ;
468
461
}
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
462
475
- munmap (map , mapsz );
463
+ link_alt_odb_entries (buf .buf , '\n' , relative_base , depth );
464
+ strbuf_release (& buf );
465
+ free (path );
476
466
}
477
467
478
468
struct alternate_object_database * alloc_alt_odb (const char * dir )
@@ -527,7 +517,7 @@ void add_to_alternates_file(const char *reference)
527
517
if (commit_lock_file (lock ))
528
518
die_errno ("unable to move new alternates file into place" );
529
519
if (alt_odb_tail )
530
- link_alt_odb_entries (reference , strlen ( reference ), '\n' , NULL , 0 );
520
+ link_alt_odb_entries (reference , '\n' , NULL , 0 );
531
521
}
532
522
free (alts );
533
523
}
@@ -540,7 +530,7 @@ void add_to_alternates_memory(const char *reference)
540
530
*/
541
531
prepare_alt_odb ();
542
532
543
- link_alt_odb_entries (reference , strlen ( reference ), '\n' , NULL , 0 );
533
+ link_alt_odb_entries (reference , '\n' , NULL , 0 );
544
534
}
545
535
546
536
/*
@@ -643,7 +633,7 @@ void prepare_alt_odb(void)
643
633
if (!alt ) alt = "" ;
644
634
645
635
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 );
647
637
648
638
read_info_alternates (get_object_directory (), 0 );
649
639
}
0 commit comments