Search in sources :

Example 1 with WorkspaceFileRevision

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

the class CompareUtils method compareHeadWithWorkspace.

/**
 * Opens a compare editor. The workspace version of the given file is
 * compared with the version in the HEAD commit.
 *
 * @param repository
 * @param file
 */
public static void compareHeadWithWorkspace(Repository repository, @NonNull IFile file) {
    RepositoryMapping mapping = RepositoryMapping.getMapping(file);
    if (mapping == null) {
        Activator.error(NLS.bind(UIText.GitHistoryPage_errorLookingUpPath, file.getLocation(), repository), null);
        return;
    }
    String path = mapping.getRepoRelativePath(file);
    ITypedElement base = getHeadTypedElement(repository, path);
    if (base == null)
        return;
    IFileRevision nextFile = new WorkspaceFileRevision(file);
    String encoding = null;
    try {
        encoding = file.getCharset();
    } catch (CoreException e) {
        Activator.handleError(UIText.CompareUtils_errorGettingEncoding, e, true);
    }
    ITypedElement next = new FileRevisionTypedElement(nextFile, encoding);
    GitCompareFileRevisionEditorInput input = new GitCompareFileRevisionEditorInput(next, base, null);
    CompareUI.openCompareDialog(input);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IFileRevision(org.eclipse.team.core.history.IFileRevision) GitCompareFileRevisionEditorInput(org.eclipse.egit.ui.internal.revision.GitCompareFileRevisionEditorInput) ITypedElement(org.eclipse.compare.ITypedElement) WorkspaceFileRevision(org.eclipse.egit.core.internal.storage.WorkspaceFileRevision) FileRevisionTypedElement(org.eclipse.egit.ui.internal.revision.FileRevisionTypedElement)

Example 2 with WorkspaceFileRevision

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

the class GitModelSynchronizeParticipant method asCompareInput.

@Override
public ICompareInput asCompareInput(Object object) {
    final ICompareInput input = super.asCompareInput(object);
    final ISynchronizationContext ctx = getContext();
    if (input instanceof ResourceDiffCompareInput && ctx instanceof SubscriberMergeContext) {
        // Team only considers local resources as "left"
        // We'll use the cached data instead as left could be remote
        final IResource resource = ((ResourceNode) input.getLeft()).getResource();
        final Subscriber subscriber = ((SubscriberMergeContext) ctx).getSubscriber();
        if (resource instanceof IFile && subscriber instanceof GitResourceVariantTreeSubscriber) {
            try {
                final IFileRevision revision = ((GitResourceVariantTreeSubscriber) subscriber).getSourceFileRevision((IFile) resource);
                if (revision == null) {
                    final ITypedElement newSource = new GitCompareFileRevisionEditorInput.EmptyTypedElement(resource.getName());
                    ((ResourceDiffCompareInput) input).setLeft(newSource);
                } else if (!(revision instanceof WorkspaceFileRevision)) {
                    final ITypedElement newSource = new FileRevisionTypedElement(revision, getLocalEncoding(resource));
                    ((ResourceDiffCompareInput) input).setLeft(newSource);
                }
            } catch (TeamException e) {
                // Keep the input from super as-is
                String error = NLS.bind(UIText.GitModelSynchronizeParticipant_noCachedSourceVariant, resource.getName());
                Activator.logError(error, e);
            }
        }
    }
    return input;
}
Also used : IFile(org.eclipse.core.resources.IFile) ISynchronizationContext(org.eclipse.team.core.mapping.ISynchronizationContext) IFileRevision(org.eclipse.team.core.history.IFileRevision) ITypedElement(org.eclipse.compare.ITypedElement) WorkspaceFileRevision(org.eclipse.egit.core.internal.storage.WorkspaceFileRevision) ICompareInput(org.eclipse.compare.structuremergeviewer.ICompareInput) ResourceDiffCompareInput(org.eclipse.team.internal.ui.mapping.ResourceDiffCompareInput) ResourceNode(org.eclipse.compare.ResourceNode) TeamException(org.eclipse.team.core.TeamException) Subscriber(org.eclipse.team.core.subscribers.Subscriber) GitResourceVariantTreeSubscriber(org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber) SubscriberMergeContext(org.eclipse.team.core.subscribers.SubscriberMergeContext) GitSubscriberMergeContext(org.eclipse.egit.core.synchronize.GitSubscriberMergeContext) GitResourceVariantTreeSubscriber(org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber) FileRevisionTypedElement(org.eclipse.egit.ui.internal.revision.FileRevisionTypedElement) IResource(org.eclipse.core.resources.IResource)

Aggregations

ITypedElement (org.eclipse.compare.ITypedElement)2 WorkspaceFileRevision (org.eclipse.egit.core.internal.storage.WorkspaceFileRevision)2 FileRevisionTypedElement (org.eclipse.egit.ui.internal.revision.FileRevisionTypedElement)2 IFileRevision (org.eclipse.team.core.history.IFileRevision)2 ResourceNode (org.eclipse.compare.ResourceNode)1 ICompareInput (org.eclipse.compare.structuremergeviewer.ICompareInput)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)1 GitResourceVariantTreeSubscriber (org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber)1 GitSubscriberMergeContext (org.eclipse.egit.core.synchronize.GitSubscriberMergeContext)1 GitCompareFileRevisionEditorInput (org.eclipse.egit.ui.internal.revision.GitCompareFileRevisionEditorInput)1 TeamException (org.eclipse.team.core.TeamException)1 ISynchronizationContext (org.eclipse.team.core.mapping.ISynchronizationContext)1 Subscriber (org.eclipse.team.core.subscribers.Subscriber)1 SubscriberMergeContext (org.eclipse.team.core.subscribers.SubscriberMergeContext)1 ResourceDiffCompareInput (org.eclipse.team.internal.ui.mapping.ResourceDiffCompareInput)1