Merge branch 'jk/allow-fetch-onelevel-refname'
[gitweb.git] / diffcore-order.c
index 23e93852d8c701760d56e7e728dba7c08367fbe8..fe7f1f4647a16a5882cc4c1e63738c7faa4bc677 100644 (file)
@@ -10,28 +10,21 @@ static int order_cnt;
 
 static void prepare_order(const char *orderfile)
 {
-       int fd, cnt, pass;
+       int cnt, pass;
+       struct strbuf sb = STRBUF_INIT;
        void *map;
        char *cp, *endp;
-       struct stat st;
-       size_t sz;
+       ssize_t sz;
 
        if (order)
                return;
 
-       fd = open(orderfile, O_RDONLY);
-       if (fd < 0)
-               return;
-       if (fstat(fd, &st)) {
-               close(fd);
-               return;
-       }
-       sz = xsize_t(st.st_size);
-       map = mmap(NULL, sz, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
-       close(fd);
-       if (map == MAP_FAILED)
-               return;
+       sz = strbuf_read_file(&sb, orderfile, 0);
+       if (sz < 0)
+               die_errno(_("failed to read orderfile '%s'"), orderfile);
+       map = strbuf_detach(&sb, NULL);
        endp = (char *) map + sz;
+
        for (pass = 0; pass < 2; pass++) {
                cnt = 0;
                cp = map;
@@ -73,15 +66,16 @@ struct pair_order {
 static int match_order(const char *path)
 {
        int i;
-       char p[PATH_MAX];
+       static struct strbuf p = STRBUF_INIT;
 
        for (i = 0; i < order_cnt; i++) {
-               strcpy(p, path);
-               while (p[0]) {
+               strbuf_reset(&p);
+               strbuf_addstr(&p, path);
+               while (p.buf[0]) {
                        char *cp;
-                       if (!fnmatch(order[i], p, 0))
+                       if (!fnmatch(order[i], p.buf, 0))
                                return i;
-                       cp = strrchr(p, '/');
+                       cp = strrchr(p.buf, '/');
                        if (!cp)
                                break;
                        *cp = 0;