2 * Copyright (C) 2005 Junio C Hamano
8 static unsigned int contains(struct diff_filespec
*one
,
9 const char *needle
, unsigned long len
)
12 unsigned long offset
, sz
;
14 if (diff_populate_filespec(one
, 0))
21 /* Yes, I've heard of strstr(), but the thing is *data may
22 * not be NUL terminated. Sue me.
24 for (offset
= 0; offset
+ len
<= sz
; offset
++) {
25 /* we count non-overlapping occurrences of needle */
26 if (!memcmp(needle
, data
+ offset
, len
)) {
34 void diffcore_pickaxe(const char *needle
, int opts
)
36 struct diff_queue_struct
*q
= &diff_queued_diff
;
37 unsigned long len
= strlen(needle
);
39 struct diff_queue_struct outq
;
41 outq
.nr
= outq
.alloc
= 0;
43 if (opts
& DIFF_PICKAXE_ALL
) {
44 /* Showing the whole changeset if needle exists */
45 for (i
= has_changes
= 0; !has_changes
&& i
< q
->nr
; i
++) {
46 struct diff_filepair
*p
= q
->queue
[i
];
47 if (!DIFF_FILE_VALID(p
->one
)) {
48 if (!DIFF_FILE_VALID(p
->two
))
49 continue; /* ignore unmerged */
51 if (contains(p
->two
, needle
, len
))
54 else if (!DIFF_FILE_VALID(p
->two
)) {
55 if (contains(p
->one
, needle
, len
))
58 else if (!diff_unmodified_pair(p
) &&
59 contains(p
->one
, needle
, len
) !=
60 contains(p
->two
, needle
, len
))
64 return; /* not munge the queue */
66 /* otherwise we will clear the whole queue
67 * by copying the empty outq at the end of this
68 * function, but first clear the current entries
71 for (i
= 0; i
< q
->nr
; i
++)
72 diff_free_filepair(q
->queue
[i
]);
75 /* Showing only the filepairs that has the needle */
76 for (i
= 0; i
< q
->nr
; i
++) {
77 struct diff_filepair
*p
= q
->queue
[i
];
79 if (!DIFF_FILE_VALID(p
->one
)) {
80 if (!DIFF_FILE_VALID(p
->two
))
81 ; /* ignore unmerged */
83 else if (contains(p
->two
, needle
, len
))
86 else if (!DIFF_FILE_VALID(p
->two
)) {
87 if (contains(p
->one
, needle
, len
))
90 else if (!diff_unmodified_pair(p
) &&
91 contains(p
->one
, needle
, len
) !=
92 contains(p
->two
, needle
, len
))
98 diff_free_filepair(p
);