View | Details | Raw Unified | Return to bug 267020
Collapse All | Expand All

(-)src/org/eclipse/compare/internal/core/patch/FileDiffResult.java (-5 / +5 lines)
Lines 32-38 Link Here
32
32
33
public class FileDiffResult implements IFilePatchResult {
33
public class FileDiffResult implements IFilePatchResult {
34
34
35
	private FileDiff fDiff;
35
	private FilePatch2 fDiff;
36
	private boolean fMatches= false;
36
	private boolean fMatches= false;
37
	private boolean fDiffProblem;
37
	private boolean fDiffProblem;
38
	private String fErrorMessage;
38
	private String fErrorMessage;
Lines 41-47 Link Here
41
	private final PatchConfiguration configuration;
41
	private final PatchConfiguration configuration;
42
	private String charset;
42
	private String charset;
43
	
43
	
44
	public FileDiffResult(FileDiff diff, PatchConfiguration configuration) {
44
	public FileDiffResult(FilePatch2 diff, PatchConfiguration configuration) {
45
		super();
45
		super();
46
		fDiff = diff;
46
		fDiff = diff;
47
		this.configuration = configuration;
47
		this.configuration = configuration;
Lines 73-79 Link Here
73
		charset = Utilities.getCharset(content);
73
		charset = Utilities.getCharset(content);
74
		//If this diff is an addition, make sure that it doesn't already exist
74
		//If this diff is an addition, make sure that it doesn't already exist
75
		boolean exists = targetExists(content);
75
		boolean exists = targetExists(content);
76
		if (fDiff.getDiffType(getConfiguration().isReversed()) == FileDiff.ADDITION) {
76
		if (fDiff.getDiffType(getConfiguration().isReversed()) == FilePatch2.ADDITION) {
77
			if ((!exists || isEmpty(content)) && canCreateTarget(content)) {
77
			if ((!exists || isEmpty(content)) && canCreateTarget(content)) {
78
				fMatches= true;
78
				fMatches= true;
79
			} else {
79
			} else {
Lines 220-226 Link Here
220
			monitor = new NullProgressMonitor();
220
			monitor = new NullProgressMonitor();
221
		fBeforeLines = new ArrayList(lines);
221
		fBeforeLines = new ArrayList(lines);
222
		// TODO: What about deletions?
222
		// TODO: What about deletions?
223
		if (fDiff.getDiffType(getConfiguration().isReversed()) == FileDiff.ADDITION) {
223
		if (fDiff.getDiffType(getConfiguration().isReversed()) == FilePatch2.ADDITION) {
224
			// Additions don't need to adjust the fuzz factor
224
			// Additions don't need to adjust the fuzz factor
225
			// TODO: What about the after lines?
225
			// TODO: What about the after lines?
226
			return -1;
226
			return -1;
Lines 268-274 Link Here
268
		return failedHunks;
268
		return failedHunks;
269
	}
269
	}
270
270
271
	public FileDiff getDiff() {
271
	public FilePatch2 getDiff() {
272
		return fDiff;
272
		return fDiff;
273
	}
273
	}
274
274
(-)src/org/eclipse/compare/internal/core/patch/FileDiff.java (-266 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.compare.internal.core.patch;
12
13
import java.util.ArrayList;
14
import java.util.Iterator;
15
import java.util.List;
16
17
import org.eclipse.compare.patch.IFilePatch2;
18
import org.eclipse.compare.patch.IFilePatchResult;
19
import org.eclipse.compare.patch.IHunk;
20
import org.eclipse.compare.patch.PatchConfiguration;
21
import org.eclipse.compare.patch.ReaderCreator;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.Path;
25
26
/**
27
 * A file diff represents a set of hunks that were associated with the
28
 * same path in a patch file.
29
 */
30
public class FileDiff implements IFilePatch2 {
31
32
	/**
33
	 * Difference constant (value 1) indicating one side was added.
34
	 */
35
	public static final int ADDITION= 1;
36
	/**
37
	 * Difference constant (value 2) indicating one side was removed.
38
	 */
39
	public static final int DELETION= 2;
40
	/**
41
	 * Difference constant (value 3) indicating side changed.
42
	 */
43
	public static final int CHANGE= 3;
44
	
45
	private IPath fOldPath, fNewPath;
46
	private long oldDate, newDate;
47
	private List fHunks= new ArrayList();
48
	private DiffProject fProject; //the project that contains this diff
49
	private String header;
50
	private int addedLines, removedLines;
51
	
52
	/**
53
	 * Create a file diff for the given path and date information.
54
	 * @param oldPath the path of the before state of the file
55
	 * @param oldDate the timestamp of the before state
56
	 * @param newPath the path of the after state
57
	 * @param newDate the timestamp of the after state
58
	 */
59
 	public FileDiff(IPath oldPath, long oldDate, IPath newPath, long newDate) {
60
		fOldPath= oldPath;
61
		this.oldDate = oldDate;
62
		fNewPath= newPath;
63
		this.newDate = newDate;
64
	}
65
	
66
 	/**
67
 	 * Return the parent project or <code>null</code> if there isn't one.
68
 	 * @return the parent project or <code>null</code>
69
 	 */
70
	public DiffProject getProject() {
71
		return fProject;
72
	}
73
	
74
	/**
75
	 * Set the project of this diff to the given project.
76
	 * This method should only be called from
77
	 * {@link DiffProject#add(FileDiff)}
78
	 * @param diffProject the parent project
79
	 */
80
	void setProject(DiffProject diffProject) {
81
		if (fProject == diffProject)
82
			return;
83
		if (fProject != null)
84
			fProject.remove(this);
85
		this.fProject= diffProject;
86
	}
87
	
88
	/**
89
	 * Get the path of the file diff.
90
	 * @param reverse whether the path of the before state or after state 
91
	 * should be used
92
	 * @return the path of the file diff
93
	 */
94
	public IPath getPath(boolean reverse) {
95
		if (getDiffType(reverse) == ADDITION) {
96
			if (reverse)
97
				return fOldPath;
98
			return fNewPath;
99
		}
100
		if (reverse && fNewPath != null)
101
			return fNewPath;
102
		if (fOldPath != null)
103
			return fOldPath;
104
		return fNewPath;
105
	}
106
	
107
	/**
108
	 * Add the hunk to this file diff.
109
	 * @param hunk the hunk
110
	 */
111
	public void add(Hunk hunk) {
112
		fHunks.add(hunk);
113
		hunk.setParent(this);
114
	}
115
	
116
	/**
117
	 * Remove the hunk from this file diff
118
	 * @param hunk the hunk
119
	 */
120
	protected void remove(Hunk hunk) {
121
		fHunks.remove(hunk);
122
	}
123
	
124
	/**
125
	 * Return the hunks associated with this file diff.
126
	 * @return the hunks associated with this file diff
127
	 */
128
	public IHunk[] getHunks() {
129
		return (IHunk[]) fHunks.toArray(new IHunk[fHunks.size()]);
130
	}
131
	
132
	/**
133
	 * Return the number of hunks associated with this file diff.
134
	 * @return the number of hunks associated with this file diff
135
	 */
136
	public int getHunkCount() {
137
		return fHunks.size();
138
	}
139
	
140
	/**
141
	 * Return the difference type of this file diff.
142
	 * @param reverse whether the patch is being reversed
143
	 * @return the type of this file diff
144
	 */
145
	public int getDiffType(boolean reverse) {
146
		if (fHunks.size() == 1) {
147
			boolean add = false;
148
			boolean delete = false;
149
			Iterator iter = fHunks.iterator();
150
			while (iter.hasNext()){
151
				Hunk hunk = (Hunk) iter.next();
152
				int type =hunk.getHunkType(reverse);
153
				if (type == ADDITION){
154
					add = true;
155
				} else if (type == DELETION ){
156
					delete = true;
157
				}
158
			}
159
			if (add && !delete){
160
				return ADDITION;
161
			} else if (!add && delete){
162
				return DELETION;
163
			}
164
		}
165
		return CHANGE;
166
	}
167
	
168
	/**
169
	 * Return the path of this file diff with the specified number
170
	 * of leading segments striped.
171
	 * @param strip the number of leading segments to strip from the path
172
	 * @param reverse whether the patch is being reversed
173
	 * @return the path of this file diff with the specified number
174
	 * of leading segments striped
175
	 */
176
	public IPath getStrippedPath(int strip, boolean reverse) {
177
		IPath path= getPath(reverse);
178
		if (strip > 0 && strip < path.segmentCount())
179
			path= path.removeFirstSegments(strip);
180
		return path;
181
	}
182
	
183
	/**
184
	 * Return the segment count of the path of this file diff.
185
	 * @return the segment count of the path of this file diff
186
	 */
187
	public int segmentCount() {
188
		//Update prefix count - go through all of the diffs and find the smallest
189
		//path segment contained in all diffs.
190
		int length= 99;
191
		if (fOldPath != null)
192
			length= Math.min(length, fOldPath.segmentCount());
193
		if (fNewPath != null)
194
			length= Math.min(length, fNewPath.segmentCount());
195
		return length;
196
	}
197
	
198
	public IFilePatchResult apply(ReaderCreator content,
199
			PatchConfiguration configuration, IProgressMonitor monitor) {
200
		FileDiffResult result = new FileDiffResult(this, configuration);
201
		result.refresh(content, monitor);
202
		return result;
203
	}
204
205
	public IPath getTargetPath(PatchConfiguration configuration) {
206
		return getStrippedPath(configuration.getPrefixSegmentStripCount(), configuration.isReversed());
207
	}
208
209
	public FileDiff asRelativeDiff() {
210
		if (fProject == null)
211
			return this;
212
		IPath adjustedOldPath = null;
213
		if (fOldPath != null) {
214
			adjustedOldPath = new Path(null, fProject.getName()).append(fOldPath);
215
		}
216
		IPath adjustedNewPath = null;
217
		if (fNewPath != null) {
218
			adjustedNewPath = new Path(null, fProject.getName()).append(fNewPath);
219
		}
220
		FileDiff diff = create(adjustedOldPath, 0, adjustedNewPath, 0);
221
		for (Iterator iterator = fHunks.iterator(); iterator.hasNext();) {
222
			Hunk hunk = (Hunk) iterator.next();
223
			// Creating the hunk adds it to the parent diff
224
			new Hunk(diff, hunk);
225
		}
226
		return diff;
227
	}
228
229
	protected FileDiff create(IPath oldPath, long oldDate, IPath newPath,
230
			long newDate) {
231
		return new FileDiff(oldPath, oldDate, newPath, newDate);
232
	}
233
234
	public void setHeader(String header) {
235
		this.header = header;
236
	}
237
238
	public String getHeader() {
239
		return header;
240
	}
241
242
	public long getBeforeDate() {
243
		return oldDate;
244
	}
245
246
	public long getAfterDate() {
247
		return newDate;
248
	}
249
250
	public void setAddedLines(int addedLines) {
251
		this.addedLines = addedLines;
252
	}
253
	
254
	public void setRemovedLines(int removedLines) {
255
		this.removedLines = removedLines;
256
	}
257
258
	public int getAddedLines() {
259
		return addedLines;
260
	}
261
	
262
	public int getRemovedLines() {
263
		return removedLines;
264
	}
265
266
}
(-)src/org/eclipse/compare/internal/core/patch/DiffProject.java (-5 / +5 lines)
Lines 35-41 Link Here
35
	 * Add the file diff to this project.
35
	 * Add the file diff to this project.
36
	 * @param diff the file diff.
36
	 * @param diff the file diff.
37
	 */
37
	 */
38
	public void add(FileDiff diff) {
38
	public void add(FilePatch2 diff) {
39
		fDiffs.add(diff);
39
		fDiffs.add(diff);
40
		if (diff.getProject() != this)
40
		if (diff.getProject() != this)
41
			diff.setProject(this);
41
			diff.setProject(this);
Lines 53-59 Link Here
53
	 * Remove the file diff from this project.
53
	 * Remove the file diff from this project.
54
	 * @param diff the diff to be removed
54
	 * @param diff the diff to be removed
55
	 */
55
	 */
56
	public void remove(FileDiff diff) {
56
	public void remove(FilePatch2 diff) {
57
		fDiffs.remove(diff);
57
		fDiffs.remove(diff);
58
	}
58
	}
59
59
Lines 62-68 Link Here
62
	 * @param diff a file diff
62
	 * @param diff a file diff
63
	 * @return whether this project contains the given diff
63
	 * @return whether this project contains the given diff
64
	 */
64
	 */
65
	public boolean contains(FileDiff diff) {
65
	public boolean contains(FilePatch2 diff) {
66
		return fDiffs.contains(diff);
66
		return fDiffs.contains(diff);
67
	}
67
	}
68
68
Lines 70-76 Link Here
70
	 * Return the file diffs associated with this project.
70
	 * Return the file diffs associated with this project.
71
	 * @return the file diffs associated with this project
71
	 * @return the file diffs associated with this project
72
	 */
72
	 */
73
	public FileDiff[] getFileDiffs() {
73
	public FilePatch2[] getFileDiffs() {
74
		return (FileDiff[]) fDiffs.toArray(new FileDiff[fDiffs.size()]);
74
		return (FilePatch2[]) fDiffs.toArray(new FilePatch2[fDiffs.size()]);
75
	}
75
	}
76
}
76
}
(-)src/org/eclipse/compare/internal/core/patch/Hunk.java (-14 / +14 lines)
Lines 24-37 Link Here
24
 */
24
 */
25
public class Hunk implements IHunk {
25
public class Hunk implements IHunk {
26
26
27
	private FileDiff fParent;
27
	private FilePatch2 fParent;
28
	private int fOldStart, fOldLength;
28
	private int fOldStart, fOldLength;
29
	private int fNewStart, fNewLength;
29
	private int fNewStart, fNewLength;
30
	private String[] fLines;
30
	private String[] fLines;
31
	private int hunkType;
31
	private int hunkType;
32
	private String charset = null;
32
	private String charset = null;
33
33
34
	public static Hunk createHunk(FileDiff parent, int[] oldRange, int[] newRange, List lines, boolean hasLineAdditions, boolean hasLineDeletions, boolean hasContextLines) {
34
	public static Hunk createHunk(FilePatch2 parent, int[] oldRange, int[] newRange, List lines, boolean hasLineAdditions, boolean hasLineDeletions, boolean hasContextLines) {
35
		int oldStart = 0;
35
		int oldStart = 0;
36
		int oldLength = 0;
36
		int oldLength = 0;
37
		int newStart = 0;
37
		int newStart = 0;
Lines 46-63 Link Here
46
		else
46
		else
47
			newStart= 0;
47
			newStart= 0;
48
		newLength= newRange[1];
48
		newLength= newRange[1];
49
		int hunkType = FileDiff.CHANGE;
49
		int hunkType = FilePatch2.CHANGE;
50
		if (!hasContextLines) {
50
		if (!hasContextLines) {
51
			if (hasLineAdditions && !hasLineDeletions) {
51
			if (hasLineAdditions && !hasLineDeletions) {
52
				hunkType = FileDiff.ADDITION;
52
				hunkType = FilePatch2.ADDITION;
53
			} else if (!hasLineAdditions && hasLineDeletions) {
53
			} else if (!hasLineAdditions && hasLineDeletions) {
54
				hunkType = FileDiff.DELETION;
54
				hunkType = FilePatch2.DELETION;
55
			}
55
			}
56
		}
56
		}
57
		return new Hunk(parent, hunkType, oldStart, oldLength, newStart, newLength, (String[]) lines.toArray(new String[lines.size()]));
57
		return new Hunk(parent, hunkType, oldStart, oldLength, newStart, newLength, (String[]) lines.toArray(new String[lines.size()]));
58
	}
58
	}
59
	
59
	
60
	public Hunk(FileDiff parent, int hunkType, int oldStart, int oldLength,
60
	public Hunk(FilePatch2 parent, int hunkType, int oldStart, int oldLength,
61
			int newStart, int newLength, String[] lines) {
61
			int newStart, int newLength, String[] lines) {
62
		fParent = parent;
62
		fParent = parent;
63
        if (fParent != null) {
63
        if (fParent != null) {
Lines 71-77 Link Here
71
		fLines = lines;
71
		fLines = lines;
72
	}
72
	}
73
	
73
	
74
    public Hunk(FileDiff parent, Hunk toCopy) {
74
    public Hunk(FilePatch2 parent, Hunk toCopy) {
75
    	this(parent, toCopy.hunkType, toCopy.fOldStart, toCopy.fOldLength, toCopy.fNewStart, toCopy.fNewLength, toCopy.fLines);
75
    	this(parent, toCopy.hunkType, toCopy.fOldStart, toCopy.fOldLength, toCopy.fNewStart, toCopy.fNewLength, toCopy.fLines);
76
    }
76
    }
77
77
Lines 129-138 Link Here
129
	
129
	
130
	public int getHunkType(boolean reverse) {
130
	public int getHunkType(boolean reverse) {
131
		if (reverse) {
131
		if (reverse) {
132
			if (hunkType == FileDiff.ADDITION)
132
			if (hunkType == FilePatch2.ADDITION)
133
				return FileDiff.DELETION;
133
				return FilePatch2.DELETION;
134
			if (hunkType == FileDiff.DELETION)
134
			if (hunkType == FilePatch2.DELETION)
135
				return FileDiff.ADDITION;
135
				return FilePatch2.ADDITION;
136
		}
136
		}
137
		return hunkType;
137
		return hunkType;
138
	}
138
	}
Lines 153-162 Link Here
153
153
154
	/**
154
	/**
155
	 * Set the parent of this hunk. This method
155
	 * Set the parent of this hunk. This method
156
	 * should only be invoked from {@link FileDiff#add(Hunk)}
156
	 * should only be invoked from {@link FilePatch2#add(Hunk)}
157
	 * @param diff the parent of this hunk
157
	 * @param diff the parent of this hunk
158
	 */
158
	 */
159
	void setParent(FileDiff diff) {
159
	void setParent(FilePatch2 diff) {
160
		if (fParent == diff)
160
		if (fParent == diff)
161
			return;
161
			return;
162
		if (fParent != null)
162
		if (fParent != null)
Lines 164-170 Link Here
164
		fParent = diff;	
164
		fParent = diff;	
165
	}
165
	}
166
166
167
	public FileDiff getParent() {
167
	public FilePatch2 getParent() {
168
		return fParent;
168
		return fParent;
169
	}
169
	}
170
	
170
	
(-)src/org/eclipse/compare/internal/core/patch/PatchReader.java (-15 / +15 lines)
Lines 53-59 Link Here
53
53
54
	private boolean fIsWorkspacePatch;
54
	private boolean fIsWorkspacePatch;
55
	private DiffProject[] fDiffProjects;
55
	private DiffProject[] fDiffProjects;
56
	private FileDiff[] fDiffs;
56
	private FilePatch2[] fDiffs;
57
57
58
	// API for writing new multi-project patch format
58
	// API for writing new multi-project patch format
59
	public static final String MULTIPROJECTPATCH_HEADER= "### Eclipse Workspace Patch"; //$NON-NLS-1$
59
	public static final String MULTIPROJECTPATCH_HEADER= "### Eclipse Workspace Patch"; //$NON-NLS-1$
Lines 152-170 Link Here
152
		lr.close();
152
		lr.close();
153
153
154
		fDiffProjects= (DiffProject[]) diffProjects.values().toArray(new DiffProject[diffProjects.size()]);
154
		fDiffProjects= (DiffProject[]) diffProjects.values().toArray(new DiffProject[diffProjects.size()]);
155
		fDiffs = (FileDiff[]) diffs.toArray(new FileDiff[diffs.size()]);
155
		fDiffs = (FilePatch2[]) diffs.toArray(new FilePatch2[diffs.size()]);
156
	}
156
	}
157
157
158
	protected FileDiff createFileDiff(IPath oldPath, long oldDate,
158
	protected FilePatch2 createFileDiff(IPath oldPath, long oldDate,
159
			IPath newPath, long newDate) {
159
			IPath newPath, long newDate) {
160
		return new FileDiff(oldPath, oldDate, newPath, newDate);
160
		return new FilePatch2(oldPath, oldDate, newPath, newDate);
161
	}
161
	}
162
162
163
	private String readUnifiedDiff(List diffs, LineReader lr, String line, String diffArgs, String fileName, DiffProject diffProject) throws IOException {
163
	private String readUnifiedDiff(List diffs, LineReader lr, String line, String diffArgs, String fileName, DiffProject diffProject) throws IOException {
164
		List newDiffs= new ArrayList();
164
		List newDiffs= new ArrayList();
165
		String nextLine= readUnifiedDiff(newDiffs, lr, line, diffArgs, fileName);
165
		String nextLine= readUnifiedDiff(newDiffs, lr, line, diffArgs, fileName);
166
		for (Iterator iter= newDiffs.iterator(); iter.hasNext();) {
166
		for (Iterator iter= newDiffs.iterator(); iter.hasNext();) {
167
			FileDiff diff= (FileDiff) iter.next();
167
			FilePatch2 diff= (FilePatch2) iter.next();
168
			diffProject.add(diff);
168
			diffProject.add(diff);
169
			diffs.add(diff);
169
			diffs.add(diff);
170
		}
170
		}
Lines 195-207 Link Here
195
			} else if (line.startsWith("--- ")) { //$NON-NLS-1$
195
			} else if (line.startsWith("--- ")) { //$NON-NLS-1$
196
				line= readUnifiedDiff(diffs, lr, line, diffArgs, fileName);
196
				line= readUnifiedDiff(diffs, lr, line, diffArgs, fileName);
197
				if (!headerLines.isEmpty())
197
				if (!headerLines.isEmpty())
198
					setHeader((FileDiff)diffs.get(diffs.size() - 1), headerLines);
198
					setHeader((FilePatch2)diffs.get(diffs.size() - 1), headerLines);
199
				diffArgs= fileName= null;
199
				diffArgs= fileName= null;
200
				reread= true;
200
				reread= true;
201
			} else if (line.startsWith("*** ")) { //$NON-NLS-1$
201
			} else if (line.startsWith("*** ")) { //$NON-NLS-1$
202
				line= readContextDiff(diffs, lr, line, diffArgs, fileName);
202
				line= readContextDiff(diffs, lr, line, diffArgs, fileName);
203
				if (!headerLines.isEmpty())
203
				if (!headerLines.isEmpty())
204
					setHeader((FileDiff)diffs.get(diffs.size() - 1), headerLines);
204
					setHeader((FilePatch2)diffs.get(diffs.size() - 1), headerLines);
205
				diffArgs= fileName= null;
205
				diffArgs= fileName= null;
206
				reread= true;
206
				reread= true;
207
			}
207
			}
Lines 215-224 Link Here
215
		
215
		
216
		lr.close();
216
		lr.close();
217
		
217
		
218
		fDiffs = (FileDiff[]) diffs.toArray(new FileDiff[diffs.size()]);
218
		fDiffs = (FilePatch2[]) diffs.toArray(new FilePatch2[diffs.size()]);
219
	}
219
	}
220
	
220
	
221
	private void setHeader(FileDiff diff, List headerLines) {
221
	private void setHeader(FilePatch2 diff, List headerLines) {
222
		String header = LineReader.createString(false, headerLines);
222
		String header = LineReader.createString(false, headerLines);
223
		diff.setHeader(header);
223
		diff.setHeader(header);
224
		headerLines.clear();
224
		headerLines.clear();
Lines 238-244 Link Here
238
			
238
			
239
		String[] newArgs= split(line.substring(4));
239
		String[] newArgs= split(line.substring(4));
240
	
240
	
241
		FileDiff diff = createFileDiff(extractPath(oldArgs, 0, fileName),
241
		FilePatch2 diff = createFileDiff(extractPath(oldArgs, 0, fileName),
242
				extractDate(oldArgs, 1), extractPath(newArgs, 0, fileName),
242
				extractDate(oldArgs, 1), extractPath(newArgs, 0, fileName),
243
				extractDate(newArgs, 1));
243
				extractDate(newArgs, 1));
244
		diffs.add(diff);
244
		diffs.add(diff);
Lines 344-350 Link Here
344
		
344
		
345
		String[] newArgs= split(line.substring(4));
345
		String[] newArgs= split(line.substring(4));
346
						
346
						
347
		FileDiff diff = createFileDiff(extractPath(oldArgs, 0, fileName),
347
		FilePatch2 diff = createFileDiff(extractPath(oldArgs, 0, fileName),
348
				extractDate(oldArgs, 1), extractPath(newArgs, 0, fileName),
348
				extractDate(oldArgs, 1), extractPath(newArgs, 0, fileName),
349
				extractDate(newArgs, 1));
349
				extractDate(newArgs, 1));
350
		diffs.add(diff);
350
		diffs.add(diff);
Lines 657-675 Link Here
657
		return fDiffProjects;
657
		return fDiffProjects;
658
	}
658
	}
659
659
660
	public FileDiff[] getDiffs() {
660
	public FilePatch2[] getDiffs() {
661
		return fDiffs;
661
		return fDiffs;
662
	}
662
	}
663
	
663
	
664
	public FileDiff[] getAdjustedDiffs() {
664
	public FilePatch2[] getAdjustedDiffs() {
665
		if (!isWorkspacePatch() || fDiffs.length == 0)
665
		if (!isWorkspacePatch() || fDiffs.length == 0)
666
			return fDiffs;
666
			return fDiffs;
667
		List result = new ArrayList();
667
		List result = new ArrayList();
668
		for (int i = 0; i < fDiffs.length; i++) {
668
		for (int i = 0; i < fDiffs.length; i++) {
669
			FileDiff diff = fDiffs[i];
669
			FilePatch2 diff = fDiffs[i];
670
			result.add(diff.asRelativeDiff());
670
			result.add(diff.asRelativeDiff());
671
		}
671
		}
672
		return (FileDiff[]) result.toArray(new FileDiff[result.size()]);
672
		return (FilePatch2[]) result.toArray(new FilePatch2[result.size()]);
673
	}
673
	}
674
674
675
}
675
}
(-)src/org/eclipse/compare/patch/PatchBuilder.java (-5 / +5 lines)
Lines 13-19 Link Here
13
import java.util.Arrays;
13
import java.util.Arrays;
14
import java.util.Comparator;
14
import java.util.Comparator;
15
15
16
import org.eclipse.compare.internal.core.patch.FileDiff;
16
import org.eclipse.compare.internal.core.patch.FilePatch2;
17
import org.eclipse.compare.internal.core.patch.Hunk;
17
import org.eclipse.compare.internal.core.patch.Hunk;
18
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.core.runtime.IPath;
19
19
Lines 90-96 Link Here
90
	public static IFilePatch2 createFilePatch(IPath oldPath, long oldDate,
90
	public static IFilePatch2 createFilePatch(IPath oldPath, long oldDate,
91
			IPath newPath, long newDate, IHunk[] hunks) {
91
			IPath newPath, long newDate, IHunk[] hunks) {
92
		reorder(hunks);
92
		reorder(hunks);
93
		FileDiff fileDiff = new FileDiff(oldPath, oldDate, newPath, newDate);
93
		FilePatch2 fileDiff = new FilePatch2(oldPath, oldDate, newPath, newDate);
94
		for (int i = 0; i < hunks.length; i++) {
94
		for (int i = 0; i < hunks.length; i++) {
95
			fileDiff.add((Hunk) hunks[i]);
95
			fileDiff.add((Hunk) hunks[i]);
96
		}
96
		}
Lines 152-163 Link Here
152
			boolean hasLineAdditions = checkForPrefix(ADDITION_PREFIX, lines);
152
			boolean hasLineAdditions = checkForPrefix(ADDITION_PREFIX, lines);
153
			boolean hasLineDeletions = checkForPrefix(REMOVAL_PREFIX, lines);
153
			boolean hasLineDeletions = checkForPrefix(REMOVAL_PREFIX, lines);
154
			if (hasLineAdditions && !hasLineDeletions) {
154
			if (hasLineAdditions && !hasLineDeletions) {
155
				return FileDiff.ADDITION;
155
				return FilePatch2.ADDITION;
156
			} else if (!hasLineAdditions && hasLineDeletions) {
156
			} else if (!hasLineAdditions && hasLineDeletions) {
157
				return FileDiff.DELETION;
157
				return FilePatch2.DELETION;
158
			}
158
			}
159
		}
159
		}
160
		return FileDiff.CHANGE;
160
		return FilePatch2.CHANGE;
161
	}
161
	}
162
162
163
	private static int getHunkLength(String[] lines, boolean old) {
163
	private static int getHunkLength(String[] lines, boolean old) {
(-)src/org/eclipse/compare/internal/core/patch/FilePatch2.java (+266 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.compare.internal.core.patch;
12
13
import java.util.ArrayList;
14
import java.util.Iterator;
15
import java.util.List;
16
17
import org.eclipse.compare.patch.IFilePatch2;
18
import org.eclipse.compare.patch.IFilePatchResult;
19
import org.eclipse.compare.patch.IHunk;
20
import org.eclipse.compare.patch.PatchConfiguration;
21
import org.eclipse.compare.patch.ReaderCreator;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.Path;
25
26
/**
27
 * A file diff represents a set of hunks that were associated with the
28
 * same path in a patch file.
29
 */
30
public class FilePatch2 implements IFilePatch2 {
31
32
	/**
33
	 * Difference constant (value 1) indicating one side was added.
34
	 */
35
	public static final int ADDITION= 1;
36
	/**
37
	 * Difference constant (value 2) indicating one side was removed.
38
	 */
39
	public static final int DELETION= 2;
40
	/**
41
	 * Difference constant (value 3) indicating side changed.
42
	 */
43
	public static final int CHANGE= 3;
44
	
45
	private IPath fOldPath, fNewPath;
46
	private long oldDate, newDate;
47
	private List fHunks= new ArrayList();
48
	private DiffProject fProject; //the project that contains this diff
49
	private String header;
50
	private int addedLines, removedLines;
51
	
52
	/**
53
	 * Create a file diff for the given path and date information.
54
	 * @param oldPath the path of the before state of the file
55
	 * @param oldDate the timestamp of the before state
56
	 * @param newPath the path of the after state
57
	 * @param newDate the timestamp of the after state
58
	 */
59
 	public FilePatch2(IPath oldPath, long oldDate, IPath newPath, long newDate) {
60
		fOldPath= oldPath;
61
		this.oldDate = oldDate;
62
		fNewPath= newPath;
63
		this.newDate = newDate;
64
	}
65
	
66
 	/**
67
 	 * Return the parent project or <code>null</code> if there isn't one.
68
 	 * @return the parent project or <code>null</code>
69
 	 */
70
	public DiffProject getProject() {
71
		return fProject;
72
	}
73
	
74
	/**
75
	 * Set the project of this diff to the given project.
76
	 * This method should only be called from
77
	 * {@link DiffProject#add(FilePatch2)}
78
	 * @param diffProject the parent project
79
	 */
80
	void setProject(DiffProject diffProject) {
81
		if (fProject == diffProject)
82
			return;
83
		if (fProject != null)
84
			fProject.remove(this);
85
		this.fProject= diffProject;
86
	}
87
	
88
	/**
89
	 * Get the path of the file diff.
90
	 * @param reverse whether the path of the before state or after state 
91
	 * should be used
92
	 * @return the path of the file diff
93
	 */
94
	public IPath getPath(boolean reverse) {
95
		if (getDiffType(reverse) == ADDITION) {
96
			if (reverse)
97
				return fOldPath;
98
			return fNewPath;
99
		}
100
		if (reverse && fNewPath != null)
101
			return fNewPath;
102
		if (fOldPath != null)
103
			return fOldPath;
104
		return fNewPath;
105
	}
106
	
107
	/**
108
	 * Add the hunk to this file diff.
109
	 * @param hunk the hunk
110
	 */
111
	public void add(Hunk hunk) {
112
		fHunks.add(hunk);
113
		hunk.setParent(this);
114
	}
115
	
116
	/**
117
	 * Remove the hunk from this file diff
118
	 * @param hunk the hunk
119
	 */
120
	protected void remove(Hunk hunk) {
121
		fHunks.remove(hunk);
122
	}
123
	
124
	/**
125
	 * Return the hunks associated with this file diff.
126
	 * @return the hunks associated with this file diff
127
	 */
128
	public IHunk[] getHunks() {
129
		return (IHunk[]) fHunks.toArray(new IHunk[fHunks.size()]);
130
	}
131
	
132
	/**
133
	 * Return the number of hunks associated with this file diff.
134
	 * @return the number of hunks associated with this file diff
135
	 */
136
	public int getHunkCount() {
137
		return fHunks.size();
138
	}
139
	
140
	/**
141
	 * Return the difference type of this file diff.
142
	 * @param reverse whether the patch is being reversed
143
	 * @return the type of this file diff
144
	 */
145
	public int getDiffType(boolean reverse) {
146
		if (fHunks.size() == 1) {
147
			boolean add = false;
148
			boolean delete = false;
149
			Iterator iter = fHunks.iterator();
150
			while (iter.hasNext()){
151
				Hunk hunk = (Hunk) iter.next();
152
				int type =hunk.getHunkType(reverse);
153
				if (type == ADDITION){
154
					add = true;
155
				} else if (type == DELETION ){
156
					delete = true;
157
				}
158
			}
159
			if (add && !delete){
160
				return ADDITION;
161
			} else if (!add && delete){
162
				return DELETION;
163
			}
164
		}
165
		return CHANGE;
166
	}
167
	
168
	/**
169
	 * Return the path of this file diff with the specified number
170
	 * of leading segments striped.
171
	 * @param strip the number of leading segments to strip from the path
172
	 * @param reverse whether the patch is being reversed
173
	 * @return the path of this file diff with the specified number
174
	 * of leading segments striped
175
	 */
176
	public IPath getStrippedPath(int strip, boolean reverse) {
177
		IPath path= getPath(reverse);
178
		if (strip > 0 && strip < path.segmentCount())
179
			path= path.removeFirstSegments(strip);
180
		return path;
181
	}
182
	
183
	/**
184
	 * Return the segment count of the path of this file diff.
185
	 * @return the segment count of the path of this file diff
186
	 */
187
	public int segmentCount() {
188
		//Update prefix count - go through all of the diffs and find the smallest
189
		//path segment contained in all diffs.
190
		int length= 99;
191
		if (fOldPath != null)
192
			length= Math.min(length, fOldPath.segmentCount());
193
		if (fNewPath != null)
194
			length= Math.min(length, fNewPath.segmentCount());
195
		return length;
196
	}
197
	
198
	public IFilePatchResult apply(ReaderCreator content,
199
			PatchConfiguration configuration, IProgressMonitor monitor) {
200
		FileDiffResult result = new FileDiffResult(this, configuration);
201
		result.refresh(content, monitor);
202
		return result;
203
	}
204
205
	public IPath getTargetPath(PatchConfiguration configuration) {
206
		return getStrippedPath(configuration.getPrefixSegmentStripCount(), configuration.isReversed());
207
	}
208
209
	public FilePatch2 asRelativeDiff() {
210
		if (fProject == null)
211
			return this;
212
		IPath adjustedOldPath = null;
213
		if (fOldPath != null) {
214
			adjustedOldPath = new Path(null, fProject.getName()).append(fOldPath);
215
		}
216
		IPath adjustedNewPath = null;
217
		if (fNewPath != null) {
218
			adjustedNewPath = new Path(null, fProject.getName()).append(fNewPath);
219
		}
220
		FilePatch2 diff = create(adjustedOldPath, 0, adjustedNewPath, 0);
221
		for (Iterator iterator = fHunks.iterator(); iterator.hasNext();) {
222
			Hunk hunk = (Hunk) iterator.next();
223
			// Creating the hunk adds it to the parent diff
224
			new Hunk(diff, hunk);
225
		}
226
		return diff;
227
	}
228
229
	protected FilePatch2 create(IPath oldPath, long oldDate, IPath newPath,
230
			long newDate) {
231
		return new FilePatch2(oldPath, oldDate, newPath, newDate);
232
	}
233
234
	public void setHeader(String header) {
235
		this.header = header;
236
	}
237
238
	public String getHeader() {
239
		return header;
240
	}
241
242
	public long getBeforeDate() {
243
		return oldDate;
244
	}
245
246
	public long getAfterDate() {
247
		return newDate;
248
	}
249
250
	public void setAddedLines(int addedLines) {
251
		this.addedLines = addedLines;
252
	}
253
	
254
	public void setRemovedLines(int removedLines) {
255
		this.removedLines = removedLines;
256
	}
257
258
	public int getAddedLines() {
259
		return addedLines;
260
	}
261
	
262
	public int getRemovedLines() {
263
		return removedLines;
264
	}
265
266
}
(-)src/org/eclipse/compare/tests/FileDiffResultTest.java (-2 / +2 lines)
Lines 18-24 Link Here
18
import java.util.ArrayList;
18
import java.util.ArrayList;
19
19
20
import org.eclipse.compare.internal.Utilities;
20
import org.eclipse.compare.internal.Utilities;
21
import org.eclipse.compare.internal.core.patch.FileDiff;
21
import org.eclipse.compare.internal.core.patch.FilePatch2;
22
import org.eclipse.compare.internal.core.patch.FileDiffResult;
22
import org.eclipse.compare.internal.core.patch.FileDiffResult;
23
import org.eclipse.compare.internal.core.patch.Hunk;
23
import org.eclipse.compare.internal.core.patch.Hunk;
24
import org.eclipse.compare.internal.patch.Patcher;
24
import org.eclipse.compare.internal.patch.Patcher;
Lines 216-222 Link Here
216
	/**
216
	/**
217
	 * A mock FileDiff class.
217
	 * A mock FileDiff class.
218
	 */
218
	 */
219
	private class MyFileDiff extends FileDiff {
219
	private class MyFileDiff extends FilePatch2 {
220
		protected MyFileDiff() {
220
		protected MyFileDiff() {
221
			super(null, 0, null, 0);
221
			super(null, 0, null, 0);
222
			add(Hunk.createHunk(this, new int[] { 0, 0 }, new int[] { 0, 0 },
222
			add(Hunk.createHunk(this, new int[] { 0, 0 }, new int[] { 0, 0 },
(-)src/org/eclipse/compare/tests/PatchTest.java (-3 / +3 lines)
Lines 36-42 Link Here
36
import junit.framework.AssertionFailedError;
36
import junit.framework.AssertionFailedError;
37
import junit.framework.TestCase;
37
import junit.framework.TestCase;
38
38
39
import org.eclipse.compare.internal.core.patch.FileDiff;
39
import org.eclipse.compare.internal.core.patch.FilePatch2;
40
import org.eclipse.compare.internal.core.patch.FileDiffResult;
40
import org.eclipse.compare.internal.core.patch.FileDiffResult;
41
import org.eclipse.compare.internal.core.patch.LineReader;
41
import org.eclipse.compare.internal.core.patch.LineReader;
42
import org.eclipse.compare.internal.patch.WorkspacePatcher;
42
import org.eclipse.compare.internal.patch.WorkspacePatcher;
Lines 456-462 Link Here
456
			e.printStackTrace();
456
			e.printStackTrace();
457
		}
457
		}
458
		
458
		
459
		FileDiff[] diffs= patcher.getDiffs();
459
		FilePatch2[] diffs= patcher.getDiffs();
460
		Assert.assertEquals(diffs.length, 1);
460
		Assert.assertEquals(diffs.length, 1);
461
		
461
		
462
		FileDiffResult diffResult = patcher.getDiffResult(diffs[0]);
462
		FileDiffResult diffResult = patcher.getDiffResult(diffs[0]);
Lines 513-519 Link Here
513
		}
513
		}
514
		
514
		
515
		//Sort the diffs by project 
515
		//Sort the diffs by project 
516
		FileDiff[] diffs= patcher.getDiffs();
516
		FilePatch2[] diffs= patcher.getDiffs();
517
		
517
		
518
		//Iterate through all of the original files, apply the diffs that belong to the file and compare
518
		//Iterate through all of the original files, apply the diffs that belong to the file and compare
519
		//with the corresponding outcome file
519
		//with the corresponding outcome file
(-)compare/org/eclipse/compare/patch/ApplyPatchOperation.java (-6 / +6 lines)
Lines 16-24 Link Here
16
import org.eclipse.compare.CompareConfiguration;
16
import org.eclipse.compare.CompareConfiguration;
17
import org.eclipse.compare.internal.ComparePreferencePage;
17
import org.eclipse.compare.internal.ComparePreferencePage;
18
import org.eclipse.compare.internal.CompareUIPlugin;
18
import org.eclipse.compare.internal.CompareUIPlugin;
19
import org.eclipse.compare.internal.core.patch.FileDiff;
19
import org.eclipse.compare.internal.core.patch.FilePatch2;
20
import org.eclipse.compare.internal.core.patch.PatchReader;
20
import org.eclipse.compare.internal.core.patch.PatchReader;
21
import org.eclipse.compare.internal.patch.FileDiffWrapper;
21
import org.eclipse.compare.internal.patch.FilePatch;
22
import org.eclipse.compare.internal.patch.PatchWizard;
22
import org.eclipse.compare.internal.patch.PatchWizard;
23
import org.eclipse.compare.internal.patch.PatchWizardDialog;
23
import org.eclipse.compare.internal.patch.PatchWizardDialog;
24
import org.eclipse.compare.internal.patch.Utilities;
24
import org.eclipse.compare.internal.patch.Utilities;
Lines 206-223 Link Here
206
		BufferedReader reader = Utilities.createReader(storage);
206
		BufferedReader reader = Utilities.createReader(storage);
207
		try {
207
		try {
208
			PatchReader patchReader = new PatchReader() {
208
			PatchReader patchReader = new PatchReader() {
209
				protected FileDiff createFileDiff(IPath oldPath, long oldDate,
209
				protected FilePatch2 createFileDiff(IPath oldPath, long oldDate,
210
						IPath newPath, long newDate) {
210
						IPath newPath, long newDate) {
211
					return new FileDiffWrapper(oldPath, oldDate, newPath,
211
					return new FilePatch(oldPath, oldDate, newPath,
212
							newDate);
212
							newDate);
213
				}
213
				}
214
			};
214
			};
215
			patchReader.parse(reader);
215
			patchReader.parse(reader);
216
			FileDiff[] fileDiffs = patchReader.getAdjustedDiffs();
216
			FilePatch2[] fileDiffs = patchReader.getAdjustedDiffs();
217
217
218
			IFilePatch[] filePatch = new IFilePatch[fileDiffs.length];
218
			IFilePatch[] filePatch = new IFilePatch[fileDiffs.length];
219
			for (int i = 0; i < fileDiffs.length; i++) {
219
			for (int i = 0; i < fileDiffs.length; i++) {
220
				filePatch[i] = (FileDiffWrapper) fileDiffs[i];
220
				filePatch[i] = (FilePatch) fileDiffs[i];
221
			}
221
			}
222
222
223
			return filePatch;
223
			return filePatch;
(-)compare/org/eclipse/compare/internal/patch/Patcher.java (-40 / +40 lines)
Lines 28-34 Link Here
28
28
29
import org.eclipse.compare.internal.core.Messages;
29
import org.eclipse.compare.internal.core.Messages;
30
import org.eclipse.compare.internal.core.patch.DiffProject;
30
import org.eclipse.compare.internal.core.patch.DiffProject;
31
import org.eclipse.compare.internal.core.patch.FileDiff;
31
import org.eclipse.compare.internal.core.patch.FilePatch2;
32
import org.eclipse.compare.internal.core.patch.FileDiffResult;
32
import org.eclipse.compare.internal.core.patch.FileDiffResult;
33
import org.eclipse.compare.internal.core.patch.Hunk;
33
import org.eclipse.compare.internal.core.patch.Hunk;
34
import org.eclipse.compare.internal.core.patch.PatchReader;
34
import org.eclipse.compare.internal.core.patch.PatchReader;
Lines 77-83 Link Here
77
	//	private static final int NORMAL= 2;
77
	//	private static final int NORMAL= 2;
78
	//	private static final int UNIFIED= 3;
78
	//	private static final int UNIFIED= 3;
79
	
79
	
80
	private FileDiff[] fDiffs;
80
	private FilePatch2[] fDiffs;
81
	private IResource fTarget;
81
	private IResource fTarget;
82
	// patch options
82
	// patch options
83
	private Set disabledElements = new HashSet();
83
	private Set disabledElements = new HashSet();
Lines 98-110 Link Here
98
	 * Returns an array of Diffs after a sucessfull call to <code>parse</code>.
98
	 * Returns an array of Diffs after a sucessfull call to <code>parse</code>.
99
	 * If <code>parse</code> hasn't been called returns <code>null</code>.
99
	 * If <code>parse</code> hasn't been called returns <code>null</code>.
100
	 */
100
	 */
101
	public FileDiff[] getDiffs() {
101
	public FilePatch2[] getDiffs() {
102
		if (fDiffs == null)
102
		if (fDiffs == null)
103
			return new FileDiff[0];
103
			return new FilePatch2[0];
104
		return fDiffs;
104
		return fDiffs;
105
	}
105
	}
106
	
106
	
107
	public IPath getPath(FileDiff diff) {
107
	public IPath getPath(FilePatch2 diff) {
108
		return diff.getStrippedPath(getStripPrefixSegments(), isReversed());
108
		return diff.getStrippedPath(getStripPrefixSegments(), isReversed());
109
	}
109
	}
110
110
Lines 177-185 Link Here
177
	
177
	
178
	public void parse(BufferedReader reader) throws IOException {
178
	public void parse(BufferedReader reader) throws IOException {
179
		PatchReader patchReader = new PatchReader() {
179
		PatchReader patchReader = new PatchReader() {
180
			protected FileDiff createFileDiff(IPath oldPath, long oldDate,
180
			protected FilePatch2 createFileDiff(IPath oldPath, long oldDate,
181
					IPath newPath, long newDate) {
181
					IPath newPath, long newDate) {
182
				return new FileDiffWrapper(oldPath, oldDate, newPath, newDate);
182
				return new FilePatch(oldPath, oldDate, newPath, newDate);
183
			}
183
			}
184
		};
184
		};
185
		patchReader.parse(reader);
185
		patchReader.parse(reader);
Lines 191-201 Link Here
191
	}
191
	}
192
	
192
	
193
	public void countLines() {
193
	public void countLines() {
194
		FileDiff[] fileDiffs = getDiffs();
194
		FilePatch2[] fileDiffs = getDiffs();
195
		for (int i = 0; i < fileDiffs.length; i++) {
195
		for (int i = 0; i < fileDiffs.length; i++) {
196
			int addedLines = 0;
196
			int addedLines = 0;
197
			int removedLines = 0;
197
			int removedLines = 0;
198
			FileDiff fileDiff = fileDiffs[i];
198
			FilePatch2 fileDiff = fileDiffs[i];
199
			for (int j = 0; j < fileDiff.getHunkCount(); j++) {
199
			for (int j = 0; j < fileDiff.getHunkCount(); j++) {
200
				IHunk hunk = fileDiff.getHunks()[j];
200
				IHunk hunk = fileDiff.getHunks()[j];
201
				String[] lines = ((Hunk) hunk).getLines();
201
				String[] lines = ((Hunk) hunk).getLines();
Lines 239-248 Link Here
239
			list.add(singleFile);
239
			list.add(singleFile);
240
		else {
240
		else {
241
			for (i= 0; i < fDiffs.length; i++) {
241
			for (i= 0; i < fDiffs.length; i++) {
242
				FileDiff diff= fDiffs[i];
242
				FilePatch2 diff= fDiffs[i];
243
				if (isEnabled(diff)) {
243
				if (isEnabled(diff)) {
244
					switch (diff.getDiffType(isReversed())) {
244
					switch (diff.getDiffType(isReversed())) {
245
					case FileDiff.CHANGE:
245
					case FilePatch2.CHANGE:
246
						list.add(createPath(container, getPath(diff)));
246
						list.add(createPath(container, getPath(diff)));
247
						break;
247
						break;
248
					}
248
					}
Lines 263-269 Link Here
263
			
263
			
264
			int workTicks= WORK_UNIT;
264
			int workTicks= WORK_UNIT;
265
			
265
			
266
			FileDiff diff= fDiffs[i];
266
			FilePatch2 diff= fDiffs[i];
267
			if (isEnabled(diff)) {
267
			if (isEnabled(diff)) {
268
				
268
				
269
				IPath path= getPath(diff);
269
				IPath path= getPath(diff);
Lines 278-295 Link Here
278
				
278
				
279
				int type= diff.getDiffType(isReversed());
279
				int type= diff.getDiffType(isReversed());
280
				switch (type) {
280
				switch (type) {
281
				case FileDiff.ADDITION:
281
				case FilePatch2.ADDITION:
282
					// patch it and collect rejected hunks
282
					// patch it and collect rejected hunks
283
					List result= apply(diff, file, true, failed);
283
					List result= apply(diff, file, true, failed);
284
					if (result != null)
284
					if (result != null)
285
						store(LineReader.createString(isPreserveLineDelimeters(), result), file, new SubProgressMonitor(pm, workTicks));
285
						store(LineReader.createString(isPreserveLineDelimeters(), result), file, new SubProgressMonitor(pm, workTicks));
286
					workTicks-= WORK_UNIT;
286
					workTicks-= WORK_UNIT;
287
					break;
287
					break;
288
				case FileDiff.DELETION:
288
				case FilePatch2.DELETION:
289
					file.delete(true, true, new SubProgressMonitor(pm, workTicks));
289
					file.delete(true, true, new SubProgressMonitor(pm, workTicks));
290
					workTicks-= WORK_UNIT;
290
					workTicks-= WORK_UNIT;
291
					break;
291
					break;
292
				case FileDiff.CHANGE:
292
				case FilePatch2.CHANGE:
293
					// patch it and collect rejected hunks
293
					// patch it and collect rejected hunks
294
					result= apply(diff, file, false, failed);
294
					result= apply(diff, file, false, failed);
295
					if (result != null)
295
					if (result != null)
Lines 333-339 Link Here
333
		return pp;
333
		return pp;
334
	}
334
	}
335
	
335
	
336
	List apply(FileDiff diff, IFile file, boolean create, List failedHunks) {
336
	List apply(FilePatch2 diff, IFile file, boolean create, List failedHunks) {
337
		FileDiffResult result = getDiffResult(diff);
337
		FileDiffResult result = getDiffResult(diff);
338
		List lines = LineReader.load(file, create);
338
		List lines = LineReader.load(file, create);
339
		result.patch(lines, null);
339
		result.patch(lines, null);
Lines 437-443 Link Here
437
	}
437
	}
438
	
438
	
439
439
440
	public IFile getTargetFile(FileDiff diff) {
440
	public IFile getTargetFile(FilePatch2 diff) {
441
		IPath path = diff.getStrippedPath(getStripPrefixSegments(), isReversed());
441
		IPath path = diff.getStrippedPath(getStripPrefixSegments(), isReversed());
442
		return existsInTarget(path);
442
		return existsInTarget(path);
443
	}
443
	}
Lines 481-501 Link Here
481
		int length= 99;
481
		int length= 99;
482
		if (fDiffs!=null)
482
		if (fDiffs!=null)
483
			for (int i= 0; i<fDiffs.length; i++) {
483
			for (int i= 0; i<fDiffs.length; i++) {
484
				FileDiff diff= fDiffs[i];
484
				FilePatch2 diff= fDiffs[i];
485
				length= Math.min(length, diff.segmentCount());
485
				length= Math.min(length, diff.segmentCount());
486
			}
486
			}
487
		return length;
487
		return length;
488
	}
488
	}
489
	
489
	
490
	public void addDiff(FileDiff newDiff){
490
	public void addDiff(FilePatch2 newDiff){
491
		FileDiff[] temp = new FileDiff[fDiffs.length + 1];
491
		FilePatch2[] temp = new FilePatch2[fDiffs.length + 1];
492
		System.arraycopy(fDiffs,0, temp, 0, fDiffs.length);
492
		System.arraycopy(fDiffs,0, temp, 0, fDiffs.length);
493
		temp[fDiffs.length] = newDiff;
493
		temp[fDiffs.length] = newDiff;
494
		fDiffs = temp;
494
		fDiffs = temp;
495
	}
495
	}
496
	
496
	
497
	public void removeDiff(FileDiff diffToRemove){
497
	public void removeDiff(FilePatch2 diffToRemove){
498
		FileDiff[] temp = new FileDiff[fDiffs.length - 1];
498
		FilePatch2[] temp = new FilePatch2[fDiffs.length - 1];
499
		int counter = 0;
499
		int counter = 0;
500
		for (int i = 0; i < fDiffs.length; i++) {
500
		for (int i = 0; i < fDiffs.length; i++) {
501
			if (fDiffs[i] != diffToRemove){
501
			if (fDiffs[i] != diffToRemove){
Lines 508-527 Link Here
508
	public void setEnabled(Object element, boolean enabled) {
508
	public void setEnabled(Object element, boolean enabled) {
509
		if (element instanceof DiffProject) 
509
		if (element instanceof DiffProject) 
510
			setEnabledProject((DiffProject) element, enabled);
510
			setEnabledProject((DiffProject) element, enabled);
511
		if (element instanceof FileDiff) 
511
		if (element instanceof FilePatch2) 
512
			setEnabledFile((FileDiff)element, enabled);
512
			setEnabledFile((FilePatch2)element, enabled);
513
		if (element instanceof Hunk) 
513
		if (element instanceof Hunk) 
514
			setEnabledHunk((Hunk) element, enabled);
514
			setEnabledHunk((Hunk) element, enabled);
515
	}
515
	}
516
	
516
	
517
	private void setEnabledProject(DiffProject projectDiff, boolean enabled) {
517
	private void setEnabledProject(DiffProject projectDiff, boolean enabled) {
518
		FileDiff[] diffFiles = projectDiff.getFileDiffs();
518
		FilePatch2[] diffFiles = projectDiff.getFileDiffs();
519
		for (int i = 0; i < diffFiles.length; i++) {
519
		for (int i = 0; i < diffFiles.length; i++) {
520
			setEnabledFile(diffFiles[i], enabled);
520
			setEnabledFile(diffFiles[i], enabled);
521
		}
521
		}
522
	}
522
	}
523
	
523
	
524
	private void setEnabledFile(FileDiff fileDiff, boolean enabled) {
524
	private void setEnabledFile(FilePatch2 fileDiff, boolean enabled) {
525
		IHunk[] hunks = fileDiff.getHunks();
525
		IHunk[] hunks = fileDiff.getHunks();
526
		for (int i = 0; i < hunks.length; i++) {
526
		for (int i = 0; i < hunks.length; i++) {
527
			setEnabledHunk((Hunk) hunks[i], enabled);
527
			setEnabledHunk((Hunk) hunks[i], enabled);
Lines 531-544 Link Here
531
	private void setEnabledHunk(Hunk hunk, boolean enabled) {
531
	private void setEnabledHunk(Hunk hunk, boolean enabled) {
532
		if (enabled) {
532
		if (enabled) {
533
			disabledElements.remove(hunk);
533
			disabledElements.remove(hunk);
534
			FileDiff file = hunk.getParent();
534
			FilePatch2 file = hunk.getParent();
535
			disabledElements.remove(file);
535
			disabledElements.remove(file);
536
			DiffProject project = file.getProject();
536
			DiffProject project = file.getProject();
537
			if (project != null)
537
			if (project != null)
538
				disabledElements.remove(project);
538
				disabledElements.remove(project);
539
		} else {
539
		} else {
540
			disabledElements.add(hunk);
540
			disabledElements.add(hunk);
541
			FileDiff file = hunk.getParent();
541
			FilePatch2 file = hunk.getParent();
542
			if (disabledElements.containsAll(Arrays.asList(file.getHunks()))) {
542
			if (disabledElements.containsAll(Arrays.asList(file.getHunks()))) {
543
				disabledElements.add(file);
543
				disabledElements.add(file);
544
				DiffProject project = file.getProject();
544
				DiffProject project = file.getProject();
Lines 575-586 Link Here
575
	public int guessFuzzFactor(IProgressMonitor monitor) {
575
	public int guessFuzzFactor(IProgressMonitor monitor) {
576
		try {
576
		try {
577
			monitor.beginTask(Messages.Patcher_2, IProgressMonitor.UNKNOWN);
577
			monitor.beginTask(Messages.Patcher_2, IProgressMonitor.UNKNOWN);
578
			FileDiff[] diffs= getDiffs();
578
			FilePatch2[] diffs= getDiffs();
579
			if (diffs==null||diffs.length<=0)
579
			if (diffs==null||diffs.length<=0)
580
				return -1;
580
				return -1;
581
			int fuzz= -1;
581
			int fuzz= -1;
582
			for (int i= 0; i<diffs.length; i++) {
582
			for (int i= 0; i<diffs.length; i++) {
583
				FileDiff d= diffs[i];
583
				FilePatch2 d= diffs[i];
584
				IFile file= getTargetFile(d);
584
				IFile file= getTargetFile(d);
585
				if (file != null && file.exists()) {
585
				if (file != null && file.exists()) {
586
					List lines= LineReader.load(file, false);
586
					List lines= LineReader.load(file, false);
Lines 601-615 Link Here
601
		refresh(getDiffs());
601
		refresh(getDiffs());
602
	}
602
	}
603
	
603
	
604
	protected void refresh(FileDiff[] diffs) {
604
	protected void refresh(FilePatch2[] diffs) {
605
		for (int i = 0; i < diffs.length; i++) {
605
		for (int i = 0; i < diffs.length; i++) {
606
			FileDiff diff = diffs[i];
606
			FilePatch2 diff = diffs[i];
607
			FileDiffResult result = getDiffResult(diff);
607
			FileDiffResult result = getDiffResult(diff);
608
			((WorkspaceFileDiffResult)result).refresh();
608
			((WorkspaceFileDiffResult)result).refresh();
609
		}
609
		}
610
	}
610
	}
611
	
611
	
612
	public FileDiffResult getDiffResult(FileDiff diff) {
612
	public FileDiffResult getDiffResult(FilePatch2 diff) {
613
		FileDiffResult result = (FileDiffResult)diffResults.get(diff);
613
		FileDiffResult result = (FileDiffResult)diffResults.get(diff);
614
		if (result == null) {
614
		if (result == null) {
615
			result = new WorkspaceFileDiffResult(diff, getConfiguration());
615
			result = new WorkspaceFileDiffResult(diff, getConfiguration());
Lines 628-634 Link Here
628
	 * @param diff the diff
628
	 * @param diff the diff
629
	 * @return the project that contains the diff
629
	 * @return the project that contains the diff
630
	 */
630
	 */
631
	public DiffProject getProject(FileDiff diff) {
631
	public DiffProject getProject(FilePatch2 diff) {
632
		return diff.getProject();
632
		return diff.getProject();
633
	}
633
	}
634
634
Lines 656-662 Link Here
656
	 * @param diff the file diff
656
	 * @param diff the file diff
657
	 * @param contents the contents for the file diff
657
	 * @param contents the contents for the file diff
658
	 */
658
	 */
659
	public void cacheContents(FileDiff diff, byte[] contents) {
659
	public void cacheContents(FilePatch2 diff, byte[] contents) {
660
		contentCache.put(diff, contents);
660
		contentCache.put(diff, contents);
661
	}
661
	}
662
	
662
	
Lines 665-673 Link Here
665
	 * given file diff.
665
	 * given file diff.
666
	 * @param diff the file diff
666
	 * @param diff the file diff
667
	 * @return whether contents have been cached for the file diff
667
	 * @return whether contents have been cached for the file diff
668
	 * @see #cacheContents(FileDiff, byte[])
668
	 * @see #cacheContents(FilePatch2, byte[])
669
	 */
669
	 */
670
	public boolean hasCachedContents(FileDiff diff) {
670
	public boolean hasCachedContents(FilePatch2 diff) {
671
		return contentCache.containsKey(diff);
671
		return contentCache.containsKey(diff);
672
	}
672
	}
673
673
Lines 677-683 Link Here
677
	 * @param diff the file diff
677
	 * @param diff the file diff
678
	 * @return the content lines that are cached for the file diff
678
	 * @return the content lines that are cached for the file diff
679
	 */
679
	 */
680
	public List getCachedLines(FileDiff diff) {
680
	public List getCachedLines(FilePatch2 diff) {
681
		byte[] contents = (byte[])contentCache.get(diff);
681
		byte[] contents = (byte[])contentCache.get(diff);
682
		if (contents != null) {
682
		if (contents != null) {
683
			BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(contents)));
683
			BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(contents)));
Lines 693-699 Link Here
693
	 * @return the contents that are cached for the given diff or
693
	 * @return the contents that are cached for the given diff or
694
	 * <code>null</code>
694
	 * <code>null</code>
695
	 */
695
	 */
696
	public byte[] getCachedContents(FileDiff diff) {
696
	public byte[] getCachedContents(FilePatch2 diff) {
697
		return (byte[])contentCache.get(diff);
697
		return (byte[])contentCache.get(diff);
698
	}
698
	}
699
	
699
	
Lines 732-738 Link Here
732
			mergedHunks.remove(hunk);
732
			mergedHunks.remove(hunk);
733
	}
733
	}
734
734
735
	public IProject getTargetProject(FileDiff diff) {
735
	public IProject getTargetProject(FilePatch2 diff) {
736
		DiffProject dp = getProject(diff);
736
		DiffProject dp = getProject(diff);
737
		if (dp != null)
737
		if (dp != null)
738
			return Utilities.getProject(dp);
738
			return Utilities.getProject(dp);
(-)compare/org/eclipse/compare/internal/patch/UnmatchedHunkTypedElement.java (-2 / +2 lines)
Lines 21-27 Link Here
21
import org.eclipse.compare.ITypedElement;
21
import org.eclipse.compare.ITypedElement;
22
import org.eclipse.compare.internal.CompareUIPlugin;
22
import org.eclipse.compare.internal.CompareUIPlugin;
23
import org.eclipse.compare.internal.ContentChangeNotifier;
23
import org.eclipse.compare.internal.ContentChangeNotifier;
24
import org.eclipse.compare.internal.core.patch.FileDiff;
24
import org.eclipse.compare.internal.core.patch.FilePatch2;
25
import org.eclipse.compare.internal.core.patch.HunkResult;
25
import org.eclipse.compare.internal.core.patch.HunkResult;
26
import org.eclipse.compare.patch.PatchConfiguration;
26
import org.eclipse.compare.patch.PatchConfiguration;
27
import org.eclipse.core.resources.IFile;
27
import org.eclipse.core.resources.IFile;
Lines 79-85 Link Here
79
			changeNotifier.fireContentChanged();
79
			changeNotifier.fireContentChanged();
80
	}
80
	}
81
81
82
	private FileDiff getDiff() {
82
	private FilePatch2 getDiff() {
83
		return getHunkResult().getDiffResult().getDiff();
83
		return getHunkResult().getDiffResult().getDiff();
84
	}
84
	}
85
85
(-)compare/org/eclipse/compare/internal/patch/WorkspaceFileDiffResult.java (-2 / +2 lines)
Lines 12-18 Link Here
12
12
13
import java.util.List;
13
import java.util.List;
14
14
15
import org.eclipse.compare.internal.core.patch.FileDiff;
15
import org.eclipse.compare.internal.core.patch.FilePatch2;
16
import org.eclipse.compare.internal.core.patch.FileDiffResult;
16
import org.eclipse.compare.internal.core.patch.FileDiffResult;
17
import org.eclipse.compare.patch.PatchConfiguration;
17
import org.eclipse.compare.patch.PatchConfiguration;
18
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFile;
Lines 21-27 Link Here
21
21
22
public class WorkspaceFileDiffResult extends FileDiffResult {
22
public class WorkspaceFileDiffResult extends FileDiffResult {
23
23
24
	public WorkspaceFileDiffResult(FileDiff diff,
24
	public WorkspaceFileDiffResult(FilePatch2 diff,
25
			PatchConfiguration configuration) {
25
			PatchConfiguration configuration) {
26
		super(diff, configuration);
26
		super(diff, configuration);
27
	}
27
	}
(-)compare/org/eclipse/compare/internal/patch/WorkspacePatcher.java (-22 / +22 lines)
Lines 18-24 Link Here
18
18
19
import org.eclipse.compare.internal.core.Messages;
19
import org.eclipse.compare.internal.core.Messages;
20
import org.eclipse.compare.internal.core.patch.DiffProject;
20
import org.eclipse.compare.internal.core.patch.DiffProject;
21
import org.eclipse.compare.internal.core.patch.FileDiff;
21
import org.eclipse.compare.internal.core.patch.FilePatch2;
22
import org.eclipse.compare.internal.core.patch.Hunk;
22
import org.eclipse.compare.internal.core.patch.Hunk;
23
import org.eclipse.compare.internal.core.patch.PatchReader;
23
import org.eclipse.compare.internal.core.patch.PatchReader;
24
import org.eclipse.compare.patch.IHunk;
24
import org.eclipse.compare.patch.IHunk;
Lines 91-97 Link Here
91
				return;
91
				return;
92
			}
92
			}
93
93
94
			FileDiff[] diffs = getDiffs();
94
			FilePatch2[] diffs = getDiffs();
95
			if (pm != null) {
95
			if (pm != null) {
96
				String message= Messages.WorkspacePatcher_0;
96
				String message= Messages.WorkspacePatcher_0;
97
				pm.beginTask(message, diffs.length * WORK_UNIT);
97
				pm.beginTask(message, diffs.length * WORK_UNIT);
Lines 101-107 Link Here
101
101
102
				int workTicks= WORK_UNIT;
102
				int workTicks= WORK_UNIT;
103
103
104
				FileDiff diff= diffs[i];
104
				FilePatch2 diff= diffs[i];
105
				if (isAccessible(diff)) {
105
				if (isAccessible(diff)) {
106
					IFile file= getTargetFile(diff);
106
					IFile file= getTargetFile(diff);
107
					IPath path= file.getProjectRelativePath();
107
					IPath path= file.getProjectRelativePath();
Lines 113-130 Link Here
113
113
114
					int type= diff.getDiffType(isReversed());
114
					int type= diff.getDiffType(isReversed());
115
					switch (type) {
115
					switch (type) {
116
						case FileDiff.ADDITION :
116
						case FilePatch2.ADDITION :
117
							// patch it and collect rejected hunks
117
							// patch it and collect rejected hunks
118
							List result= apply(diff, file, true, failed);
118
							List result= apply(diff, file, true, failed);
119
							if (result != null)
119
							if (result != null)
120
								store(LineReader.createString(isPreserveLineDelimeters(), result), file, new SubProgressMonitor(pm, workTicks));
120
								store(LineReader.createString(isPreserveLineDelimeters(), result), file, new SubProgressMonitor(pm, workTicks));
121
							workTicks -= WORK_UNIT;
121
							workTicks -= WORK_UNIT;
122
							break;
122
							break;
123
						case FileDiff.DELETION :
123
						case FilePatch2.DELETION :
124
							file.delete(true, true, new SubProgressMonitor(pm, workTicks));
124
							file.delete(true, true, new SubProgressMonitor(pm, workTicks));
125
							workTicks -= WORK_UNIT;
125
							workTicks -= WORK_UNIT;
126
							break;
126
							break;
127
						case FileDiff.CHANGE :
127
						case FilePatch2.CHANGE :
128
							// patch it and collect rejected hunks
128
							// patch it and collect rejected hunks
129
							result= apply(diff, file, false, failed);
129
							result= apply(diff, file, false, failed);
130
							if (result != null)
130
							if (result != null)
Lines 164-170 Link Here
164
		}
164
		}
165
	}
165
	}
166
	
166
	
167
	private boolean isAccessible(FileDiff diff) {
167
	private boolean isAccessible(FilePatch2 diff) {
168
		return isEnabled(diff) && Utilities.getProject(diff.getProject()).isAccessible();
168
		return isEnabled(diff) && Utilities.getProject(diff.getProject()).isAccessible();
169
	}
169
	}
170
170
Lines 176-184 Link Here
176
	 */
176
	 */
177
	public IFile[] getTargetFiles(DiffProject project) {
177
	public IFile[] getTargetFiles(DiffProject project) {
178
		List files= new ArrayList();
178
		List files= new ArrayList();
179
		FileDiff[] diffs = project.getFileDiffs();
179
		FilePatch2[] diffs = project.getFileDiffs();
180
		for (int i = 0; i < diffs.length; i++) {
180
		for (int i = 0; i < diffs.length; i++) {
181
			FileDiff diff = diffs[i];
181
			FilePatch2 diff = diffs[i];
182
			if (isEnabled(diff)) {
182
			if (isEnabled(diff)) {
183
				files.add(getTargetFile(diff));
183
				files.add(getTargetFile(diff));
184
			}
184
			}
Lines 186-192 Link Here
186
		return (IFile[]) files.toArray(new IFile[files.size()]);
186
		return (IFile[]) files.toArray(new IFile[files.size()]);
187
	}
187
	}
188
188
189
	public IFile getTargetFile(FileDiff diff) {
189
	public IFile getTargetFile(FilePatch2 diff) {
190
		IPath path = diff.getStrippedPath(getStripPrefixSegments(), isReversed());
190
		IPath path = diff.getStrippedPath(getStripPrefixSegments(), isReversed());
191
		DiffProject project = getProject(diff);
191
		DiffProject project = getProject(diff);
192
		if (project != null)
192
		if (project != null)
Lines 194-200 Link Here
194
		return super.getTargetFile(diff);
194
		return super.getTargetFile(diff);
195
	}
195
	}
196
	
196
	
197
	private IPath getFullPath(FileDiff diff) {
197
	private IPath getFullPath(FilePatch2 diff) {
198
		IPath path = diff.getStrippedPath(getStripPrefixSegments(), isReversed());
198
		IPath path = diff.getStrippedPath(getStripPrefixSegments(), isReversed());
199
		DiffProject project = getProject(diff);
199
		DiffProject project = getProject(diff);
200
		if (project != null)
200
		if (project != null)
Lines 238-245 Link Here
238
	}	
238
	}	
239
	
239
	
240
	protected Object getElementParent(Object element) {
240
	protected Object getElementParent(Object element) {
241
		if (element instanceof FileDiff && fDiffProjects != null) {
241
		if (element instanceof FilePatch2 && fDiffProjects != null) {
242
			FileDiff diff = (FileDiff) element;
242
			FilePatch2 diff = (FilePatch2) element;
243
			for (int i = 0; i < fDiffProjects.length; i++) {
243
			for (int i = 0; i < fDiffProjects.length; i++) {
244
				DiffProject project = fDiffProjects[i];
244
				DiffProject project = fDiffProjects[i];
245
				if (project.contains(diff))
245
				if (project.contains(diff))
Lines 257-263 Link Here
257
		return (IPath)retargetedDiffs.get(object);
257
		return (IPath)retargetedDiffs.get(object);
258
	}
258
	}
259
259
260
	public void retargetDiff(FileDiff diff, IFile file) {
260
	public void retargetDiff(FilePatch2 diff, IFile file) {
261
		retargetedDiffs.put(diff, diff.getPath(false));
261
		retargetedDiffs.put(diff, diff.getPath(false));
262
		IHunk[] hunks = diff.getHunks();
262
		IHunk[] hunks = diff.getHunks();
263
		
263
		
Lines 266-281 Link Here
266
			diff.getProject().remove(diff);
266
			diff.getProject().remove(diff);
267
		}
267
		}
268
		removeDiff(diff);
268
		removeDiff(diff);
269
		FileDiff newDiff = getDiffForFile(file);
269
		FilePatch2 newDiff = getDiffForFile(file);
270
		for (int i = 0; i < hunks.length; i++) {
270
		for (int i = 0; i < hunks.length; i++) {
271
			Hunk hunk = (Hunk) hunks[i];
271
			Hunk hunk = (Hunk) hunks[i];
272
			newDiff.add(hunk);
272
			newDiff.add(hunk);
273
		}
273
		}
274
	}
274
	}
275
275
276
	private FileDiff getDiffForFile(IFile file) {
276
	private FilePatch2 getDiffForFile(IFile file) {
277
		DiffProject diffProject = null;
277
		DiffProject diffProject = null;
278
		FileDiff[] diffsToCheck;
278
		FilePatch2[] diffsToCheck;
279
		if (isWorkspacePatch()){
279
		if (isWorkspacePatch()){
280
			// Check if the diff project already exists for the file
280
			// Check if the diff project already exists for the file
281
			IProject project = file.getProject();
281
			IProject project = file.getProject();
Lines 296-302 Link Here
296
		}
296
		}
297
		// Check to see if a diff already exists for the file
297
		// Check to see if a diff already exists for the file
298
		for (int i = 0; i < diffsToCheck.length; i++) {
298
		for (int i = 0; i < diffsToCheck.length; i++) {
299
			FileDiff fileDiff = diffsToCheck[i];
299
			FilePatch2 fileDiff = diffsToCheck[i];
300
			if (isDiffForFile(fileDiff, file)) {
300
			if (isDiffForFile(fileDiff, file)) {
301
				return fileDiff;
301
				return fileDiff;
302
			}
302
			}
Lines 304-310 Link Here
304
		
304
		
305
		// Create a new diff for the file
305
		// Create a new diff for the file
306
		IPath path = getDiffPath(file);
306
		IPath path = getDiffPath(file);
307
		FileDiff newDiff = new FileDiff(path, 0, path, 0);
307
		FilePatch2 newDiff = new FilePatch2(path, 0, path, 0);
308
		if (diffProject != null){
308
		if (diffProject != null){
309
			diffProject.add(newDiff);
309
			diffProject.add(newDiff);
310
		}
310
		}
Lines 320-326 Link Here
320
		return file.getFullPath().removeFirstSegments(getTarget().getFullPath().segmentCount());
320
		return file.getFullPath().removeFirstSegments(getTarget().getFullPath().segmentCount());
321
	}
321
	}
322
322
323
	private boolean isDiffForFile(FileDiff fileDiff, IFile file) {
323
	private boolean isDiffForFile(FilePatch2 fileDiff, IFile file) {
324
		return getFullPath(fileDiff).equals(file.getFullPath());
324
		return getFullPath(fileDiff).equals(file.getFullPath());
325
	}
325
	}
326
326
Lines 335-347 Link Here
335
	}
335
	}
336
336
337
	public void retargetHunk(Hunk hunk, IFile file) {
337
	public void retargetHunk(Hunk hunk, IFile file) {
338
		FileDiff newDiff = getDiffForFile(file);
338
		FilePatch2 newDiff = getDiffForFile(file);
339
		newDiff.add(hunk);
339
		newDiff.add(hunk);
340
	}
340
	}
341
341
342
	public void retargetProject(DiffProject project, IProject targetProject) {
342
	public void retargetProject(DiffProject project, IProject targetProject) {
343
		retargetedDiffs.put(project, Utilities.getProject(project).getFullPath());
343
		retargetedDiffs.put(project, Utilities.getProject(project).getFullPath());
344
		FileDiff[] diffs = project.getFileDiffs();
344
		FilePatch2[] diffs = project.getFileDiffs();
345
		DiffProject selectedProject = getDiffProject(targetProject);
345
		DiffProject selectedProject = getDiffProject(targetProject);
346
		if (selectedProject == null)
346
		if (selectedProject == null)
347
			selectedProject = addDiffProjectForProject(targetProject);
347
			selectedProject = addDiffProjectForProject(targetProject);
(-)compare/org/eclipse/compare/internal/patch/RetargetPatchElementDialog.java (-3 / +3 lines)
Lines 13-19 Link Here
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
14
15
import org.eclipse.compare.internal.core.patch.DiffProject;
15
import org.eclipse.compare.internal.core.patch.DiffProject;
16
import org.eclipse.compare.internal.core.patch.FileDiff;
16
import org.eclipse.compare.internal.core.patch.FilePatch2;
17
import org.eclipse.compare.internal.core.patch.Hunk;
17
import org.eclipse.compare.internal.core.patch.Hunk;
18
import org.eclipse.core.resources.*;
18
import org.eclipse.core.resources.*;
19
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.core.runtime.Assert;
Lines 148-154 Link Here
148
		} else if (fSelectedNode instanceof PatchFileDiffNode) {
148
		} else if (fSelectedNode instanceof PatchFileDiffNode) {
149
			PatchFileDiffNode node = (PatchFileDiffNode) fSelectedNode;
149
			PatchFileDiffNode node = (PatchFileDiffNode) fSelectedNode;
150
			//copy over all hunks to new target resource
150
			//copy over all hunks to new target resource
151
			FileDiff diff = node.getDiffResult().getDiff();
151
			FilePatch2 diff = node.getDiffResult().getDiff();
152
			return NLS.bind(PatchMessages.RetargetPatchElementDialog_0, fPatcher.getPath(diff));
152
			return NLS.bind(PatchMessages.RetargetPatchElementDialog_0, fPatcher.getPath(diff));
153
		} else if (fSelectedNode instanceof HunkDiffNode) {
153
		} else if (fSelectedNode instanceof HunkDiffNode) {
154
			HunkDiffNode node = (HunkDiffNode) fSelectedNode;
154
			HunkDiffNode node = (HunkDiffNode) fSelectedNode;
Lines 167-173 Link Here
167
			} else if (fSelectedNode instanceof PatchFileDiffNode && fSelectedResource instanceof IFile) {
167
			} else if (fSelectedNode instanceof PatchFileDiffNode && fSelectedResource instanceof IFile) {
168
				PatchFileDiffNode node = (PatchFileDiffNode) fSelectedNode;
168
				PatchFileDiffNode node = (PatchFileDiffNode) fSelectedNode;
169
				//copy over all hunks to new target resource
169
				//copy over all hunks to new target resource
170
				FileDiff diff = node.getDiffResult().getDiff();
170
				FilePatch2 diff = node.getDiffResult().getDiff();
171
				fPatcher.retargetDiff(diff, (IFile)fSelectedResource);
171
				fPatcher.retargetDiff(diff, (IFile)fSelectedResource);
172
			} else if (fSelectedNode instanceof HunkDiffNode && fSelectedResource instanceof IFile) {
172
			} else if (fSelectedNode instanceof HunkDiffNode && fSelectedResource instanceof IFile) {
173
				HunkDiffNode node = (HunkDiffNode) fSelectedNode;
173
				HunkDiffNode node = (HunkDiffNode) fSelectedNode;
(-)compare/org/eclipse/compare/internal/patch/PatchCompareEditorInput.java (-5 / +5 lines)
Lines 15-21 Link Here
15
import org.eclipse.compare.*;
15
import org.eclipse.compare.*;
16
import org.eclipse.compare.internal.*;
16
import org.eclipse.compare.internal.*;
17
import org.eclipse.compare.internal.core.patch.DiffProject;
17
import org.eclipse.compare.internal.core.patch.DiffProject;
18
import org.eclipse.compare.internal.core.patch.FileDiff;
18
import org.eclipse.compare.internal.core.patch.FilePatch2;
19
import org.eclipse.compare.internal.core.patch.FileDiffResult;
19
import org.eclipse.compare.internal.core.patch.FileDiffResult;
20
import org.eclipse.compare.internal.core.patch.HunkResult;
20
import org.eclipse.compare.internal.core.patch.HunkResult;
21
import org.eclipse.compare.patch.PatchConfiguration;
21
import org.eclipse.compare.patch.PatchConfiguration;
Lines 206-212 Link Here
206
		getViewer().refresh();
206
		getViewer().refresh();
207
	}
207
	}
208
	
208
	
209
	private void processDiffs(FileDiff[] diffs) { 
209
	private void processDiffs(FilePatch2[] diffs) { 
210
		for (int i = 0; i < diffs.length; i++) {
210
		for (int i = 0; i < diffs.length; i++) {
211
			processDiff(diffs[i], getRoot());
211
			processDiff(diffs[i], getRoot());
212
		}
212
		}
Lines 216-230 Link Here
216
		//create diffProject nodes
216
		//create diffProject nodes
217
		for (int i = 0; i < diffProjects.length; i++) {
217
		for (int i = 0; i < diffProjects.length; i++) {
218
			PatchProjectDiffNode projectNode = new PatchProjectDiffNode(getRoot(), diffProjects[i], getPatcher().getConfiguration());
218
			PatchProjectDiffNode projectNode = new PatchProjectDiffNode(getRoot(), diffProjects[i], getPatcher().getConfiguration());
219
			FileDiff[] diffs = diffProjects[i].getFileDiffs();
219
			FilePatch2[] diffs = diffProjects[i].getFileDiffs();
220
			for (int j = 0; j < diffs.length; j++) {
220
			for (int j = 0; j < diffs.length; j++) {
221
				FileDiff fileDiff = diffs[j];
221
				FilePatch2 fileDiff = diffs[j];
222
				processDiff(fileDiff, projectNode);
222
				processDiff(fileDiff, projectNode);
223
			}
223
			}
224
		}
224
		}
225
	}
225
	}
226
226
227
	private void processDiff(FileDiff diff, DiffNode parent) {
227
	private void processDiff(FilePatch2 diff, DiffNode parent) {
228
		FileDiffResult diffResult = getPatcher().getDiffResult(diff);
228
		FileDiffResult diffResult = getPatcher().getDiffResult(diff);
229
		PatchFileDiffNode node = PatchFileDiffNode.createDiffNode(parent, diffResult);
229
		PatchFileDiffNode node = PatchFileDiffNode.createDiffNode(parent, diffResult);
230
		HunkResult[] hunkResults = diffResult.getHunkResults();
230
		HunkResult[] hunkResults = diffResult.getHunkResults();
(-)compare/org/eclipse/compare/internal/patch/PreviewPatchPage2.java (-3 / +3 lines)
Lines 19-25 Link Here
19
import org.eclipse.compare.internal.ComparePreferencePage;
19
import org.eclipse.compare.internal.ComparePreferencePage;
20
import org.eclipse.compare.internal.CompareUIPlugin;
20
import org.eclipse.compare.internal.CompareUIPlugin;
21
import org.eclipse.compare.internal.ICompareUIConstants;
21
import org.eclipse.compare.internal.ICompareUIConstants;
22
import org.eclipse.compare.internal.core.patch.FileDiff;
22
import org.eclipse.compare.internal.core.patch.FilePatch2;
23
import org.eclipse.compare.internal.core.patch.Hunk;
23
import org.eclipse.compare.internal.core.patch.Hunk;
24
import org.eclipse.compare.patch.IHunk;
24
import org.eclipse.compare.patch.IHunk;
25
import org.eclipse.core.runtime.Assert;
25
import org.eclipse.core.runtime.Assert;
Lines 705-711 Link Here
705
				&& (removedLinesRegex == null || "".equals(removedLinesRegex))) { //$NON-NLS-1$
705
				&& (removedLinesRegex == null || "".equals(removedLinesRegex))) { //$NON-NLS-1$
706
			
706
			
707
			fPatcher.countLines();
707
			fPatcher.countLines();
708
			FileDiff[] fileDiffs = fPatcher.getDiffs();
708
			FilePatch2[] fileDiffs = fPatcher.getDiffs();
709
			for (int i = 0; i < fileDiffs.length; i++) {
709
			for (int i = 0; i < fileDiffs.length; i++) {
710
				added += fileDiffs[i].getAddedLines();
710
				added += fileDiffs[i].getAddedLines();
711
				removed += fileDiffs[i].getRemovedLines();
711
				removed += fileDiffs[i].getRemovedLines();
Lines 716-722 Link Here
716
			Pattern addedPattern = Pattern.compile(addedLinesRegex);
716
			Pattern addedPattern = Pattern.compile(addedLinesRegex);
717
			Pattern removedPattern = Pattern.compile(removedLinesRegex);
717
			Pattern removedPattern = Pattern.compile(removedLinesRegex);
718
718
719
			FileDiff[] fileDiffs = fPatcher.getDiffs();
719
			FilePatch2[] fileDiffs = fPatcher.getDiffs();
720
			for (int i = 0; i < fileDiffs.length; i++) {
720
			for (int i = 0; i < fileDiffs.length; i++) {
721
				IHunk[] hunks = fileDiffs[i].getHunks();
721
				IHunk[] hunks = fileDiffs[i].getHunks();
722
				for (int j = 0; j < hunks.length; j++) {
722
				for (int j = 0; j < hunks.length; j++) {
(-)compare/org/eclipse/compare/internal/patch/PatchFileDiffNode.java (-5 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
2
 * Copyright (c) 2006, 2009 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-17 Link Here
11
package org.eclipse.compare.internal.patch;
11
package org.eclipse.compare.internal.patch;
12
12
13
import org.eclipse.compare.*;
13
import org.eclipse.compare.*;
14
import org.eclipse.compare.internal.core.patch.FileDiff;
14
import org.eclipse.compare.internal.core.patch.FilePatch2;
15
import org.eclipse.compare.internal.core.patch.FileDiffResult;
15
import org.eclipse.compare.internal.core.patch.FileDiffResult;
16
import org.eclipse.compare.patch.PatchConfiguration;
16
import org.eclipse.compare.patch.PatchConfiguration;
17
import org.eclipse.compare.structuremergeviewer.*;
17
import org.eclipse.compare.structuremergeviewer.*;
Lines 36-48 Link Here
36
	private static int convertFileDiffTypeToDifferencerType(int fileDiffKind) {
36
	private static int convertFileDiffTypeToDifferencerType(int fileDiffKind) {
37
		int kind;
37
		int kind;
38
		switch (fileDiffKind) {
38
		switch (fileDiffKind) {
39
		case FileDiff.ADDITION:
39
		case FilePatch2.ADDITION:
40
			kind = Differencer.ADDITION;
40
			kind = Differencer.ADDITION;
41
			break;
41
			break;
42
		case FileDiff.DELETION:
42
		case FilePatch2.DELETION:
43
			kind = Differencer.DELETION;
43
			kind = Differencer.DELETION;
44
			break;
44
			break;
45
		case FileDiff.CHANGE:
45
		case FilePatch2.CHANGE:
46
			kind = Differencer.CHANGE;
46
			kind = Differencer.CHANGE;
47
			break;
47
			break;
48
		default:
48
		default:
(-)compare/org/eclipse/compare/internal/patch/InputPatchPage.java (-4 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 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 22-28 Link Here
22
22
23
import org.eclipse.compare.internal.ICompareContextIds;
23
import org.eclipse.compare.internal.ICompareContextIds;
24
import org.eclipse.compare.internal.Utilities;
24
import org.eclipse.compare.internal.Utilities;
25
import org.eclipse.compare.internal.core.patch.FileDiff;
25
import org.eclipse.compare.internal.core.patch.FilePatch2;
26
import org.eclipse.core.resources.IFile;
26
import org.eclipse.core.resources.IFile;
27
import org.eclipse.core.resources.IFolder;
27
import org.eclipse.core.resources.IFolder;
28
import org.eclipse.core.resources.IProject;
28
import org.eclipse.core.resources.IProject;
Lines 189-195 Link Here
189
		// Read in the patch
189
		// Read in the patch
190
		readInPatch();
190
		readInPatch();
191
		
191
		
192
		FileDiff[] diffs= patcher.getDiffs();
192
		FilePatch2[] diffs= patcher.getDiffs();
193
		if (diffs == null || diffs.length == 0) {
193
		if (diffs == null || diffs.length == 0) {
194
			String format= PatchMessages.InputPatchPage_NoDiffsFound_format;	
194
			String format= PatchMessages.InputPatchPage_NoDiffsFound_format;	
195
			String message= MessageFormat.format(format, new String[] { fPatchSource });
195
			String message= MessageFormat.format(format, new String[] { fPatchSource });
Lines 792-798 Link Here
792
			return false;
792
			return false;
793
		}
793
		}
794
794
795
		FileDiff[] diffs= patcher.getDiffs();
795
		FilePatch2[] diffs= patcher.getDiffs();
796
		if (diffs == null || diffs.length == 0)
796
		if (diffs == null || diffs.length == 0)
797
			return false;
797
			return false;
798
		return true;
798
		return true;
(-)compare/org/eclipse/compare/internal/patch/FileDiffWrapper.java (-47 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.compare.internal.patch;
12
13
import org.eclipse.compare.internal.core.patch.FileDiff;
14
import org.eclipse.compare.patch.IFilePatch;
15
import org.eclipse.compare.patch.IFilePatchResult;
16
import org.eclipse.compare.patch.PatchConfiguration;
17
import org.eclipse.core.resources.IStorage;
18
import org.eclipse.core.runtime.IPath;
19
import org.eclipse.core.runtime.IProgressMonitor;
20
21
public class FileDiffWrapper extends FileDiff implements IFilePatch {
22
23
	public FileDiffWrapper(IPath oldPath, long oldDate, IPath newPath,
24
			long newDate) {
25
		super(oldPath, oldDate, newPath, newDate);
26
	}
27
28
	/*
29
	 * (non-Javadoc)
30
	 * 
31
	 * @see
32
	 * org.eclipse.compare.patch.IFilePatch#apply(org.eclipse.core.resources
33
	 * .IStorage, org.eclipse.compare.patch.PatchConfiguration,
34
	 * org.eclipse.core.runtime.IProgressMonitor)
35
	 */
36
	public IFilePatchResult apply(IStorage content,
37
			PatchConfiguration configuration, IProgressMonitor monitor) {
38
		return apply(content != null ? Utilities.getReaderCreator(content)
39
				: null, configuration, monitor);
40
	}
41
42
	protected FileDiff create(IPath oldPath, long oldDate, IPath newPath,
43
			long newDate) {
44
		return new FileDiffWrapper(oldPath, oldDate, newPath, newDate);
45
	}
46
47
}
(-)compare/org/eclipse/compare/internal/patch/FilePatch.java (+47 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.compare.internal.patch;
12
13
import org.eclipse.compare.internal.core.patch.FilePatch2;
14
import org.eclipse.compare.patch.IFilePatch;
15
import org.eclipse.compare.patch.IFilePatchResult;
16
import org.eclipse.compare.patch.PatchConfiguration;
17
import org.eclipse.core.resources.IStorage;
18
import org.eclipse.core.runtime.IPath;
19
import org.eclipse.core.runtime.IProgressMonitor;
20
21
public class FilePatch extends FilePatch2 implements IFilePatch {
22
23
	public FilePatch(IPath oldPath, long oldDate, IPath newPath,
24
			long newDate) {
25
		super(oldPath, oldDate, newPath, newDate);
26
	}
27
28
	/*
29
	 * (non-Javadoc)
30
	 * 
31
	 * @see
32
	 * org.eclipse.compare.patch.IFilePatch#apply(org.eclipse.core.resources
33
	 * .IStorage, org.eclipse.compare.patch.PatchConfiguration,
34
	 * org.eclipse.core.runtime.IProgressMonitor)
35
	 */
36
	public IFilePatchResult apply(IStorage content,
37
			PatchConfiguration configuration, IProgressMonitor monitor) {
38
		return apply(content != null ? Utilities.getReaderCreator(content)
39
				: null, configuration, monitor);
40
	}
41
42
	protected FilePatch2 create(IPath oldPath, long oldDate, IPath newPath,
43
			long newDate) {
44
		return new FilePatch(oldPath, oldDate, newPath, newDate);
45
	}
46
47
}

Return to bug 267020