Search in sources :

Example 1 with RevisionInformation

use of org.eclipse.jface.text.revisions.RevisionInformation in project egit by eclipse.

the class BlameOperation method execute.

@Override
public void execute(IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, 3);
    final RevisionInformation info = new RevisionInformation();
    final BlameCommand command = new BlameCommand(repository).setFollowFileRenames(true).setFilePath(path);
    if (startCommit != null)
        command.setStartCommit(startCommit);
    else {
        try {
            command.setStartCommit(repository.resolve(Constants.HEAD));
        } catch (IOException e) {
            Activator.error("Error resolving HEAD for showing annotations in repository: " + repository, // $NON-NLS-1$
            e);
            return;
        }
    }
    if (Activator.getDefault().getPreferenceStore().getBoolean(UIPreferences.BLAME_IGNORE_WHITESPACE))
        command.setTextComparator(RawTextComparator.WS_IGNORE_ALL);
    BlameResult result;
    try {
        result = command.call();
    } catch (Exception e1) {
        Activator.error(e1.getMessage(), e1);
        return;
    }
    progress.worked(1);
    if (result == null)
        return;
    Map<RevCommit, BlameRevision> revisions = new HashMap<>();
    int lineCount = result.getResultContents().size();
    BlameRevision previous = null;
    for (int i = 0; i < lineCount; i++) {
        RevCommit commit = result.getSourceCommit(i);
        String sourcePath = result.getSourcePath(i);
        if (commit == null) {
            // Unregister the current revision
            if (previous != null) {
                previous.register();
                previous = null;
            }
            continue;
        }
        BlameRevision revision = revisions.get(commit);
        if (revision == null) {
            revision = new BlameRevision();
            revision.setRepository(repository);
            revision.setCommit(commit);
            revision.setSourcePath(sourcePath);
            revisions.put(commit, revision);
            info.addRevision(revision);
        }
        revision.addSourceLine(i, result.getSourceLine(i));
        if (previous != null)
            if (previous == revision)
                previous.addLine();
            else {
                previous.register();
                previous = revision.reset(i);
            }
        else
            previous = revision.reset(i);
    }
    if (previous != null)
        previous.register();
    progress.worked(1);
    if (shell.isDisposed()) {
        return;
    }
    if (fileRevision != null) {
        storage = fileRevision.getStorage(progress.newChild(1));
    } else {
        progress.worked(1);
    }
    shell.getDisplay().asyncExec(new Runnable() {

        @Override
        public void run() {
            openEditor(info);
        }
    });
}
Also used : BlameResult(org.eclipse.jgit.blame.BlameResult) HashMap(java.util.HashMap) SubMonitor(org.eclipse.core.runtime.SubMonitor) BlameCommand(org.eclipse.jgit.api.BlameCommand) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) BadLocationException(org.eclipse.jface.text.BadLocationException) IOException(java.io.IOException) RevisionInformation(org.eclipse.jface.text.revisions.RevisionInformation) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 CoreException (org.eclipse.core.runtime.CoreException)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 RevisionInformation (org.eclipse.jface.text.revisions.RevisionInformation)1 BlameCommand (org.eclipse.jgit.api.BlameCommand)1 BlameResult (org.eclipse.jgit.blame.BlameResult)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1