aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2020-08-10 21:38:50 +0200
committerThomas Wolf <thomas.wolf@paranor.ch>2020-08-15 12:47:45 +0200
commite9cb0a8e475f796e22d01fae63f5820e1fd1f318 (patch)
treeeb0828da28572ea75aada54bdf3fdebf50b55623 /org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
parent72b111ecd7ddd5fb980767e87ff5515c05a48dbc (diff)
downloadjgit-e9cb0a8e475f796e22d01fae63f5820e1fd1f318.tar.gz
jgit-e9cb0a8e475f796e22d01fae63f5820e1fd1f318.zip
DirCache: support index V4
Index format version 4 was introduced in C git in 2012. It's about time that JGit can deal with it. Version 4 added prefix path compression. Instead of writing the full path for each index entry to disk, only the difference to the previous entry's path is written: a variable-encoded int telling how many bytes to remove from the previous entry's path to get the common prefix, followed by the new suffix. Also, cache entries in a version 4 index are not padded anymore. Internally, version 3 and version 4 index entries are identical; it's only the stored format that changes. Implement this path compression, and make sure we write an index file that we read previously in the same format. (Only changing from version 2 to version 3 if there are extended flags.) Add support for the "feature.manyFiles" and the "index.version" git configs, and honor them when writing a new index file. Add tests, including a compatibility test that verifies that JGit can read a version 4 index generated by C git and write an identical version 4 index. Bug: 565774 Change-Id: Id83241cf009e50f950eb42f8d56b834fb47da1ed Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java32
1 files changed, 31 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
index c57cb263d1..6d4d0b4ab3 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2010, Google Inc. and others
+ * Copyright (C) 2008, 2020, Google Inc. and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -28,6 +28,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
+import org.eclipse.jgit.dircache.DirCache.DirCacheVersion;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
@@ -188,6 +189,28 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
assertArrayEquals(expectedBytes, indexBytes);
}
+ @Test
+ public void testReadWriteV4() throws Exception {
+ final File file = pathOf("gitgit.index.v4");
+ final DirCache dc = new DirCache(file, FS.DETECTED);
+ dc.read();
+ assertEquals(DirCacheVersion.DIRC_VERSION_PATHCOMPRESS,
+ dc.getVersion());
+ assertEquals(5, dc.getEntryCount());
+ assertV4TreeEntry(0, "src/org/eclipse/jgit/atest/foo.txt", false, dc);
+ assertV4TreeEntry(1, "src/org/eclipse/jgit/atest/foobar.txt", false,
+ dc);
+ assertV4TreeEntry(2, "src/org/eclipse/jgit/other/bar.txt", true, dc);
+ assertV4TreeEntry(3, "test.txt", false, dc);
+ assertV4TreeEntry(4, "test.txt2", false, dc);
+
+ final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ dc.writeTo(null, bos);
+ final byte[] indexBytes = bos.toByteArray();
+ final byte[] expectedBytes = IO.readFully(file);
+ assertArrayEquals(expectedBytes, indexBytes);
+ }
+
private static void assertV3TreeEntry(int indexPosition, String path,
boolean skipWorkTree, boolean intentToAdd, DirCache dc) {
final DirCacheEntry entry = dc.getEntry(indexPosition);
@@ -196,6 +219,13 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
assertEquals(intentToAdd, entry.isIntentToAdd());
}
+ private static void assertV4TreeEntry(int indexPosition, String path,
+ boolean skipWorkTree, DirCache dc) {
+ final DirCacheEntry entry = dc.getEntry(indexPosition);
+ assertEquals(path, entry.getPathString());
+ assertEquals(skipWorkTree, entry.isSkipWorkTree());
+ }
+
private static File pathOf(String name) {
return JGitTestUtil.getTestResourceFile(name);
}