mergetool: Add a test for running mergetool in a sub-directory
[gitweb.git] / diffcore-order.c
index b38122361f837e2e2577a89ae7aec311730b7f10..23e93852d8c701760d56e7e728dba7c08367fbe8 100644 (file)
@@ -4,7 +4,6 @@
 #include "cache.h"
 #include "diff.h"
 #include "diffcore.h"
-#include <fnmatch.h>
 
 static char **order;
 static int order_cnt;
@@ -15,6 +14,7 @@ static void prepare_order(const char *orderfile)
        void *map;
        char *cp, *endp;
        struct stat st;
+       size_t sz;
 
        if (order)
                return;
@@ -26,11 +26,12 @@ static void prepare_order(const char *orderfile)
                close(fd);
                return;
        }
-       map = mmap(NULL, st.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+       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;
-       endp = map + st.st_size;
+       endp = (char *) map + sz;
        for (pass = 0; pass < 2; pass++) {
                cnt = 0;
                cp = map;
@@ -47,11 +48,8 @@ static void prepare_order(const char *orderfile)
                                if (*ep == '\n') {
                                        *ep = 0;
                                        order[cnt] = cp;
-                               }
-                               else {
-                                       order[cnt] = xmalloc(ep-cp+1);
-                                       memcpy(order[cnt], cp, ep-cp);
-                                       order[cnt][ep-cp] = 0;
+                               } else {
+                                       order[cnt] = xmemdupz(cp, ep - cp);
                                }
                                cnt++;
                        }
@@ -105,9 +103,13 @@ static int compare_pair_order(const void *a_, const void *b_)
 void diffcore_order(const char *orderfile)
 {
        struct diff_queue_struct *q = &diff_queued_diff;
-       struct pair_order *o = xmalloc(sizeof(*o) * q->nr);
+       struct pair_order *o;
        int i;
 
+       if (!q->nr)
+               return;
+
+       o = xmalloc(sizeof(*o) * q->nr);
        prepare_order(orderfile);
        for (i = 0; i < q->nr; i++) {
                o[i].pair = q->queue[i];