### Eclipse Workspace Patch 1.0 #P org.eclipse.compare Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/META-INF/MANIFEST.MF,v retrieving revision 1.26.2.1 diff -u -r1.26.2.1 MANIFEST.MF --- META-INF/MANIFEST.MF 15 Dec 2009 14:08:21 -0000 1.26.2.1 +++ META-INF/MANIFEST.MF 19 Jan 2010 17:54:35 -0000 @@ -10,7 +10,7 @@ org.eclipse.compare.contentmergeviewer, org.eclipse.compare.internal;x-internal:=true, org.eclipse.compare.internal.merge;x-internal:=true, - org.eclipse.compare.internal.patch;x-friends:="org.eclipse.team.ui", + org.eclipse.compare.internal.patch;x-internal:=true, org.eclipse.compare.patch, org.eclipse.compare.structuremergeviewer Require-Bundle: org.eclipse.ui;bundle-version="[3.5.0,4.0.0)", Index: compare/org/eclipse/compare/internal/patch/Patcher.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java,v retrieving revision 1.69 diff -u -r1.69 Patcher.java --- compare/org/eclipse/compare/internal/patch/Patcher.java 4 Mar 2009 15:45:39 -0000 1.69 +++ compare/org/eclipse/compare/internal/patch/Patcher.java 19 Jan 2010 17:54:35 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -28,8 +28,8 @@ import org.eclipse.compare.internal.core.Messages; import org.eclipse.compare.internal.core.patch.DiffProject; -import org.eclipse.compare.internal.core.patch.FilePatch2; import org.eclipse.compare.internal.core.patch.FileDiffResult; +import org.eclipse.compare.internal.core.patch.FilePatch2; import org.eclipse.compare.internal.core.patch.Hunk; import org.eclipse.compare.internal.core.patch.PatchReader; import org.eclipse.compare.patch.IHunk; @@ -601,7 +601,7 @@ refresh(getDiffs()); } - protected void refresh(FilePatch2[] diffs) { + public void refresh(FilePatch2[] diffs) { for (int i = 0; i < diffs.length; i++) { FilePatch2 diff = diffs[i]; FileDiffResult result = getDiffResult(diff); #P org.eclipse.team.ui Index: src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchSubscriber.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/Attic/ApplyPatchSubscriber.java,v retrieving revision 1.1.2.9 diff -u -r1.1.2.9 ApplyPatchSubscriber.java --- src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchSubscriber.java 19 Jan 2010 12:24:36 -0000 1.1.2.9 +++ src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchSubscriber.java 19 Jan 2010 17:54:37 -0000 @@ -29,6 +29,24 @@ public class ApplyPatchSubscriber extends Subscriber { + private class ApplyPatchSyncInfo extends SyncInfo { + private ApplyPatchSyncInfo(IResource local, IResourceVariant base, + IResourceVariant remote, IResourceVariantComparator comparator) { + super(local, base, remote, comparator); + } + + protected int calculateKind() throws TeamException { + // TODO: this works only for files, what about excluding individual hunks? + if (!getPatcher().isEnabled(PatchModelProvider.getPatchObject(getLocal(), patcher))) + return IN_SYNC; + // mark diffs with problems as conflicts + if (getRemote() != null + && getPatcher().getDiffResult(((PatchedFileVariant)getRemote()).getDiff()).containsProblems()) + return CONFLICTING; + return super.calculateKind(); + } + } + private WorkspacePatcher patcher; private IResourceVariantComparator comparator; @@ -47,46 +65,35 @@ } public SyncInfo getSyncInfo(IResource resource) throws TeamException { - FilePatch2[] diffs = getPatcher().getDiffs(); + if (!isSupervised(resource)) return null; + // XXX: doing this here is highly inefficient! + // getPatcher().refresh(); + // a little bit better but still called gazzilon times + refresh(new IResource[] { resource }, IResource.DEPTH_ZERO, null); try { + FilePatch2 diff = (FilePatch2) PatchModelProvider.getPatchObject(resource, getPatcher()); + // use null as remote variant for deletions IResourceVariant variant = null; - if (resource.getType() == IResource.FILE) { - for (int i = 0; i < diffs.length; i++) { - if (resource.equals(PatchModelProvider.getFile(diffs[i], getPatcher()))) { - // null as 'variant' for deletions - if (diffs[i].getDiffType(patcher.isReversed()) != FilePatch2.DELETION) - variant = new PatchedFileVariant(getPatcher(), diffs[i]); - IResourceVariant base = resource.exists() ? new LocalResourceVariant(resource) : null; - SyncInfo info = new SyncInfo(resource, base, variant, getResourceComparator()) { - protected int calculateKind() throws TeamException { - // TODO: this will work only for files, what about excluding individual hunks? - if (!getPatcher().isEnabled(PatchModelProvider.getPatchObject(getLocal(), patcher))) - return IN_SYNC; - if (getRemote() != null - && getPatcher().getDiffResult(((PatchedFileVariant)getRemote()).getDiff()).containsProblems()) - return CONFLICTING; - return super.calculateKind(); - } - }; - info.init(); - return info; - } - } - } - return null; + if (diff.getDiffType(patcher.isReversed()) != FilePatch2.DELETION) + variant = new PatchedFileVariant(getPatcher(), diff); + IResourceVariant base = resource.exists() ? new LocalResourceVariant(resource) : null; + SyncInfo info = new ApplyPatchSyncInfo(resource, base, variant, getResourceComparator()); + info.init(); + return info; } catch (CoreException e) { throw TeamException.asTeamException(e); } } public boolean isSupervised(IResource resource) throws TeamException { - return true; + return resource.getType() == IResource.FILE + && PatchModelProvider.getPatchObject(resource, getPatcher()) != null; } public IResource[] members(IResource resource) throws TeamException { try { if(resource.getType() == IResource.FILE) - // file has no members + // file has no IResource members return new IResource[0]; IContainer container = (IContainer) resource; @@ -109,8 +116,16 @@ public void refresh(IResource[] resources, int depth, IProgressMonitor monitor) throws TeamException { - // TODO: refresh 'resources' only, not the whole patch - getPatcher().refresh(); + Set /* */diffs = new HashSet(); + for (int i = 0; i < resources.length; i++) { + Object object = PatchModelProvider.getPatchObject(resources[i], + getPatcher()); + if (object instanceof FilePatch2) { + FilePatch2 filePatch = (FilePatch2) object; + diffs.add(filePatch); + } + } + getPatcher().refresh((FilePatch2[]) diffs.toArray(new FilePatch2[0])); } public IResource[] roots() {