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
))
18 for (offset
= 0; offset
+ len
<= sz
; offset
++)
19 if (!strncmp(needle
, data
+ offset
, len
))
24 void diff_pickaxe(struct diff_queue_struct
*q
, const char *needle
)
26 unsigned long len
= strlen(needle
);
28 struct diff_queue_struct outq
;
30 outq
.nr
= outq
.alloc
= 0;
32 for (i
= 0; i
< q
->nr
; i
++) {
33 struct diff_filepair
*p
= q
->queue
[i
];
34 if (!p
->one
->file_valid
) {
35 if (!p
->two
->file_valid
)
36 continue; /* ignore nonsense */
38 if (contains(p
->two
, needle
, len
))
39 diff_queue(&outq
, p
->one
, p
->two
);
41 else if (!p
->two
->file_valid
) {
42 if (contains(p
->one
, needle
, len
))
43 diff_queue(&outq
, p
->one
, p
->two
);
45 else if (contains(p
->one
, needle
, len
) !=
46 contains(p
->two
, needle
, len
))
47 diff_queue(&outq
, p
->one
, p
->two
);
49 for (i
= 0; i
< q
->nr
; i
++) {
50 struct diff_filepair
*p
= q
->queue
[i
];