(hunk, mineOffset, mineLines, theirOffset, theirLines)
| 1250 | } |
| 1251 | |
| 1252 | function mergeLines(hunk, mineOffset, mineLines, theirOffset, theirLines) { |
| 1253 | // This will generally result in a conflicted hunk, but there are cases where the context |
| 1254 | // is the only overlap where we can successfully merge the content here. |
| 1255 | var mine = { |
| 1256 | offset: mineOffset, |
| 1257 | lines: mineLines, |
| 1258 | index: 0 |
| 1259 | }, |
| 1260 | their = { |
| 1261 | offset: theirOffset, |
| 1262 | lines: theirLines, |
| 1263 | index: 0 |
| 1264 | }; // Handle any leading content |
| 1265 | |
| 1266 | insertLeading(hunk, mine, their); |
| 1267 | insertLeading(hunk, their, mine); // Now in the overlap content. Scan through and select the best changes from each. |
| 1268 | |
| 1269 | while (mine.index < mine.lines.length && their.index < their.lines.length) { |
| 1270 | var mineCurrent = mine.lines[mine.index], |
| 1271 | theirCurrent = their.lines[their.index]; |
| 1272 | |
| 1273 | if ((mineCurrent[0] === '-' || mineCurrent[0] === '+') && (theirCurrent[0] === '-' || theirCurrent[0] === '+')) { |
| 1274 | // Both modified ... |
| 1275 | mutualChange(hunk, mine, their); |
| 1276 | } else if (mineCurrent[0] === '+' && theirCurrent[0] === ' ') { |
| 1277 | var _hunk$lines; |
| 1278 | |
| 1279 | // Mine inserted |
| 1280 | (_hunk$lines = hunk.lines).push.apply(_hunk$lines, _toConsumableArray(collectChange(mine))); |
| 1281 | } else if (theirCurrent[0] === '+' && mineCurrent[0] === ' ') { |
| 1282 | var _hunk$lines2; |
| 1283 | |
| 1284 | // Theirs inserted |
| 1285 | (_hunk$lines2 = hunk.lines).push.apply(_hunk$lines2, _toConsumableArray(collectChange(their))); |
| 1286 | } else if (mineCurrent[0] === '-' && theirCurrent[0] === ' ') { |
| 1287 | // Mine removed or edited |
| 1288 | removal(hunk, mine, their); |
| 1289 | } else if (theirCurrent[0] === '-' && mineCurrent[0] === ' ') { |
| 1290 | // Their removed or edited |
| 1291 | removal(hunk, their, mine, true); |
| 1292 | } else if (mineCurrent === theirCurrent) { |
| 1293 | // Context identity |
| 1294 | hunk.lines.push(mineCurrent); |
| 1295 | mine.index++; |
| 1296 | their.index++; |
| 1297 | } else { |
| 1298 | // Context mismatch |
| 1299 | conflict(hunk, collectChange(mine), collectChange(their)); |
| 1300 | } |
| 1301 | } // Now push anything that may be remaining |
| 1302 | |
| 1303 | |
| 1304 | insertTrailing(hunk, mine); |
| 1305 | insertTrailing(hunk, their); |
| 1306 | calcLineCount(hunk); |
| 1307 | } |
| 1308 | |
| 1309 | function mutualChange(hunk, mine, their) { |
no test coverage detected