aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2015-01-04 02:18:27 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2015-01-04 02:18:27 +0100
commit79dacba9229e6c46e98e1f7d3912c3091e56da6a (patch)
tree90a47cc383dc6415a8c6cf5240f2c0d980ceb9b4 /org.eclipse.jgit/src
parent6224d24e000a7bcaf680b2e5d6955fd8fd2ac46d (diff)
parent741ebca8b71f5ca37de61349019fe66d5e7cfc85 (diff)
downloadjgit-79dacba9229e6c46e98e1f7d3912c3091e56da6a.tar.gz
jgit-79dacba9229e6c46e98e1f7d3912c3091e56da6a.zip
Merge branch 'stable-3.6'
* stable-3.6: Prepare 3.6.2-SNAPSHOT builds JGit v3.6.1.201501031845-r Trim author/committer name and email in commit header Rename detection should canonicalize line endings PathMatcher should respect "assumeDirectory" flag Change-Id: Idd48c6d94cf1ab09abc07f70d50890b1b78e1833 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java64
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/PathMatcher.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java4
3 files changed, 46 insertions, 25 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java
index 17ccb9726f..f376b8e36e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java
@@ -79,8 +79,11 @@ class SimilarityIndex {
/** Maximum value of the count field, also mask to extract the count. */
private static final long MAX_COUNT = (1L << KEY_SHIFT) - 1;
- /** Total size of the file we hashed into the structure. */
- private long fileSize;
+ /**
+ * Total amount of bytes hashed into the structure, including \n. This is
+ * usually the size of the file minus number of CRLF encounters.
+ */
+ private long hashedCnt;
/** Number of non-zero entries in {@link #idHash}. */
private int idSize;
@@ -108,48 +111,59 @@ class SimilarityIndex {
idGrowAt = growAt(idHashBits);
}
- long getFileSize() {
- return fileSize;
- }
-
- void setFileSize(long size) {
- fileSize = size;
- }
-
void hash(ObjectLoader obj) throws MissingObjectException, IOException,
TableFullException {
if (obj.isLarge()) {
- ObjectStream in = obj.openStream();
- try {
- setFileSize(in.getSize());
- hash(in, fileSize);
- } finally {
- in.close();
- }
+ hashLargeObject(obj);
} else {
byte[] raw = obj.getCachedBytes();
- setFileSize(raw.length);
hash(raw, 0, raw.length);
}
}
+ private void hashLargeObject(ObjectLoader obj) throws IOException,
+ TableFullException {
+ ObjectStream in1 = obj.openStream();
+ boolean text;
+ try {
+ text = !RawText.isBinary(in1);
+ } finally {
+ in1.close();
+ }
+
+ ObjectStream in2 = obj.openStream();
+ try {
+ hash(in2, in2.getSize(), text);
+ } finally {
+ in2.close();
+ }
+ }
+
void hash(byte[] raw, int ptr, final int end) throws TableFullException {
+ final boolean text = !RawText.isBinary(raw);
+ hashedCnt = 0;
while (ptr < end) {
int hash = 5381;
+ int blockHashedCnt = 0;
int start = ptr;
// Hash one line, or one block, whichever occurs first.
do {
int c = raw[ptr++] & 0xff;
+ // Ignore CR in CRLF sequence if text
+ if (text && c == '\r' && ptr < end && raw[ptr] == '\n')
+ continue;
+ blockHashedCnt++;
if (c == '\n')
break;
hash = (hash << 5) + hash + c;
} while (ptr < end && ptr - start < 64);
- add(hash, ptr - start);
+ hashedCnt += blockHashedCnt;
+ add(hash, blockHashedCnt);
}
}
- void hash(InputStream in, long remaining) throws IOException,
+ void hash(InputStream in, long remaining, boolean text) throws IOException,
TableFullException {
byte[] buf = new byte[4096];
int ptr = 0;
@@ -157,6 +171,7 @@ class SimilarityIndex {
while (0 < remaining) {
int hash = 5381;
+ int blockHashedCnt = 0;
// Hash one line, or one block, whichever occurs first.
int n = 0;
@@ -170,11 +185,16 @@ class SimilarityIndex {
n++;
int c = buf[ptr++] & 0xff;
+ // Ignore CR in CRLF sequence if text
+ if (text && c == '\r' && ptr < cnt && buf[ptr] == '\n')
+ continue;
+ blockHashedCnt++;
if (c == '\n')
break;
hash = (hash << 5) + hash + c;
} while (n < 64 && n < remaining);
- add(hash, n);
+ hashedCnt += blockHashedCnt;
+ add(hash, blockHashedCnt);
remaining -= n;
}
}
@@ -193,7 +213,7 @@ class SimilarityIndex {
}
int score(SimilarityIndex dst, int maxScore) {
- long max = Math.max(fileSize, dst.fileSize);
+ long max = Math.max(hashedCnt, dst.hashedCnt);
if (max == 0)
return maxScore;
return (int) ((common(dst) * maxScore) / max);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/PathMatcher.java b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/PathMatcher.java
index dcecf303c4..d3e5f6a053 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/PathMatcher.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/PathMatcher.java
@@ -217,7 +217,8 @@ public class PathMatcher extends AbstractMatcher {
matcher++;
match = matches(matcher, path, left, endExcl,
assumeDirectory);
- } else if (dirOnly)
+ } else if (dirOnly && !assumeDirectory)
+ // Directory expectations not met
return false;
}
return match && matcher + 1 == matchers.size();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java
index 69f7fd4404..8f7e3eff7c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java
@@ -254,9 +254,9 @@ public class PersonIdent implements Serializable {
*/
public String toExternalString() {
final StringBuilder r = new StringBuilder();
- r.append(getName());
+ r.append(getName().trim());
r.append(" <"); //$NON-NLS-1$
- r.append(getEmailAddress());
+ r.append(getEmailAddress().trim());
r.append("> "); //$NON-NLS-1$
r.append(when / 1000);
r.append(' ');