From 29a93998df8405e8799ad23934a56cd99fb36403 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Tue, 8 Jan 2013 03:32:53 +0200 Subject: Remove braces for single lines of conditions #!/usr/bin/env ruby Dir.glob('**/*.cpp') { |file| # skip ast (excluding paste, astpath, and canv'ast'imer) next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i s = File.read(file) next if s.include?('qlalr') orig = s.dup s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m| res = $& if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces res else res.gsub!('} else', 'else') res.gsub!(/\n +} *\n/m, "\n") res.gsub(/ *{$/, '') end } s.gsub!(/ *$/, '') File.open(file, 'wb').write(s) if s != orig } Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc Reviewed-by: hjk --- src/plugins/git/clonewizardpage.cpp | 3 +- src/plugins/git/gerrit/gerritmodel.cpp | 10 ++--- src/plugins/git/gerrit/gerritplugin.cpp | 15 +++---- src/plugins/git/gitclient.cpp | 40 +++++++---------- src/plugins/git/gitorious/gitorious.cpp | 52 ++++++++++------------ src/plugins/git/gitorious/gitorioushostwidget.cpp | 3 +- .../git/gitorious/gitoriousprojectwidget.cpp | 10 ++--- src/plugins/git/gitplugin.cpp | 5 +-- src/plugins/git/gitsubmiteditorwidget.cpp | 5 +-- src/plugins/git/stashdialog.cpp | 5 +-- 10 files changed, 61 insertions(+), 87 deletions(-) (limited to 'src/plugins/git') diff --git a/src/plugins/git/clonewizardpage.cpp b/src/plugins/git/clonewizardpage.cpp index bb90cc8a64..5f37438e7b 100644 --- a/src/plugins/git/clonewizardpage.cpp +++ b/src/plugins/git/clonewizardpage.cpp @@ -115,9 +115,8 @@ QString CloneWizardPage::directoryFromRepository(const QString &urlIn) const if (url.endsWith(d->mainLinePostfix)) { url.truncate(url.size() - d->mainLinePostfix.size()); } else { - if (url.endsWith(d->gitPostFix)) { + if (url.endsWith(d->gitPostFix)) url.truncate(url.size() - d->gitPostFix.size()); - } } // Check for equal parts, something like "qt/qt" -> "qt" const int slashPos = url.indexOf(slash); diff --git a/src/plugins/git/gerrit/gerritmodel.cpp b/src/plugins/git/gerrit/gerritmodel.cpp index 9af51c1367..10e251925b 100644 --- a/src/plugins/git/gerrit/gerritmodel.cpp +++ b/src/plugins/git/gerrit/gerritmodel.cpp @@ -354,11 +354,10 @@ void QueryContext::errorTermination(const QString &msg) void QueryContext::processError(QProcess::ProcessError e) { const QString msg = tr("Error running %1: %2").arg(m_binary, m_process.errorString()); - if (e == QProcess::FailedToStart) { + if (e == QProcess::FailedToStart) errorTermination(msg); - } else { + else VcsBase::VcsBaseOutputWindow::instance()->appendError(msg); - } } void QueryContext::processFinished(int exitCode, QProcess::ExitStatus es) @@ -413,11 +412,10 @@ void QueryContext::timeout() box.exec(); if (m_process.state() != QProcess::Running) return; - if (box.clickedButton() == terminateButton) { + if (box.clickedButton() == terminateButton) Utils::SynchronousProcess::stopProcess(m_process); - } else { + else m_timer.start(); - } } GerritModel::GerritModel(const QSharedPointer &p, QObject *parent) diff --git a/src/plugins/git/gerrit/gerritplugin.cpp b/src/plugins/git/gerrit/gerritplugin.cpp index cc7671003d..1cb9930d99 100644 --- a/src/plugins/git/gerrit/gerritplugin.cpp +++ b/src/plugins/git/gerrit/gerritplugin.cpp @@ -243,21 +243,19 @@ void FetchContext::processReadyReadStandardError() { // Note: fetch displays progress on stderr. const QString errorOutput = QString::fromLocal8Bit(m_process.readAllStandardError()); - if (m_state == FetchState || m_state == CheckoutState) { + if (m_state == FetchState || m_state == CheckoutState) VcsBase::VcsBaseOutputWindow::instance()->append(errorOutput); - } else { + else VcsBase::VcsBaseOutputWindow::instance()->appendError(errorOutput); - } } void FetchContext::processReadyReadStandardOutput() { const QByteArray output = m_process.readAllStandardOutput(); - if (m_state == WritePatchFileState) { + if (m_state == WritePatchFileState) m_patchFile->write(output); - } else { + else VcsBase::VcsBaseOutputWindow::instance()->append(QString::fromLocal8Bit(output)); - } } void FetchContext::handleError(const QString &e) @@ -272,11 +270,10 @@ void FetchContext::handleError(const QString &e) void FetchContext::processError(QProcess::ProcessError e) { const QString msg = tr("Error running %1: %2").arg(m_git, m_process.errorString()); - if (e == QProcess::FailedToStart) { + if (e == QProcess::FailedToStart) handleError(msg); - } else { + else VcsBase::VcsBaseOutputWindow::instance()->appendError(msg); - } } void FetchContext::startWritePatchFile() diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index 0fdbcc5f98..77597f43a5 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -801,11 +801,10 @@ bool GitClient::synchronousCheckoutBranch(const QString &workingDirectory, const QString stdErr = commandOutputFromLocal8Bit(errorText); //: Meaning of the arguments: %1: Branch, %2: Repository, %3: Error message const QString msg = tr("Cannot checkout \"%1\" of \"%2\": %3").arg(branch, workingDirectory, stdErr); - if (errorMessage) { + if (errorMessage) *errorMessage = msg; - } else { + else outputWindow()->appendError(msg); - } return false; } return true; @@ -859,11 +858,10 @@ bool GitClient::synchronousLog(const QString &workingDirectory, const QStringLis const QString errorMessage = tr("Cannot obtain log of \"%1\": %2"). arg(QDir::toNativeSeparators(workingDirectory), commandOutputFromLocal8Bit(errorText)); - if (errorMessageIn) { + if (errorMessageIn) *errorMessageIn = errorMessage; - } else { + else outputWindow()->appendError(errorMessage); - } } return rc; } @@ -954,11 +952,10 @@ bool GitClient::synchronousReset(const QString &workingDirectory, tr("Cannot reset \"%1\": %2").arg(QDir::toNativeSeparators(workingDirectory), stdErr) : tr("Cannot reset %n file(s) in \"%1\": %2", 0, files.size()). arg(QDir::toNativeSeparators(workingDirectory), stdErr); - if (errorMessage) { + if (errorMessage) *errorMessage = msg; - } else { + else outputWindow()->appendError(msg); - } return false; } return true; @@ -1010,11 +1007,10 @@ bool GitClient::synchronousCheckoutFiles(const QString &workingDirectory, //: %4: Error message const QString msg = tr("Cannot checkout \"%1\" of %2 in \"%3\": %4"). arg(revision, fileArg, workingDirectory, commandOutputFromLocal8Bit(errorText)); - if (errorMessage) { + if (errorMessage) *errorMessage = msg; - } else { + else outputWindow()->appendError(msg); - } return false; } return true; @@ -1316,11 +1312,10 @@ bool GitClient::executeSynchronousStash(const QString &workingDirectory, const QString msg = tr("Cannot stash in \"%1\": %2"). arg(QDir::toNativeSeparators(workingDirectory), commandOutputFromLocal8Bit(errorText)); - if (errorMessage) { + if (errorMessage) *errorMessage = msg; - } else { + else outputWindow()->append(msg); - } return false; } return true; @@ -1348,11 +1343,10 @@ bool GitClient::stashNameFromMessage(const QString &workingDirectory, } //: Look-up of a stash via its descriptive message failed. const QString msg = tr("Cannot resolve stash message \"%1\" in \"%2\".").arg(message, workingDirectory); - if (errorMessage) { + if (errorMessage) *errorMessage = msg; - } else { + else outputWindow()->append(msg); - } return false; } @@ -2263,11 +2257,10 @@ bool GitClient::synchronousStashRemove(const QString &workingDirectory, QString *errorMessage /* = 0 */) { QStringList arguments(QLatin1String("stash")); - if (stash.isEmpty()) { + if (stash.isEmpty()) arguments << QLatin1String("clear"); - } else { + else arguments << QLatin1String("drop") << stash; - } QByteArray outputText; QByteArray errorText; const bool rc = fullySynchronousGit(workingDirectory, arguments, &outputText, &errorText); @@ -2319,11 +2312,10 @@ bool GitClient::synchronousStashList(const QString &workingDirectory, const QString msg = tr("Cannot retrieve stash list of \"%1\": %2"). arg(QDir::toNativeSeparators(workingDirectory), commandOutputFromLocal8Bit(errorText)); - if (errorMessage) { + if (errorMessage) *errorMessage = msg; - } else { + else outputWindow()->append(msg); - } return false; } Stash stash; diff --git a/src/plugins/git/gitorious/gitorious.cpp b/src/plugins/git/gitorious/gitorious.cpp index a89ca8b657..56c0ebe6e4 100644 --- a/src/plugins/git/gitorious/gitorious.cpp +++ b/src/plugins/git/gitorious/gitorious.cpp @@ -207,11 +207,10 @@ GitoriousProjectReader::ProjectList GitoriousProjectReader::read(const QByteArra while (!reader.atEnd()) { reader.readNext(); if (reader.isStartElement()) { - if (reader.name() == QLatin1String("projects")) { + if (reader.name() == QLatin1String("projects")) readProjects(reader); - } else { + else readUnknownElement(reader); - } } } @@ -259,17 +258,16 @@ QSharedPointer GitoriousProjectReader::readProject(QXmlStreamR if (reader.isStartElement()) { const QStringRef name = reader.name(); - if (name == QLatin1String("description")) { + if (name == QLatin1String("description")) project->description = reader.readElementText(); - } else if (name == QLatin1String("title")) { + else if (name == QLatin1String("title")) project->name = reader.readElementText(); - } else if (name == QLatin1String("slug") && project->name.isEmpty()) { + else if (name == QLatin1String("slug") && project->name.isEmpty()) project->name = reader.readElementText(); - } else if (name == QLatin1String("repositories")) { + else if (name == QLatin1String("repositories")) project->repositories = readRepositories(reader); - } else { + else readUnknownElement(reader); - } } } return project; @@ -287,24 +285,22 @@ QList GitoriousProjectReader::readRepositories(QXmlStreamRe if (reader.isEndElement()) { const QStringRef name = reader.name(); - if (name == m_mainLinesElement || name == m_clonesElement) { + if (name == m_mainLinesElement || name == m_clonesElement) defaultType = -1; - } else { + else break; - } } if (reader.isStartElement()) { const QStringRef name = reader.name(); - if (reader.name() == QLatin1String("repository")) { + if (reader.name() == QLatin1String("repository")) repositories.push_back(readRepository(reader, defaultType)); - } else if (name == m_mainLinesElement) { + else if (name == m_mainLinesElement) defaultType = GitoriousRepository::MainLineRepository; - } else if (name == m_clonesElement) { + else if (name == m_clonesElement) defaultType = GitoriousRepository::CloneRepository; - } else { + else readUnknownElement(reader); - } } } return repositories; @@ -324,23 +320,22 @@ GitoriousRepository GitoriousProjectReader::readRepository(QXmlStreamReader &rea if (reader.isStartElement()) { const QStringRef name = reader.name(); - if (name == QLatin1String("name")) { + if (name == QLatin1String("name")) repository.name = reader.readElementText(); - } else if (name == QLatin1String("owner")) { + else if (name == QLatin1String("owner")) repository.owner = reader.readElementText(); - } else if (name == QLatin1String("id")) { + else if (name == QLatin1String("id")) repository.id = reader.readElementText().toInt(); - } else if (name == QLatin1String("description")) { + else if (name == QLatin1String("description")) repository.description = reader.readElementText(); - } else if (name == QLatin1String("push_url")) { + else if (name == QLatin1String("push_url")) repository.pushUrl = reader.readElementText(); - } else if (name == QLatin1String("clone_url")) { + else if (name == QLatin1String("clone_url")) repository.cloneUrl = reader.readElementText(); - } else if (name == QLatin1String("namespace")) { + else if (name == QLatin1String("namespace")) repository.type = repositoryType(reader.readElementText()); - } else { + else readUnknownElement(reader); - } } } return repository; @@ -588,11 +583,10 @@ void Gitorious::restoreSettings(const QString &group, const QSettings *s) const QStringList hosts = s->value(group + QLatin1Char('/') + QLatin1String(settingsKeyC), QStringList()).toStringList(); foreach (const QString &h, hosts) { const int sepPos = h.indexOf(separator); - if (sepPos == -1) { + if (sepPos == -1) addHost(GitoriousHost(h)); - } else { + else addHost(GitoriousHost(h.mid(0, sepPos), h.mid(sepPos + 1))); - } } } diff --git a/src/plugins/git/gitorious/gitorioushostwidget.cpp b/src/plugins/git/gitorious/gitorioushostwidget.cpp index 2042afc449..92000ac139 100644 --- a/src/plugins/git/gitorious/gitorioushostwidget.cpp +++ b/src/plugins/git/gitorious/gitorioushostwidget.cpp @@ -64,9 +64,8 @@ static QList hostEntry(const QString &host, // Empty for dummy, else "..." or count QStandardItem *projectCountItem = 0; QString countItemText; - if (!isDummyEntry) { + if (!isDummyEntry) countItemText = projectCount ? QString::number(projectCount) : QString(QLatin1String("...")); - } projectCountItem = new QStandardItem(countItemText); projectCountItem->setFlags(nonEditableFlags); QStandardItem *descriptionItem = new QStandardItem(description); diff --git a/src/plugins/git/gitorious/gitoriousprojectwidget.cpp b/src/plugins/git/gitorious/gitoriousprojectwidget.cpp index 844beaa22a..08af912f70 100644 --- a/src/plugins/git/gitorious/gitoriousprojectwidget.cpp +++ b/src/plugins/git/gitorious/gitoriousprojectwidget.cpp @@ -212,11 +212,10 @@ void GitoriousProjectWidget::setDescription(const QString &description, descLine.truncate(newLinePos); if (descLine.size() > MaxDescriptionLineLength) { const int dotPos = descLine.lastIndexOf(QLatin1Char('.'), MaxDescriptionLineLength); - if (dotPos != -1) { + if (dotPos != -1) descLine.truncate(dotPos); - } else { + else descLine.truncate(MaxDescriptionLineLength); - } descLine += QLatin1String("..."); } items->at(descriptionColumn)->setText(descLine); @@ -230,11 +229,10 @@ void GitoriousProjectWidget::setDescription(const QString &description, // Do not fall for "(http://XX)", strip special characters static QRegExp urlRegExp(QLatin1String("(http://[\\w\\.-]+/[a-zA-Z0-9/\\-&]*)")); QTC_CHECK(urlRegExp.isValid()); - if (urlRegExp.indexIn(description) != -1) { + if (urlRegExp.indexIn(description) != -1) *url= urlRegExp.cap(1); - } else { + else url->clear(); - } } } diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index 850553992c..1027ddfb39 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -1034,11 +1034,10 @@ void GitPlugin::applyPatch(const QString &workingDirectory, QString file) VcsBase::VcsBaseOutputWindow *outwin = VcsBase::VcsBaseOutputWindow::instance(); QString errorMessage; if (m_gitClient->synchronousApplyPatch(workingDirectory, file, &errorMessage)) { - if (errorMessage.isEmpty()) { + if (errorMessage.isEmpty()) outwin->append(tr("Patch %1 successfully applied to %2").arg(file, workingDirectory)); - } else { + else outwin->append(errorMessage); - } } else { outwin->appendError(errorMessage); } diff --git a/src/plugins/git/gitsubmiteditorwidget.cpp b/src/plugins/git/gitsubmiteditorwidget.cpp index 8c79265e3e..f34062c7ec 100644 --- a/src/plugins/git/gitsubmiteditorwidget.cpp +++ b/src/plugins/git/gitsubmiteditorwidget.cpp @@ -181,11 +181,10 @@ QString GitSubmitEditorWidget::cleanupDescription(const QString &input) const for (int pos = 0; pos < message.size(); ) { const int newLinePos = message.indexOf(newLine, pos); const int startOfNextLine = newLinePos == -1 ? message.size() : newLinePos + 1; - if (message.at(pos) == hash) { + if (message.at(pos) == hash) message.remove(pos, startOfNextLine - pos); - } else { + else pos = startOfNextLine; - } } return message; diff --git a/src/plugins/git/stashdialog.cpp b/src/plugins/git/stashdialog.cpp index 69c582e870..c12d491b60 100644 --- a/src/plugins/git/stashdialog.cpp +++ b/src/plugins/git/stashdialog.cpp @@ -198,11 +198,10 @@ void StashDialog::deleteAll() if (!ask(title, tr("Do you want to delete all stashes?"))) return; QString errorMessage; - if (gitClient()->synchronousStashRemove(m_repository, QString(), &errorMessage)) { + if (gitClient()->synchronousStashRemove(m_repository, QString(), &errorMessage)) refresh(m_repository, true); - } else { + else warning(title, errorMessage); - } } void StashDialog::deleteSelection() -- cgit v1.2.1