Changeset View
Changeset View
Standalone View
Standalone View
vcs/dvcs/ui/branchmanager.cpp
Show First 20 Lines • Show All 188 Lines • ▼ Show 20 Line(s) | 186 | } else { | |||
---|---|---|---|---|---|
189 | close(); | 189 | close(); | ||
190 | } | 190 | } | ||
191 | } else { | 191 | } else { | ||
192 | KMessageBox::messageBox(this, KMessageBox::Error, | 192 | KMessageBox::messageBox(this, KMessageBox::Error, | ||
193 | i18n("You must select a branch to merge into current one from the list.")); | 193 | i18n("You must select a branch to merge into current one from the list.")); | ||
194 | } | 194 | } | ||
195 | } | 195 | } | ||
196 | 196 | | |||
197 | // adapted from VCSStandardDiffUpdater | ||||
198 | class VCSBranchDiffUpdater : public VCSDiffUpdater { | ||||
199 | public: | ||||
200 | VCSBranchDiffUpdater(const QString& repo, const QString& src, KDevelop::DistributedVersionControlPlugin* vcs); | ||||
201 | ~VCSBranchDiffUpdater() override; | ||||
202 | KDevelop::VcsDiff update() const override; | ||||
203 | KDevelop::IBasicVersionControl* vcs() const override { return m_vcs; } | ||||
204 | QUrl url() const override { return QUrl::fromLocalFile(m_repository); } | ||||
205 | private: | ||||
206 | const QString m_repository; | ||||
207 | const QString m_src; | ||||
208 | KDevelop::DistributedVersionControlPlugin* m_vcs; | ||||
209 | }; | ||||
210 | | ||||
211 | VCSBranchDiffUpdater::VCSBranchDiffUpdater(const QString& repo, const QString& src, | ||||
212 | KDevelop::DistributedVersionControlPlugin* vcs) | ||||
213 | : m_repository(repo) | ||||
214 | , m_src(src) | ||||
215 | , m_vcs(vcs) | ||||
216 | { | ||||
217 | } | ||||
218 | | ||||
219 | VCSBranchDiffUpdater::~VCSBranchDiffUpdater() { | ||||
220 | } | ||||
221 | | ||||
222 | VcsDiff VCSBranchDiffUpdater::update() const | ||||
223 | { | ||||
224 | VcsRevision srcRev; | ||||
225 | srcRev.setRevisionValue(m_src, KDevelop::VcsRevision::GlobalNumber); | ||||
226 | // see comment in BranchManager::diffFromBranch() | ||||
227 | const auto destRev = VcsRevision::createSpecialRevision(KDevelop::VcsRevision::Working); | ||||
228 | QScopedPointer<VcsJob> diffJob(m_vcs->diff(QUrl::fromLocalFile(m_repository), srcRev, destRev)); | ||||
229 | const bool success = diffJob ? diffJob->exec() : false; | ||||
230 | if (!success) { | ||||
231 | KMessageBox::error(nullptr, i18n("Could not create a patch for the current version.")); | ||||
232 | return {}; | ||||
233 | } | ||||
234 | | ||||
235 | return diffJob->fetchResults().value<VcsDiff>(); | ||||
236 | } | ||||
237 | | ||||
197 | void BranchManager::diffFromBranch() | 238 | void BranchManager::diffFromBranch() | ||
198 | { | 239 | { | ||
199 | const auto dest = m_model->currentBranch(); | 240 | const auto dest = m_model->currentBranch(); | ||
200 | const auto src = m_ui->branchView->currentIndex().data().toString(); | 241 | const auto src = m_ui->branchView->currentIndex().data().toString(); | ||
201 | if (src == dest) { | 242 | if (src == dest) { | ||
202 | KMessageBox::messageBox(this, KMessageBox::Information, i18n("Already on branch \"%1\"\n", src)); | 243 | KMessageBox::messageBox(this, KMessageBox::Information, i18n("Already on branch \"%1\"\n", src)); | ||
203 | return; | 244 | return; | ||
204 | } | 245 | } | ||
Show All 24 Lines | 260 | { | |||
229 | auto diff = vcsjob->fetchResults().value<KDevelop::VcsDiff>(); | 270 | auto diff = vcsjob->fetchResults().value<KDevelop::VcsDiff>(); | ||
230 | if(diff.isEmpty()){ | 271 | if(diff.isEmpty()){ | ||
231 | KMessageBox::information(ICore::self()->uiController()->activeMainWindow(), | 272 | KMessageBox::information(ICore::self()->uiController()->activeMainWindow(), | ||
232 | i18n("There are no committed differences."), | 273 | i18n("There are no committed differences."), | ||
233 | i18n("VCS support")); | 274 | i18n("VCS support")); | ||
234 | return; | 275 | return; | ||
235 | } | 276 | } | ||
236 | 277 | | |||
237 | auto patch = new VCSDiffPatchSource(diff); | 278 | auto patch = new VCSDiffPatchSource(new VCSBranchDiffUpdater(m_repository, | ||
279 | m_ui->branchView->currentIndex().data().toString(), m_dvcPlugin)); | ||||
238 | showVcsDiff(patch); | 280 | showVcsDiff(patch); | ||
239 | close(); | 281 | close(); | ||
240 | } | 282 | } |