Search in sources :

Example 1 with GitCompareEditorInput

use of org.eclipse.egit.ui.internal.merge.GitCompareEditorInput in project egit by eclipse.

the class CompareVersionsHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IStructuredSelection selection = getSelection(event);
    if (selection.size() == 2) {
        Iterator<?> it = selection.iterator();
        RevCommit commit1 = (RevCommit) it.next();
        RevCommit commit2 = (RevCommit) it.next();
        Object input = getPage(event).getInputInternal().getSingleItem();
        Repository repo = getRepository(event);
        IWorkbenchPage workBenchPage = HandlerUtil.getActiveWorkbenchWindowChecked(event).getActivePage();
        if (input instanceof IFile) {
            IFile resource = (IFile) input;
            final RepositoryMapping map = RepositoryMapping.getMapping(resource);
            if (map != null) {
                final String gitPath = map.getRepoRelativePath(resource);
                final String commit1Path = getRenamedPath(gitPath, commit1);
                final String commit2Path = getRenamedPath(gitPath, commit2);
                CompareUtils.openInCompare(commit1, commit2, commit1Path, commit2Path, map.getRepository(), workBenchPage);
            }
        } else if (input instanceof File) {
            File fileInput = (File) input;
            final String gitPath = getRepoRelativePath(repo, fileInput);
            final String commit1Path = getRenamedPath(gitPath, commit1);
            final String commit2Path = getRenamedPath(gitPath, commit2);
            CompareUtils.openInCompare(commit1, commit2, commit1Path, commit2Path, repo, workBenchPage);
        } else if (input instanceof IResource) {
            GitCompareEditorInput compareInput = new GitCompareEditorInput(commit1.name(), commit2.name(), repo, (IResource) input);
            CompareUtils.openInCompare(workBenchPage, compareInput);
        } else if (input == null) {
            GitCompareEditorInput compareInput = new GitCompareEditorInput(commit1.name(), commit2.name(), repo);
            CompareUtils.openInCompare(workBenchPage, compareInput);
        }
    }
    return null;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IFile(org.eclipse.core.resources.IFile) GitCompareEditorInput(org.eclipse.egit.ui.internal.merge.GitCompareEditorInput) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IResource(org.eclipse.core.resources.IResource) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

File (java.io.File)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)1 GitCompareEditorInput (org.eclipse.egit.ui.internal.merge.GitCompareEditorInput)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Repository (org.eclipse.jgit.lib.Repository)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1