OSDN Git Service

Merge branch 'jk/info-alternates-fix-2.11' into jk/info-alternates-fix
authorJunio C Hamano <gitster@pobox.com>
Wed, 20 Sep 2017 02:33:06 +0000 (11:33 +0900)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 Sep 2017 02:33:06 +0000 (11:33 +0900)
* jk/info-alternates-fix-2.11:
  read_info_alternates: read contents into strbuf

1  2 
sha1_file.c

diff --cc 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)