Search in sources :

Example 1 with CommitFileRevision

use of org.eclipse.egit.core.internal.storage.CommitFileRevision in project egit by eclipse.

the class ShowBlameActionHandler method execute.

/**
 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 */
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    IStructuredSelection selection = getSelection(event);
    if (selection.size() != 1) {
        return null;
    }
    Object element = selection.getFirstElement();
    IResource resource = AdapterUtils.adapt(element, IResource.class);
    if (resource instanceof IFile) {
        RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
        if (mapping != null) {
            String repoRelativePath = mapping.getRepoRelativePath(resource);
            Shell shell = HandlerUtil.getActiveShell(event);
            IWorkbenchPage page = HandlerUtil.getActiveSite(event).getPage();
            JobUtil.scheduleUserJob(new BlameOperation(mapping.getRepository(), (IFile) resource, repoRelativePath, null, shell, page), UIText.ShowBlameHandler_JobName, JobFamilies.BLAME);
        }
    } else if (element instanceof CommitFileRevision) {
        Shell shell = HandlerUtil.getActiveShell(event);
        IWorkbenchPage page = HandlerUtil.getActiveSite(event).getPage();
        JobUtil.scheduleUserJob(new BlameOperation((CommitFileRevision) element, shell, page), UIText.ShowBlameHandler_JobName, JobFamilies.BLAME);
    }
    return null;
}
Also used : CommitFileRevision(org.eclipse.egit.core.internal.storage.CommitFileRevision) Shell(org.eclipse.swt.widgets.Shell) IFile(org.eclipse.core.resources.IFile) BlameOperation(org.eclipse.egit.ui.internal.blame.BlameOperation) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource)

Example 2 with CommitFileRevision

use of org.eclipse.egit.core.internal.storage.CommitFileRevision in project egit by eclipse.

the class ShowBlameActionHandler method isEnabled.

@Override
public boolean isEnabled() {
    IStructuredSelection selection = getSelection();
    if (selection.size() != 1) {
        return false;
    }
    Object element = selection.getFirstElement();
    IResource resource = AdapterUtils.adapt(element, IResource.class);
    if (resource instanceof IStorage) {
        return RepositoryMapping.getMapping(resource) != null;
    }
    return element instanceof CommitFileRevision;
}
Also used : CommitFileRevision(org.eclipse.egit.core.internal.storage.CommitFileRevision) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStorage(org.eclipse.core.resources.IStorage) IResource(org.eclipse.core.resources.IResource)

Example 3 with CommitFileRevision

use of org.eclipse.egit.core.internal.storage.CommitFileRevision in project egit by eclipse.

the class CommitFileDiffViewer method showAnnotations.

private void showAnnotations(FileDiff d) {
    try {
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        IWorkbenchPage page = window.getActivePage();
        RevCommit commit = d.getChange().equals(ChangeType.DELETE) ? d.getCommit().getParent(0) : d.getCommit();
        String path = d.getPath();
        IFileRevision rev = CompareUtils.getFileRevision(path, commit, getRepository(), d.getChange().equals(ChangeType.DELETE) ? d.getBlobs()[0] : d.getBlobs()[d.getBlobs().length - 1]);
        if (rev instanceof CommitFileRevision) {
            BlameOperation op = new BlameOperation((CommitFileRevision) rev, window.getShell(), page);
            JobUtil.scheduleUserJob(op, UIText.ShowBlameHandler_JobName, JobFamilies.BLAME);
        } else {
            String message = NLS.bind(UIText.DiffViewer_notContainedInCommit, path, d.getCommit().getId().getName());
            Activator.showError(message, null);
        }
    } catch (IOException e) {
        Activator.logError(UIText.GitHistoryPage_openFailed, e);
        Activator.showError(UIText.GitHistoryPage_openFailed, null);
    }
}
Also used : CommitFileRevision(org.eclipse.egit.core.internal.storage.CommitFileRevision) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) BlameOperation(org.eclipse.egit.ui.internal.blame.BlameOperation) IFileRevision(org.eclipse.team.core.history.IFileRevision) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IOException(java.io.IOException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 4 with CommitFileRevision

use of org.eclipse.egit.core.internal.storage.CommitFileRevision in project egit by eclipse.

the class ShowBlameHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    GitHistoryPage page = getPage(event);
    if (page == null) {
        return null;
    }
    Object input = page.getInputInternal().getSingleItem();
    if (input == null) {
        return null;
    }
    Repository repo = getRepository(event);
    if (repo == null) {
        return null;
    }
    String path = getPath(repo, page);
    if (path == null) {
        return null;
    }
    RevCommit commit = getSelectedCommit(event);
    if (commit == null) {
        return null;
    }
    try {
        IFileRevision revision = CompareUtils.getFileRevision(path, commit, repo, null);
        if (revision instanceof CommitFileRevision) {
            BlameOperation op = new BlameOperation((CommitFileRevision) revision, HandlerUtil.getActiveShell(event), page.getSite().getPage());
            JobUtil.scheduleUserJob(op, UIText.ShowBlameHandler_JobName, JobFamilies.BLAME);
        }
    } catch (IOException e) {
        Activator.showError(UIText.ShowBlameHandler_errorMessage, e);
    }
    return null;
}
Also used : CommitFileRevision(org.eclipse.egit.core.internal.storage.CommitFileRevision) Repository(org.eclipse.jgit.lib.Repository) GitHistoryPage(org.eclipse.egit.ui.internal.history.GitHistoryPage) BlameOperation(org.eclipse.egit.ui.internal.blame.BlameOperation) IFileRevision(org.eclipse.team.core.history.IFileRevision) IOException(java.io.IOException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 5 with CommitFileRevision

use of org.eclipse.egit.core.internal.storage.CommitFileRevision in project egit by eclipse.

the class BlameInformationControl method blameParent.

private void blameParent(RevCommit parent, Diff diff, Integer sourceLine) {
    try {
        String path = diff.getOldPath();
        IFileRevision rev = CompareUtils.getFileRevision(path, parent, revision.getRepository(), null);
        int line = sourceLine == null ? -1 : sourceLine.intValue();
        if (rev instanceof CommitFileRevision) {
            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            BlameOperation operation = new BlameOperation((CommitFileRevision) rev, getShell(), page, line);
            JobUtil.scheduleUserJob(operation, UIText.ShowBlameHandler_JobName, JobFamilies.BLAME);
        }
    } catch (IOException e) {
        Activator.logError(UIText.ShowBlameHandler_errorMessage, e);
    }
}
Also used : CommitFileRevision(org.eclipse.egit.core.internal.storage.CommitFileRevision) IFileRevision(org.eclipse.team.core.history.IFileRevision) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IOException(java.io.IOException) Point(org.eclipse.swt.graphics.Point)

Aggregations

CommitFileRevision (org.eclipse.egit.core.internal.storage.CommitFileRevision)5 IOException (java.io.IOException)3 BlameOperation (org.eclipse.egit.ui.internal.blame.BlameOperation)3 IFileRevision (org.eclipse.team.core.history.IFileRevision)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 IResource (org.eclipse.core.resources.IResource)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 IFile (org.eclipse.core.resources.IFile)1 IStorage (org.eclipse.core.resources.IStorage)1 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)1 GitHistoryPage (org.eclipse.egit.ui.internal.history.GitHistoryPage)1 Repository (org.eclipse.jgit.lib.Repository)1 Point (org.eclipse.swt.graphics.Point)1 Shell (org.eclipse.swt.widgets.Shell)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1