forked from qt-creator/qt-creator
VcsBase & dependent: Fix const correctness
And some minor cleanups. Change-Id: Id0c2df6865ba84c054f0fb97c0ac42a76a128355 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -441,7 +441,7 @@ bool BranchModel::refresh(const FilePath &workingDirectory, QString *errorMessag
|
||||
|
||||
void BranchModel::setCurrentBranch()
|
||||
{
|
||||
QString currentBranch = d->client->synchronousCurrentLocalBranch(d->workingDirectory);
|
||||
const QString currentBranch = d->client->synchronousCurrentLocalBranch(d->workingDirectory);
|
||||
if (currentBranch.isEmpty())
|
||||
return;
|
||||
|
||||
@@ -563,7 +563,7 @@ bool BranchModel::isTag(const QModelIndex &idx) const
|
||||
|
||||
void BranchModel::removeBranch(const QModelIndex &idx)
|
||||
{
|
||||
QString branch = fullName(idx);
|
||||
const QString branch = fullName(idx);
|
||||
if (branch.isEmpty())
|
||||
return;
|
||||
|
||||
@@ -579,7 +579,7 @@ void BranchModel::removeBranch(const QModelIndex &idx)
|
||||
|
||||
void BranchModel::removeTag(const QModelIndex &idx)
|
||||
{
|
||||
QString tag = fullName(idx);
|
||||
const QString tag = fullName(idx);
|
||||
if (tag.isEmpty())
|
||||
return;
|
||||
|
||||
@@ -608,7 +608,7 @@ void BranchModel::checkoutBranch(const QModelIndex &idx, const QObject *context,
|
||||
|
||||
bool BranchModel::branchIsMerged(const QModelIndex &idx)
|
||||
{
|
||||
QString branch = fullName(idx);
|
||||
const QString branch = fullName(idx);
|
||||
if (branch.isEmpty())
|
||||
return false;
|
||||
|
||||
@@ -622,9 +622,9 @@ bool BranchModel::branchIsMerged(const QModelIndex &idx)
|
||||
|
||||
const QStringList lines = output.split('\n', Qt::SkipEmptyParts);
|
||||
for (const QString &l : lines) {
|
||||
QString currentBranch = l.mid(2); // remove first letters (those are either
|
||||
// " " or "* " depending on whether it is
|
||||
// the currently checked out branch or not)
|
||||
const QString currentBranch = l.mid(2); // remove first letters (those are either
|
||||
// " " or "* " depending on whether it is
|
||||
// the currently checked out branch or not)
|
||||
if (currentBranch != branch)
|
||||
return true;
|
||||
}
|
||||
@@ -745,7 +745,7 @@ void BranchModel::Private::parseOutputLine(const QString &line, bool force)
|
||||
return;
|
||||
|
||||
// objectname, refname, upstream:short, *objectname, committerdate:raw, *committerdate:raw
|
||||
QStringList lineParts = line.split('\t');
|
||||
const QStringList lineParts = line.split('\t');
|
||||
const QString shaDeref = lineParts.at(3);
|
||||
const QString sha = shaDeref.isEmpty() ? lineParts.at(0) : shaDeref;
|
||||
const QString fullName = lineParts.at(1);
|
||||
@@ -907,9 +907,7 @@ QString BranchModel::toolTip(const QString &sha) const
|
||||
// Show the sha description excluding diff as toolTip
|
||||
QString output;
|
||||
QString errorMessage;
|
||||
QStringList arguments("-n1");
|
||||
arguments << sha;
|
||||
if (!d->client->synchronousLog(d->workingDirectory, arguments, &output, &errorMessage,
|
||||
if (!d->client->synchronousLog(d->workingDirectory, {"-n1", sha}, &output, &errorMessage,
|
||||
RunFlags::SuppressCommandLogging)) {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
@@ -448,7 +448,7 @@ bool BranchView::remove()
|
||||
const QModelIndex selected = selectedIndex();
|
||||
QTC_CHECK(selected != m_model->currentBranch());
|
||||
|
||||
QString branchName = m_model->fullName(selected);
|
||||
const QString branchName = m_model->fullName(selected);
|
||||
if (branchName.isEmpty())
|
||||
return false;
|
||||
|
||||
@@ -480,7 +480,7 @@ bool BranchView::rename()
|
||||
const bool isTag = m_model->isTag(selected);
|
||||
QTC_CHECK(m_model->isLocal(selected) || isTag);
|
||||
|
||||
QString oldName = m_model->fullName(selected);
|
||||
const QString oldName = m_model->fullName(selected);
|
||||
QStringList localNames;
|
||||
if (!isTag)
|
||||
localNames = m_model->localBranchNames();
|
||||
|
||||
@@ -782,9 +782,8 @@ static bool parseOutput(const QSharedPointer<GerritParameters> ¶meters,
|
||||
QJsonParseError error;
|
||||
const QJsonDocument doc = QJsonDocument::fromJson(adaptedOutput, &error);
|
||||
if (doc.isNull()) {
|
||||
QString errorMessage = Git::Tr::tr("Parse error: \"%1\" -> %2")
|
||||
.arg(QString::fromUtf8(output))
|
||||
.arg(error.errorString());
|
||||
const QString errorMessage = Git::Tr::tr("Parse error: \"%1\" -> %2")
|
||||
.arg(QString::fromUtf8(output), error.errorString());
|
||||
qWarning() << errorMessage;
|
||||
VcsOutputWindow::appendError(errorMessage);
|
||||
res = false;
|
||||
@@ -919,9 +918,8 @@ void GerritModel::resultRetrieved(const QByteArray &output)
|
||||
// too-deeply nested items.
|
||||
for (; changeFromItem(parent)->depth >= 1; parent = parent->parent()) {}
|
||||
parent->appendRow(newRow);
|
||||
QString parentFilterString = parent->data(FilterRole).toString();
|
||||
parentFilterString += ' ';
|
||||
parentFilterString += newRow.first()->data(FilterRole).toString();
|
||||
const QString parentFilterString = parent->data(FilterRole).toString() + ' '
|
||||
+ newRow.first()->data(FilterRole).toString();
|
||||
parent->setData(QVariant(parentFilterString), FilterRole);
|
||||
} else {
|
||||
appendRow(newRow);
|
||||
|
||||
@@ -86,7 +86,7 @@ void GerritPushDialog::initRemoteBranches()
|
||||
QString output;
|
||||
const QString head = "/HEAD";
|
||||
|
||||
QString remotesPrefix("refs/remotes/");
|
||||
const QString remotesPrefix("refs/remotes/");
|
||||
if (!GitClient::instance()->synchronousForEachRefCmd(
|
||||
m_workingDir, {"--format=%(refname)\t%(committerdate:raw)", remotesPrefix}, &output)) {
|
||||
return;
|
||||
@@ -94,7 +94,7 @@ void GerritPushDialog::initRemoteBranches()
|
||||
|
||||
const QStringList refs = output.split("\n");
|
||||
for (const QString &reference : refs) {
|
||||
QStringList entries = reference.split('\t');
|
||||
const QStringList entries = reference.split('\t');
|
||||
if (entries.count() < 2 || entries.first().endsWith(head))
|
||||
continue;
|
||||
const QString ref = entries.at(0).mid(remotesPrefix.size());
|
||||
@@ -194,16 +194,11 @@ QString GerritPushDialog::selectedCommit() const
|
||||
|
||||
QString GerritPushDialog::calculateChangeRange(const QString &branch)
|
||||
{
|
||||
QString remote = selectedRemoteName();
|
||||
remote += '/';
|
||||
remote += selectedRemoteBranchName();
|
||||
|
||||
const QString remote = selectedRemoteName() + '/' + selectedRemoteBranchName();
|
||||
QString number;
|
||||
QString error;
|
||||
|
||||
GitClient::instance()->synchronousRevListCmd(
|
||||
m_workingDir, { remote + ".." + branch, "--count" }, &number, &error);
|
||||
|
||||
number.chop(1);
|
||||
return number;
|
||||
}
|
||||
@@ -376,7 +371,7 @@ void GerritPushDialog::updateCommits(int index)
|
||||
{
|
||||
const QString branch = m_localBranchComboBox->itemText(index);
|
||||
m_hasLocalCommits = m_commitView->init(m_workingDir, branch, LogChangeWidget::Silent);
|
||||
QString topic = GitClient::instance()->readConfigValue(
|
||||
const QString topic = GitClient::instance()->readConfigValue(
|
||||
m_workingDir, QString("branch.%1.topic").arg(branch));
|
||||
if (!topic.isEmpty())
|
||||
m_topicLineEdit->setText(topic);
|
||||
|
||||
@@ -1194,7 +1194,7 @@ void GitClient::archive(const FilePath &workingDirectory, QString commit)
|
||||
FilePath repoDirectory = VcsManager::findTopLevelForDirectory(workingDirectory);
|
||||
if (repoDirectory.isEmpty())
|
||||
repoDirectory = workingDirectory;
|
||||
QString repoName = repoDirectory.fileName();
|
||||
const QString repoName = repoDirectory.fileName();
|
||||
|
||||
QHash<QString, QString> filters;
|
||||
QString selectedFilter;
|
||||
@@ -1222,7 +1222,7 @@ void GitClient::archive(const FilePath &workingDirectory, QString commit)
|
||||
&selectedFilter);
|
||||
if (archiveName.isEmpty())
|
||||
return;
|
||||
QString extension = filters.value(selectedFilter);
|
||||
const QString extension = filters.value(selectedFilter);
|
||||
QFileInfo archive(archiveName.toString());
|
||||
if (extension != "." + archive.completeSuffix()) {
|
||||
archive = QFileInfo(archive.filePath() + extension);
|
||||
@@ -1691,7 +1691,7 @@ bool GitClient::synchronousHeadRefs(const FilePath &workingDirectory, QStringLis
|
||||
QString GitClient::synchronousTopic(const FilePath &workingDirectory) const
|
||||
{
|
||||
// First try to find branch
|
||||
QString branch = synchronousCurrentLocalBranch(workingDirectory);
|
||||
const QString branch = synchronousCurrentLocalBranch(workingDirectory);
|
||||
if (!branch.isEmpty())
|
||||
return branch;
|
||||
|
||||
@@ -2000,10 +2000,10 @@ SubmoduleDataMap GitClient::submoduleList(const FilePath &workingDirectory) cons
|
||||
if (!configLine.startsWith(submoduleLineStart))
|
||||
continue;
|
||||
|
||||
int nameStart = submoduleLineStart.size();
|
||||
int nameEnd = configLine.indexOf('.', nameStart);
|
||||
const int nameStart = submoduleLineStart.size();
|
||||
const int nameEnd = configLine.indexOf('.', nameStart);
|
||||
|
||||
QString submoduleName = configLine.mid(nameStart, nameEnd - nameStart);
|
||||
const QString submoduleName = configLine.mid(nameStart, nameEnd - nameStart);
|
||||
|
||||
SubmoduleData submoduleData;
|
||||
if (result.contains(submoduleName))
|
||||
@@ -2032,7 +2032,7 @@ SubmoduleDataMap GitClient::submoduleList(const FilePath &workingDirectory) cons
|
||||
} else {
|
||||
SubmoduleData &submoduleRef = result[submoduleName];
|
||||
submoduleRef.dir = path;
|
||||
QString ignore = gitmodulesFile.value("ignore").toString();
|
||||
const QString ignore = gitmodulesFile.value("ignore").toString();
|
||||
if (!ignore.isEmpty() && submoduleRef.ignore.isEmpty())
|
||||
submoduleRef.ignore = ignore;
|
||||
}
|
||||
@@ -2130,7 +2130,7 @@ bool GitClient::synchronousApplyPatch(const FilePath &workingDirectory,
|
||||
Environment GitClient::processEnvironment() const
|
||||
{
|
||||
Environment environment = VcsBaseClientImpl::processEnvironment();
|
||||
QString gitPath = settings().path.value();
|
||||
const QString gitPath = settings().path.value();
|
||||
environment.prependOrSetPath(FilePath::fromUserInput(gitPath));
|
||||
if (HostOsInfo::isWindowsHost() && settings().winSetHomeEnvironment.value()) {
|
||||
QString homePath;
|
||||
@@ -2594,7 +2594,7 @@ FilePath GitClient::vcsBinary() const
|
||||
|
||||
QTextCodec *GitClient::encoding(const FilePath &workingDirectory, const QString &configVar) const
|
||||
{
|
||||
QString codecName = readConfigValue(workingDirectory, configVar).trimmed();
|
||||
const QString codecName = readConfigValue(workingDirectory, configVar).trimmed();
|
||||
// Set default commit encoding to 'UTF-8', when it's not set,
|
||||
// to solve displaying error of commit log with non-latin characters.
|
||||
if (codecName.isEmpty())
|
||||
@@ -2671,7 +2671,7 @@ bool GitClient::getCommitData(const FilePath &workingDirectory,
|
||||
|
||||
commitData.panelInfo.repository = repoDirectory;
|
||||
|
||||
QString gitDir = findGitDirForRepository(repoDirectory);
|
||||
const QString gitDir = findGitDirForRepository(repoDirectory);
|
||||
if (gitDir.isEmpty()) {
|
||||
*errorMessage = Tr::tr("The repository \"%1\" is not initialized.").arg(repoDirectory.toString());
|
||||
return false;
|
||||
@@ -2818,7 +2818,7 @@ bool GitClient::addAndCommit(const FilePath &repositoryDirectory,
|
||||
|
||||
for (int i = 0; i < model->rowCount(); ++i) {
|
||||
const FileStates state = static_cast<FileStates>(model->extraData(i).toInt());
|
||||
QString file = model->file(i);
|
||||
const QString file = model->file(i);
|
||||
const bool checked = model->checked(i);
|
||||
|
||||
if (checked)
|
||||
@@ -3004,7 +3004,7 @@ void GitClient::revertFiles(const QStringList &files, bool revertStaging)
|
||||
|
||||
void GitClient::fetch(const FilePath &workingDirectory, const QString &remote)
|
||||
{
|
||||
QStringList const arguments = {"fetch", (remote.isEmpty() ? "--all" : remote)};
|
||||
const QStringList arguments{"fetch", (remote.isEmpty() ? "--all" : remote)};
|
||||
const auto commandHandler = [workingDirectory](const CommandResult &result) {
|
||||
if (result.result() == ProcessResult::FinishedWithSuccess)
|
||||
GitPlugin::updateBranches(workingDirectory);
|
||||
@@ -3050,7 +3050,7 @@ void GitClient::synchronousAbortCommand(const FilePath &workingDir, const QStrin
|
||||
if (abortCommand.isEmpty()) {
|
||||
// no abort command - checkout index to clean working copy.
|
||||
synchronousCheckoutFiles(VcsManager::findTopLevelForDirectory(workingDir),
|
||||
QStringList(), QString(), nullptr, false);
|
||||
{}, {}, nullptr, false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3064,15 +3064,15 @@ QString GitClient::synchronousTrackingBranch(const FilePath &workingDirectory, c
|
||||
QString remote;
|
||||
QString localBranch = branch.isEmpty() ? synchronousCurrentLocalBranch(workingDirectory) : branch;
|
||||
if (localBranch.isEmpty())
|
||||
return QString();
|
||||
return {};
|
||||
localBranch.prepend("branch.");
|
||||
remote = readConfigValue(workingDirectory, localBranch + ".remote");
|
||||
if (remote.isEmpty())
|
||||
return QString();
|
||||
return {};
|
||||
const QString rBranch = readConfigValue(workingDirectory, localBranch + ".merge")
|
||||
.replace("refs/heads/", QString());
|
||||
if (rBranch.isEmpty())
|
||||
return QString();
|
||||
return {};
|
||||
return remote + '/' + rBranch;
|
||||
}
|
||||
|
||||
@@ -3252,7 +3252,7 @@ void GitClient::push(const FilePath &workingDirectory, const QStringList &pushAr
|
||||
bool GitClient::synchronousMerge(const FilePath &workingDirectory, const QString &branch,
|
||||
bool allowFastForward)
|
||||
{
|
||||
QString command = "merge";
|
||||
const QString command = "merge";
|
||||
QStringList arguments = {command};
|
||||
if (!allowFastForward)
|
||||
arguments << "--no-ff";
|
||||
|
||||
@@ -1634,8 +1634,8 @@ bool GitPluginPrivate::activateCommit()
|
||||
return true;
|
||||
|
||||
auto model = qobject_cast<SubmitFileModel *>(editor->fileModel());
|
||||
CommitType commitType = editor->commitType();
|
||||
QString amendSHA1 = editor->amendSHA1();
|
||||
const CommitType commitType = editor->commitType();
|
||||
const QString amendSHA1 = editor->amendSHA1();
|
||||
if (model->hasCheckedFiles() || !amendSHA1.isEmpty()) {
|
||||
// get message & commit
|
||||
if (!DocumentManager::saveDocument(editorDocument))
|
||||
|
||||
@@ -245,7 +245,7 @@ GitSubmitEditorPanelData GitSubmitEditor::panelData() const
|
||||
|
||||
QString GitSubmitEditor::amendSHA1() const
|
||||
{
|
||||
QString commit = submitEditorWidget()->amendSHA1();
|
||||
const QString commit = submitEditorWidget()->amendSHA1();
|
||||
return commit.isEmpty() ? m_amendSHA1 : commit;
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ void LogChangeWidget::setItemDelegate(QAbstractItemDelegate *delegate)
|
||||
void LogChangeWidget::emitCommitActivated(const QModelIndex &index)
|
||||
{
|
||||
if (index.isValid()) {
|
||||
QString commit = index.sibling(index.row(), Sha1Column).data().toString();
|
||||
const QString commit = index.sibling(index.row(), Sha1Column).data().toString();
|
||||
if (!commit.isEmpty())
|
||||
emit commitActivated(commit);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user