From: Junio C Hamano Date: Wed, 20 Sep 2017 02:33:06 +0000 (+0900) Subject: Merge branch 'jk/info-alternates-fix-2.11' into jk/info-alternates-fix X-Git-Tag: v2.14.3~1^2~1 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/0db625f5d69c9d1fb6ace137fc755887aef3049e Merge branch 'jk/info-alternates-fix-2.11' into jk/info-alternates-fix * jk/info-alternates-fix-2.11: read_info_alternates: read contents into strbuf --- 0db625f5d69c9d1fb6ace137fc755887aef3049e diff --cc sha1_file.c index 4fa4b185f3,bfebf78707..a913865df8 --- a/sha1_file.c +++ b/sha1_file.c @@@ -449,30 -386,20 +449,20 @@@ static void link_alt_odb_entries(const strbuf_release(&objdirbuf); } -void read_info_alternates(const char * relative_base, int depth) +static void read_info_alternates(const char * relative_base, int depth) { - char *map; - size_t mapsz; - struct stat st; char *path; - int fd; + struct strbuf buf = STRBUF_INIT; path = xstrfmt("%s/info/alternates", relative_base); - fd = git_open(path); - free(path); - if (fd < 0) - return; - if (fstat(fd, &st) || (st.st_size == 0)) { - close(fd); + if (strbuf_read_file(&buf, path, 1024) < 0) { + free(path); return; } - mapsz = xsize_t(st.st_size); - map = xmmap(NULL, mapsz, PROT_READ, MAP_PRIVATE, fd, 0); - close(fd); - link_alt_odb_entries(map, mapsz, '\n', relative_base, depth); - - munmap(map, mapsz); + link_alt_odb_entries(buf.buf, '\n', relative_base, depth); + strbuf_release(&buf); + free(path); } struct alternate_object_database *alloc_alt_odb(const char *dir)