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

View File

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

View File

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