]> source.dussan.org Git - jgit.git/commitdiff
Move DirCache factory methods to Repository 14/1014/1
authorShawn O. Pearce <spearce@spearce.org>
Wed, 30 Jun 2010 17:39:00 +0000 (10:39 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Wed, 30 Jun 2010 17:39:00 +0000 (10:39 -0700)
Instead of creating the DirCache from a static factory method, use
an instance method on Repository, permitting the implementation to
override the method with a completely different type of DirCache
reading and writing.  This would better support a repository in the
cloud strategy, or even just an in-memory unit test environment.

Change-Id: I6399894b12d6480c4b3ac84d10775dfd1b8d13e7
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
21 files changed:
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/MakeCacheTree.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ReadDirCache.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowCacheTree.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowDirCache.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/WriteDirCache.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheFindTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheLargePathTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheTreeTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/NameConflictTreeWalkTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTestCase.java
org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

index b0cc5248c9b53af59a5b7d6b9e73d224ab1bfc61..9f577ff05e26ea9cce8244d1a6a0fc04d856ab43 100644 (file)
@@ -69,7 +69,7 @@ class Rm extends TextBuiltin {
        protected void run() throws Exception {
                root = db.getWorkTree();
 
-               final DirCache dirc = DirCache.lock(db);
+               final DirCache dirc = db.lockDirCache();
                final DirCacheBuilder edit = dirc.builder();
 
                final TreeWalk walk = new TreeWalk(db);
index d772ffe23f13fc4a2a5b3866f9baebc5a6123554..709b45a17b3cb9ec8c8171e246c1cba4eafa0966 100644 (file)
@@ -54,7 +54,7 @@ import org.eclipse.jgit.pgm.TextBuiltin;
 class MakeCacheTree extends TextBuiltin {
        @Override
        protected void run() throws Exception {
-               final DirCache cache = DirCache.read(db);
+               final DirCache cache = db.readDirCache();
                final DirCacheTree tree = cache.getCacheTree(true);
                show(tree);
        }
index 2a1079b313bf90bd8daad6a96083fa291f3722d1..0ca050880eafc576a4789b30ef96cd8f9b2b2939 100644 (file)
@@ -46,7 +46,6 @@ package org.eclipse.jgit.pgm.debug;
 
 import java.text.MessageFormat;
 
-import org.eclipse.jgit.dircache.DirCache;
 import org.eclipse.jgit.pgm.CLIText;
 import org.eclipse.jgit.pgm.TextBuiltin;
 
@@ -56,7 +55,7 @@ class ReadDirCache extends TextBuiltin {
                final int cnt = 100;
                final long start = System.currentTimeMillis();
                for (int i = 0; i < cnt; i++)
-                       DirCache.read(db);
+                       db.readDirCache();
                final long end = System.currentTimeMillis();
                out.print(" ");
                out.println(MessageFormat.format(CLIText.get().averageMSPerRead, (end - start) / cnt));
index 09796edb30e09534c8265bf36f0aa048ef3ae49b..c49aefbf2fe1b1300ce513effd5ccc7b6b7b0ca8 100644 (file)
@@ -54,7 +54,7 @@ import org.eclipse.jgit.pgm.TextBuiltin;
 class ShowCacheTree extends TextBuiltin {
        @Override
        protected void run() throws Exception {
-               final DirCache cache = DirCache.read(db);
+               final DirCache cache = db.readDirCache();
                final DirCacheTree tree = cache.getCacheTree(false);
                if (tree == null)
                        throw die(CLIText.get().noTREESectionInIndex);
index 854596c97b05732ec813a960fe277db32e933129..a94d37ff87d17d982688ebfad85c19d37792f768 100644 (file)
@@ -59,7 +59,7 @@ class ShowDirCache extends TextBuiltin {
                final SimpleDateFormat fmt;
                fmt = new SimpleDateFormat("yyyyMMdd,HHmmss.SSS");
 
-               final DirCache cache = DirCache.read(db);
+               final DirCache cache = db.readDirCache();
                for (int i = 0; i < cache.getEntryCount(); i++) {
                        final DirCacheEntry ent = cache.getEntry(i);
                        final FileMode mode = FileMode.fromBits(ent.getRawMode());
index cee5966a0384a74842a004556c6b4a8250f75c90..142dbeecc8a617eb2e73be242de2aae2def1f000 100644 (file)
@@ -51,7 +51,7 @@ import org.eclipse.jgit.pgm.TextBuiltin;
 class WriteDirCache extends TextBuiltin {
        @Override
        protected void run() throws Exception {
-               final DirCache cache = DirCache.read(db);
+               final DirCache cache = db.readDirCache();
                if (!cache.lock())
                        throw die(CLIText.get().failedToLockIndex);
                cache.read();
index f4692b168deda2539c60b3e8189c2cc4671714f6..c3ac952a11d7650416c8249b87eaedb2d9498fdb 100644 (file)
@@ -54,7 +54,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
                final File idx = new File(db.getDirectory(), "index");
                assertFalse(idx.exists());
 
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
                assertNotNull(dc);
                assertEquals(0, dc.getEntryCount());
        }
@@ -74,7 +74,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
                assertFalse(idx.exists());
                assertFalse(lck.exists());
 
-               final DirCache dc = DirCache.lock(db);
+               final DirCache dc = db.lockDirCache();
                assertNotNull(dc);
                assertFalse(idx.exists());
                assertTrue(lck.exists());
@@ -108,7 +108,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
                assertFalse(idx.exists());
                assertFalse(lck.exists());
 
-               final DirCache dc = DirCache.lock(db);
+               final DirCache dc = db.lockDirCache();
                assertEquals(0, lck.length());
                dc.write();
                assertEquals(12 + 20, lck.length());
@@ -124,7 +124,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
                assertFalse(idx.exists());
                assertFalse(lck.exists());
 
-               final DirCache dc = DirCache.lock(db);
+               final DirCache dc = db.lockDirCache();
                assertEquals(0, lck.length());
                dc.write();
                assertEquals(12 + 20, lck.length());
@@ -141,13 +141,13 @@ public class DirCacheBasicTest extends RepositoryTestCase {
                assertFalse(idx.exists());
                assertFalse(lck.exists());
                {
-                       final DirCache dc = DirCache.lock(db);
+                       final DirCache dc = db.lockDirCache();
                        dc.write();
                        assertTrue(dc.commit());
                        assertTrue(idx.exists());
                }
                {
-                       final DirCache dc = DirCache.read(db);
+                       final DirCache dc = db.readDirCache();
                        assertEquals(0, dc.getEntryCount());
                }
        }
@@ -158,13 +158,13 @@ public class DirCacheBasicTest extends RepositoryTestCase {
                assertFalse(idx.exists());
                assertFalse(lck.exists());
                {
-                       final DirCache dc = DirCache.lock(db);
+                       final DirCache dc = db.lockDirCache();
                        dc.write();
                        assertTrue(dc.commit());
                        assertTrue(idx.exists());
                }
                {
-                       final DirCache dc = DirCache.lock(db);
+                       final DirCache dc = db.lockDirCache();
                        assertEquals(0, dc.getEntryCount());
                        assertTrue(idx.exists());
                        assertTrue(lck.exists());
@@ -173,7 +173,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
        }
 
        public void testBuildThenClear() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
 
                final String[] paths = { "a.", "a.b", "a/b", "a0b" };
                final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
@@ -195,7 +195,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
        }
 
        public void testDetectUnmergedPaths() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
                final DirCacheEntry[] ents = new DirCacheEntry[3];
 
                ents[0] = new DirCacheEntry("a", 1);
index 03bb7f5e830edebc696d767c89f19c4d0950a1ee..a09f8e86c4496e068b0758b0fbcebbf08501b76e 100644 (file)
@@ -52,7 +52,7 @@ import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
 
 public class DirCacheBuilderIteratorTest extends RepositoryTestCase {
        public void testPathFilterGroup_DoesNotSkipTail() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
 
                final FileMode mode = FileMode.REGULAR_FILE;
                final String[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" };
index e919e41f4d947338d74bbb091404367a5d91cb83..81ffab91487d69372ca0cea05370f3735495e918 100644 (file)
@@ -52,7 +52,7 @@ import org.eclipse.jgit.lib.RepositoryTestCase;
 public class DirCacheBuilderTest extends RepositoryTestCase {
        public void testBuildEmpty() throws Exception {
                {
-                       final DirCache dc = DirCache.lock(db);
+                       final DirCache dc = db.lockDirCache();
                        final DirCacheBuilder b = dc.builder();
                        assertNotNull(b);
                        b.finish();
@@ -60,7 +60,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
                        assertTrue(dc.commit());
                }
                {
-                       final DirCache dc = DirCache.read(db);
+                       final DirCache dc = db.readDirCache();
                        assertEquals(0, dc.getEntryCount());
                }
        }
@@ -86,7 +86,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
                final int length = 1342;
                final DirCacheEntry entOrig;
                {
-                       final DirCache dc = DirCache.lock(db);
+                       final DirCache dc = db.lockDirCache();
                        final DirCacheBuilder b = dc.builder();
                        assertNotNull(b);
 
@@ -113,7 +113,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
                        assertTrue(dc.commit());
                }
                {
-                       final DirCache dc = DirCache.read(db);
+                       final DirCache dc = db.readDirCache();
                        assertEquals(1, dc.getEntryCount());
 
                        final DirCacheEntry entRead = dc.getEntry(0);
@@ -135,7 +135,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
                final int length = 1342;
                final DirCacheEntry entOrig;
                {
-                       final DirCache dc = DirCache.lock(db);
+                       final DirCache dc = db.lockDirCache();
                        final DirCacheBuilder b = dc.builder();
                        assertNotNull(b);
 
@@ -160,7 +160,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
                        assertFalse(new File(db.getDirectory(), "index.lock").exists());
                }
                {
-                       final DirCache dc = DirCache.read(db);
+                       final DirCache dc = db.readDirCache();
                        assertEquals(1, dc.getEntryCount());
 
                        final DirCacheEntry entRead = dc.getEntry(0);
@@ -177,7 +177,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
 
        public void testFindSingleFile() throws Exception {
                final String path = "a-file-path";
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
                final DirCacheBuilder b = dc.builder();
                assertNotNull(b);
 
@@ -202,7 +202,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
        }
 
        public void testAdd_InGitSortOrder() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
 
                final String[] paths = { "a.", "a.b", "a/b", "a0b" };
                final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
@@ -226,7 +226,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
        }
 
        public void testAdd_ReverseGitSortOrder() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
 
                final String[] paths = { "a.", "a.b", "a/b", "a0b" };
                final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
@@ -250,7 +250,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
        }
 
        public void testBuilderClear() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
 
                final String[] paths = { "a.", "a.b", "a/b", "a0b" };
                final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
index d5a632c48cbc36498e594d9885581620a8a72097..5533fe358ab2227c864fb5e7d578023a8282c692 100644 (file)
@@ -48,7 +48,7 @@ import org.eclipse.jgit.lib.RepositoryTestCase;
 
 public class DirCacheFindTest extends RepositoryTestCase {
        public void testEntriesWithin() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
 
                final String[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" };
                final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
index efea117388f714d395ccf759e8976966265a247d..24e3c34ddfc4eb93e1e2811cad533e4efccdcb7b 100644 (file)
@@ -52,7 +52,7 @@ import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
 
 public class DirCacheIteratorTest extends RepositoryTestCase {
        public void testEmptyTree_NoTreeWalk() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
                assertEquals(0, dc.getEntryCount());
 
                final DirCacheIterator i = new DirCacheIterator(dc);
@@ -60,7 +60,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
        }
 
        public void testEmptyTree_WithTreeWalk() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
                assertEquals(0, dc.getEntryCount());
 
                final TreeWalk tw = new TreeWalk(db);
@@ -70,7 +70,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
        }
 
        public void testNoSubtree_NoTreeWalk() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
 
                final String[] paths = { "a.", "a0b" };
                final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
@@ -95,7 +95,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
        }
 
        public void testNoSubtree_WithTreeWalk() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
 
                final String[] paths = { "a.", "a0b" };
                final FileMode[] modes = { FileMode.EXECUTABLE_FILE, FileMode.GITLINK };
@@ -128,7 +128,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
        }
 
        public void testSingleSubtree_NoRecursion() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
 
                final String[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" };
                final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
@@ -172,7 +172,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
        }
 
        public void testSingleSubtree_Recursive() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
 
                final FileMode mode = FileMode.REGULAR_FILE;
                final String[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" };
@@ -207,7 +207,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
        }
 
        public void testTwoLevelSubtree_Recursive() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
 
                final FileMode mode = FileMode.REGULAR_FILE;
                final String[] paths = { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };
@@ -241,7 +241,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
        }
 
        public void testTwoLevelSubtree_FilterPath() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
 
                final FileMode mode = FileMode.REGULAR_FILE;
                final String[] paths = { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };
index 0926ab9899c2618204ebc31cbd709808cc209456..a6d7e39eb59c9a4368226341fae3f2754e07bb88 100644 (file)
@@ -85,7 +85,7 @@ public class DirCacheLargePathTest extends RepositoryTestCase {
                assertEquals(shortPath, shortEnt.getPathString());
 
                {
-                       final DirCache dc1 = DirCache.lock(db);
+                       final DirCache dc1 = db.lockDirCache();
                        {
                                final DirCacheBuilder b = dc1.builder();
                                b.add(longEnt);
@@ -97,7 +97,7 @@ public class DirCacheLargePathTest extends RepositoryTestCase {
                        assertSame(shortEnt, dc1.getEntry(1));
                }
                {
-                       final DirCache dc2 = DirCache.read(db);
+                       final DirCache dc2 = db.readDirCache();
                        assertEquals(2, dc2.getEntryCount());
 
                        assertNotSame(longEnt, dc2.getEntry(0));
index 8345c5d83dada2c2c0621540ea22016468b3f12b..dfca2fb29865b59346f1ac9262d79e37d98b5b0d 100644 (file)
@@ -51,12 +51,12 @@ import org.eclipse.jgit.lib.RepositoryTestCase;
 
 public class DirCacheTreeTest extends RepositoryTestCase {
        public void testEmptyCache_NoCacheTree() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
                assertNull(dc.getCacheTree(false));
        }
 
        public void testEmptyCache_CreateEmptyCacheTree() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
                final DirCacheTree tree = dc.getCacheTree(true);
                assertNotNull(tree);
                assertSame(tree, dc.getCacheTree(false));
@@ -69,7 +69,7 @@ public class DirCacheTreeTest extends RepositoryTestCase {
        }
 
        public void testEmptyCache_Clear_NoCacheTree() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
                final DirCacheTree tree = dc.getCacheTree(true);
                assertNotNull(tree);
                dc.clear();
@@ -78,7 +78,7 @@ public class DirCacheTreeTest extends RepositoryTestCase {
        }
 
        public void testSingleSubtree() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
 
                final String[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" };
                final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
@@ -115,7 +115,7 @@ public class DirCacheTreeTest extends RepositoryTestCase {
        }
 
        public void testTwoLevelSubtree() throws Exception {
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
 
                final String[] paths = { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };
                final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
@@ -172,7 +172,7 @@ public class DirCacheTreeTest extends RepositoryTestCase {
         * @throws IOException
         */
        public void testWriteReadTree() throws CorruptObjectException, IOException {
-               final DirCache dc = DirCache.lock(db);
+               final DirCache dc = db.lockDirCache();
 
                final String A = String.format("a%2000s", "a");
                final String B = String.format("b%2000s", "b");
@@ -188,7 +188,7 @@ public class DirCacheTreeTest extends RepositoryTestCase {
                        b.add(ents[i]);
 
                b.commit();
-               DirCache read = DirCache.read(db);
+               DirCache read = db.readDirCache();
 
                assertEquals(paths.length, read.getEntryCount());
                assertEquals(1, read.getCacheTree(true).getChildCount());
index 1b4a11db500ac0a54bd606b47b9b135e7c8928cf..1cd1261636e4078776d70ea0fb9d33e1848df92c 100644 (file)
@@ -67,10 +67,10 @@ public class CherryPickTest extends RepositoryTestCase {
                // Cherry-pick "T" onto "O". This shouldn't introduce "p-fail", which
                // was created by "P", nor should it modify "a", which was done by "P".
                //
-               final DirCache treeB = DirCache.read(db);
-               final DirCache treeO = DirCache.read(db);
-               final DirCache treeP = DirCache.read(db);
-               final DirCache treeT = DirCache.read(db);
+               final DirCache treeB = db.readDirCache();
+               final DirCache treeO = db.readDirCache();
+               final DirCache treeP = db.readDirCache();
+               final DirCache treeT = db.readDirCache();
                {
                        final DirCacheBuilder b = treeB.builder();
                        final DirCacheBuilder o = treeO.builder();
index a4ef2cd6434e92b8310555f28c54af2af8b229b6..8657c52b167cde408e87497cd9f5e18830cd5948 100644 (file)
@@ -105,9 +105,9 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
        }
 
        public void testTrivialTwoWay_validSubtreeSort() throws Exception {
-               final DirCache treeB = DirCache.read(db);
-               final DirCache treeO = DirCache.read(db);
-               final DirCache treeT = DirCache.read(db);
+               final DirCache treeB = db.readDirCache();
+               final DirCache treeO = db.readDirCache();
+               final DirCache treeT = db.readDirCache();
                {
                        final DirCacheBuilder b = treeB.builder();
                        final DirCacheBuilder o = treeO.builder();
@@ -157,9 +157,9 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
        }
 
        public void testTrivialTwoWay_concurrentSubtreeChange() throws Exception {
-               final DirCache treeB = DirCache.read(db);
-               final DirCache treeO = DirCache.read(db);
-               final DirCache treeT = DirCache.read(db);
+               final DirCache treeB = db.readDirCache();
+               final DirCache treeO = db.readDirCache();
+               final DirCache treeT = db.readDirCache();
                {
                        final DirCacheBuilder b = treeB.builder();
                        final DirCacheBuilder o = treeO.builder();
@@ -204,9 +204,9 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
        }
 
        public void testTrivialTwoWay_conflictSubtreeChange() throws Exception {
-               final DirCache treeB = DirCache.read(db);
-               final DirCache treeO = DirCache.read(db);
-               final DirCache treeT = DirCache.read(db);
+               final DirCache treeB = db.readDirCache();
+               final DirCache treeO = db.readDirCache();
+               final DirCache treeT = db.readDirCache();
                {
                        final DirCacheBuilder b = treeB.builder();
                        final DirCacheBuilder o = treeO.builder();
@@ -237,9 +237,9 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
        }
 
        public void testTrivialTwoWay_leftDFconflict1() throws Exception {
-               final DirCache treeB = DirCache.read(db);
-               final DirCache treeO = DirCache.read(db);
-               final DirCache treeT = DirCache.read(db);
+               final DirCache treeB = db.readDirCache();
+               final DirCache treeO = db.readDirCache();
+               final DirCache treeT = db.readDirCache();
                {
                        final DirCacheBuilder b = treeB.builder();
                        final DirCacheBuilder o = treeO.builder();
@@ -269,9 +269,9 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
        }
 
        public void testTrivialTwoWay_rightDFconflict1() throws Exception {
-               final DirCache treeB = DirCache.read(db);
-               final DirCache treeO = DirCache.read(db);
-               final DirCache treeT = DirCache.read(db);
+               final DirCache treeB = db.readDirCache();
+               final DirCache treeO = db.readDirCache();
+               final DirCache treeT = db.readDirCache();
                {
                        final DirCacheBuilder b = treeB.builder();
                        final DirCacheBuilder o = treeO.builder();
@@ -301,9 +301,9 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
        }
 
        public void testTrivialTwoWay_leftDFconflict2() throws Exception {
-               final DirCache treeB = DirCache.read(db);
-               final DirCache treeO = DirCache.read(db);
-               final DirCache treeT = DirCache.read(db);
+               final DirCache treeB = db.readDirCache();
+               final DirCache treeO = db.readDirCache();
+               final DirCache treeT = db.readDirCache();
                {
                        final DirCacheBuilder b = treeB.builder();
                        final DirCacheBuilder o = treeO.builder();
@@ -331,9 +331,9 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
        }
 
        public void testTrivialTwoWay_rightDFconflict2() throws Exception {
-               final DirCache treeB = DirCache.read(db);
-               final DirCache treeO = DirCache.read(db);
-               final DirCache treeT = DirCache.read(db);
+               final DirCache treeB = db.readDirCache();
+               final DirCache treeO = db.readDirCache();
+               final DirCache treeT = db.readDirCache();
                {
                        final DirCacheBuilder b = treeB.builder();
                        final DirCacheBuilder o = treeO.builder();
index 35298b803fa542b0a8918028a0b0e018eb70f527..675331baf47261cc94da6d73315b818a7d7a575f 100644 (file)
@@ -66,8 +66,8 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase {
        private static final FileMode EXECUTABLE_FILE = FileMode.EXECUTABLE_FILE;
 
        public void testNoDF_NoGap() throws Exception {
-               final DirCache tree0 = DirCache.read(db);
-               final DirCache tree1 = DirCache.read(db);
+               final DirCache tree0 = db.readDirCache();
+               final DirCache tree1 = db.readDirCache();
                {
                        final DirCacheBuilder b0 = tree0.builder();
                        final DirCacheBuilder b1 = tree1.builder();
@@ -97,8 +97,8 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase {
        }
 
        public void testDF_NoGap() throws Exception {
-               final DirCache tree0 = DirCache.read(db);
-               final DirCache tree1 = DirCache.read(db);
+               final DirCache tree0 = db.readDirCache();
+               final DirCache tree1 = db.readDirCache();
                {
                        final DirCacheBuilder b0 = tree0.builder();
                        final DirCacheBuilder b1 = tree1.builder();
@@ -128,8 +128,8 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase {
        }
 
        public void testDF_GapByOne() throws Exception {
-               final DirCache tree0 = DirCache.read(db);
-               final DirCache tree1 = DirCache.read(db);
+               final DirCache tree0 = db.readDirCache();
+               final DirCache tree1 = db.readDirCache();
                {
                        final DirCacheBuilder b0 = tree0.builder();
                        final DirCacheBuilder b1 = tree1.builder();
@@ -160,8 +160,8 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase {
        }
 
        public void testDF_SkipsSeenSubtree() throws Exception {
-               final DirCache tree0 = DirCache.read(db);
-               final DirCache tree1 = DirCache.read(db);
+               final DirCache tree0 = db.readDirCache();
+               final DirCache tree1 = db.readDirCache();
                {
                        final DirCacheBuilder b0 = tree0.builder();
                        final DirCacheBuilder b1 = tree1.builder();
index d136b8f2973d14923e2b5a450fd43d1820fce174..274df5bec0e8b3c0a7e72c0b6a600dbcb30b871e 100644 (file)
@@ -86,7 +86,7 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
        }
 
        public void testNoPostOrder() throws Exception {
-               final DirCache tree = DirCache.read(db);
+               final DirCache tree = db.readDirCache();
                {
                        final DirCacheBuilder b = tree.builder();
 
@@ -115,7 +115,7 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
        }
 
        public void testWithPostOrder_EnterSubtree() throws Exception {
-               final DirCache tree = DirCache.read(db);
+               final DirCache tree = db.readDirCache();
                {
                        final DirCacheBuilder b = tree.builder();
 
@@ -150,7 +150,7 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
        }
 
        public void testWithPostOrder_NoEnterSubtree() throws Exception {
-               final DirCache tree = DirCache.read(db);
+               final DirCache tree = db.readDirCache();
                {
                        final DirCacheBuilder b = tree.builder();
 
index ad51ac2ddf3d1fdcf0ac4ce9a5e8c287527ab9fa..302eada999d6342e0d568faa790b747a5e3ae3e3 100644 (file)
@@ -64,7 +64,7 @@ public class PathSuffixFilterTestCase extends RepositoryTestCase {
                final ObjectInserter odi = db.newObjectInserter();
                final ObjectId aSth = odi.insert(OBJ_BLOB, "a.sth".getBytes());
                final ObjectId aTxt = odi.insert(OBJ_BLOB, "a.txt".getBytes());
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
                final DirCacheBuilder builder = dc.builder();
                final DirCacheEntry aSthEntry = new DirCacheEntry("a.sth");
                aSthEntry.setFileMode(FileMode.REGULAR_FILE);
@@ -100,7 +100,7 @@ public class PathSuffixFilterTestCase extends RepositoryTestCase {
                final ObjectId aTxt = odi.insert(OBJ_BLOB, "a.txt".getBytes());
                final ObjectId bSth = odi.insert(OBJ_BLOB, "b.sth".getBytes());
                final ObjectId bTxt = odi.insert(OBJ_BLOB, "b.txt".getBytes());
-               final DirCache dc = DirCache.read(db);
+               final DirCache dc = db.readDirCache();
                final DirCacheBuilder builder = dc.builder();
                final DirCacheEntry aSthEntry = new DirCacheEntry("a.sth");
                aSthEntry.setFileMode(FileMode.REGULAR_FILE);
index c2db140b05b56cf64d03d926eae38aecfb358012..17b711347087b70eeb9ab40e1321662d541ae33e 100644 (file)
@@ -139,7 +139,7 @@ public class CommitCommand extends GitCommand<RevCommit> {
                                parents.add(0, headId);
 
                        // lock the index
-                       DirCache index = DirCache.lock(repo);
+                       DirCache index = repo.lockDirCache();
                        try {
                                ObjectInserter odi = repo.newObjectInserter();
                                try {
index e5b5771d7f137bbdfdeaea5e789db06f0092c85c..cc10fad2b4102c765037b7acd0be6fd886c29b7a 100644 (file)
@@ -62,12 +62,10 @@ import java.util.Comparator;
 
 import org.eclipse.jgit.JGitText;
 import org.eclipse.jgit.errors.CorruptObjectException;
-import org.eclipse.jgit.errors.NoWorkTreeException;
 import org.eclipse.jgit.errors.UnmergedPathException;
 import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.ObjectInserter;
-import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.storage.file.LockFile;
 import org.eclipse.jgit.util.IO;
 import org.eclipse.jgit.util.MutableInteger;
@@ -158,30 +156,6 @@ public class DirCache {
                return c;
        }
 
-       /**
-        * Create a new in-core index representation and read an index from disk.
-        * <p>
-        * The new index will be read before it is returned to the caller. Read
-        * failures are reported as exceptions and therefore prevent the method from
-        * returning a partially populated index.
-        *
-        * @param db
-        *            repository the caller wants to read the default index of.
-        * @return a cache representing the contents of the specified index file (if
-        *         it exists) or an empty cache if the file does not exist.
-        * @throws NoWorkTreeException
-        *             if the repository is bare (lacks a working directory).
-        * @throws IOException
-        *             the index file is present but could not be read.
-        * @throws CorruptObjectException
-        *             the index file is using a format or extension that this
-        *             library does not support.
-        */
-       public static DirCache read(final Repository db)
-                       throws NoWorkTreeException, CorruptObjectException, IOException {
-               return read(db.getIndexFile());
-       }
-
        /**
         * Create a new in-core index representation, lock it, and read from disk.
         * <p>
@@ -223,31 +197,6 @@ public class DirCache {
                return c;
        }
 
-       /**
-        * Create a new in-core index representation, lock it, and read from disk.
-        * <p>
-        * The new index will be locked and then read before it is returned to the
-        * caller. Read failures are reported as exceptions and therefore prevent
-        * the method from returning a partially populated index.
-        *
-        * @param db
-        *            repository the caller wants to read the default index of.
-        * @return a cache representing the contents of the specified index file (if
-        *         it exists) or an empty cache if the file does not exist.
-        * @throws NoWorkTreeException
-        *             if the repository is bare (lacks a working directory).
-        * @throws IOException
-        *             the index file is present but could not be read, or the lock
-        *             could not be obtained.
-        * @throws CorruptObjectException
-        *             the index file is using a format or extension that this
-        *             library does not support.
-        */
-       public static DirCache lock(final Repository db)
-                       throws NoWorkTreeException, CorruptObjectException, IOException {
-               return lock(db.getIndexFile());
-       }
-
        /** Location of the current version of the index file. */
        private final File liveFile;
 
index 70550a8325ae8256f8d760d72c19552b49852cdb..a60cba56faf7750dc0b956cda54f03e197962eba 100644 (file)
@@ -60,6 +60,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 import org.eclipse.jgit.JGitText;
 import org.eclipse.jgit.dircache.DirCache;
+import org.eclipse.jgit.errors.CorruptObjectException;
 import org.eclipse.jgit.errors.IncorrectObjectTypeException;
 import org.eclipse.jgit.errors.MissingObjectException;
 import org.eclipse.jgit.errors.NoWorkTreeException;
@@ -887,6 +888,51 @@ public abstract class Repository {
                return indexFile;
        }
 
+       /**
+        * Create a new in-core index representation and read an index from disk.
+        * <p>
+        * The new index will be read before it is returned to the caller. Read
+        * failures are reported as exceptions and therefore prevent the method from
+        * returning a partially populated index.
+        *
+        * @return a cache representing the contents of the specified index file (if
+        *         it exists) or an empty cache if the file does not exist.
+        * @throws NoWorkTreeException
+        *             if the repository is bare (lacks a working directory).
+        * @throws IOException
+        *             the index file is present but could not be read.
+        * @throws CorruptObjectException
+        *             the index file is using a format or extension that this
+        *             library does not support.
+        */
+       public DirCache readDirCache() throws NoWorkTreeException,
+                       CorruptObjectException, IOException {
+               return DirCache.read(getIndexFile());
+       }
+
+       /**
+        * Create a new in-core index representation, lock it, and read from disk.
+        * <p>
+        * The new index will be locked and then read before it is returned to the
+        * caller. Read failures are reported as exceptions and therefore prevent
+        * the method from returning a partially populated index.
+        *
+        * @return a cache representing the contents of the specified index file (if
+        *         it exists) or an empty cache if the file does not exist.
+        * @throws NoWorkTreeException
+        *             if the repository is bare (lacks a working directory).
+        * @throws IOException
+        *             the index file is present but could not be read, or the lock
+        *             could not be obtained.
+        * @throws CorruptObjectException
+        *             the index file is using a format or extension that this
+        *             library does not support.
+        */
+       public DirCache lockDirCache() throws NoWorkTreeException,
+                       CorruptObjectException, IOException {
+               return DirCache.lock(getIndexFile());
+       }
+
        static byte[] gitInternalSlash(byte[] bytes) {
                if (File.separatorChar == '/')
                        return bytes;
@@ -926,7 +972,7 @@ public abstract class Repository {
                if (new File(getDirectory(), "MERGE_HEAD").exists()) {
                        // we are merging - now check whether we have unmerged paths
                        try {
-                               if (!DirCache.read(this).hasUnmergedPaths()) {
+                               if (!readDirCache().hasUnmergedPaths()) {
                                        // no unmerged paths -> return the MERGING_RESOLVED state
                                        return RepositoryState.MERGING_RESOLVED;
                                }