Package org.eclipse.jgit.dircache

Examples of org.eclipse.jgit.dircache.DirCacheIterator


    try {
      dc = repo.lockDirCache();
      edit = dc.editor();

      final TreeWalk tw = new TreeWalk(repo);
      tw.addTree(new DirCacheIterator(dc));
      tw.addTree(commit.getTree());
      tw.setFilter(PathFilterGroup.createFromStrings(filepaths));

      while (tw.next()) {
        final String path = tw.getPathString();
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

    // 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 (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

    // 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

    } catch (NoWorkTreeException e) {
      return Collections.emptySet();
    }
    TreeWalk treeWalk = new TreeWalk(repo);
    try {
      treeWalk.addTree(new DirCacheIterator(repo.readDirCache()));
      ObjectId headID = repo.resolve(Constants.HEAD);
      if (headID != null) {
        revWalk = new RevWalk(repo);
        treeWalk.addTree(revWalk.parseTree(headID));
        revWalk.dispose();
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) {
          contentIdOffset = i.idOffset();
          contentIdFromPtr = ptr;
          return contentId = i.idBuffer();
        }
        contentIdOffset = 0;
      } else {
        contentIdOffset = 0;
      }
View Full Code Here

      CanonicalTreeParser hTree = null;
      if (hIdx != -1)
        hTree = treeWalk.getTree(hIdx, CanonicalTreeParser.class);

      DirCacheIterator dcTree = treeWalk.getTree(dcIdx,
          DirCacheIterator.class);

      if (pos >= 0) {
        // include entry in commit

        FileTreeIterator fTree = treeWalk.getTree(fIdx,
            FileTreeIterator.class);

        // check if entry refers to a tracked file
        boolean tracked = dcTree != null || hTree != null;
        if (!tracked)
          break;

        // for an unmerged path, DirCacheBuildIterator will yield 3
        // entries, we only want to add one
        if (path.equals(lastAddedFile))
          continue;

        lastAddedFile = path;

        if (fTree != null) {
          // create a new DirCacheEntry with data retrieved from disk
          final DirCacheEntry dcEntry = new DirCacheEntry(path);
          long entryLength = fTree.getEntryLength();
          dcEntry.setLength(entryLength);
          dcEntry.setLastModified(fTree.getEntryLastModified());
          dcEntry.setFileMode(fTree.getIndexFileMode(dcTree));

          boolean objectExists = (dcTree != null && fTree
              .idEqual(dcTree))
              || (hTree != null && fTree.idEqual(hTree));
          if (objectExists) {
            dcEntry.setObjectId(fTree.getEntryObjectId());
          } else {
            if (FileMode.GITLINK.equals(dcEntry.getFileMode()))
              dcEntry.setObjectId(fTree.getEntryObjectId());
            else {
              // insert object
              if (inserter == null)
                inserter = repo.newObjectInserter();
              long contentLength = fTree.getEntryContentLength();
              InputStream inputStream = fTree.openEntryStream();
              try {
                dcEntry.setObjectId(inserter.insert(
                    Constants.OBJ_BLOB, contentLength,
                    inputStream));
              } finally {
                inputStream.close();
              }
            }
          }

          // add to existing index
          existingBuilder.add(dcEntry);
          // add to temporary in-core index
          tempBuilder.add(dcEntry);

          if (emptyCommit
              && (hTree == null || !hTree.idEqual(fTree) || hTree
                  .getEntryRawMode() != fTree
                  .getEntryRawMode()))
            // this is a change
            emptyCommit = false;
        } else {
          // if no file exists on disk, neither add it to
          // index nor to temporary in-core index

          if (emptyCommit && hTree != null)
            // this is a change
            emptyCommit = false;
        }

        // keep track of processed path
        onlyProcessed[pos] = true;
      } else {
        // add entries from HEAD for all other paths
        if (hTree != null) {
          // create a new DirCacheEntry with data retrieved from HEAD
          final DirCacheEntry dcEntry = new DirCacheEntry(path);
          dcEntry.setObjectId(hTree.getEntryObjectId());
          dcEntry.setFileMode(hTree.getEntryFileMode());

          // add to temporary in-core index
          tempBuilder.add(dcEntry);
        }

        // preserve existing entry in index
        if (dcTree != null)
          existingBuilder.add(dcTree.getDirCacheEntry());
      }
    }

    // there must be no unprocessed paths left at this point; otherwise an
    // untracked or unknown path has been specified
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

    try {
      DirCacheBuilder builder = dc.builder();

      walk = new TreeWalk(repo);
      walk.addTree(commit.getTree());
      walk.addTree(new DirCacheIterator(dc));
      walk.setRecursive(true);

      while (walk.next()) {
        AbstractTreeIterator cIter = walk.getTree(0,
            AbstractTreeIterator.class);
        if (cIter == null) {
          // Not in commit, don't add to new index
          continue;
        }

        final DirCacheEntry entry = new DirCacheEntry(walk.getRawPath());
        entry.setFileMode(cIter.getEntryFileMode());
        entry.setObjectIdFromRaw(cIter.idBuffer(), cIter.idOffset());

        DirCacheIterator dcIter = walk.getTree(1,
            DirCacheIterator.class);
        if (dcIter != null && dcIter.idEqual(cIter)) {
          DirCacheEntry indexEntry = dcIter.getDirCacheEntry();
          entry.setLastModified(indexEntry.getLastModified());
          entry.setLength(indexEntry.getLength());
        }

        builder.add(entry);
View Full Code Here

    return this;
  }

  private void checkoutPathsFromIndex(TreeWalk treeWalk, DirCache dc)
      throws IOException {
    DirCacheIterator dci = new DirCacheIterator(dc);
    treeWalk.addTree(dci);

    final ObjectReader r = treeWalk.getObjectReader();
    DirCacheEditor editor = dc.editor();
    while (treeWalk.next()) {
      DirCacheEntry entry = dci.getDirCacheEntry();
      // Only add one edit per path
      if (entry != null && entry.getStage() > DirCacheEntry.STAGE_1)
        continue;
      editor.add(new PathEdit(treeWalk.getPathString()) {
        public void apply(DirCacheEntry ent) {
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.