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 <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2024-01-21 20:46:09 +01:00
parent f200fe99a1
commit 3769c40cbb
3 changed files with 10 additions and 14 deletions

View File

@@ -58,11 +58,7 @@ VcsBase::BaseAnnotationHighlighterCreator PerforceEditorWidget::annotationHighli
QString PerforceEditorWidget::findDiffFile(const QString &f) const QString PerforceEditorWidget::findDiffFile(const QString &f) const
{ {
QString errorMessage; return fileNameFromPerforceName(f.trimmed(), false);
const QString fileName = fileNameFromPerforceName(f.trimmed(), false, &errorMessage);
if (fileName.isEmpty())
qWarning("%s", qPrintable(errorMessage));
return fileName;
} }
QStringList PerforceEditorWidget::annotationPreviousVersions(const QString &v) const QStringList PerforceEditorWidget::annotationPreviousVersions(const QString &v) const

View File

@@ -691,7 +691,6 @@ void PerforcePluginPrivate::printOpenedFileList()
return; return;
// reformat "//depot/file.cpp#1 - description" into "file.cpp # - description" // reformat "//depot/file.cpp#1 - description" into "file.cpp # - description"
// for context menu opening to work. This produces absolute paths, then. // for context menu opening to work. This produces absolute paths, then.
QString errorMessage;
QString mapped; QString mapped;
const QChar delimiter = QLatin1Char('#'); const QChar delimiter = QLatin1Char('#');
const QStringList lines = perforceResponse.stdOut.split(QLatin1Char('\n')); const QStringList lines = perforceResponse.stdOut.split(QLatin1Char('\n'));
@@ -699,7 +698,7 @@ void PerforcePluginPrivate::printOpenedFileList()
mapped.clear(); mapped.clear();
const int delimiterPos = line.indexOf(delimiter); const int delimiterPos = line.indexOf(delimiter);
if (delimiterPos > 0) if (delimiterPos > 0)
mapped = fileNameFromPerforceName(line.left(delimiterPos), true, &errorMessage); mapped = fileNameFromPerforceName(line.left(delimiterPos), true);
if (mapped.isEmpty()) if (mapped.isEmpty())
VcsOutputWindow::appendSilently(line); VcsOutputWindow::appendSilently(line);
else 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 // 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 // All happy, already mapped
if (!perforceName.startsWith(QLatin1String("//"))) if (!perforceName.startsWith(QLatin1String("//")))
@@ -1630,10 +1629,8 @@ QString fileNameFromPerforceName(const QString &perforceName, bool quiet, QStrin
if (!quiet) if (!quiet)
flags |= CommandToWindow|StdErrToWindow|ErrorToWindow; flags |= CommandToWindow|StdErrToWindow|ErrorToWindow;
const PerforceResponse response = dd->runP4Cmd(settings().topLevelSymLinkTarget(), args, flags); const PerforceResponse response = dd->runP4Cmd(settings().topLevelSymLinkTarget(), args, flags);
if (response.error) { if (response.error)
*errorMessage = msgWhereFailed(perforceName, response.message);
return {}; return {};
}
QString output = response.stdOut; QString output = response.stdOut;
if (output.endsWith(QLatin1Char('\r'))) if (output.endsWith(QLatin1Char('\r')))
@@ -1642,8 +1639,11 @@ QString fileNameFromPerforceName(const QString &perforceName, bool quiet, QStrin
output.chop(1); output.chop(1);
if (output.isEmpty()) { if (output.isEmpty()) {
//: File is not managed by Perforce if (!quiet) {
*errorMessage = msgWhereFailed(perforceName, Tr::tr("The file is not mapped")); //: File is not managed by Perforce
VcsOutputWindow::appendError(msgWhereFailed(perforceName,
Tr::tr("The file is not mapped")));
}
return {}; return {};
} }
const QString p4fileSpec = output.mid(output.lastIndexOf(QLatin1Char(' ')) + 1); const QString p4fileSpec = output.mid(output.lastIndexOf(QLatin1Char(' ')) + 1);

View File

@@ -8,6 +8,6 @@
namespace Perforce::Internal { namespace Perforce::Internal {
// Map a perforce name "//xx" to its real name in the file system // 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 } // Perforce::Internal