|
23 | 23 |
|
24 | 24 | DiffParser.prototype.LINE_TYPE = LINE_TYPE;
|
25 | 25 |
|
26 |
| - DiffParser.prototype.generateDiffJson = function(diffInput) { |
| 26 | + DiffParser.prototype.generateDiffJson = function(diffInput, config) { |
27 | 27 | var files = [];
|
28 | 28 | var currentFile = null;
|
29 | 29 | var currentBlock = null;
|
|
133 | 133 | var deletedFileMode = /^deleted file mode (\d{6})/;
|
134 | 134 | var newFileMode = /^new file mode (\d{6})/;
|
135 | 135 |
|
136 |
| - var copyFrom = /^copy from (.+)/; |
137 |
| - var copyTo = /^copy to (.+)/; |
| 136 | + var copyFrom = /^copy from "?(.+?)"?/; |
| 137 | + var copyTo = /^copy to "?(.+?)"?/; |
138 | 138 |
|
139 |
| - var renameFrom = /^rename from (.+)/; |
140 |
| - var renameTo = /^rename to (.+)/; |
| 139 | + var renameFrom = /^rename from "?(.+?)"?/; |
| 140 | + var renameTo = /^rename to "?(.+?)"?/; |
141 | 141 |
|
142 | 142 | var similarityIndex = /^similarity index (\d+)%/;
|
143 | 143 | var dissimilarityIndex = /^dissimilarity index (\d+)%/;
|
|
160 | 160 | var values = [];
|
161 | 161 | if (utils.startsWith(line, 'diff')) {
|
162 | 162 | startFile();
|
163 |
| - } else if (currentFile && !currentFile.oldName && (values = /^--- [aiwco]\/(.+)$/.exec(line))) { |
| 163 | + } else if (currentFile && !currentFile.oldName && (values = getSrcFilename(line, config))) { |
164 | 164 | currentFile.oldName = values[1];
|
165 | 165 | currentFile.language = getExtension(currentFile.oldName, currentFile.language);
|
166 |
| - } else if (currentFile && !currentFile.newName && (values = /^\+\+\+ [biwco]?\/(.+)$/.exec(line))) { |
| 166 | + } else if (currentFile && !currentFile.newName && (values = getDstFilename(line, config))) { |
167 | 167 | currentFile.newName = values[1];
|
168 | 168 | currentFile.language = getExtension(currentFile.newName, currentFile.language);
|
169 | 169 | } else if (currentFile && utils.startsWith(line, '@@')) {
|
|
226 | 226 | return language;
|
227 | 227 | }
|
228 | 228 |
|
| 229 | + function getSrcFilename(line, cfg) { |
| 230 | + var prefixes = ["a\\/", "i\\/", "w\\/", "c\\/", "o\\/"]; |
| 231 | + |
| 232 | + if (cfg.srcPrefix) prefixes.push(cfg.srcPrefix); |
| 233 | + |
| 234 | + return _getFilename('---', line, prefixes); |
| 235 | + } |
| 236 | + |
| 237 | + function getDstFilename(line, cfg) { |
| 238 | + var prefixes = ["b\\/", "i\\/", "w\\/", "c\\/", "o\\/"]; |
| 239 | + |
| 240 | + if (cfg.dstPrefix) prefixes.push(cfg.dstPrefix); |
| 241 | + |
| 242 | + return _getFilename('\\+\\+\\+', line, prefixes); |
| 243 | + } |
| 244 | + |
| 245 | + function _getFilename(linePrefix, line, prefixes) { |
| 246 | + var prefixesStr = prefixes.join("|"); |
| 247 | + return new RegExp('^' + linePrefix + ' "?(?:' + prefixesStr + ')(.+?)"?$').exec(line); |
| 248 | + } |
| 249 | + |
229 | 250 | module.exports.DiffParser = new DiffParser();
|
230 | 251 |
|
231 | 252 | })();
|
0 commit comments