MCPcopy Create free account
hub / github.com/Palm1r/QodeAssist / createDiffInfo

Method createDiffInfo

context/ChangesManager.cpp:1247–1391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1245}
1246
1247ChangesManager::DiffInfo ChangesManager::createDiffInfo(
1248 const QString &originalContent,
1249 const QString &modifiedContent,
1250 const QString &filePath)
1251{
1252 LOG_MESSAGE(QString("=== Creating DiffInfo for file: %1 ===").arg(filePath));
1253
1254 DiffInfo diffInfo;
1255 diffInfo.originalContent = originalContent;
1256 diffInfo.modifiedContent = modifiedContent;
1257 diffInfo.contextLines = 3;
1258
1259 QStringList originalLines = originalContent.split('\n');
1260 QStringList modifiedLines = modifiedContent.split('\n');
1261
1262 LOG_MESSAGE(QString(" Original lines: %1, Modified lines: %2")
1263 .arg(originalLines.size()).arg(modifiedLines.size()));
1264
1265 int origLen = originalLines.size();
1266 int modLen = modifiedLines.size();
1267
1268 QVector<QVector<int>> lcs(origLen + 1, QVector<int>(modLen + 1, 0));
1269
1270 for (int i = 1; i <= origLen; ++i) {
1271 for (int j = 1; j <= modLen; ++j) {
1272 if (originalLines[i - 1] == modifiedLines[j - 1]) {
1273 lcs[i][j] = lcs[i - 1][j - 1] + 1;
1274 } else {
1275 lcs[i][j] = qMax(lcs[i - 1][j], lcs[i][j - 1]);
1276 }
1277 }
1278 }
1279
1280 LOG_MESSAGE(QString(" LCS computation complete. LCS length: %1").arg(lcs[origLen][modLen]));
1281
1282 QList<DiffHunk> hunks;
1283 DiffHunk currentHunk;
1284 bool inHunk = false;
1285
1286 int i = origLen;
1287 int j = modLen;
1288 int hunkCount = 0;
1289
1290 QList<QPair<int, int>> changes;
1291 while (i > 0 || j > 0) {
1292 if (i > 0 && j > 0 && originalLines[i - 1] == modifiedLines[j - 1]) {
1293 changes.prepend({i - 1, j - 1});
1294 i--;
1295 j--;
1296 } else if (j > 0 && (i == 0 || lcs[i][j - 1] >= lcs[i - 1][j])) {
1297 changes.prepend({-1, j - 1});
1298 j--;
1299 } else if (i > 0) {
1300 changes.prepend({i - 1, -1});
1301 i--;
1302 }
1303 }
1304

Callers

nothing calls this directly

Calls 3

sizeMethod · 0.80
appendMethod · 0.80
isEmptyMethod · 0.45

Tested by

no test coverage detected