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


  public static SubmoduleWalk forIndex(Repository repository)
      throws IOException {
    SubmoduleWalk generator = new SubmoduleWalk(repository);
    try {
      DirCache index = repository.readDirCache();
      generator.setTree(new DirCacheIterator(index));
    } catch (IOException e) {
      generator.release();
      throw e;
    }
    return generator;
View Full Code Here

    onlyProcessed = new boolean[only.size()];
    boolean emptyCommit = true;

    TreeWalk treeWalk = new TreeWalk(repo);
    int dcIdx = treeWalk.addTree(new DirCacheIterator(index));
    int fIdx = treeWalk.addTree(new FileTreeIterator(repo));
    int hIdx = -1;
    if (headId != null)
      hIdx = treeWalk.addTree(new RevWalk(repo).parseTree(headId));
    treeWalk.setRecursive(true);

    while (treeWalk.next()) {
      String path = treeWalk.getPathString();
      // check if current entry's path matches a specified path
      int pos = lookupOnly(path);

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

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

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

        // check if entry refers to a tracked file
View Full Code Here

    SubmoduleWalk generator;
    if (isInMemory()) {
      generator = new InMemorySubmoduleWalk(repository, submodulesConfig);
      try {
        DirCache index = repository.readDirCache();
        generator.setTree(new DirCacheIterator(index));
      } catch (IOException e) {
        generator.release();
        throw e;
      }
    } else {
View Full Code Here

    onlyProcessed = new boolean[only.size()];
    boolean emptyCommit = true;

    TreeWalk treeWalk = new TreeWalk(repo);
    int dcIdx = treeWalk.addTree(new DirCacheIterator(index));
    int fIdx = treeWalk.addTree(new FileTreeIterator(repo));
    int hIdx = -1;
    if (headId != null)
      hIdx = treeWalk.addTree(new RevWalk(repo).parseTree(headId));
    treeWalk.setRecursive(true);

    while (treeWalk.next()) {
      String path = treeWalk.getPathString();
      // check if current entry's path matches a specified path
      int pos = lookupOnly(path);

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

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

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

        // check if entry refers to a tracked 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()) {
                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());
              }

            } else if (c != null
                && (!update || FileMode.GITLINK == c
                    .getEntryFileMode()))
              builder.add(c.getDirCacheEntry());
          }
        }
      }
      inserter.flush();
      builder.commit();
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

      headIter.reset(reader, headTree);

      DirCache cache = repo.lockDirCache();
      DirCacheEditor editor = cache.editor();
      try {
        DirCacheIterator indexIter = new DirCacheIterator(cache);
        FileTreeIterator workingIter = new FileTreeIterator(repo);

        TreeWalk treeWalk = new TreeWalk(reader);
        treeWalk.setRecursive(true);
        treeWalk.setFilter(new StashDiffFilter());
View Full Code Here

          } finally {
            reader.release();
          }
          oldTree = p;
        }
        newTree = new DirCacheIterator(repo.readDirCache());
      } else {
        if (oldTree == null)
          oldTree = new DirCacheIterator(repo.readDirCache());
        if (newTree == null)
          newTree = new FileTreeIterator(repo);
      }

      diffFmt.setPathFilter(pathFilter);
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.
    DirCacheIterator di = tw.getTree(dirCache, DirCacheIterator.class);
    return wi.isModified(di.getDirCacheEntry(), true);
  }
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.