{"thread":{"id":"1322","subject":"[PATCH] diffcore-pickaxe: switch to \"counting\" behaviour.","startedAt":"2005-07-23T23:35:25Z","lastAt":"2005-07-23T23:35:25Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"6395","messageId":"7v64v1qeo2.fsf@assigned-by-dhcp.cox.net","threadId":"1322","inReplyTo":null,"subject":"[PATCH] diffcore-pickaxe: switch to \"counting\" behaviour.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-07-23T23:35:25Z","receivedAt":"2005-07-23T23:35:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Instead of finding old/new pair that one side has and the\nother side does not have the specified string, find old/new pair\nthat contains the specified string as a substring different\nnumber of times.  This would still not catch a case where you\nintroduce two static variable declarations and remove two static\nfunction definitions from a file with -S\"static\", but would make\nit behave a bit more intuitively.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n*** This was brought up as a possible improvement for the first\n*** question when you asked me two questions a couple of weeks\n*** ago.  Interestingly enough, Paul Mackerras independently\n*** suggested the same approach to make pickaxe more intuitive\n*** for gitk users.\n\n diffcore-pickaxe.c |   23 +++++++++++++++++------\n 1 files changed, 17 insertions(+), 6 deletions(-)\n\nd245f19da1e36a70e904f2414d815fc06bfe09d8\ndiff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c\n--- a/diffcore-pickaxe.c\n+++ b/diffcore-pickaxe.c\n@@ -5,19 +5,30 @@\n #include \"diff.h\"\n #include \"diffcore.h\"\n \n-static int contains(struct diff_filespec *one,\n-\t\t    const char *needle, unsigned long len)\n+static unsigned int contains(struct diff_filespec *one,\n+\t\t\t     const char *needle, unsigned long len)\n {\n+\tunsigned int cnt;\n \tunsigned long offset, sz;\n \tconst char *data;\n \tif (diff_populate_filespec(one, 0))\n \t\treturn 0;\n+\n \tsz = one->size;\n \tdata = one->data;\n-\tfor (offset = 0; offset + len <= sz; offset++)\n-\t\t     if (!strncmp(needle, data + offset, len))\n-\t\t\t     return 1;\n-\treturn 0;\n+\tcnt = 0;\n+\n+\t/* Yes, I've heard of strstr(), but the thing is *data may\n+\t * not be NUL terminated.  Sue me.\n+\t */\n+\tfor (offset = 0; offset + len <= sz; offset++) {\n+\t\t/* we count non-overlapping occurrences of needle */\n+\t\tif (!memcmp(needle, data + offset, len)) {\n+\t\t\toffset += len - 1;\n+\t\t\tcnt++;\n+\t\t}\n+\t}\n+\treturn cnt;\n }\n \n void diffcore_pickaxe(const char *needle, int opts)\n"}]}