(originalContent, newLines, pathHunks, isStaged, reverse)
| 27 | var _mergeheadForeach = Repository.prototype.mergeheadForeach; |
| 28 | |
| 29 | function applySelectedLinesToTarget |
| 30 | (originalContent, newLines, pathHunks, isStaged, reverse) { |
| 31 | // 43: ascii code for '+' |
| 32 | // 45: ascii code for '-' |
| 33 | var lineTypes = { |
| 34 | ADDED: !reverse ? 43 : 45, |
| 35 | DELETED: !reverse ? 45 : 43 |
| 36 | }; |
| 37 | var newContent = ""; |
| 38 | var oldIndex = 0; |
| 39 | var linesPromises = []; |
| 40 | |
| 41 | var oldLines = originalContent.toString().split("\n"); |
| 42 | |
| 43 | // if no selected lines were sent, return the original content |
| 44 | if (!newLines || newLines.length === 0) { |
| 45 | return originalContent; |
| 46 | } |
| 47 | |
| 48 | function lineEqualsFirstNewLine(hunkLine) { |
| 49 | return ((hunkLine.oldLineno() === newLines[0].oldLineno()) && |
| 50 | (hunkLine.newLineno() === newLines[0].newLineno())); |
| 51 | } |
| 52 | |
| 53 | function processSelectedLine(hunkLine) { |
| 54 | // if this hunk line is a selected line find the selected line |
| 55 | var newLine = newLines.filter(function(nLine) { |
| 56 | return ((hunkLine.oldLineno() === nLine.oldLineno()) && |
| 57 | (hunkLine.newLineno() === nLine.newLineno())); |
| 58 | }); |
| 59 | |
| 60 | if (hunkLine.content().indexOf("\\ No newline at end of file") !== -1) { |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | // determine what to add to the new content |
| 65 | if ((isStaged && newLine && newLine.length > 0) || |
| 66 | (!isStaged && (!newLine || newLine.length === 0))) { |
| 67 | if (hunkLine.origin() !== lineTypes.ADDED) { |
| 68 | newContent += hunkLine.content(); |
| 69 | } |
| 70 | if ((isStaged && hunkLine.origin() !== lineTypes.DELETED) || |
| 71 | (!isStaged && hunkLine.origin() !== lineTypes.ADDED)) { |
| 72 | oldIndex++; |
| 73 | } |
| 74 | } |
| 75 | else { |
| 76 | switch (hunkLine.origin()) { |
| 77 | case lineTypes.ADDED: |
| 78 | newContent += hunkLine.content(); |
| 79 | if (isStaged) { |
| 80 | oldIndex++; |
| 81 | } |
| 82 | break; |
| 83 | case lineTypes.DELETED: |
| 84 | if (!isStaged) { |
| 85 | oldIndex++; |
| 86 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…