2 * Copyright (C) 2005 Junio C Hamano
11 static void prepare_order(const char *orderfile)
14 struct strbuf sb = STRBUF_INIT;
22 sz = strbuf_read_file(&sb, orderfile, 0);
24 die_errno(_("failed to read orderfile '%s'"), orderfile);
25 map = strbuf_detach(&sb, NULL);
26 endp = (char *) map + sz;
28 for (pass = 0; pass < 2; pass++) {
33 for (ep = cp; ep < endp && *ep != '\n'; ep++)
35 /* cp to ep has one line */
36 if (*cp == '\n' || *cp == '#')
45 order[cnt] = xmemdupz(cp, ep - cp);
55 order = xmalloc(sizeof(*order) * cnt);
61 struct diff_filepair *pair;
66 static int match_order(const char *path)
69 static struct strbuf p = STRBUF_INIT;
71 for (i = 0; i < order_cnt; i++) {
73 strbuf_addstr(&p, path);
76 if (!fnmatch(order[i], p.buf, 0))
78 cp = strrchr(p.buf, '/');
87 static int compare_pair_order(const void *a_, const void *b_)
89 struct pair_order const *a, *b;
90 a = (struct pair_order const *)a_;
91 b = (struct pair_order const *)b_;
92 if (a->order != b->order)
93 return a->order - b->order;
94 return a->orig_order - b->orig_order;
97 void diffcore_order(const char *orderfile)
99 struct diff_queue_struct *q = &diff_queued_diff;
100 struct pair_order *o;
106 o = xmalloc(sizeof(*o) * q->nr);
107 prepare_order(orderfile);
108 for (i = 0; i < q->nr; i++) {
109 o[i].pair = q->queue[i];
111 o[i].order = match_order(o[i].pair->two->path);
113 qsort(o, q->nr, sizeof(*o), compare_pair_order);
114 for (i = 0; i < q->nr; i++)
115 q->queue[i] = o[i].pair;