Search in sources :

Example 1 with DiffType

use of org.eclipse.che.api.git.shared.DiffType in project che by eclipse.

the class JGitDiffPage method writeTo.

@Override
public final void writeTo(OutputStream out) throws IOException {
    DiffFormatter formatter = new DiffFormatter(new BufferedOutputStream(out));
    formatter.setRepository(repository);
    List<String> rawFileFilter = params.getFileFilter();
    TreeFilter pathFilter = (rawFileFilter != null && rawFileFilter.size() > 0) ? PathFilterGroup.createFromStrings(rawFileFilter) : TreeFilter.ALL;
    formatter.setPathFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, pathFilter));
    try {
        String commitA = params.getCommitA();
        String commitB = params.getCommitB();
        boolean cached = params.isCached();
        List<DiffEntry> diff;
        if (commitA == null && commitB == null && !cached) {
            diff = indexToWorkingTree(formatter);
        } else if (commitA != null && commitB == null && !cached) {
            diff = commitToWorkingTree(commitA, formatter);
        } else if (commitA == null && commitB != null) {
            diff = emptyToCommit(commitB, formatter);
        } else if (commitB == null) {
            diff = commitToIndex(commitA, formatter);
        } else {
            diff = commitToCommit(commitA, commitB, formatter);
        }
        DiffType type = params.getType();
        if (type == DiffType.NAME_ONLY) {
            writeNames(diff, out);
        } else if (type == DiffType.NAME_STATUS) {
            writeNamesAndStatus(diff, out);
        } else {
            writeRawDiff(diff, formatter);
        }
    } finally {
        formatter.close();
        repository.close();
    }
}
Also used : AndTreeFilter(org.eclipse.jgit.treewalk.filter.AndTreeFilter) TreeFilter(org.eclipse.jgit.treewalk.filter.TreeFilter) DiffFormatter(org.eclipse.jgit.diff.DiffFormatter) BufferedOutputStream(java.io.BufferedOutputStream) DiffType(org.eclipse.che.api.git.shared.DiffType) DiffEntry(org.eclipse.jgit.diff.DiffEntry)

Aggregations

BufferedOutputStream (java.io.BufferedOutputStream)1 DiffType (org.eclipse.che.api.git.shared.DiffType)1 DiffEntry (org.eclipse.jgit.diff.DiffEntry)1 DiffFormatter (org.eclipse.jgit.diff.DiffFormatter)1 AndTreeFilter (org.eclipse.jgit.treewalk.filter.AndTreeFilter)1 TreeFilter (org.eclipse.jgit.treewalk.filter.TreeFilter)1