aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Goubet2012-11-14 11:04:36 (EST)
committerGerrit Code Review @ Eclipse.org2013-01-11 15:45:49 (EST)
commit12b07852b07c257abca9228cb6684a6bb4450b82 (patch)
treec55a8df01a35dcf7a86bb60680cf8a2382e733b7
parent4c42f5228cedb2407e698e315cbea30b616e0153 (diff)
downloadegit-12b07852b07c257abca9228cb6684a6bb4450b82.zip
egit-12b07852b07c257abca9228cb6684a6bb4450b82.tar.gz
egit-12b07852b07c257abca9228cb6684a6bb4450b82.tar.bz2
Use model compare input if possiblerefs/changes/37/8637/7
The implementation of 'asCompareInput' may hijacked any comparison using model providers through the synchronize view. Even when double-clicking on files that are part of a model, only the "git" model would have been allowed to provide comparison input. This is a limitation of the current synchronize model that happens when a file from the local workspace is compared but without considering the working copy contents (i.e. HEAD). This commits works around the limitation by allowing the model compare adapter to be used when possible, i.e. a comparison with the local workspace is performed. Bug: 393225 Also-by: Gunnar Wagenknecht <gunnar@wagenknecht.org> Change-Id: I69c3e36b74f8eee7755a55ec9f8f4cc42149fef7
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitModelSynchronizeParticipant.java61
1 files changed, 44 insertions, 17 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitModelSynchronizeParticipant.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitModelSynchronizeParticipant.java
index 7d6a1e1..84b3e47 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitModelSynchronizeParticipant.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitModelSynchronizeParticipant.java
@@ -5,6 +5,11 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Dariusz Luksza <dariusz@luksza.org> - initial API and implementation
+ * Laurent Goubet <laurent.goubet@obeo.fr> - Logical Model enhancements
+ * Gunnar Wagenknecht <gunnar@wagenknecht.org> - Logical Model enhancements
*******************************************************************************/
package org.eclipse.egit.ui.internal.synchronize;
@@ -15,6 +20,8 @@ import java.util.HashSet;
import java.util.Set;
import org.eclipse.compare.CompareNavigator;
+import org.eclipse.compare.ITypedElement;
+import org.eclipse.compare.ResourceNode;
import org.eclipse.compare.structuremergeviewer.ICompareInput;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
@@ -24,13 +31,13 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.mapping.ModelProvider;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
+import org.eclipse.egit.core.AdapterUtils;
import org.eclipse.egit.core.project.GitProjectData;
import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber;
@@ -58,8 +65,8 @@ import org.eclipse.team.ui.TeamUI;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
import org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant;
import org.eclipse.ui.IMemento;
-import org.eclipse.ui.PartInitException;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
/**
* Git model synchronization participant
@@ -200,28 +207,48 @@ public class GitModelSynchronizeParticipant extends ModelSynchronizeParticipant
public boolean hasCompareInputFor(Object object) {
if (object instanceof GitModelBlob || object instanceof IFile)
return true;
+
// in Java Workspace model Java source files are passed as type
// CompilationUnit which can be adapted to IResource
- if (object instanceof IAdaptable) {
- IResource res = (IResource) ((IAdaptable) object)
- .getAdapter(IResource.class);
- if (res != null && res.getType() == IResource.FILE)
- return true;
- }
+ IResource res = AdapterUtils.adapt(object, IResource.class);
+ if (res != null && res.getType() == IResource.FILE)
+ return true;
+
+ // fallback to super ISynchronizationCompareAdapter
return super.hasCompareInputFor(object);
}
@Override
public ICompareInput asCompareInput(Object object) {
- // handle file comparison in Workspace model
- if (object instanceof IFile) {
- IFile file = (IFile) object;
- GitSynchronizeData gsd = gsds.getData(file.getProject());
- if (gsd != null && !gsd.shouldIncludeLocal())
- return getFileFromGit(gsd, file.getLocation());
+ ICompareInput compareInput = super.asCompareInput(object);
+
+ if (compareInput != null) {
+ // note, ResourceDiffCompareInput maybe returned from super;
+ // it always has the local resource on the left side!
+ // this is only ok if we are comparing with the working tree
+
+ // handle file comparison outside working tree
+ ITypedElement left = compareInput.getLeft();
+ if (left instanceof ResourceNode) {
+ // the left side can only be a resource node if
+ // we are comparing against the local working tree
+ IResource resource = ((ResourceNode) left).getResource();
+ if (resource.getType() == IResource.FILE) {
+ GitSynchronizeData gsd = gsds
+ .getData(resource.getProject());
+ if (gsd != null && !gsd.shouldIncludeLocal())
+ return getFileFromGit(gsd, resource.getLocation());
+ }
+ }
+ } else {
+ IResource resource = AdapterUtils.adapt(object, IResource.class);
+ if (resource.getType() == IResource.FILE) {
+ GitSynchronizeData gsd = gsds.getData(resource.getProject());
+ return getFileFromGit(gsd, resource.getLocation());
+ }
}
- return super.asCompareInput(object);
+ return compareInput;
}
@Override