Git: Support non-recursive grep

Change-Id: Ib38239e28e8b24d993015e5568df02fe2a67f0e8
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
Orgad Shaneh
2019-03-17 08:31:42 +02:00
committed by Orgad Shaneh
parent d4565be655
commit feb2db61fc
2 changed files with 15 additions and 3 deletions

View File

@@ -44,6 +44,7 @@
#include <utils/synchronousprocess.h> #include <utils/synchronousprocess.h>
#include <utils/textfileformat.h> #include <utils/textfileformat.h>
#include <QCheckBox>
#include <QFuture> #include <QFuture>
#include <QFutureWatcher> #include <QFutureWatcher>
#include <QHBoxLayout> #include <QHBoxLayout>
@@ -59,6 +60,8 @@ class GitGrepParameters
{ {
public: public:
QString ref; QString ref;
bool recurseSubmodules = false;
QString id() const { return recurseSubmodules ? ref + ".Rec" : ref; }
}; };
using namespace Core; using namespace Core;
@@ -169,10 +172,10 @@ public:
arguments << "-P"; arguments << "-P";
else else
arguments << "-F"; arguments << "-F";
if (client->gitVersion() >= 0x021300)
arguments << "--recurse-submodules";
arguments << "-e" << m_parameters.text; arguments << "-e" << m_parameters.text;
GitGrepParameters params = m_parameters.searchEngineParameters.value<GitGrepParameters>(); GitGrepParameters params = m_parameters.searchEngineParameters.value<GitGrepParameters>();
if (params.recurseSubmodules)
arguments << "--recurse-submodules";
if (!params.ref.isEmpty()) { if (!params.ref.isEmpty()) {
arguments << params.ref; arguments << params.ref;
m_ref = params.ref + ':'; m_ref = params.ref + ':';
@@ -245,6 +248,10 @@ GitGrep::GitGrep(QObject *parent)
const QRegularExpression refExpression("[\\S]*"); const QRegularExpression refExpression("[\\S]*");
m_treeLineEdit->setValidator(new QRegularExpressionValidator(refExpression, this)); m_treeLineEdit->setValidator(new QRegularExpressionValidator(refExpression, this));
layout->addWidget(m_treeLineEdit); layout->addWidget(m_treeLineEdit);
if (GitPlugin::client()->gitVersion() >= 0x021300) {
m_recurseSubmodules = new QCheckBox(tr("Recurse submodules"));
layout->addWidget(m_recurseSubmodules);
}
TextEditor::FindInFiles *findInFiles = TextEditor::FindInFiles::instance(); TextEditor::FindInFiles *findInFiles = TextEditor::FindInFiles::instance();
QTC_ASSERT(findInFiles, return); QTC_ASSERT(findInFiles, return);
connect(findInFiles, &TextEditor::FindInFiles::pathChanged, connect(findInFiles, &TextEditor::FindInFiles::pathChanged,
@@ -282,6 +289,8 @@ QVariant GitGrep::parameters() const
{ {
GitGrepParameters params; GitGrepParameters params;
params.ref = m_treeLineEdit->text(); params.ref = m_treeLineEdit->text();
if (m_recurseSubmodules)
params.recurseSubmodules = m_recurseSubmodules->isChecked();
return qVariantFromValue(params); return qVariantFromValue(params);
} }
@@ -325,7 +334,7 @@ IEditor *GitGrep::openEditor(const SearchResultItem &item,
} }
const QString documentId = QLatin1String(Git::Constants::GIT_PLUGIN) const QString documentId = QLatin1String(Git::Constants::GIT_PLUGIN)
+ QLatin1String(".GitShow.") + params.ref + QLatin1String(".GitShow.") + params.id()
+ QLatin1String(".") + relativePath; + QLatin1String(".") + relativePath;
QString title = tr("Git Show %1:%2").arg(params.ref).arg(relativePath); QString title = tr("Git Show %1:%2").arg(params.ref).arg(relativePath);
IEditor *editor = EditorManager::openEditorWithContents(Id(), &title, content, documentId, IEditor *editor = EditorManager::openEditorWithContents(Id(), &title, content, documentId,

View File

@@ -29,6 +29,8 @@
#include <QCoreApplication> #include <QCoreApplication>
QT_FORWARD_DECLARE_CLASS(QCheckBox);
namespace Utils { class FancyLineEdit; } namespace Utils { class FancyLineEdit; }
namespace Git { namespace Git {
@@ -56,6 +58,7 @@ public:
private: private:
QWidget *m_widget; QWidget *m_widget;
Utils::FancyLineEdit *m_treeLineEdit; Utils::FancyLineEdit *m_treeLineEdit;
QCheckBox *m_recurseSubmodules = nullptr;
}; };
} // namespace Internal } // namespace Internal