Search in sources :

Example 1 with DiffAlgorithm

use of org.eclipse.jgit.diff.DiffAlgorithm in project egit by eclipse.

the class BlameRevision method calculateDiffToParent.

private Diff calculateDiffToParent(RevCommit parentCommit) {
    try (ObjectReader reader = repository.newObjectReader()) {
        DiffEntry diffEntry = CompareCoreUtils.getChangeDiffEntry(repository, sourcePath, commit, parentCommit, reader);
        if (diffEntry == null)
            return null;
        RawText oldText = readText(diffEntry.getOldId(), reader);
        RawText newText = readText(diffEntry.getNewId(), reader);
        StoredConfig config = repository.getConfig();
        DiffAlgorithm diffAlgorithm = DiffAlgorithm.getAlgorithm(config.getEnum(ConfigConstants.CONFIG_DIFF_SECTION, null, ConfigConstants.CONFIG_KEY_ALGORITHM, SupportedAlgorithm.HISTOGRAM));
        EditList editList = diffAlgorithm.diff(RawTextComparator.DEFAULT, oldText, newText);
        return new Diff(diffEntry.getOldPath(), oldText, newText, editList);
    } catch (IOException e) {
        return null;
    }
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) DiffAlgorithm(org.eclipse.jgit.diff.DiffAlgorithm) ObjectReader(org.eclipse.jgit.lib.ObjectReader) EditList(org.eclipse.jgit.diff.EditList) IOException(java.io.IOException) RawText(org.eclipse.jgit.diff.RawText) DiffEntry(org.eclipse.jgit.diff.DiffEntry)

Aggregations

IOException (java.io.IOException)1 DiffAlgorithm (org.eclipse.jgit.diff.DiffAlgorithm)1 DiffEntry (org.eclipse.jgit.diff.DiffEntry)1 EditList (org.eclipse.jgit.diff.EditList)1 RawText (org.eclipse.jgit.diff.RawText)1 ObjectReader (org.eclipse.jgit.lib.ObjectReader)1 StoredConfig (org.eclipse.jgit.lib.StoredConfig)1