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

Method applyDiff

apps/lib/diff/diffwidget.cpp:484–525  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

482}
483
484void DiffWidget::applyDiff(const QString &diff, ApplyFlags flags)
485{
486 // const QString diff = getDiff(v, flags & Hunk, flags & (Staged | Discard));
487 if (diff.isEmpty()) {
488 return;
489 }
490
491 auto *file = new QTemporaryFile(this);
492 if (!file->open()) {
493 // sendMessage(i18n("Failed to stage selection"), true);
494 return;
495 }
496 file->write(diff.toUtf8());
497 file->close();
498
499 Q_ASSERT(!m_params.workingDir.isEmpty());
500 auto *git = new QProcess(this);
501 QStringList args;
502 if (flags & Discard) {
503 args = QStringList{QStringLiteral("apply"), file->fileName()};
504 } else {
505 args = QStringList{QStringLiteral("apply"), QStringLiteral("--index"), QStringLiteral("--cached"), file->fileName()};
506 }
507 if (!setupGitProcess(*git, m_params.workingDir, args)) {
508 gitNotFoundMessage();
509 return;
510 }
511
512 connect(git, &QProcess::finished, this, [this, git, file](int exitCode, QProcess::ExitStatus es) {
513 if (es != QProcess::NormalExit || exitCode != 0) {
514 onError(git->readAllStandardError(), git->exitCode());
515 } else {
516 runGitDiff();
517 if (m_params.updateStatusCallback) {
518 m_params.updateStatusCallback();
519 }
520 }
521 delete file;
522 git->deleteLater();
523 });
524 startHostProcess(*git, QProcess::ReadOnly);
525}
526
527void DiffWidget::runGitDiff()
528{

Callers

nothing calls this directly

Calls 7

setupGitProcessFunction · 0.85
gitNotFoundMessageFunction · 0.85
startHostProcessFunction · 0.85
isEmptyMethod · 0.45
openMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected