From: Junio C Hamano <junkio@cox.net>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Paul Mackerras <paulus@samba.org>, git@vger.kernel.org
Subject: [PATCH] diffcore-pickaxe: switch to "counting" behaviour.
Date: Sun, 17 Jul 2005 01:21:28 -0700 [thread overview]
Message-ID: <7vek9x3ks7.fsf_-_@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <7vy886e1ry.fsf@assigned-by-dhcp.cox.net> (Junio C. Hamano's message of "Sat, 16 Jul 2005 17:04:17 -0700")
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>
---
*** Linus, the "counting" behaviour that came up in our private
*** exchange was brought up independently by Paul. I think it
*** is a good compromise.
diffcore-pickaxe.c | 23 +++++++++++++++++------
1 files changed, 17 insertions(+), 6 deletions(-)
7532cfc15932595d679c16ae007f9a910a5b1d1e
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
--- 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)
next prev parent reply other threads:[~2005-07-17 8:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-30 12:48 problem with git-diff-tree -S Paul Mackerras
[not found] ` <7vpsu33a6z.fsf@assigned-by-dhcp.cox.net>
[not found] ` <17092.26085.238125.715025@cargo.ozlabs.ibm.com>
[not found] ` <7v3bqz1mxx.fsf@assigned-by-dhcp.cox.net>
[not found] ` <17112.46727.581664.508076@cargo.ozlabs.ibm.com>
[not found] ` <7vy886e1ry.fsf@assigned-by-dhcp.cox.net>
2005-07-17 8:21 ` Junio C Hamano [this message]
-- strict thread matches above, loose matches on Subject: below --
2005-07-23 23:35 [PATCH] diffcore-pickaxe: switch to "counting" behaviour Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vek9x3ks7.fsf_-_@assigned-by-dhcp.cox.net \
--to=junkio@cox.net \
--cc=git@vger.kernel.org \
--cc=paulus@samba.org \
--cc=torvalds@osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox