Index: plugins/bazaar/bazaarplugin.h =================================================================== --- plugins/bazaar/bazaarplugin.h +++ plugins/bazaar/bazaarplugin.h @@ -50,7 +50,7 @@ KDevelop::VcsJob* copy(const QUrl& localLocationSrc, const QUrl& localLocationDstn) override; KDevelop::VcsImportMetadataWidget* createImportMetadataWidget(QWidget* parent) override; KDevelop::VcsJob* createWorkingCopy(const KDevelop::VcsLocation& sourceRepository, const QUrl& destinationDirectory, RecursionMode recursion=Recursive) override; - KDevelop::VcsJob* diff(const QUrl& fileOrDirectory, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision, KDevelop::VcsDiff::Type, RecursionMode recursion=Recursive) override; + KDevelop::VcsJob* diff(const QUrl& fileOrDirectory, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision, int contextLines=-1, KDevelop::VcsDiff::Type=KDevelop::VcsDiff::DiffUnified, RecursionMode recursion=Recursive) override; KDevelop::VcsJob* init(const QUrl& localRepositoryRoot) override; bool isVersionControlled(const QUrl& localLocation) override; KDevelop::VcsJob* log(const QUrl& localLocation, const KDevelop::VcsRevision& rev, long unsigned int limit) override; Index: plugins/bazaar/bazaarplugin.cpp =================================================================== --- plugins/bazaar/bazaarplugin.cpp +++ plugins/bazaar/bazaarplugin.cpp @@ -122,9 +122,11 @@ return job; } -VcsJob* BazaarPlugin::diff(const QUrl& fileOrDirectory, const VcsRevision& srcRevision, const VcsRevision& dstRevision, VcsDiff::Type, IBasicVersionControl::RecursionMode recursion) +VcsJob* BazaarPlugin::diff(const QUrl& fileOrDirectory, const VcsRevision& srcRevision, const VcsRevision& dstRevision, int contextLines, VcsDiff::Type, IBasicVersionControl::RecursionMode recursion) { Q_UNUSED(recursion); + // TODO support contextLines (less urgent because Phabricator doesn't support Bazaar) + Q_UNUSED(contextLines); VcsJob* job = new DiffJob(BazaarUtils::workingCopy(fileOrDirectory), BazaarUtils::getRevisionSpecRange(srcRevision, dstRevision), fileOrDirectory, this); return job; } Index: plugins/cvs/cvsplugin.h =================================================================== --- plugins/cvs/cvsplugin.h +++ plugins/cvs/cvsplugin.h @@ -75,7 +75,8 @@ KDevelop::VcsJob* diff(const QUrl& fileOrDirectory, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision, - KDevelop::VcsDiff::Type, + int contextLines=-1, + KDevelop::VcsDiff::Type=KDevelop::VcsDiff::DiffUnified, KDevelop::IBasicVersionControl::RecursionMode = KDevelop::IBasicVersionControl::Recursive) override; KDevelop::VcsJob* log(const QUrl& localLocation, const KDevelop::VcsRevision& rev, Index: plugins/cvs/cvsplugin.cpp =================================================================== --- plugins/cvs/cvsplugin.cpp +++ plugins/cvs/cvsplugin.cpp @@ -393,9 +393,10 @@ return job; } -KDevelop::VcsJob * CvsPlugin::diff(const QUrl & fileOrDirectory, const KDevelop::VcsRevision & srcRevision, const KDevelop::VcsRevision & dstRevision, KDevelop::VcsDiff::Type, KDevelop::IBasicVersionControl::RecursionMode) +KDevelop::VcsJob * CvsPlugin::diff(const QUrl & fileOrDirectory, const KDevelop::VcsRevision & srcRevision, const KDevelop::VcsRevision & dstRevision, int contextLines, KDevelop::VcsDiff::Type, KDevelop::IBasicVersionControl::RecursionMode) { - CvsJob* job = d->m_proxy->diff(fileOrDirectory, srcRevision, dstRevision, QStringLiteral("-uN")/*always unified*/); + QString options = contextLines > 0? QStringLiteral("-uN -context=%1").arg(contextLines) : QStringLiteral("-uN")/*always unified*/; + CvsJob* job = d->m_proxy->diff(fileOrDirectory, srcRevision, dstRevision, options); return job; } Index: plugins/git/gitplugin.h =================================================================== --- plugins/git/gitplugin.h +++ plugins/git/gitplugin.h @@ -106,7 +106,7 @@ KDevelop::IBasicVersionControl::RecursionMode recursion = KDevelop::IBasicVersionControl::Recursive) override; KDevelop::VcsJob* diff(const QUrl& fileOrDirectory, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision, - KDevelop::VcsDiff::Type, RecursionMode recursion) override; + int contextLines=-1, KDevelop::VcsDiff::Type=KDevelop::VcsDiff::DiffUnified, RecursionMode recursion=IBasicVersionControl::Recursive) override; KDevelop::VcsJob* log( const QUrl& localLocation, const KDevelop::VcsRevision& rev, unsigned long limit) override; KDevelop::VcsJob* log(const QUrl& localLocation, const KDevelop::VcsRevision& rev, const KDevelop::VcsRevision& limit) override; Index: plugins/git/gitplugin.cpp =================================================================== --- plugins/git/gitplugin.cpp +++ plugins/git/gitplugin.cpp @@ -371,18 +371,21 @@ } VcsJob* GitPlugin::diff(const QUrl& fileOrDirectory, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision, - VcsDiff::Type /*type*/, IBasicVersionControl::RecursionMode recursion) + int contextLines, VcsDiff::Type /*type*/, IBasicVersionControl::RecursionMode recursion) { //TODO: control different types DVcsJob* job = new GitJob(dotGitDirectory(fileOrDirectory), this, KDevelop::OutputJob::Silent); job->setType(VcsJob::Diff); - *job << "git" << "diff" << "--no-color" << "--no-ext-diff"; + *job << "git" << "diff" << "--no-color" << "--no-ext-diff" << "--full-index"; if (!usePrefix()) { // KDE's ReviewBoard now requires p1 patchfiles, so `git diff --no-prefix` to generate p0 patches // has become optional. *job << "--no-prefix"; } + if (contextLines > 0) { + *job << QStringLiteral("-U%1").arg(contextLines); + } if (dstRevision.revisionType() == VcsRevision::Special && dstRevision.specialType() == VcsRevision::Working) { if (srcRevision.revisionType() == VcsRevision::Special && Index: plugins/git/tests/test_git.cpp =================================================================== --- plugins/git/tests/test_git.cpp +++ plugins/git/tests/test_git.cpp @@ -574,7 +574,7 @@ VcsRevision srcrev = VcsRevision::createSpecialRevision(VcsRevision::Base); VcsRevision dstrev = VcsRevision::createSpecialRevision(VcsRevision::Working); - VcsJob* j = m_plugin->diff(QUrl::fromLocalFile(gitTest_BaseDir()), srcrev, dstrev, VcsDiff::DiffUnified, IBasicVersionControl::Recursive); + VcsJob* j = m_plugin->diff(QUrl::fromLocalFile(gitTest_BaseDir()), srcrev, dstrev, -1, VcsDiff::DiffUnified, IBasicVersionControl::Recursive); VERIFYJOB(j); KDevelop::VcsDiff d = j->fetchResults().value(); Index: plugins/patchreview/patchreview.h =================================================================== --- plugins/patchreview/patchreview.h +++ plugins/patchreview/patchreview.h @@ -100,6 +100,7 @@ void highlightPatch(); void updateKompareModel(); void forceUpdate(); + void forceUpdateWithContext(int contextLines); void areaChanged(Sublime::Area* area); void executeFileReviewAction(); Index: plugins/patchreview/patchreview.cpp =================================================================== --- plugins/patchreview/patchreview.cpp +++ plugins/patchreview/patchreview.cpp @@ -223,6 +223,14 @@ } } +void PatchReviewPlugin::forceUpdateWithContext(int contextLines) { + if( m_patch ) { + m_patch->update(contextLines); + + notifyPatchChanged(); + } +} + void PatchReviewPlugin::updateKompareModel() { if ( !m_patch ) { ///TODO: this method should be cleaned up, it can be called by the timer and Index: plugins/patchreview/patchreview.ui =================================================================== --- plugins/patchreview/patchreview.ui +++ plugins/patchreview/patchreview.ui @@ -72,6 +72,28 @@ + + + lines of context for the unified diff + + + max + + + + + + 0 + + + 999 + + + 3 + + + + Index: plugins/patchreview/patchreviewtoolview.cpp =================================================================== --- plugins/patchreview/patchreviewtoolview.cpp +++ plugins/patchreview/patchreviewtoolview.cpp @@ -126,6 +126,11 @@ } void PatchReviewToolView::patchChanged() { + if(m_resetCheckedUrls) { + // set the default number of context lines + m_editPatch.diffContext->setValue(3); + } + fillEditFromPatch(); kompareModelChanged(); @@ -251,6 +256,8 @@ //connect( this, SIGNAL(finished(int)), this, SLOT(slotEditDialogFinished(int)) ); connect( m_editPatch.updateButton, &QPushButton::clicked, m_plugin, &PatchReviewPlugin::forceUpdate ); + connect( m_editPatch.diffContext, static_cast(&QSpinBox::valueChanged), + m_plugin, &PatchReviewPlugin::forceUpdateWithContext ); connect( m_editPatch.testsButton, &QPushButton::clicked, this, &PatchReviewToolView::runTests ); Index: plugins/perforce/perforceplugin.h =================================================================== --- plugins/perforce/perforceplugin.h +++ plugins/perforce/perforceplugin.h @@ -88,6 +88,7 @@ KDevelop::VcsJob* diff(const QUrl& fileOrDirectory, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision, + int contextLines=-1, KDevelop::VcsDiff::Type = KDevelop::VcsDiff::DiffUnified, KDevelop::IBasicVersionControl::RecursionMode recursion = KDevelop::IBasicVersionControl::Recursive) override; Index: plugins/perforce/perforceplugin.cpp =================================================================== --- plugins/perforce/perforceplugin.cpp +++ plugins/perforce/perforceplugin.cpp @@ -309,7 +309,7 @@ return job; } -KDevelop::VcsJob* PerforcePlugin::diff(const QUrl& fileOrDirectory, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision, KDevelop::VcsDiff::Type , KDevelop::IBasicVersionControl::RecursionMode /*recursion*/) +KDevelop::VcsJob* PerforcePlugin::diff(const QUrl& fileOrDirectory, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision, int contextLines, KDevelop::VcsDiff::Type , KDevelop::IBasicVersionControl::RecursionMode /*recursion*/) { QFileInfo curFile(fileOrDirectory.toLocalFile()); QString depotSrcFileName = getRepositoryName(curFile); @@ -328,7 +328,11 @@ case VcsRevision::Special: switch (dstRevision.revisionValue().value()) { case VcsRevision::Working: - *job << m_perforceExecutable << "diff" << "-du" << depotSrcFileName; + if (contextLines > 0) { + *job << m_perforceExecutable << "diff" << "-dU" << QString::number(contextLines) << depotSrcFileName; + } else { + *job << m_perforceExecutable << "diff" << "-du" << depotSrcFileName; + } break; case VcsRevision::Start: case VcsRevision::UserSpecialType: Index: plugins/subversion/kdevsvnplugin.h =================================================================== --- plugins/subversion/kdevsvnplugin.h +++ plugins/subversion/kdevsvnplugin.h @@ -84,6 +84,7 @@ KDevelop::VcsJob* diff(const QUrl &fileOrDirectory, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision, + int contextLines=-1, KDevelop::VcsDiff::Type = KDevelop::VcsDiff::DiffUnified, KDevelop::IBasicVersionControl::RecursionMode recursion = KDevelop::IBasicVersionControl::Recursive) override; @@ -97,6 +98,7 @@ const KDevelop::VcsLocation& localOrRepoLocationDst, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision, + int contextLines, KDevelop::VcsDiff::Type = KDevelop::VcsDiff::DiffDontCare, KDevelop::IBasicVersionControl::RecursionMode = KDevelop::IBasicVersionControl::Recursive); @@ -154,6 +156,7 @@ QAction* copy_action; QAction* move_action; ThreadWeaver::Queue* m_jobQueue; + int m_contextLines=3; }; #endif Index: plugins/subversion/kdevsvnplugin.cpp =================================================================== --- plugins/subversion/kdevsvnplugin.cpp +++ plugins/subversion/kdevsvnplugin.cpp @@ -231,20 +231,24 @@ KDevelop::VcsJob* KDevSvnPlugin::diff(const QUrl &fileOrDirectory, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision, + int contextLines, KDevelop::VcsDiff::Type diffType, KDevelop::IBasicVersionControl::RecursionMode recurse) { KDevelop::VcsLocation loc(fileOrDirectory); - return diff2(loc, loc, srcRevision, dstRevision, diffType, recurse); + return diff2(loc, loc, srcRevision, dstRevision, contextLines, diffType, recurse); } KDevelop::VcsJob* KDevSvnPlugin::diff2(const KDevelop::VcsLocation& src, const KDevelop::VcsLocation& dst, const KDevelop::VcsRevision& srcRevision, const KDevelop::VcsRevision& dstRevision, + int contextLines, KDevelop::VcsDiff::Type diffType, KDevelop::IBasicVersionControl::RecursionMode recurse) { + // TODO: support custom context lines + Q_UNUSED(contextLines); SvnDiffJob* job = new SvnDiffJob(this); job->setSource(src); job->setDestination(dst); Index: vcs/interfaces/ibasicversioncontrol.h =================================================================== --- vcs/interfaces/ibasicversioncontrol.h +++ vcs/interfaces/ibasicversioncontrol.h @@ -194,6 +194,7 @@ virtual VcsJob* diff( const QUrl& fileOrDirectory, const VcsRevision& srcRevision, const VcsRevision& dstRevision, + int contextLines=-1, VcsDiff::Type = VcsDiff::DiffUnified, IBasicVersionControl::RecursionMode recursion = IBasicVersionControl::Recursive ) = 0; Index: vcs/interfaces/ipatchsource.h =================================================================== --- vcs/interfaces/ipatchsource.h +++ vcs/interfaces/ipatchsource.h @@ -48,6 +48,12 @@ ///should re-compare the files or whatever needs to be done ///If the patch has changed, patchChanged needs to be emitted virtual void update() = 0; + ///Explicit updating of the patch with a specific number of context lines. + ///The default implementation ignores the argument and calls update() + virtual void update(int contextLines) { + Q_UNUSED(contextLines); + update(); + } ///Name of the patch file virtual QUrl file() const = 0; Index: vcs/widgets/vcsdiffpatchsources.h =================================================================== --- vcs/widgets/vcsdiffpatchsources.h +++ vcs/widgets/vcsdiffpatchsources.h @@ -45,6 +45,13 @@ virtual KDevelop::VcsDiff update() const = 0; virtual KDevelop::IBasicVersionControl* vcs() const = 0; virtual QUrl url() const = 0; + void setContextLines(int n) + { + m_contextLines = n; + } + int contextLines() { return m_contextLines; } +protected: + int m_contextLines=-1; }; class KDEVPLATFORMVCS_EXPORT VCSStandardDiffUpdater : public VCSDiffUpdater { @@ -77,6 +84,7 @@ uint depth() const override ; void update() override ; + void update(int contextLines) override; bool isAlreadyApplied() const override { return true; } Index: vcs/widgets/vcsdiffpatchsources.cpp =================================================================== --- vcs/widgets/vcsdiffpatchsources.cpp +++ vcs/widgets/vcsdiffpatchsources.cpp @@ -210,6 +210,14 @@ updateFromDiff(m_updater->update()); } +void VCSDiffPatchSource::update(int contextLines) +{ + if (m_updater) { + m_updater->setContextLines(contextLines > 0? contextLines : INT_MAX); + updateFromDiff(m_updater->update()); + } +} + VCSCommitDiffPatchSource::~VCSCommitDiffPatchSource() { delete m_commitMessageWidget.data(); } @@ -297,7 +305,8 @@ { QScopedPointer diffJob(m_vcs->diff(m_url, KDevelop::VcsRevision::createSpecialRevision(KDevelop::VcsRevision::Base), - KDevelop::VcsRevision::createSpecialRevision(KDevelop::VcsRevision::Working))); + KDevelop::VcsRevision::createSpecialRevision(KDevelop::VcsRevision::Working), + m_contextLines)); const bool success = diffJob ? diffJob->exec() : false; if (!success) { KMessageBox::error(nullptr, i18n("Could not create a patch for the current version."));