diff --git a/plugins/patchreview/patchreview.cpp b/plugins/patchreview/patchreview.cpp --- a/plugins/patchreview/patchreview.cpp +++ b/plugins/patchreview/patchreview.cpp @@ -217,9 +217,12 @@ void PatchReviewPlugin::forceUpdate() { if( m_patch ) { - m_patch->update(); - - notifyPatchChanged(); + // don't trigger an update if we know the plugin cannot update itself + VCSDiffPatchSource *vcsPatch = dynamic_cast(m_patch.data()); + if (!vcsPatch || vcsPatch->m_updater) { + m_patch->update(); + notifyPatchChanged(); + } } } diff --git a/vcs/dvcs/ui/branchmanager.cpp b/vcs/dvcs/ui/branchmanager.cpp --- a/vcs/dvcs/ui/branchmanager.cpp +++ b/vcs/dvcs/ui/branchmanager.cpp @@ -194,6 +194,47 @@ } } +// adapted from VCSStandardDiffUpdater +class VCSBranchDiffUpdater : public VCSDiffUpdater { +public: + VCSBranchDiffUpdater(const QString& repo, const QString& src, KDevelop::DistributedVersionControlPlugin* vcs); + ~VCSBranchDiffUpdater() override; + KDevelop::VcsDiff update() const override; + KDevelop::IBasicVersionControl* vcs() const override { return m_vcs; } + QUrl url() const override { return QUrl::fromLocalFile(m_repository); } +private: + const QString m_repository; + const QString m_src; + KDevelop::DistributedVersionControlPlugin* m_vcs; +}; + +VCSBranchDiffUpdater::VCSBranchDiffUpdater(const QString& repo, const QString& src, + KDevelop::DistributedVersionControlPlugin* vcs) + : m_repository(repo) + , m_src(src) + , m_vcs(vcs) +{ +} + +VCSBranchDiffUpdater::~VCSBranchDiffUpdater() { +} + +VcsDiff VCSBranchDiffUpdater::update() const +{ + VcsRevision srcRev; + srcRev.setRevisionValue(m_src, KDevelop::VcsRevision::GlobalNumber); + // see comment in BranchManager::diffFromBranch() + const auto destRev = VcsRevision::createSpecialRevision(KDevelop::VcsRevision::Working); + QScopedPointer diffJob(m_vcs->diff(QUrl::fromLocalFile(m_repository), srcRev, destRev)); + const bool success = diffJob ? diffJob->exec() : false; + if (!success) { + KMessageBox::error(nullptr, i18n("Could not create a patch for the current version.")); + return {}; + } + + return diffJob->fetchResults().value(); +} + void BranchManager::diffFromBranch() { const auto dest = m_model->currentBranch(); @@ -234,7 +275,8 @@ return; } - auto patch = new VCSDiffPatchSource(diff); + auto patch = new VCSDiffPatchSource(new VCSBranchDiffUpdater(m_repository, + m_ui->branchView->currentIndex().data().toString(), m_dvcPlugin)); showVcsDiff(patch); close(); }