diff options
author | Laurent Goubet | 2013-03-15 10:26:42 +0000 |
---|---|---|
committer | Matthias Sohn | 2013-04-13 23:07:15 +0000 |
commit | f2d4ffcfc3fc57e81f7629df4267b91574761aea (patch) | |
tree | 38300a802825295628775de4d2f46b9c906f77f9 /org.eclipse.egit.ui | |
parent | 3c3ad5342f07fd37a2e9b1167fb6d49db678813d (diff) | |
download | egit-f2d4ffcfc3fc57e81f7629df4267b91574761aea.tar.gz egit-f2d4ffcfc3fc57e81f7629df4267b91574761aea.tar.xz egit-f2d4ffcfc3fc57e81f7629df4267b91574761aea.zip |
Use the source revision instead of local data for synchronizations
EGit allows for comparisons with three remote revisions (notably through
"synchronize with each other" with two branches selected in the
repository explorer). However, Team always uses the local data as the
"source" (or left) side of a comparison. This patch allows us to use the
actual source commit instead of the local file when needed.
This also changes GitModelSynchronizeParticipant#asCompareInput() since
we can use the cached content fetched by the subscriber context instead
of re-fetching it from the remote.
CQ: 7175
Bug: 403363
Change-Id: I23e0f1e75b9c6d476f8ed5a24deac7cc7b64dd42
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.egit.ui')
3 files changed, 52 insertions, 63 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java index 94c2daef4a..4c0034830e 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java @@ -4758,6 +4758,9 @@ public class UIText extends NLS { /** */ public static String GitModelSynchronizeParticipant_initialScopeName; + /** */ + public static String GitModelSynchronizeParticipant_noCachedSourceVariant; + static { initializeMessages(BUNDLE_NAME, UIText.class); } 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 f8937fa77e..26d8ea635f 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (C) 2010, 2012 Dariusz Luksza <dariusz@luksza.org> and others. + * Copyright (C) 2010, 2013 Dariusz Luksza <dariusz@luksza.org> and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -13,7 +13,6 @@ *******************************************************************************/ package org.eclipse.egit.ui.internal.synchronize; -import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; @@ -24,6 +23,7 @@ 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.IEncodedStorage; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; @@ -47,20 +47,23 @@ import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData; import org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet; import org.eclipse.egit.ui.Activator; import org.eclipse.egit.ui.UIPreferences; +import org.eclipse.egit.ui.internal.FileRevisionTypedElement; import org.eclipse.egit.ui.internal.UIText; -import org.eclipse.egit.ui.internal.synchronize.compare.ComparisonDataSource; -import org.eclipse.egit.ui.internal.synchronize.compare.GitCompareInput; import org.eclipse.egit.ui.internal.synchronize.model.GitModelBlob; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.revwalk.RevCommit; -import org.eclipse.jgit.treewalk.TreeWalk; -import org.eclipse.jgit.treewalk.filter.PathFilter; +import org.eclipse.osgi.util.NLS; +import org.eclipse.team.core.TeamException; +import org.eclipse.team.core.history.IFileRevision; +import org.eclipse.team.core.mapping.ISynchronizationContext; import org.eclipse.team.core.mapping.ISynchronizationScopeManager; import org.eclipse.team.core.mapping.provider.MergeContext; import org.eclipse.team.core.mapping.provider.SynchronizationScopeManager; +import org.eclipse.team.core.subscribers.Subscriber; +import org.eclipse.team.core.subscribers.SubscriberMergeContext; +import org.eclipse.team.internal.ui.mapping.ResourceDiffCompareInput; import org.eclipse.team.ui.TeamUI; import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; import org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant; @@ -220,35 +223,48 @@ public class GitModelSynchronizeParticipant extends ModelSynchronizeParticipant @Override public ICompareInput asCompareInput(Object object) { - 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()); + 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); + 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); } } - } 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 compareInput; + return input; + } + + private static String getLocalEncoding(IResource resource) { + if (resource instanceof IEncodedStorage) { + IEncodedStorage es = (IEncodedStorage) resource; + try { + return es.getCharset(); + } catch (CoreException e) { + Activator.logError(e.getMessage(), e); + } + } + return null; } @Override @@ -334,37 +350,6 @@ public class GitModelSynchronizeParticipant extends ModelSynchronizeParticipant mappings, context, true); } - private ICompareInput getFileFromGit(GitSynchronizeData gsd, IPath location) { - Repository repo = gsd.getRepository(); - File workTree = repo.getWorkTree(); - String repoRelativeLocation = Repository.stripWorkDir(workTree, - location.toFile()); - - TreeWalk tw = new TreeWalk(repo); - tw.setRecursive(true); - tw.setFilter(PathFilter.create(repoRelativeLocation.toString())); - RevCommit baseCommit = gsd.getSrcRevCommit(); - RevCommit remoteCommit = gsd.getDstRevCommit(); - - try { - int baseNth = tw.addTree(baseCommit.getTree()); - int remoteNth = tw.addTree(remoteCommit.getTree()); - - if (tw.next()) { - ComparisonDataSource baseData = new ComparisonDataSource( - baseCommit, tw.getObjectId(baseNth)); - ComparisonDataSource remoteData = new ComparisonDataSource( - remoteCommit, tw.getObjectId(remoteNth)); - return new GitCompareInput(repo, baseData, baseData, - remoteData, repoRelativeLocation); - } - } catch (IOException e) { - Activator.logError(e.getMessage(), e); - } - - return null; - } - private void restoreSynchronizationData(IMemento[] children) { for (IMemento child : children) { String containerPath = child.getString(CONTAINER_PATH_KEY); diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties index 7afd61dc35..9ce96ac64c 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties @@ -1672,3 +1672,4 @@ RepositoryStatistics_SpaceNeededOnFilesystem=Space needed on filesystem RepositoryStatistics_PackedObjects=Packed objects GitModelSynchronizeParticipant_initialScopeName=Git +GitModelSynchronizeParticipant_noCachedSourceVariant=Could not locate cached source variant for resource: {0} |