@@ -72,26 +72,45 @@ public final class UnifiedDiffReader { |
72 | 72 | // [/^---\s/, from_file], [/^\+\+\+\s/, to_file], [/^@@\s+\-(\d+),?(\d+)?\s+\+(\d+),?(\d+)?\s@@/, chunk], |
73 | 73 | // [/^-/, del], [/^\+/, add], [/^\\ No newline at end of file$/, eof]]; |
74 | 74 | private UnifiedDiff parse() throws IOException, UnifiedDiffParserException { |
75 | | - String headerTxt = ""; |
76 | | - LOG.log(Level.FINE, "header parsing"); |
77 | | - String line = null; |
78 | | - while (READER.ready()) { |
79 | | - line = READER.readLine(); |
80 | | - LOG.log(Level.FINE, "parsing line {0}", line); |
81 | | - if (DIFF_COMMAND.validLine(line) || INDEX.validLine(line) |
82 | | - || FROM_FILE.validLine(line) || TO_FILE.validLine(line) |
83 | | - || NEW_FILE_MODE.validLine(line)) { |
84 | | - break; |
85 | | - } else { |
86 | | - headerTxt += line + "\n"; |
87 | | - } |
88 | | - } |
89 | | - if (!"".equals(headerTxt)) { |
90 | | - data.setHeader(headerTxt); |
91 | | - } |
92 | | - |
| 75 | +// String headerTxt = ""; |
| 76 | +// LOG.log(Level.FINE, "header parsing"); |
| 77 | +// String line = null; |
| 78 | +// while (READER.ready()) { |
| 79 | +// line = READER.readLine(); |
| 80 | +// LOG.log(Level.FINE, "parsing line {0}", line); |
| 81 | +// if (DIFF_COMMAND.validLine(line) || INDEX.validLine(line) |
| 82 | +// || FROM_FILE.validLine(line) || TO_FILE.validLine(line) |
| 83 | +// || NEW_FILE_MODE.validLine(line)) { |
| 84 | +// break; |
| 85 | +// } else { |
| 86 | +// headerTxt += line + "\n"; |
| 87 | +// } |
| 88 | +// } |
| 89 | +// if (!"".equals(headerTxt)) { |
| 90 | +// data.setHeader(headerTxt); |
| 91 | +// } |
| 92 | + |
| 93 | + String line = READER.readLine(); |
93 | 94 | while (line != null) { |
94 | | - if (!CHUNK.validLine(line)) { |
| 95 | + String headerTxt = ""; |
| 96 | + LOG.log(Level.FINE, "header parsing"); |
| 97 | + while (line != null) { |
| 98 | + LOG.log(Level.FINE, "parsing line {0}", line); |
| 99 | + if (validLine(line, DIFF_COMMAND, SIMILARITY_INDEX, INDEX, |
| 100 | + FROM_FILE, TO_FILE, |
| 101 | + RENAME_FROM, RENAME_TO, |
| 102 | + NEW_FILE_MODE, DELETED_FILE_MODE, |
| 103 | + CHUNK)) { |
| 104 | + break; |
| 105 | + } else { |
| 106 | + headerTxt += line + "\n"; |
| 107 | + } |
| 108 | + line = READER.readLine(); |
| 109 | + } |
| 110 | + if (!"".equals(headerTxt)) { |
| 111 | + data.setHeader(headerTxt); |
| 112 | + } |
| 113 | + if (line != null && !CHUNK.validLine(line)) { |
95 | 114 | initFileIfNecessary(); |
96 | 115 | while (line != null && !CHUNK.validLine(line)) { |
97 | 116 | if (!processLine(line, DIFF_COMMAND, SIMILARITY_INDEX, INDEX, |
@@ -107,7 +126,7 @@ private UnifiedDiff parse() throws IOException, UnifiedDiffParserException { |
107 | 126 | processLine(line, CHUNK); |
108 | 127 | while ((line = READER.readLine()) != null) { |
109 | 128 | line = checkForNoNewLineAtTheEndOfTheFile(line); |
110 | | - |
| 129 | + |
111 | 130 | if (!processLine(line, LINE_NORMAL, LINE_ADD, LINE_DEL)) { |
112 | 131 | throw new UnifiedDiffParserException("expected data line not found"); |
113 | 132 | } |
@@ -186,6 +205,19 @@ private boolean processLine(String line, UnifiedDiffLine... rules) throws Unifie |
186 | 205 | return false; |
187 | 206 | //throw new UnifiedDiffParserException("parsing error at line " + line); |
188 | 207 | } |
| 208 | + |
| 209 | + private boolean validLine(String line, UnifiedDiffLine ... rules) { |
| 210 | + if (line == null) { |
| 211 | + return false; |
| 212 | + } |
| 213 | + for (UnifiedDiffLine rule : rules) { |
| 214 | + if (rule.validLine(line)) { |
| 215 | + LOG.fine(" >>> accepted rule " + rule.toString()); |
| 216 | + return true; |
| 217 | + } |
| 218 | + } |
| 219 | + return false; |
| 220 | + } |
189 | 221 |
|
190 | 222 | private void initFileIfNecessary() { |
191 | 223 | if (!originalTxt.isEmpty() || !revisedTxt.isEmpty()) { |
|