[PATCH] Rename/copy detection fix.
[git/git.git] / diffcore-pickaxe.c
CommitLineData
52e95789
JH
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"
8
9static int contains(struct diff_filespec *one,
10 const char *needle, unsigned long len)
11{
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;
22}
23
6b14d7fa 24void diffcore_pickaxe(const char *needle)
52e95789 25{
38c6f780 26 struct diff_queue_struct *q = &diff_queued_diff;
52e95789
JH
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;
32
33 for (i = 0; i < q->nr; i++) {
34 struct diff_filepair *p = q->queue[i];
6b14d7fa 35 int onum = outq.nr;
81e50eab
JH
36 if (!DIFF_FILE_VALID(p->one)) {
37 if (!DIFF_FILE_VALID(p->two))
52e95789
JH
38 continue; /* ignore nonsense */
39 /* created */
40 if (contains(p->two, needle, len))
6b14d7fa 41 diff_q(&outq, p);
52e95789 42 }
81e50eab 43 else if (!DIFF_FILE_VALID(p->two)) {
52e95789 44 if (contains(p->one, needle, len))
6b14d7fa 45 diff_q(&outq, p);
52e95789
JH
46 }
47 else if (contains(p->one, needle, len) !=
48 contains(p->two, needle, len))
6b14d7fa
JH
49 diff_q(&outq, p);
50 if (onum == outq.nr)
f7c1512a 51 free(p);
52e95789
JH
52 }
53 free(q->queue);
54 *q = outq;
55 return;
56}