Package org.eclipse.jgit.treewalk

Examples of org.eclipse.jgit.treewalk.WorkingTreeIterator


    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 && dirCacheEntry.getStage() > 0) {
          conflicts.add(treeWalk.getPathString());
          continue;
        }
      }

      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


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

        final File file = new File(repo.getWorkTree(), path);
        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)) {
            if (f != null) { // the file exists
              DirCacheEntry entry = new DirCacheEntry(path);
              entry.setLength((int)f.getEntryLength());
              entry.setLastModified(f.getEntryLastModified());
              entry.setFileMode(f.getEntryFileMode());
              entry.setObjectId(ow.writeBlob(file));

              builder.add(entry);
              lastAddedFile = path;
            } else if (!update){
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);
      FileMode fileModeTree = treeWalk.getFileMode(TREE);

      if (treeIterator != null) {
        if (dirCacheIterator != null) {
          if (!treeIterator.getEntryObjectId().equals(
              dirCacheIterator.getEntryObjectId())) {
            // in repo, in index, content diff => changed
            changed.add(dirCacheIterator.getEntryPathString());
            changesExist = true;
          }
        } else {
          // in repo, not in index => removed
          if (!fileModeTree.equals(FileMode.TYPE_TREE)) {
            removed.add(treeIterator.getEntryPathString());
            changesExist = true;
          }
        }
      } else {
        if (dirCacheIterator != null) {
          // not in repo, in index => added
          added.add(dirCacheIterator.getEntryPathString());
          changesExist = true;
        } else {
          // not in repo, not in index => untracked
          if (workingTreeIterator != null
              && !workingTreeIterator.isEntryIgnored()) {
            untracked.add(workingTreeIterator.getEntryPathString());
            changesExist = 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

      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)) {
        return true;
      }
    }
    return false;
  }
View Full Code Here

    // 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);
    WorkingTreeIterator wi = workingTree(tw);
    if (dm == 0) {
      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) != 0)
            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.
    DirCacheIterator di = tw.getTree(dirCache, DirCacheIterator.class);
    return wi.isModified(di.getDirCacheEntry(), true);
  }
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 && dirCacheEntry.getStage() > 0) {
          conflicts.add(treeWalk.getPathString());
          continue;
        }
      }

      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

        do {
          AbstractTreeIterator headIter = treeWalk.getTree(0,
              AbstractTreeIterator.class);
          DirCacheIterator indexIter = treeWalk.getTree(1,
              DirCacheIterator.class);
          WorkingTreeIterator wtIter = treeWalk.getTree(2,
              WorkingTreeIterator.class);
          if (headIter != null && indexIter != null && wtIter != null) {
            if (wtIter.idEqual(indexIter)
                || 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

        p.accept(counter);
      } catch (CoreException e) {
        // ignore
      }
    }
    WorkingTreeIterator it = IteratorService.createInitialIterator(repo);
    if (it == null)
      throw new OperationCanceledException(); // workspace is closed
    indexDiff = new IndexDiff(repo, Constants.HEAD, it);
    indexDiff.diff(jgitMonitor, counter.count, 0, NLS.bind(
        UIText.CommitActionHandler_repository, repo.getDirectory()
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.