Search in sources :

Example 11 with FileDiff

use of org.eclipse.egit.ui.internal.history.FileDiff in project egit by eclipse.

the class RepositoryCommit method getDiffs.

/**
 * Get the changes between this commit and all parent commits
 *
 * @return non-null but possibly empty array of {@link FileDiff} instances.
 */
public FileDiff[] getDiffs() {
    if (diffs == null) {
        RevCommit[] parents = commit.getParents();
        if (isStash() && commit.getParentCount() > 0)
            parents = new RevCommit[] { commit.getParent(0) };
        try (RevWalk revWalk = new RevWalk(repository);
            TreeWalk treewalk = new TreeWalk(revWalk.getObjectReader())) {
            treewalk.setRecursive(true);
            treewalk.setFilter(TreeFilter.ANY_DIFF);
            for (RevCommit parent : commit.getParents()) revWalk.parseBody(parent);
            diffs = FileDiff.compute(repository, treewalk, commit, parents, TreeFilter.ALL);
        } catch (IOException e) {
            diffs = new FileDiff[0];
        }
    }
    return diffs;
}
Also used : FileDiff(org.eclipse.egit.ui.internal.history.FileDiff) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 12 with FileDiff

use of org.eclipse.egit.ui.internal.history.FileDiff in project egit by eclipse.

the class StashEditorPage method getStagedDiffs.

/**
 * @return diffs for staged changes
 */
protected FileDiff[] getStagedDiffs() {
    List<FileDiff> stagedDiffsResult = new ArrayList<>();
    if (getCommit().getRevCommit().getParentCount() > 1) {
        RevCommit stagedCommit = getCommit().getRevCommit().getParent(PARENT_COMMIT_STAGED);
        FileDiff[] stagedDiffs = new RepositoryCommit(getCommit().getRepository(), stagedCommit).getDiffs();
        stagedDiffsResult.addAll(asList(stagedDiffs));
    }
    return stagedDiffsResult.toArray(new FileDiff[stagedDiffsResult.size()]);
}
Also used : ArrayList(java.util.ArrayList) FileDiff(org.eclipse.egit.ui.internal.history.FileDiff) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

FileDiff (org.eclipse.egit.ui.internal.history.FileDiff)12 ArrayList (java.util.ArrayList)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 IOException (java.io.IOException)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 Job (org.eclipse.core.runtime.jobs.Job)3 File (java.io.File)2 DiffEntry (org.eclipse.jgit.diff.DiffEntry)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Collectors (java.util.stream.Collectors)1 IStatus (org.eclipse.core.runtime.IStatus)1 Path (org.eclipse.core.runtime.Path)1