Package org.eclipse.jgit.diff

Examples of org.eclipse.jgit.diff.DiffFormatter


      "2e1d65e4cf6c5e267e109aa20fd68ae119fa5ec9",
      "5a10bd6ee431e362facb03cfe763b9a3d9dfd02d",
      "README.md");

    // Display the diff.
    DiffFormatter formatter = new DiffFormatter(System.out);
    formatter.setRepository(repo);
    formatter.format(diff);
  }
View Full Code Here


    commit = testRepository.addAndCommit(project.getProject(), deletedFile,
        "whatever");
    FileUtils.delete(deletedFile);

    // unprocessed patch
    DiffFormatter diffFmt = new DiffFormatter(null);
    diffFmt.setRepository(testRepository.getRepository());
    StringBuilder sb = new StringBuilder();
    sb.append("diff --git a/deleted-file b/deleted-file").append("\n");
    sb.append("deleted file mode 100644").append("\n");
    sb.append("index e69de29..0000000").append("\n");
    sb.append("--- a/deleted-file").append("\n");
View Full Code Here

   * of the command. Don't call this method twice on an instance.
   *
   * @return a DiffEntry for each path which is different
   */
  public List<DiffEntry> call() throws GitAPIException, IOException {
    final DiffFormatter diffFmt = new DiffFormatter(null);
    diffFmt.setRepository(repo);
    try {
      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;
        }
        newTree = new DirCacheIterator(repo.readDirCache());
      } else {
        if (oldTree == null)
          oldTree = new DirCacheIterator(repo.readDirCache());
        if (newTree == null)
          newTree = new FileTreeIterator(repo);
      }

      diffFmt.setPathFilter(pathFilter);

      if (showNameAndStatusOnly) {
        return diffFmt.scan(oldTree, newTree);
      } else {
        // TODO: not implemented yet
        throw new UnsupportedOperationException();
      }
    } finally {
      diffFmt.release();
    }
  }
View Full Code Here

    private String parseDiff(Context context, RevWalk walk, RevCommit revCommit) throws Exception {
        if (context.isIndexingDiff() && revCommit.getParentCount() > 0) {
            RevCommit parentCommit = walk.parseCommit(revCommit.getParent(0).getId());
            ByteArrayOutputStream diffOutputStream = new ByteArrayOutputStream();
            DiffFormatter diffFormatter = new DiffFormatter(diffOutputStream);
            diffFormatter.setRepository(context.getRepository());
            diffFormatter.setDiffComparator(RawTextComparator.DEFAULT);
            diffFormatter.setDetectRenames(true);
            diffFormatter.format(parentCommit.getTree(), revCommit.getTree());
            return new String(diffOutputStream.toByteArray());
        } else {
            return null;
        }
    }
View Full Code Here

    PersonIdent author = commitToPick.getAuthorIdent();
    String authorScript = toAuthorScript(author);
    createFile(rebaseDir, AUTHOR_SCRIPT, authorScript);
    createFile(rebaseDir, MESSAGE, commitToPick.getFullMessage());
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DiffFormatter df = new DiffFormatter(bos);
    df.setRepository(repo);
    df.format(commitToPick.getParent(0), commitToPick);
    createFile(rebaseDir, PATCH, new String(bos.toByteArray(),
        Constants.CHARACTER_ENCODING));
    createFile(rebaseDir, STOPPED_SHA, repo.newObjectReader().abbreviate(
        commitToPick).name());
    // Remove cherry pick state file created by CherryPickCommand, it's not
View Full Code Here

                    list.add(tw.getPathString());
                }
                tw.release();
            } else {
                RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
                DiffFormatter df = new DiffFormatter(NullOutputStream.INSTANCE);
                df.setRepository(repository);
                df.setDiffComparator(RawTextComparator.DEFAULT);
                df.setDetectRenames(true);
                List<DiffEntry> diffs = df.scan(parent.getTree(), commit.getTree());
                for (DiffEntry diff : diffs) {

                    if (diff.getChangeType().equals(DiffEntry.ChangeType.DELETE)) {
                        list.add(diff.getOldPath());
                    } else if (diff.getChangeType().equals(DiffEntry.ChangeType.RENAME)) {
View Full Code Here

    PersonIdent author = commitToPick.getAuthorIdent();
    String authorScript = toAuthorScript(author);
    rebaseState.createFile(AUTHOR_SCRIPT, authorScript);
    rebaseState.createFile(MESSAGE, commitToPick.getFullMessage());
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DiffFormatter df = new DiffFormatter(bos);
    df.setRepository(repo);
    df.format(commitToPick.getParent(0), commitToPick);
    rebaseState.createFile(PATCH, new String(bos.toByteArray(),
        Constants.CHARACTER_ENCODING));
    rebaseState.createFile(STOPPED_SHA,
        repo.newObjectReader()
        .abbreviate(
View Full Code Here

        }

        ByteArrayOutputStream buffer = new ByteArrayOutputStream();

        RawTextComparator cmp = RawTextComparator.DEFAULT;
        DiffFormatter formatter = new DiffFormatter(buffer);
        formatter.setRepository(r);
        formatter.setDiffComparator(cmp);
        formatter.setDetectRenames(true);

        RevTree commitTree = commit.getTree();
        RevTree baseTree;
        try {
            if (baseCommit == null) {
                if (commit.getParentCount() > 0) {
                    final RevWalk rw = new RevWalk(r);
                    RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
                    rw.dispose();
                    baseTree = parent.getTree();
                } else {
                    // FIXME initial commit. no parent?!
                    baseTree = commitTree;
                }
            } else {
                baseTree = baseCommit.getTree();
            }

            List<DiffEntry> diffEntries = formatter.scan(baseTree, commitTree);
            if (blobPath != null && blobPath.length() > 0) {
                for (DiffEntry diffEntry : diffEntries) {
                    if (diffEntry.getNewPath().equalsIgnoreCase(blobPath)) {
                        formatter.format(diffEntry);
                        break;
                    }
                }
            } else {
                formatter.format(diffEntries);
            }
            formatter.flush();
            return buffer.toString();
        } catch (IOException e) {
            throw new RuntimeIOException(e);
        }
    }
View Full Code Here

                                ChangeType.ADD));
                    }
                    treeWalk.release();
                } else {
                    RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
                    DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
                    df.setRepository(repository);
                    df.setDiffComparator(RawTextComparator.DEFAULT);
                    df.setDetectRenames(true);
                    List<DiffEntry> diffs = df.scan(parent.getTree(), commit.getTree());
                    for (DiffEntry diff : diffs) {
                        String objectId = diff.getNewId().name();
                        if (diff.getChangeType().equals(ChangeType.DELETE)) {
                            list.add(new CommitTreeInfo(diff.getOldPath(), diff.getOldPath(), 0, diff
                                    .getNewMode().getBits(), objectId, commit.getId().getName(), diff
View Full Code Here

     * class. Each instance of this class should only be used for one invocation
     * of the command. Don't call this method twice on an instance.
     * @return a DiffEntry for each path which is different
     */
    public List<DiffEntry> call() throws GitAPIException {
        final DiffFormatter diffFmt;
        if ( out != null && !showNameAndStatusOnly ) {
            diffFmt = new DiffFormatter( new BufferedOutputStream( out ) );
        } else {
            diffFmt = new DiffFormatter( NullOutputStream.INSTANCE );
        }
        diffFmt.setRepository( repo );
        diffFmt.setProgressMonitor( monitor );
        diffFmt.setDetectRenames( true );
        try {
            if ( cached ) {
                if ( oldTree == null ) {
                    ObjectId head = repo.resolve( HEAD + "^{tree}" ); //$NON-NLS-1$
                    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;
                }
                newTree = new DirCacheIterator( repo.readDirCache() );
            } else {
                if ( oldTree == null ) {
                    oldTree = new DirCacheIterator( repo.readDirCache() );
                }
                if ( newTree == null ) {
                    newTree = new FileTreeIterator( repo );
                }
            }

            diffFmt.setPathFilter( pathFilter );

            List<DiffEntry> result = diffFmt.scan( oldTree, newTree );
            if ( showNameAndStatusOnly ) {
                return result;
            } else {
                if ( contextLines >= 0 ) {
                    diffFmt.setContext( contextLines );
                }
                if ( destinationPrefix != null ) {
                    diffFmt.setNewPrefix( destinationPrefix );
                }
                if ( sourcePrefix != null ) {
                    diffFmt.setOldPrefix( sourcePrefix );
                }
                diffFmt.format( result );
                diffFmt.flush();
                return result;
            }
        } catch ( IOException e ) {
            throw new JGitInternalException( e.getMessage(), e );
        } finally {
            diffFmt.release();
        }
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.diff.DiffFormatter

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.