Commit b4195d51 authored by Tobias Hunger's avatar Tobias Hunger

Git: Modernize

* pragma once
* member initialization
* s/struct/class/
* Introduce a static GitPlugin::client() method and use it

Change-Id: Ifdcac86dd16f3cdba11d564d03e9a15f00a6afdb
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent 7db0023e
......@@ -23,8 +23,7 @@
**
****************************************************************************/
#ifndef ANNOTATIONHIGHLIGHTER_H
#define ANNOTATIONHIGHLIGHTER_H
#pragma once
#include <vcsbase/baseannotationhighlighter.h>
......@@ -47,5 +46,3 @@ private:
} // namespace Internal
} // namespace Git
#endif // ANNOTATIONHIGHLIGHTER_H
......@@ -23,8 +23,7 @@
**
****************************************************************************/
#ifndef BRANCHADDDIALOG_H
#define BRANCHADDDIALOG_H
#pragma once
#include <QDialog>
......@@ -40,7 +39,7 @@ class BranchAddDialog : public QDialog
public:
BranchAddDialog(const QStringList &localBranches, bool addBranch, QWidget *parent);
~BranchAddDialog();
~BranchAddDialog() override;
void setBranchName(const QString &);
QString branchName() const;
......@@ -57,5 +56,3 @@ private:
} // namespace Internal
} // namespace Git
#endif // BRANCHADDDIALOG_H
......@@ -23,8 +23,7 @@
**
****************************************************************************/
#ifndef BRANCHCHECKOUTDIALOG_H
#define BRANCHCHECKOUTDIALOG_H
#pragma once
#include <QDialog>
......@@ -40,7 +39,7 @@ class BranchCheckoutDialog : public QDialog
public:
explicit BranchCheckoutDialog(QWidget *parent, const QString &currentBranch,
const QString &nextBranch);
~BranchCheckoutDialog();
~BranchCheckoutDialog() override;
void foundNoLocalChanges();
void foundStashForNextBranch();
......@@ -63,5 +62,3 @@ private:
} // namespace Internal
} // namespace Git
#endif // BRANCHCHECKOUTDIALOG_H
......@@ -54,7 +54,7 @@ namespace Internal {
BranchDialog::BranchDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::BranchDialog),
m_model(new BranchModel(GitPlugin::instance()->client(), this))
m_model(new BranchModel(GitPlugin::client(), this))
{
setModal(false);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
......@@ -192,13 +192,13 @@ void BranchDialog::checkout()
QLatin1Char(' ') + nextBranch + QLatin1String("-AutoStash ");
BranchCheckoutDialog branchCheckoutDialog(this, currentBranch, nextBranch);
GitClient *gitClient = GitPlugin::instance()->client();
GitClient *client = GitPlugin::client();
if (gitClient->gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules)) != GitClient::StatusChanged)
if (client->gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules)) != GitClient::StatusChanged)
branchCheckoutDialog.foundNoLocalChanges();
QList<Stash> stashes;
gitClient->synchronousStashList(m_repository, &stashes);
client->synchronousStashList(m_repository, &stashes);
foreach (const Stash &stash, stashes) {
if (stash.message.startsWith(popMessageStart)) {
branchCheckoutDialog.foundStashForNextBranch();
......@@ -213,22 +213,22 @@ void BranchDialog::checkout()
} else if (branchCheckoutDialog.exec() == QDialog::Accepted) {
if (branchCheckoutDialog.makeStashOfCurrentBranch()) {
if (gitClient->synchronousStash(m_repository,
if (client->synchronousStash(m_repository,
currentBranch + QLatin1String("-AutoStash")).isEmpty()) {
return;
}
} else if (branchCheckoutDialog.moveLocalChangesToNextBranch()) {
if (!gitClient->beginStashScope(m_repository, QLatin1String("Checkout"), NoPrompt))
if (!client->beginStashScope(m_repository, QLatin1String("Checkout"), NoPrompt))
return;
} else if (branchCheckoutDialog.discardLocalChanges()) {
if (!gitClient->synchronousReset(m_repository))
if (!client->synchronousReset(m_repository))
return;
}
m_model->checkoutBranch(idx);
QString stashName;
gitClient->synchronousStashList(m_repository, &stashes);
client->synchronousStashList(m_repository, &stashes);
foreach (const Stash &stash, stashes) {
if (stash.message.startsWith(popMessageStart)) {
stashName = stash.name;
......@@ -237,9 +237,9 @@ void BranchDialog::checkout()
}
if (branchCheckoutDialog.moveLocalChangesToNextBranch())
gitClient->endStashScope(m_repository);
client->endStashScope(m_repository);
else if (branchCheckoutDialog.popStashOfNextBranch())
gitClient->synchronousStashRestore(m_repository, stashName, true);
client->synchronousStashRestore(m_repository, stashName, true);
}
enableButtons();
}
......@@ -311,7 +311,7 @@ void BranchDialog::diff()
QString fullName = m_model->fullName(selectedIndex(), true);
if (fullName.isEmpty())
return;
GitPlugin::instance()->client()->diffBranch(m_repository, fullName);
GitPlugin::client()->diffBranch(m_repository, fullName);
}
void BranchDialog::log()
......@@ -319,7 +319,7 @@ void BranchDialog::log()
QString branchName = m_model->fullName(selectedIndex(), true);
if (branchName.isEmpty())
return;
GitPlugin::instance()->client()->log(m_repository, QString(), false, QStringList(branchName));
GitPlugin::client()->log(m_repository, QString(), false, QStringList(branchName));
}
void BranchDialog::reset()
......@@ -332,7 +332,7 @@ void BranchDialog::reset()
if (QMessageBox::question(this, tr("Git Reset"), tr("Hard reset branch \"%1\" to \"%2\"?")
.arg(currentName).arg(branchName),
QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) {
GitPlugin::instance()->client()->reset(m_repository, QLatin1String("--hard"), branchName);
GitPlugin::client()->reset(m_repository, QLatin1String("--hard"), branchName);
}
}
......@@ -344,7 +344,7 @@ void BranchDialog::merge()
QTC_CHECK(idx != m_model->currentBranch()); // otherwise the button would not be enabled!
const QString branch = m_model->fullName(idx, true);
GitClient *client = GitPlugin::instance()->client();
GitClient *client = GitPlugin::client();
bool allowFastForward = true;
if (client->isFastForwardMerge(m_repository, branch)) {
QMenu popup;
......@@ -367,7 +367,7 @@ void BranchDialog::rebase()
QTC_CHECK(idx != m_model->currentBranch()); // otherwise the button would not be enabled!
const QString baseBranch = m_model->fullName(idx, true);
GitClient *client = GitPlugin::instance()->client();
GitClient *client = GitPlugin::client();
if (client->beginStashScope(m_repository, QLatin1String("rebase")))
client->rebase(m_repository, baseBranch);
}
......@@ -380,7 +380,7 @@ void BranchDialog::cherryPick()
QTC_CHECK(idx != m_model->currentBranch()); // otherwise the button would not be enabled!
const QString branch = m_model->fullName(idx, true);
GitPlugin::instance()->client()->synchronousCherryPick(m_repository, branch);
GitPlugin::client()->synchronousCherryPick(m_repository, branch);
}
void BranchDialog::setRemoteTracking()
......
......@@ -23,8 +23,7 @@
**
****************************************************************************/
#ifndef BRANCHDIALOG_H
#define BRANCHDIALOG_H
#pragma once
#include <QDialog>
......@@ -51,7 +50,7 @@ class BranchDialog : public QDialog
public:
explicit BranchDialog(QWidget *parent = 0);
~BranchDialog();
~BranchDialog() override;
public slots:
void refresh(const QString &repository, bool force);
......@@ -81,5 +80,3 @@ private:
} // namespace Internal
} // namespace Git
#endif // BRANCHDIALOG_H
......@@ -193,8 +193,7 @@ public:
BranchModel::BranchModel(GitClient *client, QObject *parent) :
QAbstractItemModel(parent),
m_client(client),
m_rootNode(new BranchNode),
m_currentBranch(0)
m_rootNode(new BranchNode)
{
QTC_CHECK(m_client);
......
......@@ -23,8 +23,7 @@
**
****************************************************************************/
#ifndef BRANCHMODEL_H
#define BRANCHMODEL_H
#pragma once
#include <QAbstractListModel>
#include <QVariant>
......@@ -44,8 +43,8 @@ class BranchModel : public QAbstractItemModel {
Q_OBJECT
public:
explicit BranchModel(GitClient *client, QObject *parent = 0);
~BranchModel();
explicit BranchModel(GitClient *client, QObject *parent = nullptr);
~BranchModel() override;
// QAbstractItemModel
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
......@@ -93,11 +92,9 @@ private:
GitClient *m_client;
QString m_workingDirectory;
BranchNode *m_rootNode;
BranchNode *m_currentBranch;
BranchNode *m_currentBranch = nullptr;
QString m_currentSha;
};
} // namespace Internal
} // namespace Git
#endif // BRANCHMODEL_H
......@@ -52,19 +52,17 @@ using namespace Utils;
namespace Git {
namespace Internal {
ChangeSelectionDialog::ChangeSelectionDialog(const QString &workingDirectory, Core::Id id, QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::ChangeSelectionDialog)
, m_process(0)
, m_command(NoCommand)
ChangeSelectionDialog::ChangeSelectionDialog(const QString &workingDirectory, Core::Id id,
QWidget *parent) :
QDialog(parent), m_ui(new Ui::ChangeSelectionDialog)
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
m_gitExecutable = GitPlugin::instance()->client()->vcsBinary();
m_gitExecutable = GitPlugin::client()->vcsBinary();
m_ui->setupUi(this);
m_ui->workingDirectoryChooser->setExpectedKind(PathChooser::ExistingDirectory);
m_ui->workingDirectoryChooser->setPromptDialogTitle(tr("Select Git Directory"));
m_ui->workingDirectoryChooser->setPath(workingDirectory);
m_gitEnvironment = GitPlugin::instance()->client()->processEnvironment();
m_gitEnvironment = GitPlugin::client()->processEnvironment();
m_ui->changeNumberEdit->setFocus();
m_ui->changeNumberEdit->selectAll();
......@@ -216,7 +214,7 @@ void ChangeSelectionDialog::recalculateCompletion()
m_oldWorkingDir = workingDir;
if (!workingDir.isEmpty()) {
GitClient *client = GitPlugin::instance()->client();
GitClient *client = GitPlugin::client();
QStringList args;
args << QLatin1String("--format=%(refname:short)");
QString output;
......
......@@ -23,8 +23,7 @@
**
****************************************************************************/
#ifndef CHANGESELECTIONDIALOG_H
#define CHANGESELECTIONDIALOG_H
#pragma once
#include <coreplugin/id.h>
......@@ -60,7 +59,7 @@ class ChangeSelectionDialog : public QDialog
Q_OBJECT
public:
ChangeSelectionDialog(const QString &workingDirectory, Core::Id id, QWidget *parent);
~ChangeSelectionDialog();
~ChangeSelectionDialog() override;
QString change() const;
......@@ -83,15 +82,13 @@ private:
Ui::ChangeSelectionDialog *m_ui;
QProcess *m_process;
QProcess *m_process = nullptr;
Utils::FileName m_gitExecutable;
QProcessEnvironment m_gitEnvironment;
ChangeCommand m_command;
QStringListModel *m_changeModel;
ChangeCommand m_command = NoCommand;
QStringListModel *m_changeModel = nullptr;
QString m_oldWorkingDir;
};
} // namespace Internal
} // namespace Git
#endif // CHANGESELECTIONDIALOG_H
......@@ -28,7 +28,6 @@
#include <utils/qtcassert.h>
#include <QCoreApplication>
#include <QDebug>
namespace Git {
namespace Internal {
......@@ -39,12 +38,6 @@ void GitSubmitEditorPanelInfo::clear()
branch.clear();
}
QDebug operator<<(QDebug d, const GitSubmitEditorPanelInfo &data)
{
d.nospace() << "Rep: " << data.repository << " branch: " << data.branch;
return d;
}
void GitSubmitEditorPanelData::clear()
{
author.clear();
......@@ -67,14 +60,6 @@ QString GitSubmitEditorPanelData::authorString() const
return rc;
}
QDebug operator<<(QDebug d, const GitSubmitEditorPanelData &data)
{
d.nospace() << " author:" << data.author << " email: " << data.email
<< " bypass hooks: " << data.bypassHooks
<< " action after commit " << data.pushAction;
return d;
}
CommitData::CommitData(CommitType type)
: commitType(type)
, commitEncoding(0)
......
......@@ -23,39 +23,34 @@
**
****************************************************************************/
#ifndef COMMITDATA_H
#define COMMITDATA_H
#pragma once
#include "gitsettings.h" // CommitType
#include <QStringList>
#include <QPair>
QT_BEGIN_NAMESPACE
class QDebug;
QT_END_NAMESPACE
namespace Git {
namespace Internal {
// Read-only
struct GitSubmitEditorPanelInfo
class GitSubmitEditorPanelInfo
{
public:
void clear();
QString repository;
QString branch;
};
QDebug operator<<(QDebug d, const GitSubmitEditorPanelInfo &);
enum PushAction {
NoPush,
NormalPush,
PushToGerrit
};
struct GitSubmitEditorPanelData
class GitSubmitEditorPanelData
{
public:
void clear();
// Format as "John Doe <jdoe@foobar.com>"
QString authorString() const;
......@@ -66,8 +61,6 @@ struct GitSubmitEditorPanelData
PushAction pushAction;
};
QDebug operator<<(QDebug d, const GitSubmitEditorPanelData &);
enum FileState {
EmptyFileState = 0x00,
......@@ -132,5 +125,3 @@ bool operator<(const CommitData::StateFilePair &a,
} // namespace Internal
} // namespace Git
#endif // COMMITDATA_H
......@@ -30,17 +30,13 @@
using namespace Git::Internal;
using namespace Gerrit::Internal;
BranchComboBox::BranchComboBox(QWidget *parent) :
QComboBox(parent),
m_detached(false)
{
m_client = GitPlugin::instance()->client();
}
BranchComboBox::BranchComboBox(QWidget *parent) : QComboBox(parent)
{ }
void BranchComboBox::init(const QString &repository)
{
m_repository = repository;
QString currentBranch = m_client->synchronousCurrentLocalBranch(repository);
QString currentBranch = GitPlugin::client()->synchronousCurrentLocalBranch(repository);
if (currentBranch.isEmpty()) {
m_detached = true;
currentBranch = QLatin1String("HEAD");
......@@ -50,7 +46,7 @@ void BranchComboBox::init(const QString &repository)
const QString branchPrefix(QLatin1String("refs/heads/"));
QStringList args;
args << QLatin1String("--format=%(refname)") << branchPrefix;
if (!m_client->synchronousForEachRefCmd(m_repository, args, &output))
if (!GitPlugin::client()->synchronousForEachRefCmd(m_repository, args, &output))
return;
QStringList branches = output.trimmed().split(QLatin1Char('\n'));
foreach (const QString &ref, branches) {
......
......@@ -38,13 +38,12 @@ namespace Internal {
class BranchComboBox : public QComboBox
{
public:
BranchComboBox(QWidget *parent = 0);
explicit BranchComboBox(QWidget *parent = nullptr);
void init(const QString &repository);
private:
Git::Internal::GitClient *m_client;
QString m_repository;
bool m_detached;
bool m_detached = false;
};
} // namespace Internal
......
......@@ -272,8 +272,7 @@ QueryContext::QueryContext(const QStringList &queries,
this, &QueryContext::processError);
connect(&m_watcher, &QFutureWatcherBase::canceled, this, &QueryContext::terminate);
m_watcher.setFuture(m_progress.future());
m_process.setProcessEnvironment(Git::Internal::GitPlugin::instance()->
client()->processEnvironment());
m_process.setProcessEnvironment(Git::Internal::GitPlugin::client()->processEnvironment());
m_progress.setProgressRange(0, m_queries.size());
// Determine binary and common command line arguments.
......
......@@ -84,11 +84,6 @@ enum FetchMode
FetchCheckout
};
static inline GitClient *gitClient()
{
return GitPlugin::instance()->client();
}
/* FetchContext: Retrieves the patch and displays
* or applies it as desired. Does deleteLater() once it is done. */
......@@ -158,7 +153,7 @@ FetchContext::FetchContext(const QSharedPointer<GerritChange> &change,
connect(&m_watcher, &QFutureWatcher<void>::canceled, this, &FetchContext::terminate);
m_watcher.setFuture(m_progress.future());
m_process.setWorkingDirectory(repository);
m_process.setProcessEnvironment(gitClient()->processEnvironment());
m_process.setProcessEnvironment(GitPlugin::client()->processEnvironment());
m_process.closeWriteChannel();
}
......@@ -250,7 +245,7 @@ void FetchContext::show()
{
const QString title = QString::number(m_change->number) + QLatin1Char('/')
+ QString::number(m_change->currentPatchSet.patchSetNumber);
gitClient()->show(m_repository, QLatin1String("FETCH_HEAD"), title);
GitPlugin::client()->show(m_repository, QLatin1String("FETCH_HEAD"), title);
}
void FetchContext::cherryPick()
......@@ -258,12 +253,12 @@ void FetchContext::cherryPick()
// Point user to errors.
VcsBase::VcsOutputWindow::instance()->popup(IOutputPane::ModeSwitch
| IOutputPane::WithFocus);
gitClient()->synchronousCherryPick(m_repository, QLatin1String("FETCH_HEAD"));
GitPlugin::client()->synchronousCherryPick(m_repository, QLatin1String("FETCH_HEAD"));
}
void FetchContext::checkout()
{
gitClient()->stashAndCheckout(m_repository, QLatin1String("FETCH_HEAD"));
GitPlugin::client()->stashAndCheckout(m_repository, QLatin1String("FETCH_HEAD"));
}
void FetchContext::terminate()
......@@ -355,7 +350,7 @@ void GerritPlugin::push(const QString &topLevel)
args << target;
gitClient()->push(topLevel, args);
GitPlugin::client()->push(topLevel, args);
}
// Open or raise the Gerrit dialog window.
......@@ -393,13 +388,13 @@ void GerritPlugin::push()
Utils::FileName GerritPlugin::gitBinDirectory()
{
return gitClient()->gitBinDirectory();
return GitPlugin::client()->gitBinDirectory();
}
// Find the branch of a repository.
QString GerritPlugin::branch(const QString &repository)
{
return gitClient()->synchronousCurrentLocalBranch(repository);
return GitPlugin::client()->synchronousCurrentLocalBranch(repository);
}
void GerritPlugin::fetchDisplay(const QSharedPointer<GerritChange> &change)
......@@ -420,14 +415,12 @@ void GerritPlugin::fetchCheckout(const QSharedPointer<GerritChange> &change)
void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode)
{
// Locate git.
const Utils::FileName git = gitClient()->vcsBinary();
const Utils::FileName git = GitPlugin::client()->vcsBinary();
if (git.isEmpty()) {
VcsBase::VcsOutputWindow::appendError(tr("Git is not available."));
return;
}
GitClient *client = gitClient();
QString repository;
bool verifiedRepository = false;
if (!m_dialog.isNull() && !m_parameters.isNull() && QFile::exists(m_dialog->repositoryPath()))
......@@ -435,7 +428,7 @@ void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode)
if (!repository.isEmpty()) {
// Check if remote from a working dir is the same as remote from patch
QMap<QString, QString> remotesList = client->synchronousRemotesList(repository);
QMap<QString, QString> remotesList = GitPlugin::client()->synchronousRemotesList(repository);
if (!remotesList.isEmpty()) {
QStringList remotes = remotesList.values();
foreach (QString remote, remotes) {
......@@ -448,7 +441,7 @@ void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode)
}
if (!verifiedRepository) {
SubmoduleDataMap submodules = client->submoduleList(repository);
SubmoduleDataMap submodules = GitPlugin::client()->submoduleList(repository);
foreach (const SubmoduleData &submoduleData, submodules) {
QString remote = submoduleData.url;
if (remote.endsWith(QLatin1String(".git")))
......
......@@ -65,14 +65,14 @@ QString GerritPushDialog::determineRemoteBranch(const QString &localBranch)
args << QLatin1String("-r") << QLatin1String("--contains")
<< earliestCommit + QLatin1Char('^');
if (!m_client->synchronousBranchCmd(m_workingDir, args, &output, &error))
if (!GitPlugin::client()->synchronousBranchCmd(m_workingDir, args, &output, &error))
return QString();
const QString head = QLatin1String("/HEAD");
QStringList refs = output.split(QLatin1Char('\n'));
QString remoteTrackingBranch;
if (localBranch != QLatin1String("HEAD"))
remoteTrackingBranch = m_client->synchronousTrackingBranch(m_workingDir, localBranch);
remoteTrackingBranch = GitPlugin::client()->synchronousTrackingBranch(m_workingDir, localBranch);
QString remoteBranch;
foreach (const QString &reference, refs) {
......@@ -99,7 +99,7 @@ void GerritPushDialog::initRemoteBranches()
QString remotesPrefix(QLatin1String("refs/remotes/"));
args << QLatin1String("--format=%(refname)\t%(committerdate:raw)")
<< remotesPrefix;
if (!m_client->synchronousForEachRefCmd(m_workingDir, args, &output))
if (!GitPlugin::client()->synchronousForEachRefCmd(m_workingDir, args, &output))
return;
const QStringList refs = output.split(QLatin1String("\n"));
......@@ -113,7 +113,7 @@ void GerritPushDialog::initRemoteBranches()
BranchDate bd(ref.mid(refBranchIndex + 1), QDateTime::fromTime_t(timeT).date());
m_remoteBranches.insertMulti(ref.left(refBranchIndex), bd);
}
QStringList remotes = m_client->synchronousRemotesList(m_workingDir).keys();
QStringList remotes = GitPlugin::client()->synchronousRemotesList(m_workingDir).keys();
remotes.removeDuplicates();
{
const QString origin = QLatin1String("origin");
......@@ -130,10 +130,8 @@ void GerritPushDialog::initRemoteBranches()
GerritPushDialog::GerritPushDialog(const QString &workingDir, const QString &reviewerList, QWidget *parent) :
QDialog(parent),
m_workingDir(workingDir),
m_ui(new Ui::GerritPushDialog),
m_isValid(false)
m_ui(new Ui::GerritPushDialog)
{
m_client = GitPlugin::instance()->client();
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
m_ui->setupUi(this);
m_ui->repositoryLabel->setText(QDir::toNativeSeparators(workingDir));
......@@ -189,7 +187,7 @@ QString GerritPushDialog::calculateChangeRange(const QString &branch)
QString number;
QString error;
m_client->synchronousRevListCmd(m_workingDir, args, &number, &error);
GitPlugin