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

Function createFileTree

apps/lib/commitfilesview.cpp:259–295  ·  view source on GitHub ↗

Copied from CompareBranchView in KateProject plugin

Source from the content-addressed store, hash-verified

257
258// Copied from CompareBranchView in KateProject plugin
259static void createFileTree(QStandardItem *parent, const QString &basePath, const std::vector<GitFileItem> &files)
260{
261 QDir dir(basePath);
262 const QString dirPath = dir.path() + u'/';
263 QHash<QString, QStandardItem *> dir2Item;
264 dir2Item[QString()] = parent;
265 for (const GitFileItem &file : files) {
266 const QString filePath = QString::fromUtf8(file.file);
267 /**
268 * cheap file name computation
269 * we do this A LOT, QFileInfo is very expensive just for this operation
270 */
271 const int slashIndex = filePath.lastIndexOf(u'/');
272 const QString fileName = (slashIndex < 0) ? filePath : filePath.mid(slashIndex + 1);
273 const QString filePathName = (slashIndex < 0) ? QString() : filePath.left(slashIndex);
274 const QString fullFilePath = dirPath + filePath;
275
276 /**
277 * construct the item with right directory prefix
278 * already hang in directories in tree
279 */
280 auto *fileItem = new FileItem(FileItem::File, fileName);
281 fileItem->setData(fullFilePath, FileItem::Path);
282 fileItem->setData(file.linesAdded, FileItem::LinesAdded);
283 fileItem->setData(file.linesRemoved, FileItem::LinesRemoved);
284 if (!file.oldFileName.isEmpty()) {
285 const auto oldFileName = QString::fromUtf8(file.oldFileName);
286 fileItem->setData(oldFileName, FileItem::OldPath);
287 fileItem->setData(filePath, FileItem::NewPath);
288 // we just show name here
289 fileItem->setText(QStringLiteral("%1 => %2").arg(oldFileName, fileName));
290 }
291
292 // put in our item to the right directory parent
293 directoryParent(dir, dir2Item, filePathName)->appendRow(fileItem);
294 }
295}
296
297static void parseNumStat(const QByteArray &raw, std::vector<GitFileItem> *items)
298{

Callers 1

Calls 6

directoryParentFunction · 0.85
setTextMethod · 0.80
QStringClass · 0.50
pathMethod · 0.45
setDataMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected