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); |