Package org.eclipse.jgit.treewalk

Examples of org.eclipse.jgit.treewalk.WorkingTreeIterator


    tw.addTree(new DirCacheIterator(dc));
    tw.addTree(new FileTreeIterator(repo));
    tw.setRecursive(true);
    tw.setFilter(PathFilter.create(path));
    DirCacheIterator dcIt;
    WorkingTreeIterator wtIt;
    while(tw.next()) {
      dcIt = tw.getTree(0, DirCacheIterator.class);
      wtIt = tw.getTree(1, WorkingTreeIterator.class);
      if (dcIt == null || wtIt == null)
        return true;
      if (wtIt.isModified(dcIt.getDirCacheEntry(), true)) {
        return true;
      }
    }
    return false;
  }
View Full Code Here


        do {
          AbstractTreeIterator headIter = treeWalk.getTree(0,
              AbstractTreeIterator.class);
          DirCacheIterator indexIter = treeWalk.getTree(1,
              DirCacheIterator.class);
          WorkingTreeIterator wtIter = treeWalk.getTree(2,
              WorkingTreeIterator.class);
          if (indexIter != null
              && !indexIter.getDirCacheEntry().isMerged())
            throw new UnmergedPathsException(
                new UnmergedPathException(
                    indexIter.getDirCacheEntry()));
          if (wtIter != null) {
            if (indexIter == null && headIter == null
                && !includeUntracked)
              continue;
            hasChanges = true;
            if (indexIter != null && wtIter.idEqual(indexIter))
              continue;
            if (headIter != null && wtIter.idEqual(headIter))
              continue;
            treeWalk.getObjectId(id, 0);
            final DirCacheEntry entry = new DirCacheEntry(
                treeWalk.getRawPath());
            entry.setLength(wtIter.getEntryLength());
            entry.setLastModified(wtIter.getEntryLastModified());
            entry.setFileMode(wtIter.getEntryFileMode());
            long contentLength = wtIter.getEntryContentLength();
            InputStream in = wtIter.openEntryStream();
            try {
              entry.setObjectId(inserter.insert(
                  Constants.OBJ_BLOB, contentLength, in));
            } finally {
              in.close();
View Full Code Here

    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 (dirCacheIterator != null) {
        final DirCacheEntry dirCacheEntry = dirCacheIterator
            .getDirCacheEntry();
        if (dirCacheEntry != null) {
          int stage = dirCacheEntry.getStage();
          if (stage > 0) {
            String path = treeWalk.getPathString();
            addConflict(path, stage);
            continue;
          }
        }
      }

      if (treeIterator != null) {
        if (dirCacheIterator != null) {
          if (!treeIterator.idEqual(dirCacheIterator)
              || treeIterator.getEntryRawMode()
              != dirCacheIterator.getEntryRawMode()) {
            // in repo, in index, content diff => changed
            if (!isEntryGitLink(treeIterator)
                || !isEntryGitLink(dirCacheIterator)
                || ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
              changed.add(treeWalk.getPathString());
          }
        } else {
          // in repo, not in index => removed
          if (!isEntryGitLink(treeIterator)
              || ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
            removed.add(treeWalk.getPathString());
          if (workingTreeIterator != null)
            untracked.add(treeWalk.getPathString());
        }
      } else {
        if (dirCacheIterator != null) {
          // not in repo, in index => added
          if (!isEntryGitLink(dirCacheIterator)
              || ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
            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
          if (!isEntryGitLink(dirCacheIterator)
              || ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
            missing.add(treeWalk.getPathString());
        } else {
          if (workingTreeIterator.isModified(
              dirCacheIterator.getDirCacheEntry(), true,
              treeWalk.getObjectReader())) {
            // in index, in workdir, content differs => modified
            if (!isEntryGitLink(dirCacheIterator) || !isEntryGitLink(workingTreeIterator)
                || (ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL && ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY))
View Full Code Here

      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()) {
                FileMode mode = f.getIndexFileMode(c);
                entry.setFileMode(mode);

                if (FileMode.GITLINK != mode) {
                  entry.setLength(sz);
                  entry.setLastModified(f
                      .getEntryLastModified());
                  long contentSize = f
                      .getEntryContentLength();
                  InputStream in = f.openEntryStream();
                  try {
                    entry.setObjectId(inserter.insert(
                        Constants.OBJ_BLOB, contentSize, in));
                  } finally {
                    in.close();
                  }
                } else
                  entry.setObjectId(f.getEntryObjectId());
                builder.add(entry);
                lastAddedFile = path;
              } else {
                builder.add(c.getDirCacheEntry());
              }
View Full Code Here

      tw.addTree(new DirCacheIterator(dc));
      tw.addTree(new FileTreeIterator(repo));
      tw.setRecursive(true);
      tw.setFilter(PathFilter.create(path));
      DirCacheIterator dcIt;
      WorkingTreeIterator wtIt;
      while (tw.next()) {
        dcIt = tw.getTree(0, DirCacheIterator.class);
        wtIt = tw.getTree(1, WorkingTreeIterator.class);
        if (dcIt == null || wtIt == null)
          return true;
        if (wtIt.isModified(dcIt.getDirCacheEntry(), true,
            this.walk.getObjectReader())) {
          return true;
        }
      }
      return false;
View Full Code Here

    // disable that we update the working-tree. We set this back to the
    // original values once a single base commit is created.
    RevCommit currentBase = baseCommits.get(0);
    DirCache oldDircache = dircache;
    boolean oldIncore = inCore;
    WorkingTreeIterator oldWTreeIt = workingTreeIterator;
    workingTreeIterator = null;
    try {
      dircache = dircacheFromTree(currentBase.getTree());
      inCore = true;
View Full Code Here

      String pathName) throws IOException {
    assertTrue("walk has entry", walk.next());
    assertEquals(pathName, walk.getPathString());
    assertEquals(type, walk.getFileMode(0));

    WorkingTreeIterator itr = walk.getTree(0, WorkingTreeIterator.class);
    assertNotNull("has tree", itr);
    assertEquals("is ignored", entryIgnored, itr.isEntryIgnored());
    if (D.equals(type))
      walk.enterSubtree();
  }
View Full Code Here

  @Override
  public boolean include(TreeWalk tw) throws MissingObjectException,
      IncorrectObjectTypeException, IOException {
    final int cnt = tw.getTreeCount();
    final int wm = tw.getRawMode(workingTree);
    WorkingTreeIterator wi = workingTree(tw);
    String path = tw.getPathString();

    DirCacheIterator di = tw.getTree(dirCache, DirCacheIterator.class);
    if (di != null) {
      DirCacheEntry dce = di.getDirCacheEntry();
      if (dce != null) {
        if (dce.isAssumeValid())
          return false;
        // Never filter index entries with a stage different from 0
        if (dce.getStage() != 0)
          return true;
      }
    }

    if (!tw.isPostOrderTraversal()) {
      // detect untracked Folders
      // Whenever we enter a folder in the workingtree assume it will
      // contain only untracked files and add it to
      // untrackedParentFolders. If we later find tracked files we will
      // remove it from this list
      if (FileMode.TREE.equals(wm)
          && !(honorIgnores && wi.isEntryIgnored())) {
        // Clean untrackedParentFolders. This potentially moves entries
        // from untrackedParentFolders to untrackedFolders
        copyUntrackedFolders(path);
        // add the folder we just entered to untrackedParentFolders
        untrackedParentFolders.addFirst(path);
      }

      // detect untracked Folders
      // Whenever we see a tracked file we know that all of its parent
      // folders do not belong into untrackedParentFolders anymore. Clean
      // it.
      for (int i = 0; i < cnt; i++) {
        int rmode = tw.getRawMode(i);
        if (i != workingTree && rmode != FileMode.TYPE_MISSING
            && FileMode.TREE.equals(rmode)) {
          untrackedParentFolders.clear();
          break;
        }
      }
    }

    // If the working tree file doesn't exist, it does exist for at least
    // one other so include this difference.
    if (wm == 0)
      return true;

    // If the path does not appear in the DirCache and its ignored
    // we can avoid returning a result here, but only if its not in any
    // other tree.
    final int dm = tw.getRawMode(dirCache);
    if (dm == FileMode.TYPE_MISSING) {
      if (honorIgnores && wi.isEntryIgnored()) {
        ignoredPaths.add(wi.getEntryPathString());
        int i = 0;
        for (; i < cnt; i++) {
          if (i == dirCache || i == workingTree)
            continue;
          if (tw.getRawMode(i) != FileMode.TYPE_MISSING)
            break;
        }

        // If i is cnt then the path does not appear in any other tree,
        // and this working tree entry can be safely ignored.
        return i == cnt ? false : true;
      } else {
        // In working tree and not ignored, and not in DirCache.
        return true;
      }
    }

    // Always include subtrees as WorkingTreeIterator cannot provide
    // efficient elimination of unmodified subtrees.
    if (tw.isSubtree())
      return true;

    // Try the inexpensive comparisons between index and all real trees
    // first. Only if we don't find a diff here we have to bother with
    // the working tree
    for (int i = 0; i < cnt; i++) {
      if (i == dirCache || i == workingTree)
        continue;
      if (tw.getRawMode(i) != dm || !tw.idEqual(i, dirCache))
        return true;
    }

    // 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.
    return wi.isModified(di.getDirCacheEntry(), true, tw.getObjectReader());
  }
View Full Code Here

  }

  @Override
  public boolean include(TreeWalk tw) throws MissingObjectException,
      IncorrectObjectTypeException, IOException {
    WorkingTreeIterator i = tw.getTree(index, WorkingTreeIterator.class);
    return i == null || !i.isEntryIgnored();
  }
View Full Code Here

    tw.addTree(new DirCacheIterator(dc));
    tw.addTree(new FileTreeIterator(repo));
    tw.setRecursive(true);
    tw.setFilter(PathFilter.create(path));
    DirCacheIterator dcIt;
    WorkingTreeIterator wtIt;
    while(tw.next()) {
      dcIt = tw.getTree(0, DirCacheIterator.class);
      wtIt = tw.getTree(1, WorkingTreeIterator.class);
      if (dcIt == null || wtIt == null)
        return true;
      if (wtIt.isModified(dcIt.getDirCacheEntry(), true)) {
        return true;
      }
    }
    return false;
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.treewalk.WorkingTreeIterator

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.