@@ -398,7 +398,7 @@ static const char *parse_alt_odb_entry(const char *string,
398
398
return end ;
399
399
}
400
400
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 ,
402
402
const char * relative_base , int depth )
403
403
{
404
404
struct strbuf objdirbuf = STRBUF_INIT ;
@@ -427,28 +427,19 @@ static void link_alt_odb_entries(const char *alt, int len, int sep,
427
427
428
428
static void read_info_alternates (const char * relative_base , int depth )
429
429
{
430
- char * map ;
431
- size_t mapsz ;
432
- struct stat st ;
433
430
char * path ;
434
- int fd ;
431
+ struct strbuf buf = STRBUF_INIT ;
435
432
436
433
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 );
443
437
return ;
444
438
}
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 );
450
439
451
- munmap (map , mapsz );
440
+ link_alt_odb_entries (buf .buf , '\n' , relative_base , depth );
441
+ strbuf_release (& buf );
442
+ free (path );
452
443
}
453
444
454
445
struct alternate_object_database * alloc_alt_odb (const char * dir )
@@ -503,7 +494,7 @@ void add_to_alternates_file(const char *reference)
503
494
if (commit_lock_file (lock ))
504
495
die_errno ("unable to move new alternates file into place" );
505
496
if (alt_odb_tail )
506
- link_alt_odb_entries (reference , strlen ( reference ), '\n' , NULL , 0 );
497
+ link_alt_odb_entries (reference , '\n' , NULL , 0 );
507
498
}
508
499
free (alts );
509
500
}
@@ -516,7 +507,7 @@ void add_to_alternates_memory(const char *reference)
516
507
*/
517
508
prepare_alt_odb ();
518
509
519
- link_alt_odb_entries (reference , strlen ( reference ), '\n' , NULL , 0 );
510
+ link_alt_odb_entries (reference , '\n' , NULL , 0 );
520
511
}
521
512
522
513
/*
@@ -619,7 +610,7 @@ void prepare_alt_odb(void)
619
610
if (!alt ) alt = "" ;
620
611
621
612
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 );
623
614
624
615
read_info_alternates (get_object_directory (), 0 );
625
616
}
0 commit comments