2 * Copyright (C) 2005 Junio C Hamano
11 static void prepare_order(const char *orderfile)
21 fd = open(orderfile, O_RDONLY);
28 map = mmap(NULL, st.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
30 if (map == MAP_FAILED)
32 endp = (char *) map + st.st_size;
33 for (pass = 0; pass < 2; pass++) {
38 for (ep = cp; ep < endp && *ep != '\n'; ep++)
40 /* cp to ep has one line */
41 if (*cp == '\n' || *cp == '#')
51 order[cnt] = xmalloc(ep-cp+1);
52 memcpy(order[cnt], cp, ep-cp);
53 order[cnt][ep-cp] = 0;
63 order = xmalloc(sizeof(*order) * cnt);
69 struct diff_filepair *pair;
74 static int match_order(const char *path)
79 for (i = 0; i < order_cnt; i++) {
83 if (!fnmatch(order[i], p, 0))
94 static int compare_pair_order(const void *a_, const void *b_)
96 struct pair_order const *a, *b;
97 a = (struct pair_order const *)a_;
98 b = (struct pair_order const *)b_;
99 if (a->order != b->order)
100 return a->order - b->order;
101 return a->orig_order - b->orig_order;
104 void diffcore_order(const char *orderfile)
106 struct diff_queue_struct *q = &diff_queued_diff;
107 struct pair_order *o;
113 o = xmalloc(sizeof(*o) * q->nr);
114 prepare_order(orderfile);
115 for (i = 0; i < q->nr; i++) {
116 o[i].pair = q->queue[i];
118 o[i].order = match_order(o[i].pair->two->path);
120 qsort(o, q->nr, sizeof(*o), compare_pair_order);
121 for (i = 0; i < q->nr; i++)
122 q->queue[i] = o[i].pair;