1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.dircache;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNotSame;
15 import static org.junit.Assert.assertSame;
16 import static org.junit.Assert.assertTrue;
17
18 import java.io.IOException;
19
20 import org.eclipse.jgit.errors.CorruptObjectException;
21 import org.eclipse.jgit.junit.RepositoryTestCase;
22 import org.eclipse.jgit.lib.FileMode;
23 import org.junit.Test;
24
25 public class DirCacheLargePathTest extends RepositoryTestCase {
26 @Test
27 public void testPath_4090() throws Exception {
28 testLongPath(4090);
29 }
30
31 @Test
32 public void testPath_4094() throws Exception {
33 testLongPath(4094);
34 }
35
36 @Test
37 public void testPath_4095() throws Exception {
38 testLongPath(4095);
39 }
40
41 @Test
42 public void testPath_4096() throws Exception {
43 testLongPath(4096);
44 }
45
46 @Test
47 public void testPath_16384() throws Exception {
48 testLongPath(16384);
49 }
50
51 private void testLongPath(int len) throws CorruptObjectException,
52 IOException {
53 final String longPath = makeLongPath(len);
54 final String shortPath = "~~~ shorter-path";
55
56 final DirCacheEntry longEnt = new DirCacheEntry(longPath);
57 final DirCacheEntry shortEnt = new DirCacheEntry(shortPath);
58
59 longEnt.setFileMode(FileMode.REGULAR_FILE);
60 shortEnt.setFileMode(FileMode.REGULAR_FILE);
61
62 assertEquals(longPath, longEnt.getPathString());
63 assertEquals(shortPath, shortEnt.getPathString());
64
65 {
66 final DirCache dc1 = db.lockDirCache();
67 {
68 final DirCacheBuilder b = dc1.builder();
69 b.add(longEnt);
70 b.add(shortEnt);
71 assertTrue(b.commit());
72 }
73 assertEquals(2, dc1.getEntryCount());
74 assertSame(longEnt, dc1.getEntry(0));
75 assertSame(shortEnt, dc1.getEntry(1));
76 }
77 {
78 final DirCache dc2 = db.readDirCache();
79 assertEquals(2, dc2.getEntryCount());
80
81 assertNotSame(longEnt, dc2.getEntry(0));
82 assertEquals(longPath, dc2.getEntry(0).getPathString());
83
84 assertNotSame(shortEnt, dc2.getEntry(1));
85 assertEquals(shortPath, dc2.getEntry(1).getPathString());
86 }
87 }
88
89 private static String makeLongPath(int len) {
90 final StringBuilder r = new StringBuilder(len);
91 for (int i = 0; i < len; i++)
92 r.append('a' + (i % 26));
93 return r.toString();
94 }
95 }