Skip to content

Commit

Permalink
Optimize parch header parser
Browse files Browse the repository at this point in the history
  • Loading branch information
kpdecker committed Mar 5, 2018
1 parent a47aca9 commit 2aec429
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/patch/parse.js
Expand Up @@ -53,16 +53,16 @@ export function parsePatch(uniDiff, options = {}) {
// Parses the --- and +++ headers, if none are found, no lines
// are consumed.
function parseFileHeader(index) {
const headerPattern = /^(---|\+\+\+)\s+([\S ]*)(?:\t(.*?)\s*)?$/;
const fileHeader = headerPattern.exec(diffstr[i]);
const fileHeader = (/^(---|\+\+\+)\s+(.*)$/).exec(diffstr[i]);
if (fileHeader) {
let keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
let fileName = fileHeader[2].replace(/\\\\/g, '\\');
const data = fileHeader[2].split('\t', 2);
let fileName = data[0].replace(/\\\\/g, '\\');
if (/^".*"$/.test(fileName)) {
fileName = fileName.substr(1, fileName.length - 2);
}
index[keyPrefix + 'FileName'] = fileName;
index[keyPrefix + 'Header'] = fileHeader[3];

This comment has been minimized.

Copy link
@mariosanchezgarcia
index[keyPrefix + 'Header'] = (data[1] || '').trim();

i++;
}
Expand Down

0 comments on commit 2aec429

Please sign in to comment.