Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch')
-rw-r--r--bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FileDiffResult.java20
-rw-r--r--bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FilePatch2.java32
-rw-r--r--bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/Hunk.java72
-rw-r--r--bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/HunkResult.java20
-rw-r--r--bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/LineReader.java24
-rw-r--r--bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java90
6 files changed, 129 insertions, 129 deletions
diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FileDiffResult.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FileDiffResult.java
index 878e2fc51..a5e30b641 100644
--- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FileDiffResult.java
+++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FileDiffResult.java
@@ -39,22 +39,22 @@ public class FileDiffResult implements IFilePatchResult {
private List<String> fBeforeLines, fAfterLines;
private final PatchConfiguration configuration;
private String charset;
-
+
public FileDiffResult(FilePatch2 diff, PatchConfiguration configuration) {
super();
this.fDiff = diff;
this.configuration = configuration;
}
-
+
public PatchConfiguration getConfiguration() {
return this.configuration;
}
-
+
public boolean canApplyHunk(Hunk hunk) {
HunkResult result = getHunkResult(hunk);
return result.isOK() && !this.fDiffProblem;
}
-
+
/**
* Refreshes the state of the diff to {no matches, no problems} and checks to see what hunks contained
* by this Diff can actually be applied.
@@ -169,7 +169,7 @@ public class FileDiffResult implements IFilePatchResult {
}
this.fAfterLines = lines;
}
-
+
public boolean getDiffProblem() {
return this.fDiffProblem;
}
@@ -188,14 +188,14 @@ public class FileDiffResult implements IFilePatchResult {
}
return false;
}
-
+
public String getLabel() {
String label= getTargetPath().toString();
if (this.fDiffProblem)
return NLS.bind(Messages.FileDiffResult_2, new String[] {label, this.fErrorMessage});
return label;
}
-
+
@Override
public boolean hasMatches() {
return this.fMatches;
@@ -243,7 +243,7 @@ public class FileDiffResult implements IFilePatchResult {
this.fAfterLines = lines;
return highestFuzz;
}
-
+
public IPath getTargetPath() {
return this.fDiff.getStrippedPath(getConfiguration().getPrefixSegmentStripCount(), getConfiguration().isReversed());
}
@@ -281,7 +281,7 @@ public class FileDiffResult implements IFilePatchResult {
}
public HunkResult[] getHunkResults() {
- // return hunk results in the same order as hunks are placed in file diff
+ // return hunk results in the same order as hunks are placed in file diff
List<HunkResult> results = new ArrayList<HunkResult>();
IHunk[] hunks = this.fDiff.getHunks();
for (int i = 0; i < hunks.length; i++) {
@@ -339,5 +339,5 @@ public class FileDiffResult implements IFilePatchResult {
}
return new ByteArrayInputStream(bytes);
}
-
+
}
diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FilePatch2.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FilePatch2.java
index f15997db9..4406872f9 100644
--- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FilePatch2.java
+++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FilePatch2.java
@@ -40,14 +40,14 @@ public class FilePatch2 implements IFilePatch2 {
* Difference constant (value 3) indicating side changed.
*/
public static final int CHANGE= 3;
-
+
private IPath fOldPath, fNewPath;
private long oldDate, newDate;
private List<Hunk> fHunks= new ArrayList<Hunk>();
private DiffProject fProject; //the project that contains this diff
private String header;
private int addedLines, removedLines;
-
+
/**
* Create a file diff for the given path and date information.
* @param oldPath the path of the before state of the file
@@ -61,7 +61,7 @@ public class FilePatch2 implements IFilePatch2 {
this.fNewPath= newPath;
this.newDate = newDate;
}
-
+
/**
* Return the parent project or <code>null</code> if there isn't one.
* @return the parent project or <code>null</code>
@@ -69,7 +69,7 @@ public class FilePatch2 implements IFilePatch2 {
public DiffProject getProject() {
return this.fProject;
}
-
+
/**
* Set the project of this diff to the given project.
* This method should only be called from
@@ -83,10 +83,10 @@ public class FilePatch2 implements IFilePatch2 {
this.fProject.remove(this);
this.fProject= diffProject;
}
-
+
/**
* Get the path of the file diff.
- * @param reverse whether the path of the before state or after state
+ * @param reverse whether the path of the before state or after state
* should be used
* @return the path of the file diff
*/
@@ -102,7 +102,7 @@ public class FilePatch2 implements IFilePatch2 {
return this.fOldPath;
return this.fNewPath;
}
-
+
/**
* Add the hunk to this file diff.
* @param hunk the hunk
@@ -111,7 +111,7 @@ public class FilePatch2 implements IFilePatch2 {
this.fHunks.add(hunk);
hunk.setParent(this);
}
-
+
/**
* Remove the hunk from this file diff
* @param hunk the hunk
@@ -119,7 +119,7 @@ public class FilePatch2 implements IFilePatch2 {
protected void remove(Hunk hunk) {
this.fHunks.remove(hunk);
}
-
+
/**
* Returns the hunks associated with this file diff.
* @return the hunks associated with this file diff
@@ -128,7 +128,7 @@ public class FilePatch2 implements IFilePatch2 {
public IHunk[] getHunks() {
return this.fHunks.toArray(new IHunk[this.fHunks.size()]);
}
-
+
/**
* Returns the number of hunks associated with this file diff.
* @return the number of hunks associated with this file diff
@@ -136,7 +136,7 @@ public class FilePatch2 implements IFilePatch2 {
public int getHunkCount() {
return this.fHunks.size();
}
-
+
/**
* Returns the difference type of this file diff.
* @param reverse whether the patch is being reversed
@@ -164,7 +164,7 @@ public class FilePatch2 implements IFilePatch2 {
}
return CHANGE;
}
-
+
/**
* Return the path of this file diff with the specified number
* of leading segments striped.
@@ -179,7 +179,7 @@ public class FilePatch2 implements IFilePatch2 {
path= path.removeFirstSegments(strip);
return path;
}
-
+
/**
* Return the segment count of the path of this file diff.
* @return the segment count of the path of this file diff
@@ -194,7 +194,7 @@ public class FilePatch2 implements IFilePatch2 {
length= Math.min(length, this.fNewPath.segmentCount());
return length;
}
-
+
@Override
public IFilePatchResult apply(ReaderCreator content,
PatchConfiguration configuration, IProgressMonitor monitor) {
@@ -255,7 +255,7 @@ public class FilePatch2 implements IFilePatch2 {
public void setAddedLines(int addedLines) {
this.addedLines = addedLines;
}
-
+
public void setRemovedLines(int removedLines) {
this.removedLines = removedLines;
}
@@ -263,7 +263,7 @@ public class FilePatch2 implements IFilePatch2 {
public int getAddedLines() {
return this.addedLines;
}
-
+
public int getRemovedLines() {
return this.removedLines;
}
diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/Hunk.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/Hunk.java
index 358d2750d..033cf8e26 100644
--- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/Hunk.java
+++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/Hunk.java
@@ -56,7 +56,7 @@ public class Hunk implements IHunk {
}
return new Hunk(parent, hunkType, oldStart, oldLength, newStart, newLength, lines.toArray(new String[lines.size()]));
}
-
+
public Hunk(FilePatch2 parent, int hunkType, int oldStart, int oldLength,
int newStart, int newLength, String[] lines) {
this.fParent = parent;
@@ -70,7 +70,7 @@ public class Hunk implements IHunk {
this.fNewStart = newStart;
this.fLines = lines;
}
-
+
public Hunk(FilePatch2 parent, Hunk toCopy) {
this(parent, toCopy.hunkType, toCopy.fOldStart, toCopy.fOldLength, toCopy.fNewStart, toCopy.fNewLength, toCopy.fLines);
}
@@ -96,7 +96,7 @@ public class Hunk implements IHunk {
}
return sb.toString();
}
-
+
/*
* Returns a descriptive String for this hunk.
* It is in the form old_start,old_length -> new_start,new_length.
@@ -112,7 +112,7 @@ public class Hunk implements IHunk {
sb.append(Integer.toString(this.fNewLength));
return sb.toString();
}
-
+
public String getRejectedDescription() {
StringBuffer sb= new StringBuffer();
sb.append("@@ -"); //$NON-NLS-1$
@@ -126,7 +126,7 @@ public class Hunk implements IHunk {
sb.append(" @@"); //$NON-NLS-1$
return sb.toString();
}
-
+
public int getHunkType(boolean reverse) {
if (reverse) {
if (this.hunkType == FilePatch2.ADDITION)
@@ -162,13 +162,13 @@ public class Hunk implements IHunk {
return;
if (this.fParent != null)
this.fParent.remove(this);
- this.fParent = diff;
+ this.fParent = diff;
}
public FilePatch2 getParent() {
return this.fParent;
}
-
+
/*
* Tries to apply the given hunk on the specified lines.
* The parameter shift is added to the line numbers given
@@ -185,9 +185,9 @@ public class Hunk implements IHunk {
Assert.isTrue(s.length() > 0);
String line = s.substring(1);
char controlChar = s.charAt(0);
-
+
if (controlChar == ' ') { // context lines
-
+
if (pos < 0 || pos >= lines.size())
return false;
contextLines.add(line);
@@ -199,15 +199,15 @@ public class Hunk implements IHunk {
contextLinesMatched = false;
pos++;
continue;
- }
+ }
return false;
} else if (isDeletedDelimeter(controlChar, reverse)) {
// deleted lines
-
+
if (precedingLinesChecked && !contextLinesMatched && contextLines.size() > 0)
// context lines inside hunk don't match
return false;
-
+
// check following context lines if exist
// use the fuzz factor if needed
if (!precedingLinesChecked
@@ -218,11 +218,11 @@ public class Hunk implements IHunk {
return false;
// else if there is less or equal context line to the fuzz
// factor we ignore them all and treat as matching
-
+
precedingLinesChecked = true;
contextLines.clear();
contextLinesMatched = true;
-
+
if (pos < 0 || pos >= lines.size()) // out of the file
return false;
if (linesMatch(configuration, line, lines.get(pos))) {
@@ -235,10 +235,10 @@ public class Hunk implements IHunk {
// must be found one by one.
return false;
} else if (isAddedDelimeter(controlChar, reverse)) {
-
+
if (precedingLinesChecked && !contextLinesMatched && contextLines.size() > 0)
return false;
-
+
if (!precedingLinesChecked
&& !contextLinesMatched
&& contextLines.size() >= fuzz
@@ -249,12 +249,12 @@ public class Hunk implements IHunk {
precedingLinesChecked = true;
contextLines.clear();
contextLinesMatched = true;
-
+
// we don't have to do anything more for a 'try'
} else
Assert.isTrue(false, "tryPatch: unknown control character: " + controlChar); //$NON-NLS-1$
}
-
+
// check following context lines if exist
if (!contextLinesMatched
&& fuzz > 0
@@ -262,7 +262,7 @@ public class Hunk implements IHunk {
&& !checkFollowingContextLines(configuration, lines, fuzz, pos,
contextLines))
return false;
-
+
return true;
}
@@ -277,7 +277,7 @@ public class Hunk implements IHunk {
}
return true;
}
-
+
private boolean checkFollowingContextLines(
PatchConfiguration configuration, List<String> lines, int fuzz, int pos,
List<String> contextLines) {
@@ -291,7 +291,7 @@ public class Hunk implements IHunk {
}
return true;
}
-
+
public int getStart(boolean after) {
if (after) {
return this.fNewStart;
@@ -313,14 +313,14 @@ public class Hunk implements IHunk {
}
return this.fOldLength;
}
-
+
private int getShift(boolean reverse) {
if (reverse) {
return this.fOldLength - this.fNewLength;
}
return this.fNewLength - this.fOldLength;
}
-
+
int doPatch(PatchConfiguration configuration, List<String> lines, int shift, int fuzz) {
boolean reverse = configuration.isReversed();
int pos = getStart(reverse) + shift;
@@ -334,7 +334,7 @@ public class Hunk implements IHunk {
Assert.isTrue(s.length() > 0);
String line= s.substring(1);
char controlChar= s.charAt(0);
- if (controlChar == ' ') {
+ if (controlChar == ' ') {
// context lines
Assert.isTrue(pos < lines.size(), "doPatch: inconsistency in context"); //$NON-NLS-1$
contextLines.add(line);
@@ -350,11 +350,11 @@ public class Hunk implements IHunk {
Assert.isTrue(false, "doPatch: context doesn't match"); //$NON-NLS-1$
// pos++;
} else if (isDeletedDelimeter(controlChar, reverse)) {
- // deleted lines
+ // deleted lines
if (precedingLinesChecked && !contextLinesMatched && contextLines.size() > 0)
// context lines inside hunk don't match
Assert.isTrue(false, "doPatch: context lines inside hunk don't match"); //$NON-NLS-1$
-
+
// check following context lines if exist
// use the fuzz factor if needed
if (!precedingLinesChecked
@@ -365,17 +365,17 @@ public class Hunk implements IHunk {
Assert.isTrue(false, "doPatch: preceding context lines don't match, even though fuzz factor has been used"); //$NON-NLS-1$;
// else if there is less or equal context line to the fuzz
// factor we ignore them all and treat as matching
-
+
precedingLinesChecked = true;
contextLines.clear();
contextLinesMatched = true;
-
+
lines.remove(pos);
} else if (isAddedDelimeter(controlChar, reverse)) {
// added lines
if (precedingLinesChecked && !contextLinesMatched && contextLines.size() > 0)
Assert.isTrue(false, "doPatch: context lines inside hunk don't match"); //$NON-NLS-1$
-
+
if (!precedingLinesChecked
&& !contextLinesMatched
&& contextLines.size() >= fuzz
@@ -386,11 +386,11 @@ public class Hunk implements IHunk {
precedingLinesChecked = true;
contextLines.clear();
contextLinesMatched = true;
-
+
// if the line contains a delimiter, use a proper one
if (line.length() > LineReader.length(line))
line = line.substring(0, LineReader.length(line)) + lineDelimiter;
-
+
if (getLength(reverse) == 0 && pos+1 < lines.size())
lines.add(pos+1, line);
else
@@ -405,11 +405,11 @@ public class Hunk implements IHunk {
private boolean isDeletedDelimeter(char controlChar, boolean reverse) {
return (!reverse && controlChar == '-') || (reverse && controlChar == '+');
}
-
+
private boolean isAddedDelimeter(char controlChar, boolean reverse) {
return (reverse && controlChar == '-') || (!reverse && controlChar == '+');
}
-
+
/*
* Compares two strings.
* If fIgnoreWhitespace is true whitespace is ignored.
@@ -426,7 +426,7 @@ public class Hunk implements IHunk {
}
return line1.equals(line2);
}
-
+
private boolean isIgnoreLineDelimiter() {
return true;
}
@@ -457,7 +457,7 @@ public class Hunk implements IHunk {
}
return sb.toString();
}
-
+
public String getContents(boolean isAfterState, boolean reverse) {
StringBuffer result= new StringBuffer();
for (int i= 0; i<this.fLines.length; i++) {
@@ -467,7 +467,7 @@ public class Hunk implements IHunk {
if (c == ' ') {
result.append(rest);
} else if (isDeletedDelimeter(c, reverse) && !isAfterState) {
- result.append(rest);
+ result.append(rest);
} else if (isAddedDelimeter(c, reverse) && isAfterState) {
result.append(rest);
}
diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/HunkResult.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/HunkResult.java
index 6b37d90dc..f73ffa444 100644
--- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/HunkResult.java
+++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/HunkResult.java
@@ -26,7 +26,7 @@ public class HunkResult {
* number of context lines, which is 3.
*/
private static final int MAXIMUM_FUZZ_FACTOR = 2;
-
+
private Hunk fHunk;
private boolean fMatches;
private int fShift;
@@ -64,7 +64,7 @@ public class HunkResult {
} else {
boolean found= false;
int oldShift= this.fShift;
-
+
int hugeShift = lines.size();
for (int i = 1; i <= hugeShift; i++) {
if (this.fHunk.tryPatch(configuration, lines, this.fShift - i, fuzz)) {
@@ -74,7 +74,7 @@ public class HunkResult {
break;
}
}
-
+
if (!found) {
for (int i = 1; i <= hugeShift; i++) {
if (this.fHunk.tryPatch(configuration, lines, this.fShift + i, fuzz)) {
@@ -85,7 +85,7 @@ public class HunkResult {
}
}
}
-
+
if (found) {
if (DEBUG) System.out.println("patched hunk at offset: " + (this.fShift-oldShift)); //$NON-NLS-1$
this.fShift+= this.fHunk.doPatch(configuration, lines, this.fShift, fuzz);
@@ -108,7 +108,7 @@ public class HunkResult {
* Calculate the fuzz that will allow the most hunks to be matched. Even
* though we're interested only in the value of the fuzz, the shifting is
* done anyway.
- *
+ *
* @param lines
* the lines of the target file
* @param monitor
@@ -129,14 +129,14 @@ public class HunkResult {
this.fMatches = true;
break;
}
-
+
// TODO (tzarna): hugeShift=lines.size() is more than we need.
// Lines to the beg/end of a file would be enough but this can still
// in matching hunks out of order. Try to shift using only lines
// available "between" hunks.
- int hugeShift = lines.size();
-
- // shift up
+ int hugeShift = lines.size();
+
+ // shift up
for (int i = 1; i <= hugeShift; i++) {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
@@ -266,7 +266,7 @@ public class HunkResult {
public String getCharset() {
return this.fDiffResult.getCharset();
}
-
+
public int getFuzz() {
return this.fFuzz;
}
diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/LineReader.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/LineReader.java
index 019874b29..43a843769 100644
--- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/LineReader.java
+++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/LineReader.java
@@ -86,7 +86,7 @@ public class LineReader {
}
return sb.toString();
}
-
+
/*
* Returns the length (excluding a line delimiter CR, LF, CR/LF)
* of the given string.
@@ -105,14 +105,14 @@ public class LineReader {
}
return l;
}
-
+
private boolean fHaveChar= false;
private int fLastChar;
private boolean fSawEOF= false;
private BufferedReader fReader;
private boolean fIgnoreSingleCR= false;
private StringBuffer fBuffer= new StringBuffer();
-
+
public LineReader(BufferedReader reader) {
this.fReader= reader;
Assert.isNotNull(reader);
@@ -121,7 +121,7 @@ public class LineReader {
public void ignoreSingleCR() {
this.fIgnoreSingleCR= true;
}
-
+
/**
* Reads a line of text. A line is considered to be terminated by any one
* of a line feed ('\n'), a carriage return ('\r'), or a carriage return
@@ -150,17 +150,17 @@ public class LineReader {
}
if (c != '\n') {
if (this.fIgnoreSingleCR) {
- this.fBuffer.append((char)c);
+ this.fBuffer.append((char)c);
continue;
}
this.fHaveChar= true;
this.fLastChar= c;
} else
- this.fBuffer.append((char)c);
+ this.fBuffer.append((char)c);
break;
}
}
-
+
if (this.fBuffer.length() != 0) {
return this.fBuffer.toString();
}
@@ -169,7 +169,7 @@ public class LineReader {
this.fBuffer.setLength(0);
}
}
-
+
void close() {
try {
this.fReader.close();
@@ -177,7 +177,7 @@ public class LineReader {
// silently ignored
}
}
-
+
public List<String> readLines() {
try {
List<String> lines= new ArrayList<>();
@@ -193,7 +193,7 @@ public class LineReader {
}
return null;
}
-
+
/*
* Returns the number of characters in the given string without
* counting a trailing line separator.
@@ -211,9 +211,9 @@ public class LineReader {
}
return length;
}
-
+
//---- private
-
+
private int readChar() throws IOException {
if (this.fHaveChar) {
this.fHaveChar= false;
diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java
index 255f50382..05a617aef 100644
--- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java
+++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java
@@ -33,7 +33,7 @@ import com.ibm.icu.text.SimpleDateFormat;
public class PatchReader {
private static final boolean DEBUG= false;
-
+
private static final String DEV_NULL= "/dev/null"; //$NON-NLS-1$
protected static final String MARKER_TYPE= "org.eclipse.compare.rejectedPatchMarker"; //$NON-NLS-1$
@@ -74,7 +74,7 @@ public class PatchReader {
/**
* Create a patch reader for the given date formats.
- *
+ *
* @param dateFormats
* Array of <code>DateFormat</code>s to be used when
* extracting dates from the patch.
@@ -83,7 +83,7 @@ public class PatchReader {
this();
this.fDateFormats = dateFormats;
}
-
+
public void parse(BufferedReader reader) throws IOException {
List<FilePatch2> diffs= new ArrayList<FilePatch2>();
HashMap<String, DiffProject> diffProjects= new HashMap<String, DiffProject>(4);
@@ -174,7 +174,7 @@ public class PatchReader {
}
return nextLine;
}
-
+
public void parse(LineReader lr, String line) throws IOException {
List<FilePatch2> diffs= new ArrayList<FilePatch2>();
boolean reread= false;
@@ -191,7 +191,7 @@ public class PatchReader {
reread= false;
if (line == null)
break;
-
+
// remember some infos
if (line.startsWith("Index: ")) { //$NON-NLS-1$
fileName= line.substring(7).trim();
@@ -213,19 +213,19 @@ public class PatchReader {
diffArgs= fileName= null;
reread= true;
}
-
+
// Any lines we read here are header lines.
// However, if reread is set, we will add them to the header on the next pass through
if (!reread) {
headerLines.add(line);
}
}
-
+
lr.close();
-
+
this.fDiffs = diffs.toArray(new FilePatch2[diffs.size()]);
}
-
+
private void setHeader(FilePatch2 diff, List<String> headerLines) {
String header = LineReader.createString(false, headerLines);
diff.setHeader(header);
@@ -243,14 +243,14 @@ public class PatchReader {
line= reader.readLine();
if (line == null || !line.startsWith("+++ ")) //$NON-NLS-1$
return line;
-
+
String[] newArgs= split(line.substring(4));
-
+
FilePatch2 diff = createFileDiff(extractPath(oldArgs, 0, fileName),
extractDate(oldArgs, 1), extractPath(newArgs, 0, fileName),
extractDate(newArgs, 1));
diffs.add(diff);
-
+
int[] oldRange= new int[2];
int[] newRange= new int[2];
int remainingOld= -1; // remaining old lines for current hunk
@@ -260,7 +260,7 @@ public class PatchReader {
boolean encounteredPlus = false;
boolean encounteredMinus = false;
boolean encounteredSpace = false;
-
+
try {
// read lines of hunk
while (true) {
@@ -357,51 +357,51 @@ public class PatchReader {
Hunk.createHunk(diff, oldRange, newRange, lines, encounteredPlus, encounteredMinus, encounteredSpace);
}
}
-
+
/*
* Returns the next line that does not belong to this diff
*/
private String readContextDiff(List<FilePatch2> diffs, LineReader reader, String line, String args, String fileName) throws IOException {
-
+
String[] oldArgs= split(line.substring(4));
-
+
// read info about new file
line= reader.readLine();
if (line == null || !line.startsWith("--- ")) //$NON-NLS-1$
return line;
-
+
String[] newArgs= split(line.substring(4));
-
+
FilePatch2 diff = createFileDiff(extractPath(oldArgs, 0, fileName),
extractDate(oldArgs, 1), extractPath(newArgs, 0, fileName),
extractDate(newArgs, 1));
diffs.add(diff);
-
+
int[] oldRange= new int[2];
int[] newRange= new int[2];
List<String> oldLines= new ArrayList<String>();
List<String> newLines= new ArrayList<String>();
List<String> lines= oldLines;
-
+
boolean encounteredPlus = false;
boolean encounteredMinus = false;
boolean encounteredSpace = false;
-
+
try {
// read lines of hunk
while (true) {
-
+
line= reader.readLine();
if (line == null)
return line;
-
+
int l= line.length();
if (l == 0)
continue;
if (l > 1) {
switch (line.charAt(0)) {
- case '*':
+ case '*':
if (line.startsWith("***************")) { // new hunk //$NON-NLS-1$
// flush old hunk
if (oldLines.size() > 0 || newLines.size() > 0) {
@@ -473,7 +473,7 @@ public class PatchReader {
Hunk.createHunk(diff, oldRange, newRange, unifyLines(oldLines, newLines), encounteredPlus, encounteredMinus, encounteredSpace);
}
}
-
+
/*
* Creates a List of lines in the unified format from
* two Lists of lines in the 'classic' format.
@@ -483,29 +483,29 @@ public class PatchReader {
String[] ol= oldLines.toArray(new String[oldLines.size()]);
String[] nl= newLines.toArray(new String[newLines.size()]);
-
+
int oi= 0, ni= 0;
-
+
while (true) {
-
+
char oc= 0;
String o= null;
if (oi < ol.length) {
o= ol[oi];
oc= o.charAt(0);
}
-
+
char nc= 0;
String n= null;
if (ni < nl.length) {
n= nl[ni];
nc= n.charAt(0);
}
-
+
// EOF
if (oc == 0 && nc == 0)
break;
-
+
// deletion in old
if (oc == '-') {
do {
@@ -517,7 +517,7 @@ public class PatchReader {
} while (o.charAt(0) == '-');
continue;
}
-
+
// addition in new
if (nc == '+') {
do {
@@ -529,7 +529,7 @@ public class PatchReader {
} while (n.charAt(0) == '+');
continue;
}
-
+
// differing lines on both sides
if (oc == '!' && nc == '!') {
// remove old
@@ -540,7 +540,7 @@ public class PatchReader {
break;
o= ol[oi];
} while (o.charAt(0) == '!');
-
+
// add new
do {
result.add('+' + n.substring(2));
@@ -549,10 +549,10 @@ public class PatchReader {
break;
n= nl[ni];
} while (n.charAt(0) == '!');
-
+
continue;
}
-
+
// context lines
if (oc == ' ' && nc == ' ') {
do {
@@ -567,7 +567,7 @@ public class PatchReader {
} while (o.charAt(0) == ' ' && n.charAt(0) == ' ');
continue;
}
-
+
if (oc == ' ') {
do {
result.add(' ' + o.substring(2));
@@ -589,13 +589,13 @@ public class PatchReader {
} while (n.charAt(0) == ' ');
continue;
}
-
+
Assert.isTrue(false, "unexpected char <" + oc + "> <" + nc + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
-
+
return result;
}
-
+
/*
* @return the parsed time/date in milliseconds or IFilePatch.DATE_UNKNOWN
* (0) on error
@@ -607,7 +607,7 @@ public class PatchReader {
this.fDateFormats[i].setLenient(true);
try {
Date date= this.fDateFormats[i].parse(line);
- return date.getTime();
+ return date.getTime();
} catch (ParseException ex) {
// silently ignored
}
@@ -616,7 +616,7 @@ public class PatchReader {
}
return IFilePatch2.DATE_UNKNOWN;
}
-
+
/*
* Returns null if file name is "/dev/null".
*/
@@ -636,7 +636,7 @@ public class PatchReader {
}
return null;
}
-
+
/*
* Tries to extract two integers separated by a comma.
* The parsing of the line starts at the position after
@@ -672,7 +672,7 @@ public class PatchReader {
/*
* Breaks the given string into tab separated substrings.
* Leading and trailing whitespace is removed from each token.
- */
+ */
private String[] split(String line) {
List<String> l= new ArrayList<>();
StringTokenizer st= new StringTokenizer(line, "\t"); //$NON-NLS-1$
@@ -699,7 +699,7 @@ public class PatchReader {
public FilePatch2[] getDiffs() {
return this.fDiffs;
}
-
+
public FilePatch2[] getAdjustedDiffs() {
if (!isWorkspacePatch() || this.fDiffs.length == 0)
return this.fDiffs;

Back to the top