diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-09-20 11:33:06 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-09-20 11:33:06 +0900 |
commit | 0db625f5d69c9d1fb6ace137fc755887aef3049e (patch) | |
tree | 3699cdbe16ca7635b40c97fdd91860ad41b15f09 /sha1_file.c | |
parent | 94c9fd268d4287f6fbfef84793288479905a7e48 (diff) | |
parent | dc732bd5cb53c7f01a2bd3e4501320145e4b9498 (diff) | |
download | git-0db625f5d69c9d1fb6ace137fc755887aef3049e.tar.gz |
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
Diffstat (limited to 'sha1_file.c')
-rw-r--r-- | sha1_file.c | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/sha1_file.c b/sha1_file.c index 4fa4b185f3..a913865df8 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -422,7 +422,7 @@ static const char *parse_alt_odb_entry(const char *string, return end; } -static void link_alt_odb_entries(const char *alt, int len, int sep, +static void link_alt_odb_entries(const char *alt, int sep, const char *relative_base, int depth) { struct strbuf objdirbuf = STRBUF_INIT; @@ -451,28 +451,18 @@ static void link_alt_odb_entries(const char *alt, int len, int sep, 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) @@ -527,7 +517,7 @@ void add_to_alternates_file(const char *reference) if (commit_lock_file(lock)) die_errno("unable to move new alternates file into place"); if (alt_odb_tail) - link_alt_odb_entries(reference, strlen(reference), '\n', NULL, 0); + link_alt_odb_entries(reference, '\n', NULL, 0); } free(alts); } @@ -540,7 +530,7 @@ void add_to_alternates_memory(const char *reference) */ prepare_alt_odb(); - link_alt_odb_entries(reference, strlen(reference), '\n', NULL, 0); + link_alt_odb_entries(reference, '\n', NULL, 0); } /* @@ -643,7 +633,7 @@ void prepare_alt_odb(void) if (!alt) alt = ""; alt_odb_tail = &alt_odb_list; - link_alt_odb_entries(alt, strlen(alt), PATH_SEP, NULL, 0); + link_alt_odb_entries(alt, PATH_SEP, NULL, 0); read_info_alternates(get_object_directory(), 0); } |