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 <qthjk@ovi.com>
This commit is contained in:
Orgad Shaneh
2013-01-08 03:32:53 +02:00
committed by hjk
parent 73a2717bed
commit 29a93998df
396 changed files with 1856 additions and 3135 deletions

View File

@@ -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);

View File

@@ -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<GerritParameters> &p, QObject *parent)

View File

@@ -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()

View File

@@ -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;

View File

@@ -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<GitoriousProject> 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<GitoriousRepository> 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)));
}
}
}

View File

@@ -64,9 +64,8 @@ static QList<QStandardItem *> 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);

View File

@@ -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();
}
}
}

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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()