2 * Copyright (C) 2005 Junio C Hamano
8 static int contains(struct diff_filespec
*one
,
9 const char *needle
, unsigned long len
)
11 unsigned long offset
, sz
;
13 if (diff_populate_filespec(one
, 0))
17 for (offset
= 0; offset
+ len
<= sz
; offset
++)
18 if (!strncmp(needle
, data
+ offset
, len
))
23 void diffcore_pickaxe(const char *needle
, int opts
)
25 struct diff_queue_struct
*q
= &diff_queued_diff
;
26 unsigned long len
= strlen(needle
);
28 struct diff_queue_struct outq
;
30 outq
.nr
= outq
.alloc
= 0;
32 if (opts
& DIFF_PICKAXE_ALL
) {
33 /* Showing the whole changeset if needle exists */
34 for (i
= has_changes
= 0; !has_changes
&& i
< q
->nr
; i
++) {
35 struct diff_filepair
*p
= q
->queue
[i
];
36 if (!DIFF_FILE_VALID(p
->one
)) {
37 if (!DIFF_FILE_VALID(p
->two
))
38 continue; /* ignore unmerged */
40 if (contains(p
->two
, needle
, len
))
43 else if (!DIFF_FILE_VALID(p
->two
)) {
44 if (contains(p
->one
, needle
, len
))
47 else if (!diff_unmodified_pair(p
) &&
48 contains(p
->one
, needle
, len
) !=
49 contains(p
->two
, needle
, len
))
53 return; /* not munge the queue */
55 /* otherwise we will clear the whole queue
56 * by copying the empty outq at the end of this
57 * function, but first clear the current entries
60 for (i
= 0; i
< q
->nr
; i
++)
61 diff_free_filepair(q
->queue
[i
]);
64 /* Showing only the filepairs that has the needle */
65 for (i
= 0; i
< q
->nr
; i
++) {
66 struct diff_filepair
*p
= q
->queue
[i
];
68 if (!DIFF_FILE_VALID(p
->one
)) {
69 if (!DIFF_FILE_VALID(p
->two
))
70 ; /* ignore unmerged */
72 else if (contains(p
->two
, needle
, len
))
75 else if (!DIFF_FILE_VALID(p
->two
)) {
76 if (contains(p
->one
, needle
, len
))
79 else if (!diff_unmodified_pair(p
) &&
80 contains(p
->one
, needle
, len
) !=
81 contains(p
->two
, needle
, len
))
87 diff_free_filepair(p
);