]>
git.ipfire.org Git - thirdparty/git.git/blob - diffcore-order.c
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
== '#')
52 order
[cnt
] = xmemdupz(cp
, ep
- cp
);
62 order
= xmalloc(sizeof(*order
) * cnt
);
68 struct diff_filepair
*pair
;
73 static int match_order(const char *path
)
78 for (i
= 0; i
< order_cnt
; i
++) {
82 if (!fnmatch(order
[i
], p
, 0))
93 static int compare_pair_order(const void *a_
, const void *b_
)
95 struct pair_order
const *a
, *b
;
96 a
= (struct pair_order
const *)a_
;
97 b
= (struct pair_order
const *)b_
;
98 if (a
->order
!= b
->order
)
99 return a
->order
- b
->order
;
100 return a
->orig_order
- b
->orig_order
;
103 void diffcore_order(const char *orderfile
)
105 struct diff_queue_struct
*q
= &diff_queued_diff
;
106 struct pair_order
*o
;
112 o
= xmalloc(sizeof(*o
) * q
->nr
);
113 prepare_order(orderfile
);
114 for (i
= 0; i
< q
->nr
; i
++) {
115 o
[i
].pair
= q
->queue
[i
];
117 o
[i
].order
= match_order(o
[i
].pair
->two
->path
);
119 qsort(o
, q
->nr
, sizeof(*o
), compare_pair_order
);
120 for (i
= 0; i
< q
->nr
; i
++)
121 q
->queue
[i
] = o
[i
].pair
;