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);
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);
}
import java.text.MessageFormat;
-import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.pgm.CLIText;
import org.eclipse.jgit.pgm.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));
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);
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());
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();
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());
}
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());
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());
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());
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());
}
}
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());
}
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];
}
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);
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" };
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();
assertTrue(dc.commit());
}
{
- final DirCache dc = DirCache.read(db);
+ final DirCache dc = db.readDirCache();
assertEquals(0, dc.getEntryCount());
}
}
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);
assertTrue(dc.commit());
}
{
- final DirCache dc = DirCache.read(db);
+ final DirCache dc = db.readDirCache();
assertEquals(1, dc.getEntryCount());
final DirCacheEntry entRead = dc.getEntry(0);
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);
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);
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);
}
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];
}
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];
}
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];
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];
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);
}
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);
}
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];
}
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 };
}
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];
}
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" };
}
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" };
}
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" };
assertEquals(shortPath, shortEnt.getPathString());
{
- final DirCache dc1 = DirCache.lock(db);
+ final DirCache dc1 = db.lockDirCache();
{
final DirCacheBuilder b = dc1.builder();
b.add(longEnt);
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));
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));
}
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();
}
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];
}
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];
* @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");
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());
// 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();
}
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();
}
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();
}
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();
}
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();
}
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();
}
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();
}
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();
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();
}
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();
}
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();
}
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();
}
public void testNoPostOrder() throws Exception {
- final DirCache tree = DirCache.read(db);
+ final DirCache tree = db.readDirCache();
{
final DirCacheBuilder b = tree.builder();
}
public void testWithPostOrder_EnterSubtree() throws Exception {
- final DirCache tree = DirCache.read(db);
+ final DirCache tree = db.readDirCache();
{
final DirCacheBuilder b = tree.builder();
}
public void testWithPostOrder_NoEnterSubtree() throws Exception {
- final DirCache tree = DirCache.read(db);
+ final DirCache tree = db.readDirCache();
{
final DirCacheBuilder b = tree.builder();
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);
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);
parents.add(0, headId);
// lock the index
- DirCache index = DirCache.lock(repo);
+ DirCache index = repo.lockDirCache();
try {
ObjectInserter odi = repo.newObjectInserter();
try {
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;
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>
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;
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;
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;
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;
}