From 3769c40cbb80d688572e56d51404ce0d6e831650 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Sun, 21 Jan 2024 20:46:09 +0100 Subject: [PATCH] Perforce: Simplify fileNameFromPerforceName() Drop errorMessage arg. There are 2 callers of this method 1. PerforcePluginPrivate::printOpenedFileList() was ignoring this arg. 2. PerforceEditorWidget::findDiffFile() was just printing qWarning(). In this case, instead of printing a warning, append a relevant error message to the VcsOutputWindow. Note, that this is done in case the passed quiet is false. Once, it's done implicitly by the call to runP4Cmd() and passing ErrorToWindow flag. The second possible message is explicitly sent to VcsOutputWindow in case of !quiet. Change-Id: I257d474b958b09965ffabdd09ff2e0fb253a0bf8 Reviewed-by: Orgad Shaneh --- src/plugins/perforce/perforceeditor.cpp | 6 +----- src/plugins/perforce/perforceplugin.cpp | 16 ++++++++-------- src/plugins/perforce/perforceplugin.h | 2 +- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/plugins/perforce/perforceeditor.cpp b/src/plugins/perforce/perforceeditor.cpp index 7f122432436..c9378505504 100644 --- a/src/plugins/perforce/perforceeditor.cpp +++ b/src/plugins/perforce/perforceeditor.cpp @@ -58,11 +58,7 @@ VcsBase::BaseAnnotationHighlighterCreator PerforceEditorWidget::annotationHighli QString PerforceEditorWidget::findDiffFile(const QString &f) const { - QString errorMessage; - const QString fileName = fileNameFromPerforceName(f.trimmed(), false, &errorMessage); - if (fileName.isEmpty()) - qWarning("%s", qPrintable(errorMessage)); - return fileName; + return fileNameFromPerforceName(f.trimmed(), false); } QStringList PerforceEditorWidget::annotationPreviousVersions(const QString &v) const diff --git a/src/plugins/perforce/perforceplugin.cpp b/src/plugins/perforce/perforceplugin.cpp index 8fc35a3ff17..3e3cbcc8ce4 100644 --- a/src/plugins/perforce/perforceplugin.cpp +++ b/src/plugins/perforce/perforceplugin.cpp @@ -691,7 +691,6 @@ void PerforcePluginPrivate::printOpenedFileList() return; // reformat "//depot/file.cpp#1 - description" into "file.cpp # - description" // for context menu opening to work. This produces absolute paths, then. - QString errorMessage; QString mapped; const QChar delimiter = QLatin1Char('#'); const QStringList lines = perforceResponse.stdOut.split(QLatin1Char('\n')); @@ -699,7 +698,7 @@ void PerforcePluginPrivate::printOpenedFileList() mapped.clear(); const int delimiterPos = line.indexOf(delimiter); if (delimiterPos > 0) - mapped = fileNameFromPerforceName(line.left(delimiterPos), true, &errorMessage); + mapped = fileNameFromPerforceName(line.left(delimiterPos), true); if (mapped.isEmpty()) VcsOutputWindow::appendSilently(line); else @@ -1618,7 +1617,7 @@ static QString msgWhereFailed(const QString & file, const QString &why) } // Map a perforce name "//xx" to its real name in the file system -QString fileNameFromPerforceName(const QString &perforceName, bool quiet, QString *errorMessage) +QString fileNameFromPerforceName(const QString &perforceName, bool quiet) { // All happy, already mapped if (!perforceName.startsWith(QLatin1String("//"))) @@ -1630,10 +1629,8 @@ QString fileNameFromPerforceName(const QString &perforceName, bool quiet, QStrin if (!quiet) flags |= CommandToWindow|StdErrToWindow|ErrorToWindow; const PerforceResponse response = dd->runP4Cmd(settings().topLevelSymLinkTarget(), args, flags); - if (response.error) { - *errorMessage = msgWhereFailed(perforceName, response.message); + if (response.error) return {}; - } QString output = response.stdOut; if (output.endsWith(QLatin1Char('\r'))) @@ -1642,8 +1639,11 @@ QString fileNameFromPerforceName(const QString &perforceName, bool quiet, QStrin output.chop(1); if (output.isEmpty()) { - //: File is not managed by Perforce - *errorMessage = msgWhereFailed(perforceName, Tr::tr("The file is not mapped")); + if (!quiet) { + //: File is not managed by Perforce + VcsOutputWindow::appendError(msgWhereFailed(perforceName, + Tr::tr("The file is not mapped"))); + } return {}; } const QString p4fileSpec = output.mid(output.lastIndexOf(QLatin1Char(' ')) + 1); diff --git a/src/plugins/perforce/perforceplugin.h b/src/plugins/perforce/perforceplugin.h index d0be5ab869f..e390e748140 100644 --- a/src/plugins/perforce/perforceplugin.h +++ b/src/plugins/perforce/perforceplugin.h @@ -8,6 +8,6 @@ namespace Perforce::Internal { // Map a perforce name "//xx" to its real name in the file system -QString fileNameFromPerforceName(const QString &perforceName, bool quiet, QString *errorMessage); +QString fileNameFromPerforceName(const QString &perforceName, bool quiet); } // Perforce::Internal