Git: Fix object leaks

Change-Id: I0efb368782ffb66cf6b8d39650fe7840c5ef2501
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Orgad Shaneh
2013-05-08 23:16:23 +03:00
committed by Orgad Shaneh
parent f7ac7fb241
commit c60ab1ca3c
10 changed files with 60 additions and 67 deletions

View File

@@ -95,7 +95,7 @@ private:
};
BranchAddDialog::BranchAddDialog(QWidget *parent, bool addBranch) :
BranchAddDialog::BranchAddDialog(bool addBranch, QWidget *parent) :
QDialog(parent),
m_ui(new Ui::BranchAddDialog)
{

View File

@@ -45,7 +45,7 @@ class BranchAddDialog : public QDialog
Q_OBJECT
public:
explicit BranchAddDialog(QWidget *parent = 0, bool addBranch = true);
BranchAddDialog(bool addBranch, QWidget *parent);
~BranchAddDialog();
void setBranchName(const QString &);

View File

@@ -139,7 +139,7 @@ void BranchDialog::add()
++i;
}
BranchAddDialog branchAddDialog;
BranchAddDialog branchAddDialog(true, this);
branchAddDialog.setBranchName(suggestedName);
branchAddDialog.setTrackedBranchName(trackedBranch, !isLocal);
@@ -249,22 +249,22 @@ void BranchDialog::rename()
QString oldBranchName = m_model->branchName(selected);
QStringList localNames = m_model->localBranchNames();
QPointer<BranchAddDialog> branchAddDialog = new BranchAddDialog(this, false);
branchAddDialog->setBranchName(oldBranchName);
branchAddDialog->setTrackedBranchName(QString(), false);
BranchAddDialog branchAddDialog(false, this);
branchAddDialog.setBranchName(oldBranchName);
branchAddDialog.setTrackedBranchName(QString(), false);
branchAddDialog->exec();
branchAddDialog.exec();
if (!branchAddDialog.isNull() && branchAddDialog->result() == QDialog::Accepted && m_model) {
if (branchAddDialog->branchName() == oldBranchName)
if (branchAddDialog.result() == QDialog::Accepted && m_model) {
if (branchAddDialog.branchName() == oldBranchName)
return;
if (localNames.contains(branchAddDialog->branchName())) {
if (localNames.contains(branchAddDialog.branchName())) {
QMessageBox::critical(this, tr("Branch Exists"),
tr("Local branch \'%1\' already exists.")
.arg(branchAddDialog->branchName()));
.arg(branchAddDialog.branchName()));
return;
}
m_model->renameBranch(oldBranchName, branchAddDialog->branchName());
m_model->renameBranch(oldBranchName, branchAddDialog.branchName());
refresh();
}
enableButtons();

View File

@@ -130,16 +130,16 @@ void ChangeSelectionDialog::selectCommitFromRecentHistory()
int tilde = commit.indexOf(QLatin1Char('~'));
if (tilde != -1)
commit.truncate(tilde);
QPointer<LogChangeDialog> dialog = new LogChangeDialog(false);
dialog->setWindowTitle(tr("Select Commit"));
LogChangeDialog dialog(false, this);
dialog.setWindowTitle(tr("Select Commit"));
dialog->runDialog(workingDir, commit);
dialog.runDialog(workingDir, commit);
if (dialog->result() == QDialog::Rejected || dialog->commitIndex() == -1)
if (dialog.result() == QDialog::Rejected || dialog.commitIndex() == -1)
return;
if (dialog->commitIndex() > 0)
commit += QLatin1Char('~') + QString::number(dialog->commitIndex());
if (dialog.commitIndex() > 0)
commit += QLatin1Char('~') + QString::number(dialog.commitIndex());
m_changeNumberEdit->setText(commit);
}

View File

@@ -50,6 +50,11 @@ GerritOptionsPage::GerritOptionsPage(const QSharedPointer<GerritParameters> &p,
setDisplayName(tr("Gerrit"));
}
GerritOptionsPage::~GerritOptionsPage()
{
delete m_widget;
}
QWidget *GerritOptionsPage::createPage(QWidget *parent)
{
GerritOptionsWidget *gow = new GerritOptionsWidget(parent);

View File

@@ -76,6 +76,7 @@ class GerritOptionsPage : public VcsBase::VcsBaseOptionsPage
public:
GerritOptionsPage(const QSharedPointer<GerritParameters> &p,
QObject *parent = 0);
~GerritOptionsPage();
QWidget *createPage(QWidget *parent);
void apply();

View File

@@ -366,34 +366,26 @@ void GerritPlugin::push()
const QString topLevel = Git::Internal::GitPlugin::instance()->currentState().topLevel();
// QScopedPointer is required to delete the dialog when leaving the function
QScopedPointer<GerritPushDialog> dialog(
new GerritPushDialog(topLevel, m_reviewers, Core::ICore::mainWindow()));
GerritPushDialog dialog(topLevel, m_reviewers, Core::ICore::mainWindow());
if (!dialog->localChangesFound()) {
if (!dialog.localChangesFound()) {
QMessageBox::warning(Core::ICore::mainWindow(), tr("No Local Changes"),
tr("Change from HEAD appears to be in remote branch already. Aborting."));
return;
}
if (!dialog->valid()) {
if (!dialog.valid()) {
QMessageBox::warning(Core::ICore::mainWindow(), tr("Initialization Failed"),
tr("Failed to initialize dialog. Aborting."));
return;
}
// QPointer is required to detect dialog deletion while in exec()
QPointer<GerritPushDialog> dlg = dialog.data();
if (dialog->exec() == QDialog::Rejected)
if (dialog.exec() == QDialog::Rejected)
return;
if (dlg.isNull()) {
dialog.take();
return;
}
QStringList args;
m_reviewers = dialog->reviewers();
m_reviewers = dialog.reviewers();
const QStringList reviewers = m_reviewers.split(QLatin1Char(','),
QString::SkipEmptyParts);
if (!reviewers.isEmpty()) {
@@ -406,13 +398,13 @@ void GerritPlugin::push()
args << reviewersFlag;
}
args << dialog->selectedRemoteName();
QString target = dialog->selectedCommit();
args << dialog.selectedRemoteName();
QString target = dialog.selectedCommit();
if (target.isEmpty())
target = QLatin1String("HEAD");
target += QLatin1String(":refs/") + dialog->selectedPushType() +
QLatin1Char('/') + dialog->selectedRemoteBranchName();
const QString topic = dialog->selectedTopic();
target += QLatin1String(":refs/") + dialog.selectedPushType() +
QLatin1Char('/') + dialog.selectedRemoteBranchName();
const QString topic = dialog.selectedTopic();
if (!topic.isEmpty())
target += QLatin1Char('/') + topic;
args << target;

View File

@@ -45,7 +45,7 @@ class GerritPushDialog : public QDialog
Q_OBJECT
public:
GerritPushDialog(const QString &workingDir, const QString &reviewerList, QWidget *parent = 0);
GerritPushDialog(const QString &workingDir, const QString &reviewerList, QWidget *parent);
~GerritPushDialog();
QString selectedCommit() const;

View File

@@ -2178,7 +2178,8 @@ void GitClient::continuePreviousGitCommand(const QString &workingDirectory,
}
if (!hasChanges)
msgBoxText.prepend(tr("No changes found. "));
QMessageBox msgBox(QMessageBox::Question, msgBoxTitle, msgBoxText);
QMessageBox msgBox(QMessageBox::Question, msgBoxTitle, msgBoxText,
QMessageBox::NoButton, Core::ICore::mainWindow());
if (hasChanges || isRebase)
msgBox.addButton(hasChanges ? buttonName : tr("Skip"), QMessageBox::AcceptRole);
msgBox.addButton(QMessageBox::Abort);
@@ -2746,7 +2747,8 @@ void GitClient::handleMergeConflicts(const QString &workingDir, const QString &c
{
QString message = commit.isEmpty() ? tr("Conflicts detected")
: tr("Conflicts detected with commit %1").arg(commit);
QMessageBox mergeOrAbort(QMessageBox::Question, tr("Conflicts Detected"), message);
QMessageBox mergeOrAbort(QMessageBox::Question, tr("Conflicts Detected"), message,
QMessageBox::NoButton, Core::ICore::mainWindow());
QPushButton *mergeToolButton = mergeOrAbort.addButton(tr("Run &Merge Tool"),
QMessageBox::AcceptRole);
mergeOrAbort.addButton(QMessageBox::Ignore);
@@ -3201,44 +3203,40 @@ void GitClient::StashGuard::stashPrompt(const QString &keyword, QString *errorMe
return;
}
QPointer<QMessageBox> msgBox = new QMessageBox(QMessageBox::Question,
tr("Uncommitted Changes Found"),
tr("What would you like to do with local changes in:")
+ QLatin1String("\n\n\"") + workingDir + QLatin1Char('\"'),
QMessageBox::NoButton, Core::ICore::mainWindow());
QMessageBox msgBox(QMessageBox::Question, tr("Uncommitted Changes Found"),
tr("What would you like to do with local changes in:")
+ QLatin1String("\n\n\"") + workingDir + QLatin1Char('\"'),
QMessageBox::NoButton, Core::ICore::mainWindow());
msgBox->setDetailedText(statusOutput);
msgBox.setDetailedText(statusOutput);
QPushButton *stashButton = msgBox->addButton(tr("Stash"), QMessageBox::AcceptRole);
QPushButton *stashButton = msgBox.addButton(tr("Stash"), QMessageBox::AcceptRole);
stashButton->setToolTip(tr("Stash local changes and continue."));
QPushButton *discardButton = msgBox->addButton(tr("Discard"), QMessageBox::AcceptRole);
QPushButton *discardButton = msgBox.addButton(tr("Discard"), QMessageBox::AcceptRole);
discardButton->setToolTip(tr("Discard (reset) local changes and continue."));
QPushButton *ignoreButton = 0;
if (flags & AllowUnstashed) {
ignoreButton = msgBox->addButton(QMessageBox::Ignore);
ignoreButton = msgBox.addButton(QMessageBox::Ignore);
ignoreButton->setToolTip(tr("Continue with local changes in working directory."));
}
QPushButton *cancelButton = msgBox->addButton(QMessageBox::Cancel);
QPushButton *cancelButton = msgBox.addButton(QMessageBox::Cancel);
cancelButton->setToolTip(tr("Cancel current command."));
msgBox->exec();
msgBox.exec();
if (msgBox.isNull())
return;
if (msgBox->clickedButton() == discardButton) {
if (msgBox.clickedButton() == discardButton) {
if (!client->synchronousReset(workingDir, QStringList(), errorMessage))
stashResult = StashFailed;
else
stashResult = StashUnchanged;
} else if (msgBox->clickedButton() == ignoreButton) { // At your own risk, so.
} else if (msgBox.clickedButton() == ignoreButton) { // At your own risk, so.
stashResult = NotStashed;
} else if (msgBox->clickedButton() == cancelButton) {
} else if (msgBox.clickedButton() == cancelButton) {
stashResult = StashCanceled;
} else if (msgBox->clickedButton() == stashButton) {
} else if (msgBox.clickedButton() == stashButton) {
executeStash(keyword, errorMessage);
}
}

View File

@@ -779,28 +779,27 @@ void GitPlugin::startChangeRelatedAction()
if (!state.hasTopLevel())
return;
QPointer<ChangeSelectionDialog> dialog = new ChangeSelectionDialog
(state.topLevel(), Core::ICore::mainWindow());
ChangeSelectionDialog dialog(state.topLevel(), Core::ICore::mainWindow());
int result = dialog->exec();
int result = dialog.exec();
if (dialog.isNull() || result == QDialog::Rejected)
if (result == QDialog::Rejected)
return;
const QString workingDirectory = dialog->workingDirectory();
const QString change = dialog->change();
const QString workingDirectory = dialog.workingDirectory();
const QString change = dialog.change();
if (workingDirectory.isEmpty() || change.isEmpty())
return;
if (dialog->command() == Show) {
if (dialog.command() == Show) {
m_gitClient->show(workingDirectory, change);
return;
}
QString command;
bool (GitClient::*commandFunction)(const QString&, const QString&);
switch (dialog->command()) {
switch (dialog.command()) {
case CherryPick:
command = QLatin1String("Cherry-pick");
commandFunction = &GitClient::synchronousCherryPick;
@@ -823,8 +822,6 @@ void GitPlugin::startChangeRelatedAction()
if (!(m_gitClient->*commandFunction)(workingDirectory, change))
stashGuard.preventPop();
delete dialog;
}
void GitPlugin::stageFile()