# # # patch "guitone/src/model/GetFile.cpp" # from [804d622b89d86576e92a3dd043b792ebf1366a26] # to [f9190876d9095f73a4204d1579515025a743de4f] # # patch "guitone/src/util/DiffParser.cpp" # from [3d8de18d24695935c0c1b002544f6f4706c496c3] # to [ee79215f94252db70870ed6897b16a029b0b7758] # # patch "guitone/src/util/DiffParser.h" # from [09081b3461bf1b5a588c4288f25db08bb1d1af80] # to [4bc8265bccbdc1de9ad878c53864604503fd76c0] # ============================================================ --- guitone/src/model/GetFile.cpp 804d622b89d86576e92a3dd043b792ebf1366a26 +++ guitone/src/model/GetFile.cpp f9190876d9095f73a4204d1579515025a743de4f @@ -90,8 +90,9 @@ void GetFile::parseOutput(AutomateComman return; } - QStringList lines(AutomateCommand::data.split(QChar('\n'))); - for (int i=0, s=lines.size(); ihunks.size(); ihunks.at(i); + int lineStart = hunk->leftStart + lineOffset; - // skip unrelated left/right lines - if ((version == Left || version == Both)) + for (int j=0, t=hunk->lines.size(); jleftStart; - } - - if (version == Right && hunk->rightStart > 0) - { - curLine = hunk->rightStart; - } - - qDebug("GetFile::applyDiff: current line: %d", curLine); - - int leftLastLine = 0, rightLastLine = 0; - - for (int j=0, t=hunk->lineGroups.size(); jlineGroups.at(j); + DiffLine * line = hunk->lines.at(j); - qDebug("GetFile::applyDiff: linegroup: %d, State: %d", j, group->state); - qDebug("StartPos: %d, ChangeLen: %d", group->startPos, group->changeLen); - qDebug("Lines: %s", qPrintable(group->contents.join("\\n"))); - - if (version == Left) + // skip unchanged lines + if (line->state == DiffLine::Unchanged) { - // skip the added part, this is not used here - if (group->state == DiffLineGroup::Added) continue; - - // skip even more unchanged lines - if (leftLastLine < group->startPos) - { - curLine += group->startPos - leftLastLine; - } - - Q_ASSERT(fileContents.size() >= curLine + group->changeLen); - - // set the following lines to "Removed" - for (int k = curLine, l = k+group->changeLen; kmarker = ContentLine::Removed; - } - curLine += group->changeLen; - - leftLastLine = group->startPos + group->changeLen; + lineStart++; continue; } - if (version == Right) + if (line->state == DiffLine::Removed) { - // each removed line group is followed by an added line group - // we're processing here these two at once - if (group->state == DiffLineGroup::Removed) + fileContents.value(lineStart-1)->marker = ContentLine::Removed; + // lower the linecount for all following lines + for (int x = lineStart, y=fileContents.size(); xstartPos) - { - curLine += group->startPos - rightLastLine; - } - - // remove deleted lines from the right - // don't raise the curLine counter! - fileContents.remove(curLine, group->changeLen); - - // go to the next add part - j += 1; - - // add the new lines accordingly - group = hunk->lineGroups.at(j); - - for (int x=0, y=group->changeLen; xcontents.at(x), - ContentLine::Added, - curLine+x - ) - ); - } - curLine += group->changeLen; - - // raise the line count for the other items - for (int x=curLine, y=fileContents.size(); xnumber = x; - } - - // to the next "removed" line group - continue; + fileContents.value(x)->number -= 1; } - - // should never be reached - Q_ASSERT(false); + lineStart++; + continue; } - // now the complex part: both, added and removed parts in one file - // each removed line group is followed by an added line group - // again, we're processing two line groups at once - if (group->state == DiffLineGroup::Removed) + Q_ASSERT(line->state == DiffLine::Added); + + int lastNum = fileContents.at(lineStart)->number; + fileContents.insert( + lineStart - 1, + new ContentLine( + line->content, + ContentLine::Added, + lastNum + ) + ); + // raise the linecount for all following lines + for (int x = lineStart, y=fileContents.size(); xstartPos) - { - curLine += group->startPos - rightLastLine; - } - - qDebug("marking %d removed lines", group->changeLen); - // mark deleted lines - for (int k = curLine, l = k+group->changeLen; kmarker = ContentLine::Removed; - } - int oldLineStart = curLine; - - // go to the next add part - j += 1; - - // add the new lines accordingly - group = hunk->lineGroups.at(j); - - qDebug("adding %d added lines", group->changeLen); - for (int x=0, y=group->contents.size(); xcontents.at(x), - ContentLine::Added, - oldLineStart+x - ) - ); - } - - int lineDiff = hunk->rightCount - hunk->leftCount; - curLine += lineDiff; - - // raise the line count for the other items - for (int x=curLine, y=fileContents.size(); xnumber = x; - } - - // to the next "removed" line - continue; + fileContents.value(x)->number += 1; } - - // should never be reached - Q_ASSERT(false); + lineOffset++; + lineStart++; } } ============================================================ --- guitone/src/util/DiffParser.cpp 3d8de18d24695935c0c1b002544f6f4706c496c3 +++ guitone/src/util/DiffParser.cpp ee79215f94252db70870ed6897b16a029b0b7758 @@ -45,8 +45,6 @@ void DiffParser::parse(const QString & i Diff * curDiff; DiffHunk * curHunk; - DiffLineGroup * curGroup; - int leftLinesCount = 0, rightLinesCount = 0; for (int i=0, s=lines.size(); irightCount = list.at(6).toInt(); else curHunk->rightCount = 1; - - curGroup = 0; - leftLinesCount = 0; - rightLinesCount = 0; - + continue; } - // unchanged lines are simply skipped, but counted for both sides - if (curChar == ' ') - { - leftLinesCount++; - rightLinesCount++; - continue; - } + DiffLine * diffLine = new DiffLine(); + curHunk->lines.push_back(diffLine); + diffLine->content = line.mid(1); - curGroup = new DiffLineGroup(); - curGroup->changeLen = 1; - curGroup->contents.push_back(line.mid(1)); - - if (curChar == '+') - { - QChar lastChar; - if (i > 0) - { - lastChar = lines.at(i-1).at(0); - } - - // check for any last group - if (lastChar == ' ') - { - // insert dummy group - DiffLineGroup * dummy = new DiffLineGroup(); - dummy->changeLen = 0; - dummy->startPos = leftLinesCount; - dummy->state = DiffLineGroup::Removed; - dummy->friendGroup = curGroup; - curGroup->friendGroup = dummy; - curHunk->lineGroups.push_back(dummy); - } - else - if (lastChar == '-') - { - // connect the last group with this group - DiffLineGroup * lastGroup = curHunk->lineGroups.last(); - Q_ASSERT(lastGroup); - curGroup->friendGroup = lastGroup; - lastGroup->friendGroup = curGroup; - } - - curGroup->startPos = leftLinesCount; - curGroup->state = DiffLineGroup::Added; - } - else - { - curGroup->startPos = rightLinesCount; - curGroup->state = DiffLineGroup::Removed; - } - - curHunk->lineGroups.push_back(curGroup); - - // "eat" as much lines with the same change type - QChar nextChar; - while (++i < s) - { - nextChar = lines.at(i).at(0); - if (nextChar == curChar) - { - curGroup->changeLen++; - QString nextLine(lines.at(i)); - curGroup->contents.push_back(nextLine.mid(1)); - continue; - } - i--; - break; - } - - Q_ASSERT(nextChar != curChar); - - // we just processed a plusline, the connections should already be there - if (curChar == '+') - { - Q_ASSERT(curGroup->friendGroup); - continue; - } - - // if the next line is a plusline, the connection happens in the - // next round, otherwise we need to do it by hand - if (curChar == '-' && nextChar == '+') - { - continue; - } - - // if we either reached the last line or the next line is a - // unchanged line, insert dummy group - DiffLineGroup * dummy = new DiffLineGroup(); - dummy->changeLen = 0; - dummy->startPos = rightLinesCount; - dummy->state = DiffLineGroup::Added; - dummy->friendGroup = curGroup; - curGroup->friendGroup = dummy; - curHunk->lineGroups.push_back(dummy); + if (curChar == '+') diffLine->state = DiffLine::Added; + else if (curChar == '-') diffLine->state = DiffLine::Removed; + else if (curChar == ' ') diffLine->state = DiffLine::Unchanged; + else Q_ASSERT(false); } } ============================================================ --- guitone/src/util/DiffParser.h 09081b3461bf1b5a588c4288f25db08bb1d1af80 +++ guitone/src/util/DiffParser.h 4bc8265bccbdc1de9ad878c53864604503fd76c0 @@ -27,18 +27,15 @@ #include #include -struct DiffLineGroup +struct DiffLine { - enum State {Added, Removed} state; - int startPos; - int changeLen; - QStringList contents; - DiffLineGroup * friendGroup; + enum State {Added, Removed, Unchanged} state; + QString content; }; struct DiffHunk { - QList lineGroups; + QList lines; int leftStart; int leftCount; int rightStart;