[PATCH] check_file_directory_conflict path fix
[git/haiku.git] / diffcore-pickaxe.c
blobfea62d51a090e22e43938245747e409ea7ede883
1 /*
2 * Copyright (C) 2005 Junio C Hamano
3 */
4 #include "cache.h"
5 #include "diff.h"
6 #include "diffcore.h"
7 #include "delta.h"
9 static int contains(struct diff_filespec *one,
10 const char *needle, unsigned long len)
12 unsigned long offset, sz;
13 const char *data;
14 if (diff_populate_filespec(one))
15 return 0;
16 sz = one->size;
17 data = one->data;
18 for (offset = 0; offset + len <= sz; offset++)
19 if (!strncmp(needle, data + offset, len))
20 return 1;
21 return 0;
24 void diffcore_pickaxe(const char *needle)
26 struct diff_queue_struct *q = &diff_queued_diff;
27 unsigned long len = strlen(needle);
28 int i;
29 struct diff_queue_struct outq;
30 outq.queue = NULL;
31 outq.nr = outq.alloc = 0;
33 for (i = 0; i < q->nr; i++) {
34 struct diff_filepair *p = q->queue[i];
35 int onum = outq.nr;
36 if (!DIFF_FILE_VALID(p->one)) {
37 if (!DIFF_FILE_VALID(p->two))
38 continue; /* ignore nonsense */
39 /* created */
40 if (contains(p->two, needle, len))
41 diff_q(&outq, p);
43 else if (!DIFF_FILE_VALID(p->two)) {
44 if (contains(p->one, needle, len))
45 diff_q(&outq, p);
47 else if (!diff_unmodified_pair(p) &&
48 contains(p->one, needle, len) !=
49 contains(p->two, needle, len))
50 diff_q(&outq, p);
51 if (onum == outq.nr)
52 free(p);
54 free(q->queue);
55 *q = outq;
56 return;