Package org.eclipse.jgit.dircache

Examples of org.eclipse.jgit.dircache.DirCacheIterator


    // determine whether we need to commit
    TreeWalk treeWalk = new TreeWalk(repo);
    treeWalk.reset();
    treeWalk.setRecursive(true);
    treeWalk.addTree(new DirCacheIterator(dc));
    ObjectId id = repo.resolve(Constants.HEAD + "^{tree}");
    if (id == null)
      throw new NoHeadException(
          JGitText.get().cannotRebaseWithoutCurrentHead);
View Full Code Here


    // Only one chance left to detect a diff: between index and working
    // tree. Make use of the WorkingTreeIterator#isModified() method to
    // avoid computing SHA1 on filesystem content if not really needed.
    WorkingTreeIterator wi = workingTree(tw);
    DirCacheIterator di = tw.getTree(dirCache, DirCacheIterator.class);
    return wi.isModified(di.getDirCacheEntry(), true);
  }
View Full Code Here

    this.treeIdx = treeIdx;
  }

  @Override
  public boolean include(TreeWalk walker) {
    DirCacheIterator i = walker.getTree(treeIdx, DirCacheIterator.class);
    if (i == null)
      return true;

    DirCacheEntry e = i.getDirCacheEntry();
    return e == null || !e.isSkipWorkTree();
  }
View Full Code Here

    if (state.walk != null) {
      // If there is a matching DirCacheIterator, we can reuse
      // its idBuffer, but only if we appear to be clean against
      // the cached index information for the path.
      //
      DirCacheIterator i = state.walk.getTree(state.dirCacheTree,
          DirCacheIterator.class);
      if (i != null) {
        DirCacheEntry ent = i.getDirCacheEntry();
        if (ent != null && compareMetadata(ent) == MetadataDiff.EQUAL)
          return i.idBuffer();
      }
    }

    switch (mode & FileMode.TYPE_MASK) {
    case FileMode.TYPE_FILE:
View Full Code Here

      addAll = true;

    ObjectInserter inserter = repo.newObjectInserter();
    try {
      dc = repo.lockDirCache();
      DirCacheIterator c;

      DirCacheBuilder builder = dc.builder();
      final TreeWalk tw = new TreeWalk(repo);
      tw.addTree(new DirCacheBuildIterator(builder));
      if (workingTreeIterator == null)
        workingTreeIterator = new FileTreeIterator(repo);
      tw.addTree(workingTreeIterator);
      tw.setRecursive(true);
      if (!addAll)
        tw.setFilter(PathFilterGroup.createFromStrings(filepatterns));

      String lastAddedFile = null;

      while (tw.next()) {
        String path = tw.getPathString();

        WorkingTreeIterator f = tw.getTree(1, WorkingTreeIterator.class);
        if (tw.getTree(0, DirCacheIterator.class) == null &&
            f != null && f.isEntryIgnored()) {
          // file is not in index but is ignored, do nothing
        }
        // In case of an existing merge conflict the
        // DirCacheBuildIterator iterates over all stages of
        // this path, we however want to add only one
        // new DirCacheEntry per path.
        else if (!(path.equals(lastAddedFile))) {
          if (!(update && tw.getTree(0, DirCacheIterator.class) == null)) {
            c = tw.getTree(0, DirCacheIterator.class);
            if (f != null) { // the file exists
              long sz = f.getEntryLength();
              DirCacheEntry entry = new DirCacheEntry(path);
              if (c == null || c.getDirCacheEntry() == null
                  || !c.getDirCacheEntry().isAssumeValid()) {
                entry.setLength(sz);
                entry.setLastModified(f.getEntryLastModified());
                entry.setFileMode(f.getEntryFileMode());

                InputStream in = f.openEntryStream();
                try {
                  entry.setObjectId(inserter.insert(
                      Constants.OBJ_BLOB, sz, in));
                } finally {
                  in.close();
                }

                builder.add(entry);
                lastAddedFile = path;
              } else {
                builder.add(c.getDirCacheEntry());
              }

            } else if (!update){
              builder.add(c.getDirCacheEntry());
            }
          }
        }
      }
      inserter.flush();
View Full Code Here

    // add the trees (tree, dirchache, workdir)
    if (tree != null)
      treeWalk.addTree(tree);
    else
      treeWalk.addTree(new EmptyTreeIterator());
    treeWalk.addTree(new DirCacheIterator(dirCache));
    treeWalk.addTree(initialWorkingTreeIterator);
    Collection<TreeFilter> filters = new ArrayList<TreeFilter>(4);

    if (monitor != null) {
      // Get the maximum size of the work tree and index
      // and add some (quite arbitrary)
      if (estIndexSize == 0)
        estIndexSize = dirCache.getEntryCount();
      int total = Math.max(estIndexSize * 10 / 9,
          estWorkTreeSize * 10 / 9);
      monitor.beginTask(title, total);
      filters.add(new ProgressReportingFilter(monitor, total));
    }

    if (filter != null)
      filters.add(filter);
    filters.add(new SkipWorkTreeFilter(INDEX));
    filters.add(new IndexDiffFilter(INDEX, WORKDIR));
    treeWalk.setFilter(AndTreeFilter.create(filters));
    while (treeWalk.next()) {
      AbstractTreeIterator treeIterator = treeWalk.getTree(TREE,
          AbstractTreeIterator.class);
      DirCacheIterator dirCacheIterator = treeWalk.getTree(INDEX,
          DirCacheIterator.class);
      WorkingTreeIterator workingTreeIterator = treeWalk.getTree(WORKDIR,
          WorkingTreeIterator.class);

      if (treeIterator != null) {
        if (dirCacheIterator != null) {
          if (!treeIterator.idEqual(dirCacheIterator)
              || treeIterator.getEntryRawMode()
              != dirCacheIterator.getEntryRawMode()) {
            // in repo, in index, content diff => changed
            changed.add(treeWalk.getPathString());
          }
        } else {
          // in repo, not in index => removed
          removed.add(treeWalk.getPathString());
          if (workingTreeIterator != null)
            untracked.add(treeWalk.getPathString());
        }
      } else {
        if (dirCacheIterator != null) {
          // not in repo, in index => added
          added.add(treeWalk.getPathString());
        } else {
          // not in repo, not in index => untracked
          if (workingTreeIterator != null
              && !workingTreeIterator.isEntryIgnored()) {
            untracked.add(treeWalk.getPathString());
          }
        }
      }

      if (dirCacheIterator != null) {
        if (workingTreeIterator == null) {
          // in index, not in workdir => missing
          missing.add(treeWalk.getPathString());
        } else {
          if (workingTreeIterator.isModified(
              dirCacheIterator.getDirCacheEntry(), true)) {
            // in index, in workdir, content differs => modified
            modified.add(treeWalk.getPathString());
          }
        }
      }
View Full Code Here

    // add the trees (tree, dirchache, workdir)
    if (tree != null)
      treeWalk.addTree(tree);
    else
      treeWalk.addTree(new EmptyTreeIterator());
    treeWalk.addTree(new DirCacheIterator(dirCache));
    treeWalk.addTree(initialWorkingTreeIterator);
    Collection<TreeFilter> filters = new ArrayList<TreeFilter>(4);

    if (monitor != null) {
      // Get the maximum size of the work tree and index
      // and add some (quite arbitrary)
      if (estIndexSize == 0)
        estIndexSize = dirCache.getEntryCount();
      int total = Math.max(estIndexSize * 10 / 9,
          estWorkTreeSize * 10 / 9);
      monitor.beginTask(title, total);
      filters.add(new ProgressReportingFilter(monitor, total));
    }

    if (filter != null)
      filters.add(filter);
    filters.add(new SkipWorkTreeFilter(INDEX));
    filters.add(new IndexDiffFilter(INDEX, WORKDIR));
    treeWalk.setFilter(AndTreeFilter.create(filters));
    while (treeWalk.next()) {
      AbstractTreeIterator treeIterator = treeWalk.getTree(TREE,
          AbstractTreeIterator.class);
      DirCacheIterator dirCacheIterator = treeWalk.getTree(INDEX,
          DirCacheIterator.class);
      WorkingTreeIterator workingTreeIterator = treeWalk.getTree(WORKDIR,
          WorkingTreeIterator.class);

      if (treeIterator != null) {
        if (dirCacheIterator != null) {
          if (!treeIterator.idEqual(dirCacheIterator)
              || treeIterator.getEntryRawMode()
              != dirCacheIterator.getEntryRawMode()) {
            // in repo, in index, content diff => changed
            changed.add(treeWalk.getPathString());
          }
        } else {
          // in repo, not in index => removed
          removed.add(treeWalk.getPathString());
          if (workingTreeIterator != null)
            untracked.add(treeWalk.getPathString());
        }
      } else {
        if (dirCacheIterator != null) {
          // not in repo, in index => added
          added.add(treeWalk.getPathString());
        } else {
          // not in repo, not in index => untracked
          if (workingTreeIterator != null
              && !workingTreeIterator.isEntryIgnored()) {
            untracked.add(treeWalk.getPathString());
          }
        }
      }

      if (dirCacheIterator != null) {
        if (workingTreeIterator == null) {
          // in index, not in workdir => missing
          missing.add(treeWalk.getPathString());
        } else {
          if (workingTreeIterator.isModified(
              dirCacheIterator.getDirCacheEntry(), true)) {
            // in index, in workdir, content differs => modified
            modified.add(treeWalk.getPathString());
          }
        }
      }
View Full Code Here

    // determine whether we need to commit
    TreeWalk treeWalk = new TreeWalk(repo);
    treeWalk.reset();
    treeWalk.setRecursive(true);
    treeWalk.addTree(new DirCacheIterator(dc));
    ObjectId id = repo.resolve(Constants.HEAD + "^{tree}");
    if (id == null)
      throw new NoHeadException(
          JGitText.get().cannotRebaseWithoutCurrentHead);
View Full Code Here

  @Test
  public void testEmpty() throws IOException {
    DirCache dc1 = DirCache.newInCore();
    DirCache dc2 = DirCache.newInCore();
    TreeWalk tw = new TreeWalk(db);
    tw.addTree(new DirCacheIterator(dc1));
    tw.addTree(new DirCacheIterator(dc2));
    assertFalse(tw.next());
  }
View Full Code Here

    editor.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, false));
    editor.finish();

    TreeWalk tw = new TreeWalk(db);
    tw.setRecursive(true);
    tw.addTree(new DirCacheIterator(dc1));
    tw.addTree(new DirCacheIterator(dc2));
    tw.setFilter(InterIndexDiffFilter.INSTANCE);
    assertTrue(tw.next());
    assertEquals("a/a", tw.getPathString());
    assertFalse(tw.next());
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.dircache.DirCacheIterator

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.