| 472 | } |
| 473 | |
| 474 | ChunkData GitDiffWorker::calculateOriginalData(const QList<Diff> &leftDiffList, |
| 475 | const QList<Diff> &rightDiffList) |
| 476 | { |
| 477 | int i = 0; |
| 478 | int j = 0; |
| 479 | |
| 480 | QList<TextLineData> leftLines; |
| 481 | QList<TextLineData> rightLines; |
| 482 | |
| 483 | // <line number, span count> |
| 484 | QMap<int, int> leftSpans; |
| 485 | QMap<int, int> rightSpans; |
| 486 | // <left line number, right line number> |
| 487 | QMap<int, int> equalLines; |
| 488 | |
| 489 | int leftLineNumber = 0; |
| 490 | int rightLineNumber = 0; |
| 491 | int leftLineAligned = -1; |
| 492 | int rightLineAligned = -1; |
| 493 | bool lastLineEqual = true; |
| 494 | |
| 495 | while (i <= leftDiffList.size() && j <= rightDiffList.size()) { |
| 496 | const Diff leftDiff = i < leftDiffList.size() ? leftDiffList.at(i) : Diff(Diff::Equal); |
| 497 | const Diff rightDiff = j < rightDiffList.size() ? rightDiffList.at(j) : Diff(Diff::Equal); |
| 498 | |
| 499 | if (leftDiff.command == Diff::Delete) { |
| 500 | if (j == rightDiffList.size() && lastLineEqual && leftDiff.text.startsWith('\n')) |
| 501 | equalLines.insert(leftLineNumber, rightLineNumber); |
| 502 | // process delete |
| 503 | handleDifference(leftDiff.text, &leftLines, &leftLineNumber); |
| 504 | lastLineEqual = lastLinesEqual(leftLines, rightLines); |
| 505 | if (j == rightDiffList.size()) |
| 506 | lastLineEqual = false; |
| 507 | i++; |
| 508 | } |
| 509 | if (rightDiff.command == Diff::Insert) { |
| 510 | if (i == leftDiffList.size() && lastLineEqual && rightDiff.text.startsWith('\n')) |
| 511 | equalLines.insert(leftLineNumber, rightLineNumber); |
| 512 | // process insert |
| 513 | handleDifference(rightDiff.text, &rightLines, &rightLineNumber); |
| 514 | lastLineEqual = lastLinesEqual(leftLines, rightLines); |
| 515 | if (i == leftDiffList.size()) |
| 516 | lastLineEqual = false; |
| 517 | j++; |
| 518 | } |
| 519 | if (leftDiff.command == Diff::Equal && rightDiff.command == Diff::Equal) { |
| 520 | // process equal |
| 521 | const QStringList newLeftLines = leftDiff.text.split('\n'); |
| 522 | const QStringList newRightLines = rightDiff.text.split('\n'); |
| 523 | |
| 524 | int line = 0; |
| 525 | |
| 526 | if (i < leftDiffList.size() || j < rightDiffList.size() |
| 527 | || (!leftLines.isEmpty() && !rightLines.isEmpty())) { |
| 528 | while (line < qMax(newLeftLines.size(), newRightLines.size())) { |
| 529 | handleLine(newLeftLines, line, &leftLines, &leftLineNumber); |
| 530 | handleLine(newRightLines, line, &rightLines, &rightLineNumber); |
| 531 |
nothing calls this directly
no test coverage detected