aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2020-05-26 08:50:33 +0200
committerThomas Wolf <thomas.wolf@paranor.ch>2020-05-28 12:06:57 +0200
commit6f17f9ed3fdadec1e6995f42ca34f570c0dee1b5 (patch)
treef526071a149a898828eaa79734c1ed5feb51c2a5 /org.eclipse.jgit
parent5a5d85a4a3407df5f9693ab36287e72726c512f6 (diff)
downloadjgit-6f17f9ed3fdadec1e6995f42ca34f570c0dee1b5.tar.gz
jgit-6f17f9ed3fdadec1e6995f42ca34f570c0dee1b5.zip
RawTextComparator.WS_IGNORE_CHANGE must not compare whitespace
Only the presence or absence of whitespace is significant; but not the actual whitespace characters. Don't compare whitespace bytes. Compare the C git implementation at [1]. [1] https://github.com/git/git/blob/0d0e1e8/xdiff/xutils.c#L173 Bug: 563570 Change-Id: I2d0522b637ba6b5c8b911b3376a9df5daa9d4c27 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextComparator.java28
1 files changed, 11 insertions, 17 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextComparator.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextComparator.java
index 508d07c200..0c41b8598b 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextComparator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextComparator.java
@@ -191,21 +191,15 @@ public abstract class RawTextComparator extends SequenceComparator<RawText> {
be = trimTrailingWhitespace(b.content, bs, be);
while (as < ae && bs < be) {
- byte ac = a.content[as];
- byte bc = b.content[bs];
+ byte ac = a.content[as++];
+ byte bc = b.content[bs++];
- if (ac != bc)
- return false;
-
- if (isWhitespace(ac))
+ if (isWhitespace(ac) && isWhitespace(bc)) {
as = trimLeadingWhitespace(a.content, as, ae);
- else
- as++;
-
- if (isWhitespace(bc))
bs = trimLeadingWhitespace(b.content, bs, be);
- else
- bs++;
+ } else if (ac != bc) {
+ return false;
+ }
}
return as == ae && bs == be;
}
@@ -215,12 +209,12 @@ public abstract class RawTextComparator extends SequenceComparator<RawText> {
int hash = 5381;
end = trimTrailingWhitespace(raw, ptr, end);
while (ptr < end) {
- byte c = raw[ptr];
- hash = ((hash << 5) + hash) + (c & 0xff);
- if (isWhitespace(c))
+ byte c = raw[ptr++];
+ if (isWhitespace(c)) {
ptr = trimLeadingWhitespace(raw, ptr, end);
- else
- ptr++;
+ c = ' ';
+ }
+ hash = ((hash << 5) + hash) + (c & 0xff);
}
return hash;
}