Package org.eclipse.jgit.treewalk

Examples of org.eclipse.jgit.treewalk.CanonicalTreeParser


   */
  public void addTree(final byte[] pathPrefix, final int stage,
      final ObjectReader reader, final AnyObjectId tree) throws IOException {
    final TreeWalk tw = new TreeWalk(reader);
    tw.reset();
    tw.addTree(new CanonicalTreeParser(pathPrefix, reader, tree
        .toObjectId()));
    tw.setRecursive(true);
    if (tw.next()) {
      final DirCacheEntry newEntry = toEntry(stage, tw);
      beforeAdd(newEntry);
View Full Code Here


    Ref gitHead = repo.getRef(ref);
    RevWalk revWalk = new RevWalk(repo);
    RevCommit gitCommit = revWalk.parseCommit(gitHead.getObjectId());
    RevTree gitTree = revWalk.parseTree(gitCommit.getTree().getId());
    CanonicalTreeParser treeParser = new CanonicalTreeParser();
    ObjectReader newObjectReader = repo.newObjectReader();

    try {
      treeParser.reset(newObjectReader, gitTree.getId());
    }
    finally {
      newObjectReader.release();
    }
    revWalk.dispose();
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

   *            ID of a tree containing .gitmodules
   * @return this generator
   * @throws IOException
   */
  public SubmoduleWalk setRootTree(final AnyObjectId id) throws IOException {
    final CanonicalTreeParser p = new CanonicalTreeParser();
    p.reset(walk.getObjectReader(), id);
    rootTree = p;
    modulesConfig = null;
    return this;
  }
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();
              long contentLength = fTree.getEntryContentLength();
              InputStream inputStream = fTree.openEntryStream();
              try {
                dcEntry.setObjectId(inserter.insert(
                    Constants.OBJ_BLOB, contentLength,
                    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

        AbstractTreeIterator treeParserA, treeParserB;
        RevTree treeA = null, treeB = null;

        if (commitA != null) {
            treeA = new RevWalk(repositoryA).parseTree(commitA);
            treeParserA = new CanonicalTreeParser();
            ((CanonicalTreeParser) treeParserA).reset(reader, treeA);
        } else {
            treeParserA = new EmptyTreeIterator();
        }

        if (commitB != null) {
            treeB = new RevWalk(repositoryB).parseTree(commitB);
            treeParserB = new CanonicalTreeParser();
            ((CanonicalTreeParser) treeParserB).reset(reader, treeB);
        } else {
            treeParserB = new EmptyTreeIterator();
        }
View Full Code Here

        return formatter;
    }

    private TreeFormatter rebuildExistingTreeWith(String fileName, ObjectId fileObjectId) throws IOException {
        TreeFormatter formatter = new TreeFormatter();
        CanonicalTreeParser treeParser = getCanonicalTreeParser(this.repository);

        boolean isInsertedInTree = false;
        while(!treeParser.eof()){
            String entryName = new String(treeParser.getEntryPathBuffer(), 0, treeParser.getEntryPathLength());
            String nameForComparison = entryName;

            if (treeParser.getEntryFileMode() == FileMode.TREE){
                nameForComparison = entryName.concat("/"); //for tree ordering comparison
            }
            if (nameForComparison.compareTo(fileName) == 0 && isInsertedInTree == false){
                formatter.append(fileName, FileMode.REGULAR_FILE, fileObjectId);
                isInsertedInTree = true;
            } else if (nameForComparison.compareTo(fileName) > 0 && isInsertedInTree == false) {
                formatter.append(fileName, FileMode.REGULAR_FILE, fileObjectId);
                formatter.append(entryName.getBytes()
                        , treeParser.getEntryFileMode()
                        , treeParser.getEntryObjectId());
                isInsertedInTree = true;
            } else {
                formatter.append(entryName.getBytes()
                        , treeParser.getEntryFileMode()
                        , treeParser.getEntryObjectId());
            }

            treeParser = treeParser.next();
        }
        if(!isInsertedInTree){
            formatter.append(fileName, FileMode.REGULAR_FILE, fileObjectId);
        }
        return formatter;
View Full Code Here

    }

    private CanonicalTreeParser getCanonicalTreeParser(Repository repository) throws IOException {
        RevWalk revWalk = new RevWalk(repository);
        RevCommit commit = revWalk.parseCommit(this.headObjectId);
        return new CanonicalTreeParser(new byte[]{}, revWalk.getObjectReader(), commit.getTree().getId());
    }
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);

      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();
              long contentLength = fTree.getEntryContentLength();
              InputStream inputStream = fTree.openEntryStream();
              try {
                dcEntry.setObjectId(inserter.insert(
                    Constants.OBJ_BLOB, contentLength,
                    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

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.