aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorYoussef Elghareeb <ghareeb@google.com>2021-03-11 13:01:14 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2021-03-14 11:38:13 +0100
commit4a78d911c578a6f9028d6e74b5668dfc384ef80f (patch)
tree6dc5c597adab84b5043bad901fc9aa1456bbb314 /org.eclipse.jgit.test
parent84ed57d2f63307437492f3a2c9b60ce7737b96e6 (diff)
downloadjgit-4a78d911c578a6f9028d6e74b5668dfc384ef80f.tar.gz
jgit-4a78d911c578a6f9028d6e74b5668dfc384ef80f.zip
Skip detecting content renames for large files
There are two code paths for detecting renames: one on tree diffs (using DiffFormatter#scan) and the other on single file diffs (using DiffFormatter#format). The latter skips binary and large files for rename detection - check [1], but the former doesn't. This change skips content rename detection for the tree diffs case for large files. This is essential to avoid expensive computations while reading the file, especially for callers who don't want to pay that cost. Content renames are those which involve files with slightly modified content. Exact renames will still be identified. The default threshold for file sizes is reused from PackConfig.DEFAULT_BIG_FILE_THRESHOLD: 50 MB. [1] https://git.eclipse.org/r/plugins/gitiles/jgit/jgit/+/232876421d067a1242e8afcaa33b9171342fee3e/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java#386 Change-Id: Idbc2c29bd381c6e387185204638f76fda47df41e Signed-off-by: Youssef Elghareeb <ghareeb@google.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java
index 6203feda48..2ea3cd7ebe 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java
@@ -543,6 +543,43 @@ public class RenameDetectorTest extends RepositoryTestCase {
}
@Test
+ public void testExactRename_LargeFile() throws Exception {
+ ObjectId aId = blob("blah\nblah\nfoo"); // size = 14
+
+ DiffEntry a = DiffEntry.add(PATH_A, aId);
+ DiffEntry b = DiffEntry.delete(PATH_Q, aId);
+
+ rd.add(a);
+ rd.add(b);
+
+ // Exact renames are identified for large files
+ rd.setBigFileThreshold(10);
+ List<DiffEntry> entries = rd.compute();
+ assertEquals(1, entries.size());
+ assertRename(b, a, 100, entries.get(0));
+ }
+
+ @Test
+ public void testInexactRename_LargeFile() throws Exception {
+ ObjectId aId = blob("blah\nblah\nfoo"); // size = 14
+ ObjectId bId = blob("bla\nblah\nfoo"); // size = 13
+
+ DiffEntry a = DiffEntry.add(PATH_A, aId);
+ DiffEntry b = DiffEntry.delete(PATH_Q, bId);
+
+ rd.add(a);
+ rd.add(b);
+
+ rd.setBigFileThreshold(10);
+
+ // Inexact renames are not detected for large files
+ List<DiffEntry> entries = rd.compute();
+ assertEquals(2, entries.size());
+ assertAdd(PATH_A, aId, FileMode.REGULAR_FILE, entries.get(0));
+ assertDelete(PATH_Q, bId, FileMode.REGULAR_FILE, entries.get(1));
+ }
+
+ @Test
public void testSetRenameScore_IllegalArgs() throws Exception {
try {
rd.setRenameScore(-1);
@@ -634,4 +671,15 @@ public class RenameDetectorTest extends RepositoryTestCase {
assertEquals(AbbreviatedObjectId.fromObjectId(newId), add.newId);
assertEquals(newMode, add.newMode);
}
+
+ private static void assertDelete(String oldName, ObjectId oldId,
+ FileMode oldMode, DiffEntry delete) {
+ assertEquals(DiffEntry.DEV_NULL, delete.newPath);
+ assertEquals(DiffEntry.A_ZERO, delete.newId);
+ assertEquals(FileMode.MISSING, delete.newMode);
+ assertEquals(ChangeType.DELETE, delete.changeType);
+ assertEquals(oldName, delete.oldPath);
+ assertEquals(AbbreviatedObjectId.fromObjectId(oldId), delete.oldId);
+ assertEquals(oldMode, delete.oldMode);
+ }
}