Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.FileMode


      if (tw.isSubtree() && !path.equals(tw.getPathString())) {
        tw.enterSubtree();
        continue;
      }
      final ObjectId entid = tw.getObjectId(0);
      final FileMode entmode = tw.getFileMode(0);
      return pool.lookupAny(entid, entmode.getObjectType());
    }
    fail("Can't find " + path + " in tree " + tree.name());
    return null; // never reached.
  }
View Full Code Here


  @Test
  public void testSingleSubtree_Recursive() throws Exception {
    final DirCache dc = DirCache.newInCore();

    final FileMode mode = FileMode.REGULAR_FILE;
    final String[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" };
    final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
    for (int i = 0; i < paths.length; i++) {
      ents[i] = new DirCacheEntry(paths[i]);
      ents[i].setFileMode(mode);
    }

    final DirCacheBuilder b = dc.builder();
    for (int i = 0; i < ents.length; i++)
      b.add(ents[i]);
    b.finish();

    final DirCacheIterator i = new DirCacheIterator(dc);
    final TreeWalk tw = new TreeWalk(db);
    tw.addTree(i);
    tw.setRecursive(true);
    int pathIdx = 0;
    while (tw.next()) {
      final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
      assertNotNull(c);
      assertEquals(pathIdx, c.ptr);
      assertSame(ents[pathIdx], c.getDirCacheEntry());
      assertEquals(paths[pathIdx], tw.getPathString());
      assertEquals(mode.getBits(), tw.getRawMode(0));
      assertSame(mode, tw.getFileMode(0));
      pathIdx++;
    }
    assertEquals(paths.length, pathIdx);
  }
View Full Code Here

  @Test
  public void testTwoLevelSubtree_Recursive() throws Exception {
    final DirCache dc = DirCache.newInCore();

    final FileMode mode = FileMode.REGULAR_FILE;
    final String[] paths = { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };
    final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
    for (int i = 0; i < paths.length; i++) {
      ents[i] = new DirCacheEntry(paths[i]);
      ents[i].setFileMode(mode);
    }

    final DirCacheBuilder b = dc.builder();
    for (int i = 0; i < ents.length; i++)
      b.add(ents[i]);
    b.finish();

    final TreeWalk tw = new TreeWalk(db);
    tw.addTree(new DirCacheIterator(dc));
    tw.setRecursive(true);
    int pathIdx = 0;
    while (tw.next()) {
      final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
      assertNotNull(c);
      assertEquals(pathIdx, c.ptr);
      assertSame(ents[pathIdx], c.getDirCacheEntry());
      assertEquals(paths[pathIdx], tw.getPathString());
      assertEquals(mode.getBits(), tw.getRawMode(0));
      assertSame(mode, tw.getFileMode(0));
      pathIdx++;
    }
    assertEquals(paths.length, pathIdx);
  }
View Full Code Here

  @Test
  public void testReset() throws Exception {
    final DirCache dc = DirCache.newInCore();

    final FileMode mode = FileMode.REGULAR_FILE;
    final String[] paths = { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };
    final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
    for (int i = 0; i < paths.length; i++) {
      ents[i] = new DirCacheEntry(paths[i]);
      ents[i].setFileMode(mode);
View Full Code Here

  @Test
  public void testBackBug396127() throws Exception {
    final DirCache dc = DirCache.newInCore();

    final FileMode mode = FileMode.REGULAR_FILE;
    final String[] paths = { "git-gui/po/fr.po",
        "git_remote_helpers/git/repo.py" };
    final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
    for (int i = 0; i < paths.length; i++) {
      ents[i] = new DirCacheEntry(paths[i]);
View Full Code Here

  @Test
  public void testTwoLevelSubtree_FilterPath() throws Exception {
    final DirCache dc = DirCache.newInCore();

    final FileMode mode = FileMode.REGULAR_FILE;
    final String[] paths = { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };
    final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
    for (int i = 0; i < paths.length; i++) {
      ents[i] = new DirCacheEntry(paths[i]);
      ents[i].setFileMode(mode);
    }

    final DirCacheBuilder b = dc.builder();
    for (int i = 0; i < ents.length; i++)
      b.add(ents[i]);
    b.finish();

    final TreeWalk tw = new TreeWalk(db);
    for (int victimIdx = 0; victimIdx < paths.length; victimIdx++) {
      tw.reset();
      tw.addTree(new DirCacheIterator(dc));
      tw.setFilter(PathFilterGroup.createFromStrings(Collections
          .singleton(paths[victimIdx])));
      tw.setRecursive(tw.getFilter().shouldBeRecursive());
      assertTrue(tw.next());
      final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
      assertNotNull(c);
      assertEquals(victimIdx, c.ptr);
      assertSame(ents[victimIdx], c.getDirCacheEntry());
      assertEquals(paths[victimIdx], tw.getPathString());
      assertEquals(mode.getBits(), tw.getRawMode(0));
      assertSame(mode, tw.getFileMode(0));
      assertFalse(tw.next());
    }
  }
View Full Code Here

  }

  @Test
  public void testBuildOneFile_FinishWriteCommit() throws Exception {
    final String path = "a-file-path";
    final FileMode mode = FileMode.REGULAR_FILE;
    final long lastModified = 1218123387057L;
    final int length = 1342;
    final DirCacheEntry entOrig;
    {
      final DirCache dc = db.lockDirCache();
      final DirCacheBuilder b = dc.builder();
      assertNotNull(b);

      entOrig = new DirCacheEntry(path);
      entOrig.setFileMode(mode);
      entOrig.setLastModified(lastModified);
      entOrig.setLength(length);

      assertNotSame(path, entOrig.getPathString());
      assertEquals(path, entOrig.getPathString());
      assertEquals(ObjectId.zeroId(), entOrig.getObjectId());
      assertEquals(mode.getBits(), entOrig.getRawMode());
      assertEquals(0, entOrig.getStage());
      assertEquals(lastModified, entOrig.getLastModified());
      assertEquals(length, entOrig.getLength());
      assertFalse(entOrig.isAssumeValid());
      b.add(entOrig);

      b.finish();
      assertEquals(1, dc.getEntryCount());
      assertSame(entOrig, dc.getEntry(0));

      dc.write();
      assertTrue(dc.commit());
    }
    {
      final DirCache dc = db.readDirCache();
      assertEquals(1, dc.getEntryCount());

      final DirCacheEntry entRead = dc.getEntry(0);
      assertNotSame(entOrig, entRead);
      assertEquals(path, entRead.getPathString());
      assertEquals(ObjectId.zeroId(), entOrig.getObjectId());
      assertEquals(mode.getBits(), entOrig.getRawMode());
      assertEquals(0, entOrig.getStage());
      assertEquals(lastModified, entOrig.getLastModified());
      assertEquals(length, entOrig.getLength());
      assertFalse(entOrig.isAssumeValid());
    }
View Full Code Here

  }

  @Test
  public void testBuildOneFile_Commit() throws Exception {
    final String path = "a-file-path";
    final FileMode mode = FileMode.REGULAR_FILE;
    final long lastModified = 1218123387057L;
    final int length = 1342;
    final DirCacheEntry entOrig;
    {
      final DirCache dc = db.lockDirCache();
      final DirCacheBuilder b = dc.builder();
      assertNotNull(b);

      entOrig = new DirCacheEntry(path);
      entOrig.setFileMode(mode);
      entOrig.setLastModified(lastModified);
      entOrig.setLength(length);

      assertNotSame(path, entOrig.getPathString());
      assertEquals(path, entOrig.getPathString());
      assertEquals(ObjectId.zeroId(), entOrig.getObjectId());
      assertEquals(mode.getBits(), entOrig.getRawMode());
      assertEquals(0, entOrig.getStage());
      assertEquals(lastModified, entOrig.getLastModified());
      assertEquals(length, entOrig.getLength());
      assertFalse(entOrig.isAssumeValid());
      b.add(entOrig);

      assertTrue(b.commit());
      assertEquals(1, dc.getEntryCount());
      assertSame(entOrig, dc.getEntry(0));
      assertFalse(new File(db.getDirectory(), "index.lock").exists());
    }
    {
      final DirCache dc = db.readDirCache();
      assertEquals(1, dc.getEntryCount());

      final DirCacheEntry entRead = dc.getEntry(0);
      assertNotSame(entOrig, entRead);
      assertEquals(path, entRead.getPathString());
      assertEquals(ObjectId.zeroId(), entOrig.getObjectId());
      assertEquals(mode.getBits(), entOrig.getRawMode());
      assertEquals(0, entOrig.getStage());
      assertEquals(lastModified, entOrig.getLastModified());
      assertEquals(length, entOrig.getLength());
      assertFalse(entOrig.isAssumeValid());
    }
View Full Code Here

      private static final long serialVersionUID = 1L;
      // empty
    }

    final String path = "a-file-path";
    final FileMode mode = FileMode.REGULAR_FILE;
    // "old" date in 2008
    final long lastModified = 1218123387057L;
    final int length = 1342;
    DirCacheEntry entOrig;
    boolean receivedEvent = false;
View Full Code Here

public class DirCacheBuilderIteratorTest extends RepositoryTestCase {
  @Test
  public void testPathFilterGroup_DoesNotSkipTail() throws Exception {
    final DirCache dc = db.readDirCache();

    final FileMode mode = FileMode.REGULAR_FILE;
    final String[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" };
    final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
    for (int i = 0; i < paths.length; i++) {
      ents[i] = new DirCacheEntry(paths[i]);
      ents[i].setFileMode(mode);
    }
    {
      final DirCacheBuilder b = dc.builder();
      for (int i = 0; i < ents.length; i++)
        b.add(ents[i]);
      b.finish();
    }

    final int expIdx = 2;
    final DirCacheBuilder b = dc.builder();
    final TreeWalk tw = new TreeWalk(db);
    tw.addTree(new DirCacheBuildIterator(b));
    tw.setRecursive(true);
    tw.setFilter(PathFilterGroup.createFromStrings(Collections
        .singleton(paths[expIdx])));

    assertTrue("found " + paths[expIdx], tw.next());
    final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
    assertNotNull(c);
    assertEquals(expIdx, c.ptr);
    assertSame(ents[expIdx], c.getDirCacheEntry());
    assertEquals(paths[expIdx], tw.getPathString());
    assertEquals(mode.getBits(), tw.getRawMode(0));
    assertSame(mode, tw.getFileMode(0));
    b.add(c.getDirCacheEntry());

    assertFalse("no more entries", tw.next());
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.lib.FileMode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.