Skip to content
Snippets Groups Projects
Commit 2002eed6 authored by Junio C Hamano's avatar Junio C Hamano Committed by Linus Torvalds
Browse files

[PATCH] diffcore-pickaxe: switch to "counting" behaviour.


Instead of finding old/new pair that one side has and the
other side does not have the specified string, find old/new pair
that contains the specified string as a substring different
number of times.  This would still not catch a case where you
introduce two static variable declarations and remove two static
function definitions from a file with -S"static", but would make
it behave a bit more intuitively.

Signed-off-by: default avatarJunio C Hamano <junkio@cox.net>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 399144f2
No related branches found
No related tags found
No related merge requests found
...@@ -5,19 +5,30 @@ ...@@ -5,19 +5,30 @@
#include "diff.h" #include "diff.h"
#include "diffcore.h" #include "diffcore.h"
static int contains(struct diff_filespec *one, static unsigned int contains(struct diff_filespec *one,
const char *needle, unsigned long len) const char *needle, unsigned long len)
{ {
unsigned int cnt;
unsigned long offset, sz; unsigned long offset, sz;
const char *data; const char *data;
if (diff_populate_filespec(one, 0)) if (diff_populate_filespec(one, 0))
return 0; return 0;
sz = one->size; sz = one->size;
data = one->data; data = one->data;
for (offset = 0; offset + len <= sz; offset++) cnt = 0;
if (!strncmp(needle, data + offset, len))
return 1; /* Yes, I've heard of strstr(), but the thing is *data may
return 0; * not be NUL terminated. Sue me.
*/
for (offset = 0; offset + len <= sz; offset++) {
/* we count non-overlapping occurrences of needle */
if (!memcmp(needle, data + offset, len)) {
offset += len - 1;
cnt++;
}
}
return cnt;
} }
void diffcore_pickaxe(const char *needle, int opts) void diffcore_pickaxe(const char *needle, int opts)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment