From e6da9083211ef91d52c5455ecbac32329630e02c Mon Sep 17 00:00:00 2001 From: Orgad Shaneh <orgad.shaneh@audiocodes.com> Date: Fri, 19 Apr 2013 09:20:08 +0300 Subject: [PATCH] Git: Refactor reset Remove enum, provide the associated flag in the combobox. Change-Id: I1c4751c75f59312904fe7c175678f965ac16741d Reviewed-by: Tobias Hunger <tobias.hunger@digia.com> --- src/plugins/git/gitclient.cpp | 16 ++-------------- src/plugins/git/gitclient.h | 3 +-- src/plugins/git/gitplugin.cpp | 9 +-------- src/plugins/git/logchangedialog.cpp | 10 +++++----- src/plugins/git/logchangedialog.h | 10 ++-------- 5 files changed, 11 insertions(+), 37 deletions(-) diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index b496734f340..82ff778431a 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -869,10 +869,10 @@ bool GitClient::synchronousCheckout(const QString &workingDirectory, return true; } -void GitClient::hardReset(const QString &workingDirectory, const QString &commit) +void GitClient::reset(const QString &workingDirectory, const QString &argument, const QString &commit) { QStringList arguments; - arguments << QLatin1String("reset") << QLatin1String("--hard"); + arguments << QLatin1String("reset") << argument; if (!commit.isEmpty()) arguments << commit; @@ -880,18 +880,6 @@ void GitClient::hardReset(const QString &workingDirectory, const QString &commit connectRepositoryChanged(workingDirectory, cmd); } -void GitClient::softReset(const QString &workingDirectory, const QString &commit) -{ - if (commit.isEmpty()) - return; - - QStringList arguments; - arguments << QLatin1String("reset") << QLatin1String("--soft") << commit; - - VcsBase::Command *cmd = executeGit(workingDirectory, arguments, 0, true); - connectRepositoryChanged(workingDirectory, cmd); -} - void GitClient::addFile(const QString &workingDirectory, const QString &fileName) { QStringList arguments; diff --git a/src/plugins/git/gitclient.h b/src/plugins/git/gitclient.h index 5cacc82f143..565960ec2d7 100644 --- a/src/plugins/git/gitclient.h +++ b/src/plugins/git/gitclient.h @@ -137,8 +137,7 @@ public: bool enableAnnotationContextMenu = false, const QStringList &args = QStringList()); void blame(const QString &workingDirectory, const QStringList &args, const QString &fileName, const QString &revision = QString(), int lineNumber = -1); - void hardReset(const QString &workingDirectory, const QString &commit = QString()); - void softReset(const QString &workingDirectory, const QString &commit); + void reset(const QString &workingDirectory, const QString &argument, const QString &commit = QString()); void addFile(const QString &workingDirectory, const QString &fileName); bool synchronousLog(const QString &workingDirectory, const QStringList &arguments, diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index 3dce0b7cf04..f80b661a6b0 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -708,14 +708,7 @@ void GitPlugin::resetRepository() LogChangeDialog dialog(true); dialog.setWindowTitle(tr("Undo Changes to %1").arg(QDir::toNativeSeparators(topLevel))); if (dialog.runDialog(topLevel)) - switch (dialog.resetType()) { - case HardReset: - m_gitClient->hardReset(topLevel, dialog.commit()); - break; - case SoftReset: - m_gitClient->softReset(topLevel, dialog.commit()); - break; - } + m_gitClient->reset(topLevel, dialog.resetFlag(), dialog.commit()); } void GitPlugin::startRebase() diff --git a/src/plugins/git/logchangedialog.cpp b/src/plugins/git/logchangedialog.cpp index 28a3e44d8ff..b8074707d51 100644 --- a/src/plugins/git/logchangedialog.cpp +++ b/src/plugins/git/logchangedialog.cpp @@ -72,8 +72,8 @@ LogChangeDialog::LogChangeDialog(bool isReset, QWidget *parent) if (isReset) { popUpLayout->addWidget(new QLabel(tr("Reset type:"), this)); m_resetTypeComboBox = new QComboBox(this); - m_resetTypeComboBox->addItem(tr("Hard Reset"), HardReset); - m_resetTypeComboBox->addItem(tr("Soft Reset"), SoftReset); + m_resetTypeComboBox->addItem(tr("Hard"), QLatin1String("--hard")); + m_resetTypeComboBox->addItem(tr("Soft"), QLatin1String("--soft")); popUpLayout->addWidget(m_resetTypeComboBox); popUpLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored)); } @@ -112,11 +112,11 @@ QString LogChangeDialog::commit() const return QString(); } -ResetType LogChangeDialog::resetType() const +QString LogChangeDialog::resetFlag() const { if (!m_resetTypeComboBox) - return HardReset; - return static_cast<ResetType>(m_resetTypeComboBox->itemData(m_resetTypeComboBox->currentIndex()).toInt()); + return QString(); + return m_resetTypeComboBox->itemData(m_resetTypeComboBox->currentIndex()).toString(); } bool LogChangeDialog::populateLog(const QString &repository) diff --git a/src/plugins/git/logchangedialog.h b/src/plugins/git/logchangedialog.h index 78f61f9cfc9..f0b3b1267be 100644 --- a/src/plugins/git/logchangedialog.h +++ b/src/plugins/git/logchangedialog.h @@ -44,13 +44,7 @@ namespace Git { namespace Internal { // A dialog that lists SHA1 and subject of the changes -// for reset --hard and --soft. - -enum ResetType { - HardReset, - SoftReset -}; - +// Used for reset and interactive rebased class LogChangeDialog : public QDialog { Q_OBJECT @@ -60,7 +54,7 @@ public: bool runDialog(const QString &repository); QString commit() const; - ResetType resetType() const; + QString resetFlag() const; private: bool populateLog(const QString &repository); -- GitLab