Package org.eclipse.jgit.treewalk

Examples of org.eclipse.jgit.treewalk.CanonicalTreeParser


    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


   * @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

   *             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

              .addTree(new RevWalk(repo).parseTree(headId));
        treeWalk.setRecursive(true);

        while (treeWalk.next()) {
          String path = treeWalk.getPathString();
          CanonicalTreeParser hTree = null;
          if (hIdx != -1)
            hTree = treeWalk.getTree(hIdx,
                CanonicalTreeParser.class);
          if (!ignorePaths.contains(path)) {
            // 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

            return emptyList();
        }

        try {
            ObjectReader reader = repo.newObjectReader();
            CanonicalTreeParser oldTreeIter = new CanonicalTreeParser();
            oldTreeIter.reset( reader, oldRef );
            CanonicalTreeParser newTreeIter = new CanonicalTreeParser();
            newTreeIter.reset( reader, newRef );
            return new CustomDiffCommand( repo ).setNewTree( newTreeIter ).setOldTree( oldTreeIter ).setShowNameAndStatusOnly( true ).call();
        } catch ( final Exception ex ) {
            throw new RuntimeException( ex );
        }
    }
View Full Code Here

                final int hIdx = treeWalk.addTree( new RevWalk( git.getRepository() ).parseTree( headId ) );
                treeWalk.setRecursive( true );

                while ( treeWalk.next() ) {
                    final String walkPath = treeWalk.getPathString();
                    final CanonicalTreeParser hTree = treeWalk.getTree( hIdx, CanonicalTreeParser.class );

                    if ( paths.containsKey( walkPath ) && paths.get( walkPath ).getK2().equals( hTree.getEntryObjectId() ) ) {
                        paths.remove( walkPath );
                    }

                    if ( paths.get( walkPath ) == null && !path2delete.contains( walkPath ) ) {
                        final DirCacheEntry dcEntry = new DirCacheEntry( walkPath );
                        final ObjectId _objectId = hTree.getEntryObjectId();
                        final FileMode _fileMode = hTree.getEntryFileMode();

                        // add to temporary in-core index
                        editor.add( new DirCacheEditor.PathEdit( dcEntry ) {
                            @Override
                            public void apply( final DirCacheEntry ent ) {
View Full Code Here

                final int hIdx = treeWalk.addTree( new RevWalk( git.getRepository() ).parseTree( headId ) );
                treeWalk.setRecursive( true );

                while ( treeWalk.next() ) {
                    final String walkPath = treeWalk.getPathString();
                    final CanonicalTreeParser hTree = treeWalk.getTree( hIdx, CanonicalTreeParser.class );

                    final String toPath = content.get( walkPath );

                    if ( toPath == null ) {
                        final DirCacheEntry dcEntry = new DirCacheEntry( walkPath );
                        final ObjectId _objectId = hTree.getEntryObjectId();
                        final FileMode _fileMode = hTree.getEntryFileMode();

                        // add to temporary in-core index
                        editor.add( new DirCacheEditor.PathEdit( dcEntry ) {
                            @Override
                            public void apply( final DirCacheEntry ent ) {
                                ent.setObjectId( _objectId );
                                ent.setFileMode( _fileMode );
                            }
                        } );
                    } else {
                        final DirCacheEntry dcEntry = new DirCacheEntry( toPath );
                        final ObjectId _objectId = hTree.getEntryObjectId();
                        final FileMode _fileMode = hTree.getEntryFileMode();

                        editor.add( new DirCacheEditor.PathEdit( dcEntry ) {
                            @Override
                            public void apply( final DirCacheEntry ent ) {
                                ent.setFileMode( _fileMode );
View Full Code Here

                final int hIdx = treeWalk.addTree( new RevWalk( git.getRepository() ).parseTree( headId ) );
                treeWalk.setRecursive( true );

                while ( treeWalk.next() ) {
                    final String walkPath = treeWalk.getPathString();
                    final CanonicalTreeParser hTree = treeWalk.getTree( hIdx, CanonicalTreeParser.class );

                    final String toPath = content.get( walkPath );

                    final DirCacheEntry dcEntry = new DirCacheEntry( walkPath );
                    final ObjectId _objectId = hTree.getEntryObjectId();
                    final FileMode _fileMode = hTree.getEntryFileMode();

                    // add to temporary in-core index
                    editor.add( new DirCacheEditor.PathEdit( dcEntry ) {
                        @Override
                        public void apply( final DirCacheEntry ent ) {
                            ent.setObjectId( _objectId );
                            ent.setFileMode( _fileMode );
                        }
                    } );

                    if ( toPath != null ) {
                        final DirCacheEntry newdcEntry = new DirCacheEntry( toPath );
                        final ObjectId newObjectId = hTree.getEntryObjectId();
                        final FileMode newFileMode = hTree.getEntryFileMode();

                        editor.add( new DirCacheEditor.PathEdit( newdcEntry ) {
                            @Override
                            public void apply( final DirCacheEntry ent ) {
                                ent.setFileMode( newFileMode );
View Full Code Here

                final int hIdx = treeWalk.addTree( new RevWalk( git.getRepository() ).parseTree( headId ) );
                treeWalk.setRecursive( true );

                while ( treeWalk.next() ) {
                    final String walkPath = treeWalk.getPathString();
                    final CanonicalTreeParser hTree = treeWalk.getTree( hIdx, CanonicalTreeParser.class );

                    final DirCacheEntry dcEntry = new DirCacheEntry( walkPath );
                    final ObjectId _objectId = hTree.getEntryObjectId();
                    final FileMode _fileMode = hTree.getEntryFileMode();

                    // add to temporary in-core index
                    editor.add( new DirCacheEditor.PathEdit( dcEntry ) {
                        @Override
                        public void apply( final DirCacheEntry ent ) {
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.