2 * Copyright (C) 2005 Junio C Hamano
9 static int contains(struct diff_filespec
*one
,
10 const char *needle
, unsigned long len
)
12 unsigned long offset
, sz
;
14 if (diff_populate_filespec(one
, 0))
18 for (offset
= 0; offset
+ len
<= sz
; offset
++)
19 if (!strncmp(needle
, data
+ offset
, len
))
24 void diffcore_pickaxe(const char *needle
, int opts
)
26 struct diff_queue_struct
*q
= &diff_queued_diff
;
27 unsigned long len
= strlen(needle
);
29 struct diff_queue_struct outq
;
31 outq
.nr
= outq
.alloc
= 0;
33 if (opts
& DIFF_PICKAXE_ALL
) {
34 /* Showing the whole changeset if needle exists */
35 for (i
= has_changes
= 0; !has_changes
&& i
< q
->nr
; i
++) {
36 struct diff_filepair
*p
= q
->queue
[i
];
37 if (!DIFF_FILE_VALID(p
->one
)) {
38 if (!DIFF_FILE_VALID(p
->two
))
39 continue; /* ignore unmerged */
41 if (contains(p
->two
, needle
, len
))
44 else if (!DIFF_FILE_VALID(p
->two
)) {
45 if (contains(p
->one
, needle
, len
))
48 else if (!diff_unmodified_pair(p
) &&
49 contains(p
->one
, needle
, len
) !=
50 contains(p
->two
, needle
, len
))
54 return; /* not munge the queue */
56 /* otherwise we will clear the whole queue
57 * by copying the empty outq at the end of this
58 * function, but first clear the current entries
61 for (i
= 0; i
< q
->nr
; i
++)
62 diff_free_filepair(q
->queue
[i
]);
65 /* Showing only the filepairs that has the needle */
66 for (i
= 0; i
< q
->nr
; i
++) {
67 struct diff_filepair
*p
= q
->queue
[i
];
69 if (!DIFF_FILE_VALID(p
->one
)) {
70 if (!DIFF_FILE_VALID(p
->two
))
71 ; /* ignore unmerged */
73 else if (contains(p
->two
, needle
, len
))
76 else if (!DIFF_FILE_VALID(p
->two
)) {
77 if (contains(p
->one
, needle
, len
))
80 else if (!diff_unmodified_pair(p
) &&
81 contains(p
->one
, needle
, len
) !=
82 contains(p
->two
, needle
, len
))
88 diff_free_filepair(p
);