[PATCH] Add the code to set default minimum score back in.
[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
38c6f780 24void diff_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];
81e50eab
JH
35 if (!DIFF_FILE_VALID(p->one)) {
36 if (!DIFF_FILE_VALID(p->two))
52e95789
JH
37 continue; /* ignore nonsense */
38 /* created */
39 if (contains(p->two, needle, len))
40 diff_queue(&outq, p->one, p->two);
41 }
81e50eab 42 else if (!DIFF_FILE_VALID(p->two)) {
52e95789
JH
43 if (contains(p->one, needle, len))
44 diff_queue(&outq, p->one, p->two);
45 }
46 else if (contains(p->one, needle, len) !=
47 contains(p->two, needle, len))
48 diff_queue(&outq, p->one, p->two);
49 }
50 for (i = 0; i < q->nr; i++) {
51 struct diff_filepair *p = q->queue[i];
52 free(p);
53 }
54 free(q->queue);
55 *q = outq;
56 return;
57}