View | Details | Raw Unified | Return to bug 298923 | Differences between
and this patch

Collapse All | Expand All

(-)a/src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchSubscriber.java (-2 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
2
 * Copyright (c) 2009, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 62-68 public class ApplyPatchSubscriber extends Subscriber { Link Here
62
							if (diffs[i].getDiffType(patcher.isReversed()) != FilePatch2.DELETION)
62
							if (diffs[i].getDiffType(patcher.isReversed()) != FilePatch2.DELETION)
63
								variant =  new PatchedFileVariant(getPatcher(), diffs[i]);
63
								variant =  new PatchedFileVariant(getPatcher(), diffs[i]);
64
							IResourceVariant base = resource.exists() ?  new LocalResourceVariant(resource) : null;
64
							IResourceVariant base = resource.exists() ?  new LocalResourceVariant(resource) : null;
65
							SyncInfo info = new SyncInfo(resource, base, variant, getResourceComparator());
65
							SyncInfo info = new SyncInfo(resource, base, variant, getResourceComparator()) {
66
								protected int calculateKind() throws TeamException {
67
									// TODO: this will work only for files, what about excluding individual hunks
68
									if (!getPatcher().isEnabled(((PatchedFileVariant)getRemote()).getDiff()))
69
										return IN_SYNC;
70
									return super.calculateKind();
71
								}
72
							};
66
							info.init();
73
							info.init();
67
							return info;
74
							return info;
68
						}
75
						}
(-)a/src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchSubscriberMergeContext.java (-5 / +24 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
2
 * Copyright (c) 2009, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.team.internal.ui.synchronize.patch;
11
package org.eclipse.team.internal.ui.synchronize.patch;
12
12
13
import org.eclipse.compare.internal.core.patch.DiffProject;
14
import org.eclipse.compare.internal.core.patch.FilePatch2;
15
import org.eclipse.compare.internal.patch.Patcher;
16
import org.eclipse.core.resources.*;
13
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.team.core.diff.IDiff;
19
import org.eclipse.team.core.diff.IDiff;
Lines 35-54 class ApplyPatchSubscriberMergeContext extends SubscriberMergeContext { Link Here
35
39
36
	protected void makeInSync(IDiff diff, IProgressMonitor monitor)
40
	protected void makeInSync(IDiff diff, IProgressMonitor monitor)
37
			throws CoreException {
41
			throws CoreException {
38
		// TODO Auto-generated method stub
42
		IResource resource = getDiffTree().getResource(diff);
39
		System.out.println(">> [ignore] makeInSync: " + diff.toDiffString()); //$NON-NLS-1$
43
		// IDiffElement element = PatchModelProvider.createModelObject(resource);
44
		Patcher patcher = ((ApplyPatchSubscriber)getSubscriber()).getPatcher();
45
		FilePatch2[] diffs = patcher.getDiffs();
46
		if (resource.getType() == IResource.FILE) {
47
			for (int i = 0; i < diffs.length; i++) {
48
				if (diffs[i] instanceof FilePatch2) {
49
					DiffProject diffProject = diffs[i].getProject();
50
					IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(diffProject.getName());
51
					IFile file = project.getFile(diffs[i].getPath(patcher.isReversed()));
52
					if (file.equals(resource)) {
53
						patcher.setEnabled(diffs[i], false);
54
						System.out.println(">> ApplyPatchSubscriberMergeContext.makeInSync: disable " + diffs[i]); //$NON-NLS-1$
55
					}
56
				}
57
			}
58
		}
40
	}
59
	}
41
60
42
	public void markAsMerged(IDiff node, boolean inSyncHint,
61
	public void markAsMerged(IDiff node, boolean inSyncHint,
43
			IProgressMonitor monitor) throws CoreException {
62
			IProgressMonitor monitor) throws CoreException {
44
		// TODO Auto-generated method stub
63
		// TODO Auto-generated method stub
45
		System.out
64
		System.out
46
				.println(">> [ignore] markAsMerged: " + node.toDiffString() + ", inSyncHint " + inSyncHint); //$NON-NLS-1$ //$NON-NLS-2$
65
				.println(">> [ignore] ApplyPatchSubscriberMergeContext.markAsMerged: " + node.toDiffString() + ", inSyncHint " + inSyncHint); //$NON-NLS-1$ //$NON-NLS-2$
47
	}
66
	}
48
67
49
	public void reject(IDiff diff, IProgressMonitor monitor)
68
	public void reject(IDiff diff, IProgressMonitor monitor)
50
			throws CoreException {
69
			throws CoreException {
51
		// TODO Auto-generated method stub
70
		// TODO Auto-generated method stub
52
		System.out.println(">> [ignore] reject: " + diff.toDiffString()); //$NON-NLS-1$
71
		System.out.println(">> [ignore] ApplyPatchSubscriberMergeContext.reject: " + diff.toDiffString()); //$NON-NLS-1$
53
	}
72
	}
54
}
73
}
(-)a/src/org/eclipse/team/internal/ui/synchronize/patch/PatchModelProvider.java (-2 / +5 lines)
Lines 73-78 public class PatchModelProvider extends ModelProvider { Link Here
73
	}
73
	}
74
74
75
	static IDiffElement createModelObject(IResource resource) {
75
	static IDiffElement createModelObject(IResource resource) {
76
		// TODO: using singleton here is bad
76
		PatchWorkspace pw = PatchWorkspace.getInstance();
77
		PatchWorkspace pw = PatchWorkspace.getInstance();
77
		/* pw == null means that we're not applying a patch in the sync view */
78
		/* pw == null means that we're not applying a patch in the sync view */
78
		if (pw != null) {
79
		if (pw != null) {
Lines 90-101 public class PatchModelProvider extends ModelProvider { Link Here
90
				for (int i = 0; i < children.length; i++) {
91
				for (int i = 0; i < children.length; i++) {
91
					IDiffElement[] c = ((PatchProjectDiffNode) children[i])
92
					IDiffElement[] c = ((PatchProjectDiffNode) children[i])
92
							.getChildren();
93
							.getChildren();
93
					FileDiffResult diffResult = ((PatchFileDiffNode) c[i])
94
					for (int j = 0; j < c.length; j++) {
95
						FileDiffResult diffResult = ((PatchFileDiffNode) c[j])
94
							.getDiffResult();
96
							.getDiffResult();
95
					IFile file = ((WorkspaceFileDiffResult) diffResult)
97
					IFile file = ((WorkspaceFileDiffResult) diffResult)
96
							.getTargetFile();
98
							.getTargetFile();
97
					if (resource.equals(file)) {
99
					if (resource.equals(file)) {
98
						return c[i];
100
							return c[j];
101
						}
99
					}
102
					}
100
				}
103
				}
101
			}
104
			}
(-)a/src/org/eclipse/team/internal/ui/synchronize/patch/PatchSyncLabelProvider.java (-17 / +3 lines)
Lines 10-25 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.team.internal.ui.synchronize.patch;
11
package org.eclipse.team.internal.ui.synchronize.patch;
12
12
13
import org.eclipse.compare.internal.patch.PatchDiffNode;
13
import org.eclipse.compare.structuremergeviewer.Differencer;
14
import org.eclipse.compare.structuremergeviewer.Differencer;
14
import org.eclipse.compare.structuremergeviewer.IDiffElement;
15
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.resources.mapping.ResourceMapping;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.NullProgressMonitor;
19
import org.eclipse.jface.viewers.ILabelProvider;
16
import org.eclipse.jface.viewers.ILabelProvider;
20
import org.eclipse.swt.graphics.Image;
17
import org.eclipse.swt.graphics.Image;
21
import org.eclipse.team.core.diff.IDiff;
18
import org.eclipse.team.core.diff.IDiff;
22
import org.eclipse.team.internal.ui.TeamUIPlugin;
23
import org.eclipse.team.ui.mapping.SynchronizationLabelProvider;
19
import org.eclipse.team.ui.mapping.SynchronizationLabelProvider;
24
import org.eclipse.ui.navigator.ICommonContentExtensionSite;
20
import org.eclipse.ui.navigator.ICommonContentExtensionSite;
25
21
Lines 48-66 public class PatchSyncLabelProvider extends SynchronizationLabelProvider { Link Here
48
	}
44
	}
49
45
50
	protected IDiff getDiff(Object element) {
46
	protected IDiff getDiff(Object element) {
51
		if (element instanceof IDiffElement) {
47
		if (element instanceof PatchDiffNode) {
52
			ResourceMapping mapping = PatchModelProvider
48
			IResource resource = PatchModelProvider.getResource(element);
53
					.getResourceMapping((IDiffElement) element);
54
			if (mapping != null) {
55
				// XXX: getting IResource for patch model object
56
				try {
57
					IResource resource = mapping.getTraversals(null, new NullProgressMonitor())[0]
58
							.getResources()[0];
59
					return getContext().getDiffTree().getDiff(resource);
49
					return getContext().getDiffTree().getDiff(resource);
60
				} catch (CoreException e) {
61
					TeamUIPlugin.log(e);
62
				}
63
			}
64
		}
50
		}
65
		return super.getDiff(element);
51
		return super.getDiff(element);
66
	}
52
	}
(-)a/src/org/eclipse/team/internal/ui/synchronize/patch/PatchedFileVariant.java (-1 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
2
 * Copyright (c) 2009, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 55-60 public class PatchedFileVariant implements IResourceVariant { Link Here
55
		return false;
55
		return false;
56
	}
56
	}
57
57
58
	FilePatch2 getDiff() {
59
		return diff;
60
	}
61
58
	public static class PatchedFileStorage implements IStorage {
62
	public static class PatchedFileStorage implements IStorage {
59
		private FilePatch2 diff;
63
		private FilePatch2 diff;
60
		private WorkspacePatcher patcher;
64
		private WorkspacePatcher patcher;
(-)a/src/org/eclipse/team/internal/ui/synchronize/patch/PatchedFileVariantComparator.java (-16 / +6 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
2
 * Copyright (c) 2009, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-37 Link Here
11
package org.eclipse.team.internal.ui.synchronize.patch;
11
package org.eclipse.team.internal.ui.synchronize.patch;
12
12
13
import org.eclipse.core.resources.IResource;
13
import org.eclipse.core.resources.IResource;
14
import org.eclipse.core.resources.IStorage;
15
import org.eclipse.team.core.TeamException;
16
import org.eclipse.team.core.variants.IResourceVariant;
14
import org.eclipse.team.core.variants.IResourceVariant;
17
import org.eclipse.team.core.variants.IResourceVariantComparator;
15
import org.eclipse.team.core.variants.IResourceVariantComparator;
18
import org.eclipse.team.internal.ui.TeamUIPlugin;
16
import org.eclipse.team.internal.core.mapping.LocalResourceVariant;
19
17
20
public class PatchedFileVariantComparator implements IResourceVariantComparator {
18
public class PatchedFileVariantComparator implements IResourceVariantComparator {
21
19
22
	public boolean compare(IResource local, IResourceVariant remote) {
20
	public boolean compare(IResource local, IResourceVariant remote) {
23
		/*
21
		if (remote instanceof LocalResourceVariant)
24
		 * Comparing local with base returns true, see
22
			// return true when matching with base
25
		 * org.eclipse.team.core.synchronize.SyncInfo.calculateKind()
23
			return true;
26
		 */
24
		return false;
27
		IStorage s = null;
28
		try {
29
			s = remote.getStorage(null);
30
		} catch (TeamException e) {
31
			TeamUIPlugin.log(e);
32
		}
33
		return local.equals(s);
34
		// return false;
35
	}
25
	}
36
26
37
	public boolean compare(IResourceVariant base, IResourceVariant remote) {
27
	public boolean compare(IResourceVariant base, IResourceVariant remote) {

Return to bug 298923