summaryrefslogtreecommitdiff
path: root/diffcore-pickaxe.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-07-23 16:35:25 -0700
committerLinus Torvalds <torvalds@g5.osdl.org>2005-07-23 20:27:49 -0700
commit2002eed6c9e0e08d7a30da38e459b92f7808b319 (patch)
tree24e63c40e75765318de1e1f9117aa427dc862e0d /diffcore-pickaxe.c
parent399144f21c1b3bcd4c9dadd4f534118475de840d (diff)
downloadgit-2002eed6c9e0e08d7a30da38e459b92f7808b319.tar.gz
[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: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'diffcore-pickaxe.c')
-rw-r--r--diffcore-pickaxe.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index 4c26b422f9..50e46ab863 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -5,19 +5,30 @@
#include "diff.h"
#include "diffcore.h"
-static int contains(struct diff_filespec *one,
- const char *needle, unsigned long len)
+static unsigned int contains(struct diff_filespec *one,
+ const char *needle, unsigned long len)
{
+ unsigned int cnt;
unsigned long offset, sz;
const char *data;
if (diff_populate_filespec(one, 0))
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;
+ cnt = 0;
+
+ /* Yes, I've heard of strstr(), but the thing is *data may
+ * 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)