Package org.eclipse.jgit.treewalk

Examples of org.eclipse.jgit.treewalk.CanonicalTreeParser


      if (cached) {
        if (oldTree == null) {
          ObjectId head = repo.resolve(HEAD + "^{tree}");
          if (head == null)
            throw new NoHeadException(JGitText.get().cannotReadTree);
          CanonicalTreeParser p = new CanonicalTreeParser();
          ObjectReader reader = repo.newObjectReader();
          try {
            p.reset(reader, head);
          } finally {
            reader.release();
          }
          oldTree = p;
        }
View Full Code Here


      tw.setRecursive(true);

      while (tw.next()) {
        final String path = tw.getPathString();
        // DirCacheIterator dci = tw.getTree(0, DirCacheIterator.class);
        final CanonicalTreeParser tree = tw.getTree(1,
            CanonicalTreeParser.class);
        if (tree == null)
          // file is not in the commit, remove from index
          edit.add(new DirCacheEditor.DeletePath(path));
        else { // revert index to commit
          // it seams that there is concurrent access to tree
          // variable, therefore we need to keep references to
          // entryFileMode and entryObjectId in local
          // variables
          final FileMode entryFileMode = tree.getEntryFileMode();
          final ObjectId entryObjectId = tree.getEntryObjectId();
          edit.add(new DirCacheEditor.PathEdit(path) {
            @Override
            public void apply(DirCacheEntry ent) {
              ent.setFileMode(entryFileMode);
              ent.setObjectId(entryObjectId);
View Full Code Here

    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
        boolean tracked = dcTree != null || hTree != null;
        if (!tracked)
          break;

        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();

              InputStream inputStream = fTree.openEntryStream();
              try {
                dcEntry.setObjectId(inserter.insert(
                    Constants.OBJ_BLOB, entryLength,
                    inputStream));
              } finally {
                inputStream.close();
              }
            }
          }

          // update index
          dcEditor.add(new PathEdit(path) {
            @Override
            public void apply(DirCacheEntry ent) {
              ent.copyMetaData(dcEntry);
            }
          });
          // add to temporary in-core index
          dcBuilder.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, remove entry from index and
          // don't add it to temporary in-core index
          dcEditor.add(new DeletePath(path));

          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
          dcBuilder.add(dcEntry);
        }
      }
View Full Code Here

   * @throws IOException
   *             the tree object is not found or cannot be read.
   */
  protected AbstractTreeIterator openTree(final AnyObjectId treeId)
      throws IncorrectObjectTypeException, IOException {
    return new CanonicalTreeParser(null, reader, treeId);
  }
View Full Code Here

   *             trees cannot be read or file contents cannot be read.
   */
  public List<DiffEntry> scan(RevTree a, RevTree b) throws IOException {
    assertHaveRepository();

    CanonicalTreeParser aParser = new CanonicalTreeParser();
    CanonicalTreeParser bParser = new CanonicalTreeParser();

    aParser.reset(reader, a);
    bParser.reset(reader, b);

    return scan(aParser, bParser);
  }
View Full Code Here

      tw.setFilter(PathFilterGroup.createFromStrings(filepaths));

      while (tw.next()) {
        final String path = tw.getPathString();
        // DirCacheIterator dci = tw.getTree(0, DirCacheIterator.class);
        final CanonicalTreeParser tree = tw.getTree(1,
            CanonicalTreeParser.class);
        if (tree == null)
          // file is not in the commit, remove from index
          edit.add(new DirCacheEditor.DeletePath(path));
        else {
          // revert index to commit
          edit.add(new DirCacheEditor.PathEdit(path) {
            @Override
            public void apply(DirCacheEntry ent) {
              ent.setFileMode(tree.getEntryFileMode());
              ent.setObjectId(tree.getEntryObjectId());
              ent.setLastModified(0);
            }
          });
        }
      }
View Full Code Here

    objectsMap = objects;
    edgeObjects = edges;

    alreadyProcessed = new IntSet();
    treeCache = new ObjectIdOwnerMap<TreeWithData>();
    parser = new CanonicalTreeParser();
    idBuf = new MutableObjectId();
  }
View Full Code Here

    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
        boolean tracked = dcTree != null || hTree != null;
        if (!tracked)
          break;

        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.getEntryFileMode());

          boolean objectExists = (dcTree != null && fTree
              .idEqual(dcTree))
              || (hTree != null && fTree.idEqual(hTree));
          if (objectExists) {
            dcEntry.setObjectId(fTree.getEntryObjectId());
          } else {
            // insert object
            if (inserter == null)
              inserter = repo.newObjectInserter();

            InputStream inputStream = fTree.openEntryStream();
            try {
              dcEntry.setObjectId(inserter.insert(
                  Constants.OBJ_BLOB, entryLength,
                  inputStream));
            } finally {
              inputStream.close();
            }
          }

          // update index
          dcEditor.add(new PathEdit(path) {
            @Override
            public void apply(DirCacheEntry ent) {
              ent.copyMetaData(dcEntry);
            }
          });
          // add to temporary in-core index
          dcBuilder.add(dcEntry);

          if (emptyCommit && (hTree == null || !hTree.idEqual(fTree)))
            // this is a change
            emptyCommit = false;
        } else {
          // if no file exists on disk, remove entry from index and
          // don't add it to temporary in-core index
          dcEditor.add(new DeletePath(path));

          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
          dcBuilder.add(dcEntry);
        }
      }
View Full Code Here

   *             trees cannot be read or file contents cannot be read.
   */
  public List<DiffEntry> scan(RevTree a, RevTree b) throws IOException {
    assertHaveRepository();

    CanonicalTreeParser aParser = new CanonicalTreeParser();
    CanonicalTreeParser bParser = new CanonicalTreeParser();

    aParser.reset(reader, a);
    bParser.reset(reader, b);

    return scan(aParser, bParser);
  }
View Full Code Here

    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);

      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);
        }
View Full Code Here

TOP

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

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.