MCPcopy Create free account
hub / github.com/KDE/kate / parseNumStat

Function parseNumStat

apps/lib/commitfilesview.cpp:297–351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

295}
296
297static void parseNumStat(const QByteArray &raw, std::vector<GitFileItem> *items)
298{
299 const auto splitter = ByteArraySplitter(raw, '\0');
300 for (auto it = splitter.begin(); it != splitter.end(); ++it) {
301 const auto line = *it;
302 // format: 12(adds)\t10(subs)\tFileName
303 auto lineSplitter = ByteArraySplitter(line, '\t');
304 const auto cols = lineSplitter.toContainer<QVarLengthArray<strview, 3>>();
305 if (cols.length() < 3) {
306 continue;
307 }
308
309 int add = 0;
310 int sub = 0;
311 if (cols[0] == "-") {
312 add = sub = 0;
313 } else {
314 auto col0 = cols[0].to<int>();
315 auto col1 = cols[1].to<int>();
316 if (!col0 || !col1) {
317 continue;
318 }
319 add = col0.value();
320 sub = col1.value();
321 }
322
323 if (cols[2].empty()) {
324 it++; // skip this
325 if (it == splitter.end()) {
326 qWarning() << "Unexpected EOF when parsing numstat";
327 break;
328 }
329 auto oldFileName = (*it).toByteArray().trimmed();
330 it++;
331 if (it == splitter.end()) {
332 qWarning() << "Unexpected EOF when parsing numstat";
333 break;
334 }
335 auto file = (*it).toByteArray().trimmed();
336 items->push_back(GitFileItem{
337 .oldFileName = oldFileName,
338 .file = file,
339 .linesAdded = add,
340 .linesRemoved = sub,
341 });
342 } else {
343 items->push_back(GitFileItem{
344 .oldFileName = {},
345 .file = cols[2].toByteArray(),
346 .linesAdded = add,
347 .linesRemoved = sub,
348 });
349 }
350 }
351}
352
353class CommitDiffTreeView : public QWidget
354{

Callers 1

Calls 6

ByteArraySplitterClass · 0.85
valueMethod · 0.80
emptyMethod · 0.80
toByteArrayMethod · 0.80
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected