diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java index 60408054b..16051bf68 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java @@ -473,4 +473,22 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { throw new RuntimeException(e); } } + + protected DirCacheEntry createEntry(final String path, final FileMode mode) { + return createEntry(path, mode, DirCacheEntry.STAGE_0, path); + } + + protected DirCacheEntry createEntry(final String path, final FileMode mode, + final String content) { + return createEntry(path, mode, DirCacheEntry.STAGE_0, content); + } + + protected DirCacheEntry createEntry(final String path, final FileMode mode, + final int stage, final String content) { + final DirCacheEntry entry = new DirCacheEntry(path, stage); + entry.setFileMode(mode); + entry.setObjectId(new ObjectInserter.Formatter().idFor( + Constants.OBJ_BLOB, Constants.encode(content))); + return entry; + } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java index ff9f18834..8b4a5f4db 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java @@ -44,16 +44,13 @@ package org.eclipse.jgit.merge; -import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheBuilder; -import org.eclipse.jgit.dircache.DirCacheEntry; import org.eclipse.jgit.lib.CommitBuilder; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectInserter; @@ -81,16 +78,16 @@ public class CherryPickTest extends RepositoryTestCase { final DirCacheBuilder p = treeP.builder(); final DirCacheBuilder t = treeT.builder(); - b.add(makeEntry("a", FileMode.REGULAR_FILE)); + b.add(createEntry("a", FileMode.REGULAR_FILE)); - o.add(makeEntry("a", FileMode.REGULAR_FILE)); - o.add(makeEntry("o", FileMode.REGULAR_FILE)); + o.add(createEntry("a", FileMode.REGULAR_FILE)); + o.add(createEntry("o", FileMode.REGULAR_FILE)); - p.add(makeEntry("a", FileMode.REGULAR_FILE, "q")); - p.add(makeEntry("p-fail", FileMode.REGULAR_FILE)); + p.add(createEntry("a", FileMode.REGULAR_FILE, "q")); + p.add(createEntry("p-fail", FileMode.REGULAR_FILE)); - t.add(makeEntry("a", FileMode.REGULAR_FILE)); - t.add(makeEntry("t", FileMode.REGULAR_FILE)); + t.add(createEntry("a", FileMode.REGULAR_FILE)); + t.add(createEntry("t", FileMode.REGULAR_FILE)); b.finish(); o.finish(); @@ -147,14 +144,14 @@ public class CherryPickTest extends RepositoryTestCase { final DirCacheBuilder p = treeP.builder(); final DirCacheBuilder t = treeT.builder(); - b.add(makeEntry("a", FileMode.REGULAR_FILE)); + b.add(createEntry("a", FileMode.REGULAR_FILE)); - p.add(makeEntry("a", FileMode.REGULAR_FILE, "q")); - p.add(makeEntry("p-fail", FileMode.REGULAR_FILE)); + p.add(createEntry("a", FileMode.REGULAR_FILE, "q")); + p.add(createEntry("p-fail", FileMode.REGULAR_FILE)); - t.add(makeEntry("a", FileMode.REGULAR_FILE, "q")); - t.add(makeEntry("p-fail", FileMode.REGULAR_FILE)); - t.add(makeEntry("t", FileMode.REGULAR_FILE)); + t.add(createEntry("a", FileMode.REGULAR_FILE, "q")); + t.add(createEntry("p-fail", FileMode.REGULAR_FILE)); + t.add(createEntry("t", FileMode.REGULAR_FILE)); b.finish(); p.finish(); @@ -203,18 +200,4 @@ public class CherryPickTest extends RepositoryTestCase { odi.flush(); return id; } - - private DirCacheEntry makeEntry(final String path, final FileMode mode) - throws Exception { - return makeEntry(path, mode, path); - } - - private DirCacheEntry makeEntry(final String path, final FileMode mode, - final String content) throws Exception { - final DirCacheEntry ent = new DirCacheEntry(path); - ent.setFileMode(mode); - ent.setObjectId(new ObjectInserter.Formatter().idFor(OBJ_BLOB, - Constants.encode(content))); - return ent; - } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java index 45b8aa855..81add8409 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java @@ -44,7 +44,6 @@ package org.eclipse.jgit.merge; -import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -53,9 +52,7 @@ import java.io.IOException; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheBuilder; -import org.eclipse.jgit.dircache.DirCacheEntry; import org.eclipse.jgit.lib.CommitBuilder; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectInserter; @@ -123,15 +120,15 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase { final DirCacheBuilder o = treeO.builder(); final DirCacheBuilder t = treeT.builder(); - b.add(makeEntry("libelf-po/a", FileMode.REGULAR_FILE)); - b.add(makeEntry("libelf/c", FileMode.REGULAR_FILE)); + b.add(createEntry("libelf-po/a", FileMode.REGULAR_FILE)); + b.add(createEntry("libelf/c", FileMode.REGULAR_FILE)); - o.add(makeEntry("Makefile", FileMode.REGULAR_FILE)); - o.add(makeEntry("libelf-po/a", FileMode.REGULAR_FILE)); - o.add(makeEntry("libelf/c", FileMode.REGULAR_FILE)); + o.add(createEntry("Makefile", FileMode.REGULAR_FILE)); + o.add(createEntry("libelf-po/a", FileMode.REGULAR_FILE)); + o.add(createEntry("libelf/c", FileMode.REGULAR_FILE)); - t.add(makeEntry("libelf-po/a", FileMode.REGULAR_FILE)); - t.add(makeEntry("libelf/c", FileMode.REGULAR_FILE, "blah")); + t.add(createEntry("libelf-po/a", FileMode.REGULAR_FILE)); + t.add(createEntry("libelf/c", FileMode.REGULAR_FILE, "blah")); b.finish(); o.finish(); @@ -176,14 +173,14 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase { final DirCacheBuilder o = treeO.builder(); final DirCacheBuilder t = treeT.builder(); - b.add(makeEntry("d/o", FileMode.REGULAR_FILE)); - b.add(makeEntry("d/t", FileMode.REGULAR_FILE)); + b.add(createEntry("d/o", FileMode.REGULAR_FILE)); + b.add(createEntry("d/t", FileMode.REGULAR_FILE)); - o.add(makeEntry("d/o", FileMode.REGULAR_FILE, "o !")); - o.add(makeEntry("d/t", FileMode.REGULAR_FILE)); + o.add(createEntry("d/o", FileMode.REGULAR_FILE, "o !")); + o.add(createEntry("d/t", FileMode.REGULAR_FILE)); - t.add(makeEntry("d/o", FileMode.REGULAR_FILE)); - t.add(makeEntry("d/t", FileMode.REGULAR_FILE, "t !")); + t.add(createEntry("d/o", FileMode.REGULAR_FILE)); + t.add(createEntry("d/t", FileMode.REGULAR_FILE, "t !")); b.finish(); o.finish(); @@ -224,14 +221,14 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase { final DirCacheBuilder o = treeO.builder(); final DirCacheBuilder t = treeT.builder(); - b.add(makeEntry("d/o", FileMode.REGULAR_FILE)); - b.add(makeEntry("d/t", FileMode.REGULAR_FILE)); + b.add(createEntry("d/o", FileMode.REGULAR_FILE)); + b.add(createEntry("d/t", FileMode.REGULAR_FILE)); - o.add(makeEntry("d/o", FileMode.REGULAR_FILE)); - o.add(makeEntry("d/t", FileMode.REGULAR_FILE, "o !")); + o.add(createEntry("d/o", FileMode.REGULAR_FILE)); + o.add(createEntry("d/t", FileMode.REGULAR_FILE, "o !")); - t.add(makeEntry("d/o", FileMode.REGULAR_FILE, "t !")); - t.add(makeEntry("d/t", FileMode.REGULAR_FILE, "t !")); + t.add(createEntry("d/o", FileMode.REGULAR_FILE, "t !")); + t.add(createEntry("d/t", FileMode.REGULAR_FILE, "t !")); b.finish(); o.finish(); @@ -258,13 +255,13 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase { final DirCacheBuilder o = treeO.builder(); final DirCacheBuilder t = treeT.builder(); - b.add(makeEntry("d/o", FileMode.REGULAR_FILE)); - b.add(makeEntry("d/t", FileMode.REGULAR_FILE)); + b.add(createEntry("d/o", FileMode.REGULAR_FILE)); + b.add(createEntry("d/t", FileMode.REGULAR_FILE)); - o.add(makeEntry("d", FileMode.REGULAR_FILE)); + o.add(createEntry("d", FileMode.REGULAR_FILE)); - t.add(makeEntry("d/o", FileMode.REGULAR_FILE)); - t.add(makeEntry("d/t", FileMode.REGULAR_FILE, "t !")); + t.add(createEntry("d/o", FileMode.REGULAR_FILE)); + t.add(createEntry("d/t", FileMode.REGULAR_FILE, "t !")); b.finish(); o.finish(); @@ -291,13 +288,13 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase { final DirCacheBuilder o = treeO.builder(); final DirCacheBuilder t = treeT.builder(); - b.add(makeEntry("d/o", FileMode.REGULAR_FILE)); - b.add(makeEntry("d/t", FileMode.REGULAR_FILE)); + b.add(createEntry("d/o", FileMode.REGULAR_FILE)); + b.add(createEntry("d/t", FileMode.REGULAR_FILE)); - o.add(makeEntry("d/o", FileMode.REGULAR_FILE)); - o.add(makeEntry("d/t", FileMode.REGULAR_FILE, "o !")); + o.add(createEntry("d/o", FileMode.REGULAR_FILE)); + o.add(createEntry("d/t", FileMode.REGULAR_FILE, "o !")); - t.add(makeEntry("d", FileMode.REGULAR_FILE)); + t.add(createEntry("d", FileMode.REGULAR_FILE)); b.finish(); o.finish(); @@ -324,11 +321,11 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase { final DirCacheBuilder o = treeO.builder(); final DirCacheBuilder t = treeT.builder(); - b.add(makeEntry("d", FileMode.REGULAR_FILE)); + b.add(createEntry("d", FileMode.REGULAR_FILE)); - o.add(makeEntry("d", FileMode.REGULAR_FILE, "o !")); + o.add(createEntry("d", FileMode.REGULAR_FILE, "o !")); - t.add(makeEntry("d/o", FileMode.REGULAR_FILE)); + t.add(createEntry("d/o", FileMode.REGULAR_FILE)); b.finish(); o.finish(); @@ -355,11 +352,11 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase { final DirCacheBuilder o = treeO.builder(); final DirCacheBuilder t = treeT.builder(); - b.add(makeEntry("d", FileMode.REGULAR_FILE)); + b.add(createEntry("d", FileMode.REGULAR_FILE)); - o.add(makeEntry("d/o", FileMode.REGULAR_FILE)); + o.add(createEntry("d/o", FileMode.REGULAR_FILE)); - t.add(makeEntry("d", FileMode.REGULAR_FILE, "t !")); + t.add(createEntry("d", FileMode.REGULAR_FILE, "t !")); b.finish(); o.finish(); @@ -393,18 +390,4 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase { odi.flush(); return id; } - - private DirCacheEntry makeEntry(final String path, final FileMode mode) - throws Exception { - return makeEntry(path, mode, path); - } - - private DirCacheEntry makeEntry(final String path, final FileMode mode, - final String content) throws Exception { - final DirCacheEntry ent = new DirCacheEntry(path); - ent.setFileMode(mode); - ent.setObjectId(new ObjectInserter.Formatter().idFor(OBJ_BLOB, - Constants.encode(content))); - return ent; - } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/ForPathTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/ForPathTest.java index e8b2785b7..7dd343b9f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/ForPathTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/ForPathTest.java @@ -49,7 +49,6 @@ import static org.junit.Assert.assertEquals; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheBuilder; import org.eclipse.jgit.dircache.DirCacheEntry; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectInserter; @@ -65,15 +64,6 @@ public class ForPathTest extends RepositoryTestCase { private static final FileMode EXECUTABLE_FILE = FileMode.EXECUTABLE_FILE; - private DirCacheEntry makeEntry(final String path, final FileMode mode) - throws Exception { - final DirCacheEntry ent = new DirCacheEntry(path); - ent.setFileMode(mode); - ent.setObjectId(new ObjectInserter.Formatter().idFor( - Constants.OBJ_BLOB, Constants.encode(path))); - return ent; - } - @Test public void testFindObjects() throws Exception { final DirCache tree0 = DirCache.newInCore(); @@ -81,13 +71,13 @@ public class ForPathTest extends RepositoryTestCase { ObjectReader or = db.newObjectReader(); ObjectInserter oi = db.newObjectInserter(); - DirCacheEntry aDotB = makeEntry("a.b", EXECUTABLE_FILE); + DirCacheEntry aDotB = createEntry("a.b", EXECUTABLE_FILE); b0.add(aDotB); - DirCacheEntry aSlashB = makeEntry("a/b", REGULAR_FILE); + DirCacheEntry aSlashB = createEntry("a/b", REGULAR_FILE); b0.add(aSlashB); - DirCacheEntry aSlashCSlashD = makeEntry("a/c/d", REGULAR_FILE); + DirCacheEntry aSlashCSlashD = createEntry("a/c/d", REGULAR_FILE); b0.add(aSlashCSlashD); - DirCacheEntry aZeroB = makeEntry("a0b", SYMLINK); + DirCacheEntry aZeroB = createEntry("a0b", SYMLINK); b0.add(aZeroB); b0.finish(); assertEquals(4, tree0.getEntryCount()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/NameConflictTreeWalkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/NameConflictTreeWalkTest.java index 707e6c9df..3f37e8679 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/NameConflictTreeWalkTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/NameConflictTreeWalkTest.java @@ -49,11 +49,8 @@ import static org.junit.Assert.assertTrue; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheBuilder; -import org.eclipse.jgit.dircache.DirCacheEntry; import org.eclipse.jgit.dircache.DirCacheIterator; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; -import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.RepositoryTestCase; import org.junit.Test; @@ -76,10 +73,10 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase { final DirCacheBuilder b0 = tree0.builder(); final DirCacheBuilder b1 = tree1.builder(); - b0.add(makeEntry("a", REGULAR_FILE)); - b0.add(makeEntry("a.b", EXECUTABLE_FILE)); - b1.add(makeEntry("a/b", REGULAR_FILE)); - b0.add(makeEntry("a0b", SYMLINK)); + b0.add(createEntry("a", REGULAR_FILE)); + b0.add(createEntry("a.b", EXECUTABLE_FILE)); + b1.add(createEntry("a/b", REGULAR_FILE)); + b0.add(createEntry("a0b", SYMLINK)); b0.finish(); b1.finish(); @@ -107,10 +104,10 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase { final DirCacheBuilder b0 = tree0.builder(); final DirCacheBuilder b1 = tree1.builder(); - b0.add(makeEntry("a", REGULAR_FILE)); - b0.add(makeEntry("a.b", EXECUTABLE_FILE)); - b1.add(makeEntry("a/b", REGULAR_FILE)); - b0.add(makeEntry("a0b", SYMLINK)); + b0.add(createEntry("a", REGULAR_FILE)); + b0.add(createEntry("a.b", EXECUTABLE_FILE)); + b1.add(createEntry("a/b", REGULAR_FILE)); + b0.add(createEntry("a0b", SYMLINK)); b0.finish(); b1.finish(); @@ -142,11 +139,11 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase { final DirCacheBuilder b0 = tree0.builder(); final DirCacheBuilder b1 = tree1.builder(); - b0.add(makeEntry("a", REGULAR_FILE)); - b0.add(makeEntry("a.b", EXECUTABLE_FILE)); - b1.add(makeEntry("a.b", EXECUTABLE_FILE)); - b1.add(makeEntry("a/b", REGULAR_FILE)); - b0.add(makeEntry("a0b", SYMLINK)); + b0.add(createEntry("a", REGULAR_FILE)); + b0.add(createEntry("a.b", EXECUTABLE_FILE)); + b1.add(createEntry("a.b", EXECUTABLE_FILE)); + b1.add(createEntry("a/b", REGULAR_FILE)); + b0.add(createEntry("a0b", SYMLINK)); b0.finish(); b1.finish(); @@ -178,11 +175,11 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase { final DirCacheBuilder b0 = tree0.builder(); final DirCacheBuilder b1 = tree1.builder(); - b0.add(makeEntry("a", REGULAR_FILE)); - b1.add(makeEntry("a.b", EXECUTABLE_FILE)); - b1.add(makeEntry("a/b", REGULAR_FILE)); - b0.add(makeEntry("a0b", SYMLINK)); - b1.add(makeEntry("a0b", SYMLINK)); + b0.add(createEntry("a", REGULAR_FILE)); + b1.add(createEntry("a.b", EXECUTABLE_FILE)); + b1.add(createEntry("a/b", REGULAR_FILE)); + b0.add(createEntry("a0b", SYMLINK)); + b1.add(createEntry("a0b", SYMLINK)); b0.finish(); b1.finish(); @@ -214,12 +211,12 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase { final DirCacheBuilder b0 = tree0.builder(); final DirCacheBuilder b1 = tree1.builder(); - b0.add(makeEntry("0", REGULAR_FILE)); - b0.add(makeEntry("a", REGULAR_FILE)); - b1.add(makeEntry("0", REGULAR_FILE)); - b1.add(makeEntry("a.b", REGULAR_FILE)); - b1.add(makeEntry("a/b", REGULAR_FILE)); - b1.add(makeEntry("a/c/e", REGULAR_FILE)); + b0.add(createEntry("0", REGULAR_FILE)); + b0.add(createEntry("a", REGULAR_FILE)); + b1.add(createEntry("0", REGULAR_FILE)); + b1.add(createEntry("a.b", REGULAR_FILE)); + b1.add(createEntry("a/b", REGULAR_FILE)); + b1.add(createEntry("a/c/e", REGULAR_FILE)); b0.finish(); b1.finish(); @@ -249,15 +246,6 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase { assertFalse(tw.isDirectoryFileConflict()); } - private DirCacheEntry makeEntry(final String path, final FileMode mode) - throws Exception { - final DirCacheEntry ent = new DirCacheEntry(path); - ent.setFileMode(mode); - ent.setObjectId(new ObjectInserter.Formatter().idFor( - Constants.OBJ_BLOB, Constants.encode(path))); - return ent; - } - private static void assertModes(final String path, final FileMode mode0, final FileMode mode1, final TreeWalk tw) throws Exception { assertTrue("has " + path, tw.next()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java index e80d48533..ddb31b14d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java @@ -53,9 +53,7 @@ import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheBuilder; import org.eclipse.jgit.dircache.DirCacheEntry; import org.eclipse.jgit.dircache.DirCacheIterator; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; -import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.RepositoryTestCase; import org.junit.Test; @@ -183,11 +181,7 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase { } private DirCacheEntry makeFile(final String path) throws Exception { - final DirCacheEntry ent = new DirCacheEntry(path); - ent.setFileMode(REGULAR_FILE); - ent.setObjectId(new ObjectInserter.Formatter().idFor( - Constants.OBJ_BLOB, Constants.encode(path))); - return ent; + return createEntry(path, REGULAR_FILE); } private static void assertModes(final String path, final FileMode mode0,