2 * Copyright (C) 2005 Junio C Hamano
12 static void prepare_order(const char *orderfile
)
22 fd
= open(orderfile
, O_RDONLY
);
29 map
= mmap(NULL
, st
.st_size
, PROT_READ
|PROT_WRITE
, MAP_PRIVATE
, fd
, 0);
31 if (-1 == (int)(long)map
)
33 endp
= map
+ st
.st_size
;
34 for (pass
= 0; pass
< 2; pass
++) {
39 for (ep
= cp
; ep
< endp
&& *ep
!= '\n'; ep
++)
41 /* cp to ep has one line */
42 if (*cp
== '\n' || *cp
== '#')
52 order
[cnt
] = xmalloc(ep
-cp
+1);
53 memcpy(order
[cnt
], cp
, ep
-cp
);
54 order
[cnt
][ep
-cp
] = 0;
64 order
= xmalloc(sizeof(*order
) * cnt
);
70 struct diff_filepair
*pair
;
75 static int match_order(const char *path
)
80 for (i
= 0; i
< order_cnt
; i
++) {
84 if (!fnmatch(order
[i
], p
, 0))
95 static int compare_pair_order(const void *a_
, const void *b_
)
97 struct pair_order
const *a
, *b
;
98 a
= (struct pair_order
const *)a_
;
99 b
= (struct pair_order
const *)b_
;
100 if (a
->order
!= b
->order
)
101 return a
->order
- b
->order
;
102 return a
->orig_order
- b
->orig_order
;
105 void diffcore_order(const char *orderfile
)
107 struct diff_queue_struct
*q
= &diff_queued_diff
;
108 struct pair_order
*o
= xmalloc(sizeof(*o
) * q
->nr
);
111 prepare_order(orderfile
);
112 for (i
= 0; i
< q
->nr
; i
++) {
113 o
[i
].pair
= q
->queue
[i
];
115 o
[i
].order
= match_order(o
[i
].pair
->two
->path
);
117 qsort(o
, q
->nr
, sizeof(*o
), compare_pair_order
);
118 for (i
= 0; i
< q
->nr
; i
++)
119 q
->queue
[i
] = o
[i
].pair
;