Search in sources :

Example 1 with LocalNonWorkspaceTypedElement

use of org.eclipse.egit.ui.internal.synchronize.compare.LocalNonWorkspaceTypedElement in project egit by eclipse.

the class CompareUtils method compareLocalWithRef.

/**
 * Opens a compare editor comparing the working directory version of the
 * file at the given location with the version corresponding to
 * {@code refName} of the same file.
 *
 * @param repository
 *            The repository to load file revisions from.
 * @param location
 *            Location of the file to compare revisions for.
 * @param refName
 *            Reference to compare with the workspace version of
 *            {@code file}. Can be either a commit ID, a reference or a
 *            branch name.
 * @param page
 *            If not {@null} try to re-use a compare editor on this
 *            page if any is available. Otherwise open a new one.
 */
private static void compareLocalWithRef(@NonNull final Repository repository, @NonNull final IPath location, final String refName, final IWorkbenchPage page) {
    Job job = new Job(UIText.CompareUtils_jobName) {

        @Override
        public IStatus run(IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            final String gitPath = getRepoRelativePath(location, repository);
            final ITypedElement base = new LocalNonWorkspaceTypedElement(repository, location);
            CompareEditorInput in;
            try {
                in = prepareCompareInput(repository, gitPath, base, refName);
            } catch (IOException e) {
                return Activator.createErrorStatus(UIText.CompareWithRefAction_errorOnSynchronize, e);
            }
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            openCompareEditorRunnable(page, in);
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CompareEditorInput(org.eclipse.compare.CompareEditorInput) GitCompareEditorInput(org.eclipse.egit.ui.internal.merge.GitCompareEditorInput) SaveableCompareEditorInput(org.eclipse.team.ui.synchronize.SaveableCompareEditorInput) ITypedElement(org.eclipse.compare.ITypedElement) LocalNonWorkspaceTypedElement(org.eclipse.egit.ui.internal.synchronize.compare.LocalNonWorkspaceTypedElement) IOException(java.io.IOException) Job(org.eclipse.core.runtime.jobs.Job)

Example 2 with LocalNonWorkspaceTypedElement

use of org.eclipse.egit.ui.internal.synchronize.compare.LocalNonWorkspaceTypedElement in project egit by eclipse.

the class CompareUtils method compareWorkspaceWithRef.

/**
 * Opens a compare editor comparing the working directory version of the
 * given file or link with the version of that file corresponding to
 * {@code refName}.
 *
 * @param repository
 *            The repository to load file revisions from.
 * @param file
 *            Resource to compare revisions for. Must be either
 *            {@link IFile} or a symbolic link to directory ({@link IFolder}).
 * @param refName
 *            Reference to compare with the workspace version of
 *            {@code file}. Can be either a commit ID, a reference or a
 *            branch name.
 * @param page
 *            If not {@null} try to re-use a compare editor on this page if
 *            any is available. Otherwise open a new one.
 */
public static void compareWorkspaceWithRef(@NonNull final Repository repository, final IResource file, final String refName, final IWorkbenchPage page) {
    if (file == null) {
        return;
    }
    final IPath location = file.getLocation();
    if (location == null) {
        return;
    }
    Job job = new Job(UIText.CompareUtils_jobName) {

        @Override
        public IStatus run(IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            final RepositoryMapping mapping = RepositoryMapping.getMapping(file);
            if (mapping == null) {
                return Activator.createErrorStatus(NLS.bind(UIText.GitHistoryPage_errorLookingUpPath, location, repository));
            }
            final ITypedElement base;
            if (Files.isSymbolicLink(location.toFile().toPath())) {
                base = new LocalNonWorkspaceTypedElement(repository, location);
            } else if (file instanceof IFile) {
                base = SaveableCompareEditorInput.createFileElement((IFile) file);
            } else {
                return Activator.createErrorStatus(NLS.bind(UIText.CompareUtils_wrongResourceArgument, location, file));
            }
            final String gitPath = mapping.getRepoRelativePath(file);
            CompareEditorInput in;
            try {
                in = prepareCompareInput(repository, gitPath, base, refName);
            } catch (IOException e) {
                return Activator.createErrorStatus(UIText.CompareWithRefAction_errorOnSynchronize, e);
            }
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            openCompareEditorRunnable(page, in);
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CompareEditorInput(org.eclipse.compare.CompareEditorInput) GitCompareEditorInput(org.eclipse.egit.ui.internal.merge.GitCompareEditorInput) SaveableCompareEditorInput(org.eclipse.team.ui.synchronize.SaveableCompareEditorInput) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) ITypedElement(org.eclipse.compare.ITypedElement) LocalNonWorkspaceTypedElement(org.eclipse.egit.ui.internal.synchronize.compare.LocalNonWorkspaceTypedElement) IOException(java.io.IOException) Job(org.eclipse.core.runtime.jobs.Job)

Example 3 with LocalNonWorkspaceTypedElement

use of org.eclipse.egit.ui.internal.synchronize.compare.LocalNonWorkspaceTypedElement in project egit by eclipse.

the class GitOpenInCompareAction method handleGitObjectComparison.

private void handleGitObjectComparison(GitModelBlob obj, boolean reuseEditor) {
    ITypedElement left;
    ITypedElement right;
    if (obj instanceof GitModelWorkingFile) {
        IPath location = obj.getLocation();
        if (location == null) {
            return;
        }
        IFile file = ResourceUtil.getFileForLocation(location, false);
        if (file == null) {
            Repository repository = null;
            GitModelObject modelObject = obj;
            while (modelObject != null) {
                if (modelObject instanceof GitModelRepository) {
                    repository = ((GitModelRepository) modelObject).getRepository();
                    break;
                }
                modelObject = modelObject.getParent();
            }
            if (repository == null) {
                return;
            }
            left = new LocalNonWorkspaceTypedElement(repository, location);
        } else {
            left = SaveableCompareEditorInput.createFileElement(file);
        }
        right = getCachedFileElement(obj);
    } else if (obj instanceof GitModelCacheFile) {
        left = getCachedFileElement(obj);
        right = getHeadFileElement(obj);
        if (right == null)
            return;
    } else {
        oldAction.run();
        return;
    }
    GitCompareFileRevisionEditorInput in = new GitCompareFileRevisionEditorInput(left, right, null);
    IWorkbenchPage page = getWorkbenchPage(conf.getSite());
    OpenInCompareAction.openCompareEditor(in, page, reuseEditor);
}
Also used : GitModelRepository(org.eclipse.egit.ui.internal.synchronize.model.GitModelRepository) Repository(org.eclipse.jgit.lib.Repository) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) GitModelWorkingFile(org.eclipse.egit.ui.internal.synchronize.model.GitModelWorkingFile) GitCompareFileRevisionEditorInput(org.eclipse.egit.ui.internal.revision.GitCompareFileRevisionEditorInput) ITypedElement(org.eclipse.compare.ITypedElement) LocalNonWorkspaceTypedElement(org.eclipse.egit.ui.internal.synchronize.compare.LocalNonWorkspaceTypedElement) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) GitModelRepository(org.eclipse.egit.ui.internal.synchronize.model.GitModelRepository) GitModelCacheFile(org.eclipse.egit.ui.internal.synchronize.model.GitModelCacheFile) GitModelObject(org.eclipse.egit.ui.internal.synchronize.model.GitModelObject)

Aggregations

ITypedElement (org.eclipse.compare.ITypedElement)3 LocalNonWorkspaceTypedElement (org.eclipse.egit.ui.internal.synchronize.compare.LocalNonWorkspaceTypedElement)3 IOException (java.io.IOException)2 CompareEditorInput (org.eclipse.compare.CompareEditorInput)2 IFile (org.eclipse.core.resources.IFile)2 IPath (org.eclipse.core.runtime.IPath)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 GitCompareEditorInput (org.eclipse.egit.ui.internal.merge.GitCompareEditorInput)2 SaveableCompareEditorInput (org.eclipse.team.ui.synchronize.SaveableCompareEditorInput)2 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)1 GitCompareFileRevisionEditorInput (org.eclipse.egit.ui.internal.revision.GitCompareFileRevisionEditorInput)1 GitModelCacheFile (org.eclipse.egit.ui.internal.synchronize.model.GitModelCacheFile)1 GitModelObject (org.eclipse.egit.ui.internal.synchronize.model.GitModelObject)1 GitModelRepository (org.eclipse.egit.ui.internal.synchronize.model.GitModelRepository)1 GitModelWorkingFile (org.eclipse.egit.ui.internal.synchronize.model.GitModelWorkingFile)1 Repository (org.eclipse.jgit.lib.Repository)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1