From: Steven Grimm <koreth@midwinter.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH] Ignore end-of-line style when computing similarity score for rename detection
Date: Wed, 27 Jun 2007 23:04:16 -0700 [thread overview]
Message-ID: <20070628060416.GA13162@midwinter.com> (raw)
In-Reply-To: <7vtzssog5i.fsf@assigned-by-dhcp.pobox.com>
Signed-off-by: Steven Grimm <koreth@midwinter.com>
---
Junio rightly points out that it would be a mistake to discard \r
characters from binary files when computing similarity scores. So now we
only do it if the file contents test as non-binary.
The file attributes aren't available at this level of the code, but they
could be propagated down from the higher levels if we don't trust
buffer_is_binary() to make an adequately accurate decision.
diffcore-delta.c | 19 +++++++++++++------
1 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/diffcore-delta.c b/diffcore-delta.c
index 7338a40..52e648f 100644
--- a/diffcore-delta.c
+++ b/diffcore-delta.c
@@ -1,6 +1,7 @@
#include "cache.h"
#include "diff.h"
#include "diffcore.h"
+#include "xdiff-interface.h"
/*
* Idea here is very simple.
@@ -125,7 +126,8 @@ static struct spanhash_top *add_spanhash(struct spanhash_top *top,
}
}
-static struct spanhash_top *hash_chars(unsigned char *buf, unsigned int sz)
+static struct spanhash_top *hash_chars(unsigned char *buf, unsigned int sz,
+ int is_binary)
{
int i, n;
unsigned int accum1, accum2, hashval;
@@ -143,9 +145,12 @@ static struct spanhash_top *hash_chars(unsigned char *buf, unsigned int sz)
unsigned int c = *buf++;
unsigned int old_1 = accum1;
sz--;
- accum1 = (accum1 << 7) ^ (accum2 >> 25);
- accum2 = (accum2 << 7) ^ (old_1 >> 25);
- accum1 += c;
+ /* Ignore \r\n vs. \n when computing text file similarity. */
+ if (c != '\r' && ! is_binary) {
+ accum1 = (accum1 << 7) ^ (accum2 >> 25);
+ accum2 = (accum2 << 7) ^ (old_1 >> 25);
+ accum1 += c;
+ }
if (++n < 64 && c != '\n')
continue;
hashval = (accum1 + accum2 * 0x61) % HASHBASE;
@@ -172,14 +177,16 @@ int diffcore_count_changes(void *src, unsigned long src_size,
if (src_count_p)
src_count = *src_count_p;
if (!src_count) {
- src_count = hash_chars(src, src_size);
+ int src_is_binary = buffer_is_binary(src, src_size);
+ src_count = hash_chars(src, src_size, src_is_binary);
if (src_count_p)
*src_count_p = src_count;
}
if (dst_count_p)
dst_count = *dst_count_p;
if (!dst_count) {
- dst_count = hash_chars(dst, dst_size);
+ int dst_is_binary = buffer_is_binary(dst, dst_size);
+ dst_count = hash_chars(dst, dst_size, dst_is_binary);
if (dst_count_p)
*dst_count_p = dst_count;
}
--
1.5.2.2.571.ge134
next prev parent reply other threads:[~2007-06-28 6:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-28 2:39 [PATCH] Ignore end-of-line style when computing similarity score for rename detection Steven Grimm
2007-06-28 2:46 ` Steven Grimm
2007-06-28 7:22 ` Johannes Sixt
2007-06-28 8:16 ` Junio C Hamano
2007-06-28 4:29 ` Junio C Hamano
2007-06-28 6:04 ` Steven Grimm [this message]
2007-06-28 6:18 ` Shawn O. Pearce
2007-06-29 6:34 ` Junio C Hamano
2007-06-28 12:41 ` Johannes Schindelin
2007-06-28 18:17 ` Steven Grimm
2007-06-29 10:19 ` Johannes Schindelin
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=20070628060416.GA13162@midwinter.com \
--to=koreth@midwinter.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.