MCPcopy Create free account
hub / github.com/KDE/kdevelop / parseGitLogOutput

Method parseGitLogOutput

plugins/git/gitplugin.cpp:1283–1351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1281}
1282
1283void GitPlugin::parseGitLogOutput(DVcsJob * job)
1284{
1285 static QRegExp commitRegex(QStringLiteral("^commit (\\w{8})\\w{32}"));
1286 static QRegExp infoRegex(QStringLiteral("^(\\w+):(.*)"));
1287 static QRegExp modificationsRegex(QStringLiteral("^([A-Z])[0-9]*\t([^\t]+)\t?(.*)"), Qt::CaseSensitive, QRegExp::RegExp2);
1288 //R099 plugins/git/kdevgit.desktop plugins/git/kdevgit.desktop.cmake
1289 //M plugins/grepview/CMakeLists.txt
1290
1291 QList<QVariant> commits;
1292
1293 QString contents = job->output();
1294 // check if git-log returned anything
1295 if (contents.isEmpty()) {
1296 job->setResults(commits); // empty list
1297 return;
1298 }
1299
1300 // start parsing the output
1301 QTextStream s(&contents);
1302
1303 VcsEvent item;
1304 QString message;
1305 bool pushCommit = false;
1306
1307 while (!s.atEnd()) {
1308 const auto line = s.readLine();
1309
1310 if (commitRegex.exactMatch(line)) {
1311 if (pushCommit) {
1312 item.setMessage(message.trimmed());
1313 commits.append(QVariant::fromValue(item));
1314 item.setItems(QList<VcsItemEvent>());
1315 } else {
1316 pushCommit = true;
1317 }
1318 VcsRevision rev;
1319 rev.setRevisionValue(commitRegex.cap(1), KDevelop::VcsRevision::GlobalNumber);
1320 item.setRevision(rev);
1321 message.clear();
1322 } else if (infoRegex.exactMatch(line)) {
1323 QString cap1 = infoRegex.cap(1);
1324 if (cap1 == QLatin1String("Author")) {
1325 item.setAuthor(infoRegex.cap(2).trimmed());
1326 } else if (cap1 == QLatin1String("Date")) {
1327 item.setDate(QDateTime::fromSecsSinceEpoch(
1328 infoRegex.cap(2).trimmed().split(QLatin1Char(' '))[0].toUInt(), QTimeZone::LocalTime));
1329 }
1330 } else if (modificationsRegex.exactMatch(line)) {
1331 VcsItemEvent::Actions a = actionsFromString(modificationsRegex.cap(1).at(0).toLatin1());
1332 QString filenameA = modificationsRegex.cap(2);
1333
1334 VcsItemEvent itemEvent;
1335 itemEvent.setActions(a);
1336 itemEvent.setRepositoryLocation(filenameA);
1337 if(a==VcsItemEvent::Replaced) {
1338 QString filenameB = modificationsRegex.cap(3);
1339 itemEvent.setRepositoryCopySourceLocation(filenameB);
1340 }

Callers

nothing calls this directly

Calls 15

outputMethod · 0.80
setResultsMethod · 0.80
atEndMethod · 0.80
readLineMethod · 0.80
setRevisionValueMethod · 0.80
setActionsMethod · 0.80
setRepositoryLocationMethod · 0.80
actionsFromStringFunction · 0.70
isEmptyMethod · 0.45
setMessageMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected