# # # patch "guitone/src/model/GetFile.cpp" # from [66658436c56c2acef405d391f3406e305a6cdde7] # to [03b984484941b2811fe8e32ee6ab2c68e1a566be] # # patch "guitone/src/util/DiffParser.cpp" # from [bbfb38a9a3726e8a216c405c9e5753856d4b1529] # to [962e00c66f7011d084cedabb9762b93973907403] # ============================================================ --- guitone/src/model/GetFile.cpp 66658436c56c2acef405d391f3406e305a6cdde7 +++ guitone/src/model/GetFile.cpp 03b984484941b2811fe8e32ee6ab2c68e1a566be @@ -103,10 +103,14 @@ void GetFile::applyDiff(Diff * diff, Fil int curLine = 0; int leftLastHunk = 0, rightLastHunk = 0; + qDebug("GetFile::applyDiff"); + for (int i=0, s=diff->hunks.size(); ihunks.at(i); - + + qDebug("GetFile::applyDiff: hunk: %d", i); + // skip unrelated left/right lines if (version == Left && hunk->leftStart > 0) { @@ -118,6 +122,8 @@ void GetFile::applyDiff(Diff * diff, Fil curLine += hunk->rightStart - rightLastHunk; } + qDebug("GetFile::applyDiff: current line: %d", curLine); + leftLastHunk = hunk->leftStart + hunk->leftCount; rightLastHunk = hunk->rightStart + hunk->rightCount; @@ -127,6 +133,8 @@ void GetFile::applyDiff(Diff * diff, Fil { DiffLineGroup * group = hunk->lineGroups.at(j); + qDebug("GetFile::applyDiff: linegroup: %d", j); + if (version == Left) { // skip the added part, this is not used here ============================================================ --- guitone/src/util/DiffParser.cpp bbfb38a9a3726e8a216c405c9e5753856d4b1529 +++ guitone/src/util/DiffParser.cpp 962e00c66f7011d084cedabb9762b93973907403 @@ -34,7 +34,7 @@ void DiffParser::parse(const QString & i { if (input.length() == 0) return; - QStringList lines = input.split(QRegExp("/[\\n\\r]+/")); + QStringList lines = input.split(QRegExp("[\\n\\r]+")); QString curFile; @@ -58,10 +58,11 @@ void DiffParser::parse(const QString & i // if (curChar == '=') { + Q_ASSERT(i < (s-1)); QString nextGroup(lines.at(++i)); // check if this is a binary - QRegExp rx = QRegExp("/^#\\s(.+)\\sis binary/"); + QRegExp rx = QRegExp("^#\\s(.+)\\sis binary"); if (rx.indexIn(nextGroup) != -1) { curDiff->is_binary = true; @@ -70,7 +71,7 @@ void DiffParser::parse(const QString & i } // then this should be a normal file diff - rx = QRegExp("/^---\\s(.+)\\s+\\w{40}/"); + rx = QRegExp("^---\\s(.+)\\s+\\w{40}"); Q_ASSERT(rx.indexIn(nextGroup) > -1); curFile = rx.cap(1); @@ -87,10 +88,8 @@ void DiffParser::parse(const QString & i // if (curChar == '@') { - QString nextGroup(lines.at(++i)); - - QRegExp rx = QRegExp("/^@@\\s+\\-(\\d+)(,?)(\\d*)\\s+\\+(\\d+)(,?)(\\d*)\\s+@@/"); - Q_ASSERT(rx.indexIn(nextGroup) > -1); + QRegExp rx = QRegExp("^@@\\s+\\-(\\d+)(,(\\d+))?\\s+\\+(\\d+)(,(\\d+))\\s+@@"); + Q_ASSERT(rx.indexIn(line) > -1); QStringList list = rx.capturedTexts(); Q_ASSERT(list.size() >= 2); @@ -100,13 +99,13 @@ void DiffParser::parse(const QString & i // extract line numbers and positions curHunk->leftStart = list.at(1).toInt(); - if (list.at(2) == ",") + if (list.at(2).length() > 0) curHunk->leftCount = list.at(3).toInt(); else curHunk->leftCount = 1; curHunk->rightStart = list.at(4).toInt(); - if (list.at(5) == ",") + if (list.at(5).length() > 0) curHunk->rightCount = list.at(6).toInt(); else curHunk->rightCount = 1; @@ -144,6 +143,7 @@ void DiffParser::parse(const QString & i // if (curChar == '+') { + qDebug("a plusline"); // create linked dummy item if (lastChar == ' ') { @@ -215,6 +215,8 @@ void DiffParser::parse(const QString & i // if (curChar == '-') { + qDebug("a minusline followed by %c", nextChar.toLatin1()); + // create linked dummy item if (nextChar == ' ') { @@ -227,7 +229,6 @@ void DiffParser::parse(const QString & i curHunk->lineGroups.push_back(curGroup); curHunk->lineGroups.push_back(nextGroup); - curGroup->startPos = leftLinesCount; curGroup->changeLen = 1; curGroup->contents.push_back(line.mid(1)); @@ -241,16 +242,14 @@ void DiffParser::parse(const QString & i if (nextChar == '+') { - // this case is already handled above - curGroup->contents.push_back(line.mid(1)); - curGroup->changeLen++; + // this case will be handled in the '+' section rightLinesCount++; continue; } if (nextChar == '-') { - // this case is already handled above + // FIXME: this case is NOT handled above curGroup->changeLen++; rightLinesCount++; continue;