2 * Copyright (C) 2005 Junio C Hamano
11 static void prepare_order(const char *orderfile
)
22 fd
= open(orderfile
, O_RDONLY
);
29 sz
= xsize_t(st
.st_size
);
30 map
= mmap(NULL
, sz
, PROT_READ
|PROT_WRITE
, MAP_PRIVATE
, fd
, 0);
32 if (map
== MAP_FAILED
)
34 endp
= (char *) map
+ sz
;
35 for (pass
= 0; pass
< 2; pass
++) {
40 for (ep
= cp
; ep
< endp
&& *ep
!= '\n'; ep
++)
42 /* cp to ep has one line */
43 if (*cp
== '\n' || *cp
== '#')
53 order
[cnt
] = xmalloc(ep
-cp
+1);
54 memcpy(order
[cnt
], cp
, ep
-cp
);
55 order
[cnt
][ep
-cp
] = 0;
65 order
= xmalloc(sizeof(*order
) * cnt
);
71 struct diff_filepair
*pair
;
76 static int match_order(const char *path
)
81 for (i
= 0; i
< order_cnt
; i
++) {
85 if (!fnmatch(order
[i
], p
, 0))
96 static int compare_pair_order(const void *a_
, const void *b_
)
98 struct pair_order
const *a
, *b
;
99 a
= (struct pair_order
const *)a_
;
100 b
= (struct pair_order
const *)b_
;
101 if (a
->order
!= b
->order
)
102 return a
->order
- b
->order
;
103 return a
->orig_order
- b
->orig_order
;
106 void diffcore_order(const char *orderfile
)
108 struct diff_queue_struct
*q
= &diff_queued_diff
;
109 struct pair_order
*o
;
115 o
= xmalloc(sizeof(*o
) * q
->nr
);
116 prepare_order(orderfile
);
117 for (i
= 0; i
< q
->nr
; i
++) {
118 o
[i
].pair
= q
->queue
[i
];
120 o
[i
].order
= match_order(o
[i
].pair
->two
->path
);
122 qsort(o
, q
->nr
, sizeof(*o
), compare_pair_order
);
123 for (i
= 0; i
< q
->nr
; i
++)
124 q
->queue
[i
] = o
[i
].pair
;