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

Function repairDiff

plugins/subversion/svndiffjob.cpp:31–68  ·  view source on GitHub ↗

@todo The subversion library returns borked diffs, where the headers are at the end. This function takes those headers, and moves them into the correct place to create a valid working diff. Find the source of this problem.

Source from the content-addressed store, hash-verified

29/// takes those headers, and moves them into the correct place to create a valid working diff.
30/// Find the source of this problem.
31QString repairDiff(const QString& diff) {
32 qCDebug(PLUGIN_SVN) << "diff before repair:" << diff;
33 QStringList lines = diff.split(QLatin1Char('\n'));
34 QMap<QString, QString> headers;
35 for(int a = 0; a < lines.size()-1; ++a) {
36 const QLatin1String indexLineBegin("Index: ");
37 if (lines.at(a).startsWith(indexLineBegin) && lines.at(a + 1).startsWith(QLatin1String("====="))) {
38 const auto fileName = QStringView{lines.at(a)}.sliced(indexLineBegin.size()).trimmed().toString();
39 headers[fileName] = lines.at(a);
40 qCDebug(PLUGIN_SVN) << "found header for" << fileName;
41 lines[a] = QString();
42 if (lines.at(a + 1).startsWith(QLatin1String("======"))) {
43 headers[fileName] += QLatin1Char('\n') + lines.at(a + 1);
44 lines[a + 1] = QString();
45 }
46 }
47 }
48
49 static const QRegularExpression whitespaceRegex(QStringLiteral("\\s"));
50 for(int a = 0; a < lines.size()-1; ++a) {
51 const QLatin1String threeDashLineBegin("--- ");
52 if (lines.at(a).startsWith(threeDashLineBegin)) {
53 const auto tail = lines.at(a).mid(threeDashLineBegin.size());
54 if (const auto whitespaceIndex = tail.indexOf(whitespaceRegex); whitespaceIndex != -1) {
55 const auto file = tail.left(whitespaceIndex);
56 qCDebug(PLUGIN_SVN) << "checking for" << file;
57 const auto headerIt = headers.constFind(file);
58 if (headerIt != headers.constEnd()) {
59 qCDebug(PLUGIN_SVN) << "adding header for" << file << ":" << *headerIt;
60 lines[a] = *headerIt + QLatin1Char('\n') + lines.at(a);
61 }
62 }
63 }
64 }
65 QString ret = lines.join(QLatin1Char('\n'));
66 qCDebug(PLUGIN_SVN) << "repaired diff:" << ret;
67 return ret;
68}
69
70} // unnamed namespace
71

Callers 1

runMethod · 0.85

Calls 10

midMethod · 0.80
constEndMethod · 0.80
joinMethod · 0.80
QStringClass · 0.50
splitMethod · 0.45
sizeMethod · 0.45
atMethod · 0.45
toStringMethod · 0.45
indexOfMethod · 0.45
constFindMethod · 0.45

Tested by

no test coverage detected