2005-05-21 09:40:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2005 Junio C Hamano
|
|
|
|
*/
|
|
|
|
#include "cache.h"
|
|
|
|
#include "diff.h"
|
|
|
|
#include "diffcore.h"
|
|
|
|
|
|
|
|
static int contains(struct diff_filespec *one,
|
|
|
|
const char *needle, unsigned long len)
|
|
|
|
{
|
|
|
|
unsigned long offset, sz;
|
|
|
|
const char *data;
|
2005-05-27 22:56:38 +00:00
|
|
|
if (diff_populate_filespec(one, 0))
|
2005-05-21 09:40:01 +00:00
|
|
|
return 0;
|
|
|
|
sz = one->size;
|
|
|
|
data = one->data;
|
|
|
|
for (offset = 0; offset + len <= sz; offset++)
|
|
|
|
if (!strncmp(needle, data + offset, len))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-05-27 22:55:28 +00:00
|
|
|
void diffcore_pickaxe(const char *needle, int opts)
|
2005-05-21 09:40:01 +00:00
|
|
|
{
|
2005-05-22 02:40:36 +00:00
|
|
|
struct diff_queue_struct *q = &diff_queued_diff;
|
2005-05-21 09:40:01 +00:00
|
|
|
unsigned long len = strlen(needle);
|
2005-05-27 22:55:28 +00:00
|
|
|
int i, has_changes;
|
2005-05-21 09:40:01 +00:00
|
|
|
struct diff_queue_struct outq;
|
|
|
|
outq.queue = NULL;
|
|
|
|
outq.nr = outq.alloc = 0;
|
|
|
|
|
2005-05-27 22:55:28 +00:00
|
|
|
if (opts & DIFF_PICKAXE_ALL) {
|
|
|
|
/* Showing the whole changeset if needle exists */
|
|
|
|
for (i = has_changes = 0; !has_changes && i < q->nr; i++) {
|
|
|
|
struct diff_filepair *p = q->queue[i];
|
|
|
|
if (!DIFF_FILE_VALID(p->one)) {
|
|
|
|
if (!DIFF_FILE_VALID(p->two))
|
|
|
|
continue; /* ignore unmerged */
|
|
|
|
/* created */
|
|
|
|
if (contains(p->two, needle, len))
|
|
|
|
has_changes++;
|
|
|
|
}
|
|
|
|
else if (!DIFF_FILE_VALID(p->two)) {
|
|
|
|
if (contains(p->one, needle, len))
|
|
|
|
has_changes++;
|
|
|
|
}
|
|
|
|
else if (!diff_unmodified_pair(p) &&
|
|
|
|
contains(p->one, needle, len) !=
|
|
|
|
contains(p->two, needle, len))
|
|
|
|
has_changes++;
|
2005-05-21 09:40:01 +00:00
|
|
|
}
|
2005-05-27 22:55:28 +00:00
|
|
|
if (has_changes)
|
|
|
|
return; /* not munge the queue */
|
|
|
|
|
|
|
|
/* otherwise we will clear the whole queue
|
|
|
|
* by copying the empty outq at the end of this
|
|
|
|
* function, but first clear the current entries
|
|
|
|
* in the queue.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < q->nr; i++)
|
|
|
|
diff_free_filepair(q->queue[i]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* Showing only the filepairs that has the needle */
|
|
|
|
for (i = 0; i < q->nr; i++) {
|
|
|
|
struct diff_filepair *p = q->queue[i];
|
|
|
|
has_changes = 0;
|
|
|
|
if (!DIFF_FILE_VALID(p->one)) {
|
|
|
|
if (!DIFF_FILE_VALID(p->two))
|
|
|
|
; /* ignore unmerged */
|
|
|
|
/* created */
|
|
|
|
else if (contains(p->two, needle, len))
|
|
|
|
has_changes = 1;
|
|
|
|
}
|
|
|
|
else if (!DIFF_FILE_VALID(p->two)) {
|
|
|
|
if (contains(p->one, needle, len))
|
|
|
|
has_changes = 1;
|
|
|
|
}
|
|
|
|
else if (!diff_unmodified_pair(p) &&
|
|
|
|
contains(p->one, needle, len) !=
|
|
|
|
contains(p->two, needle, len))
|
|
|
|
has_changes = 1;
|
|
|
|
|
|
|
|
if (has_changes)
|
2005-05-22 17:04:37 +00:00
|
|
|
diff_q(&outq, p);
|
2005-05-27 22:55:28 +00:00
|
|
|
else
|
|
|
|
diff_free_filepair(p);
|
2005-05-21 09:40:01 +00:00
|
|
|
}
|
2005-05-27 22:55:28 +00:00
|
|
|
|
2005-05-21 09:40:01 +00:00
|
|
|
free(q->queue);
|
|
|
|
*q = outq;
|
|
|
|
return;
|
|
|
|
}
|