Cvs: Reuse CommandResult

Get rid of CvsResponse.

Change-Id: I4f1bf6dfad56f730140a0841769b7246a22aa757
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2022-10-06 11:41:26 +02:00
parent 520e7b3b69
commit 9d4017400e

View File

@@ -92,17 +92,6 @@ const char CVS_SUBMIT_MIMETYPE[] = "text/vnd.qtcreator.cvs.submit";
const char CVSCOMMITEDITOR_ID[] = "CVS Commit Editor"; const char CVSCOMMITEDITOR_ID[] = "CVS Commit Editor";
const char CVSCOMMITEDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("VCS", "CVS Commit Editor"); const char CVSCOMMITEDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("VCS", "CVS Commit Editor");
class CvsResponse
{
public:
enum Result { Ok, NonNullExitCode, OtherError };
Result result = Ok;
QString stdOut;
QString stdErr;
QString message;
};
const VcsBaseSubmitEditorParameters submitParameters { const VcsBaseSubmitEditorParameters submitParameters {
CVS_SUBMIT_MIMETYPE, CVS_SUBMIT_MIMETYPE,
CVSCOMMITEDITOR_ID, CVSCOMMITEDITOR_ID,
@@ -140,10 +129,10 @@ const VcsBaseEditorParameters diffEditorParameters {
static inline bool messageBoxQuestion(const QString &title, const QString &question) static inline bool messageBoxQuestion(const QString &title, const QString &question)
{ {
return QMessageBox::question(ICore::dialogParent(), title, question, QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes; return QMessageBox::question(ICore::dialogParent(), title, question,
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes;
} }
// Parameter widget controlling whitespace diff mode, associated with a parameter // Parameter widget controlling whitespace diff mode, associated with a parameter
class CvsDiffConfig : public VcsBaseEditorConfig class CvsDiffConfig : public VcsBaseEditorConfig
{ {
@@ -279,29 +268,28 @@ private:
bool isCommitEditorOpen() const; bool isCommitEditorOpen() const;
Core::IEditor *showOutputInEditor(const QString& title, const QString &output, Core::IEditor *showOutputInEditor(const QString& title, const QString &output,
Utils::Id id, const QString &source, Utils::Id id, const QString &source, QTextCodec *codec);
QTextCodec *codec);
CvsResponse runCvs(const FilePath &workingDirectory, CommandResult runCvs(const FilePath &workingDirectory, const QStringList &arguments,
const QStringList &arguments, RunFlags flags = RunFlags::None, QTextCodec *outputCodec = nullptr,
RunFlags flags = RunFlags::None,
QTextCodec *outputCodec = nullptr,
int timeoutMultiplier = 1) const; int timeoutMultiplier = 1) const;
void annotate(const FilePath &workingDir, const QString &file, void annotate(const FilePath &workingDir, const QString &file,
const QString &revision = QString(), int lineNumber= -1); const QString &revision = {}, int lineNumber = -1);
bool describe(const QString &source, const QString &changeNr, QString *errorMessage); bool describe(const QString &source, const QString &changeNr, QString *errorMessage);
bool describe(const Utils::FilePath &toplevel, const QString &source, const QString &changeNr, QString *errorMessage); bool describe(const Utils::FilePath &toplevel, const QString &source,
bool describe(const Utils::FilePath &repository, QList<CvsLogEntry> entries, QString *errorMessage); const QString &changeNr, QString *errorMessage);
void filelog(const Utils::FilePath &workingDir, bool describe(const Utils::FilePath &repository, QList<CvsLogEntry> entries,
const QString &file = {}, QString *errorMessage);
void filelog(const Utils::FilePath &workingDir, const QString &file = {},
bool enableAnnotationContextMenu = false); bool enableAnnotationContextMenu = false);
bool unedit(const Utils::FilePath &topLevel, const QStringList &files); bool unedit(const Utils::FilePath &topLevel, const QStringList &files);
bool status(const Utils::FilePath &topLevel, const QString &file, const QString &title); bool status(const Utils::FilePath &topLevel, const QString &file, const QString &title);
bool update(const Utils::FilePath &topLevel, const QString &file); bool update(const Utils::FilePath &topLevel, const QString &file);
bool checkCVSDirectory(const QDir &directory) const; bool checkCVSDirectory(const QDir &directory) const;
// Quick check if files are modified // Quick check if files are modified
bool diffCheckModified(const Utils::FilePath &topLevel, const QStringList &files, bool *modified); bool diffCheckModified(const Utils::FilePath &topLevel, const QStringList &files,
bool *modified);
QString findTopLevelForDirectoryI(const QString &directory) const; QString findTopLevelForDirectoryI(const QString &directory) const;
void startCommit(const Utils::FilePath &workingDir, const QString &file = {}); void startCommit(const Utils::FilePath &workingDir, const QString &file = {});
bool commit(const QString &messageFile, const QStringList &subVersionFileList); bool commit(const QString &messageFile, const QStringList &subVersionFileList);
@@ -441,7 +429,7 @@ bool CvsPluginPrivate::vcsCreateRepository(const FilePath &)
void CvsPluginPrivate::vcsAnnotate(const FilePath &filePath, int line) void CvsPluginPrivate::vcsAnnotate(const FilePath &filePath, int line)
{ {
vcsAnnotate(filePath.parentDir(), filePath.fileName(), QString(), line); vcsAnnotate(filePath.parentDir(), filePath.fileName(), {}, line);
} }
QString CvsPluginPrivate::vcsOpenText() const QString CvsPluginPrivate::vcsOpenText() const
@@ -845,31 +833,29 @@ void CvsPluginPrivate::revertAll()
const QString title = Tr::tr("Revert Repository"); const QString title = Tr::tr("Revert Repository");
if (!messageBoxQuestion(title, Tr::tr("Revert all pending changes to the repository?"))) if (!messageBoxQuestion(title, Tr::tr("Revert all pending changes to the repository?")))
return; return;
QStringList args; const auto revertResponse = runCvs(state.topLevel(), {"update", "-C",
args << QLatin1String("update") << QLatin1String("-C") << state.topLevel().toString(); state.topLevel().toString()}, RunFlags::ShowStdOut);
const auto revertResponse = runCvs(state.topLevel(), args, RunFlags::ShowStdOut); if (revertResponse.result() != ProcessResult::FinishedWithSuccess) {
if (revertResponse.result == CvsResponse::Ok) Core::AsynchronousMessageBox::warning(title, Tr::tr("Revert failed: %1")
.arg(revertResponse.exitMessage()));
return;
}
emit repositoryChanged(state.topLevel()); emit repositoryChanged(state.topLevel());
else
Core::AsynchronousMessageBox::warning(title,
Tr::tr("Revert failed: %1").arg(revertResponse.message));
} }
void CvsPluginPrivate::revertCurrentFile() void CvsPluginPrivate::revertCurrentFile()
{ {
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return); QTC_ASSERT(state.hasFile(), return);
QStringList args; const auto diffRes = runCvs(state.currentFileTopLevel(), {"diff", state.relativeCurrentFile()});
args << QLatin1String("diff") << state.relativeCurrentFile(); switch (diffRes.result()) {
const CvsResponse diffResponse = runCvs(state.currentFileTopLevel(), args); case ProcessResult::FinishedWithSuccess:
switch (diffResponse.result) {
case CvsResponse::Ok:
return; // Not modified, diff exit code 0 return; // Not modified, diff exit code 0
case CvsResponse::NonNullExitCode: // Diff exit code != 0 case ProcessResult::FinishedWithError: // Diff exit code != 0
if (diffResponse.stdOut.isEmpty()) // Paranoia: Something else failed? if (diffRes.cleanedStdOut().isEmpty()) // Paranoia: Something else failed?
return; return;
break; break;
case CvsResponse::OtherError: default:
return; return;
} }
@@ -880,10 +866,9 @@ void CvsPluginPrivate::revertCurrentFile()
FileChangeBlocker fcb(FilePath::fromString(state.currentFile())); FileChangeBlocker fcb(FilePath::fromString(state.currentFile()));
// revert // revert
args.clear(); const auto revertRes = runCvs(state.currentFileTopLevel(),
args << QLatin1String("update") << QLatin1String("-C") << state.relativeCurrentFile(); {"update", "-C", state.relativeCurrentFile()}, RunFlags::ShowStdOut);
const auto revertResponse = runCvs(state.currentFileTopLevel(), args, RunFlags::ShowStdOut); if (revertRes.result() == ProcessResult::FinishedWithSuccess)
if (revertResponse.result == CvsResponse::Ok)
emit filesChanged(QStringList(state.currentFile())); emit filesChanged(QStringList(state.currentFile()));
} }
@@ -934,7 +919,6 @@ void CvsPluginPrivate::startCommit(const FilePath &workingDir, const QString &fi
{ {
if (!promptBeforeCommit()) if (!promptBeforeCommit())
return; return;
if (raiseSubmitEditor()) if (raiseSubmitEditor())
return; return;
if (isCommitEditorOpen()) { if (isCommitEditorOpen()) {
@@ -944,13 +928,12 @@ void CvsPluginPrivate::startCommit(const FilePath &workingDir, const QString &fi
// We need the "Examining <subdir>" stderr output to tell // We need the "Examining <subdir>" stderr output to tell
// where we are, so, have stdout/stderr channels merged. // where we are, so, have stdout/stderr channels merged.
QStringList args = QStringList(QLatin1String("status")); const auto response = runCvs(workingDir, {"status"}, RunFlags::MergeOutputChannels);
const CvsResponse response = runCvs(workingDir, args, RunFlags::MergeOutputChannels); if (response.result() != ProcessResult::FinishedWithSuccess)
if (response.result != CvsResponse::Ok)
return; return;
// Get list of added/modified/deleted files and purge out undesired ones // Get list of added/modified/deleted files and purge out undesired ones
// (do not run status with relative arguments as it will omit the directories) // (do not run status with relative arguments as it will omit the directories)
StateList statusOutput = parseStatusOutput(QString(), response.stdOut); StateList statusOutput = parseStatusOutput({}, response.cleanedStdOut());
if (!file.isEmpty()) { if (!file.isEmpty()) {
for (StateList::iterator it = statusOutput.begin(); it != statusOutput.end() ; ) { for (StateList::iterator it = statusOutput.begin(); it != statusOutput.end() ; ) {
if (file == it->second) if (file == it->second)
@@ -987,11 +970,10 @@ void CvsPluginPrivate::startCommit(const FilePath &workingDir, const QString &fi
bool CvsPluginPrivate::commit(const QString &messageFile, bool CvsPluginPrivate::commit(const QString &messageFile,
const QStringList &fileList) const QStringList &fileList)
{ {
QStringList args = QStringList(QLatin1String("commit")); const QStringList args{"commit", "-F", messageFile};
args << QLatin1String("-F") << messageFile; const auto response = runCvs(m_commitRepository, args + fileList, RunFlags::ShowStdOut, nullptr,
args.append(fileList); 10);
const auto response = runCvs(m_commitRepository, args, RunFlags::ShowStdOut, nullptr, 10); return response.result() == ProcessResult::FinishedWithSuccess;
return response.result == CvsResponse::Ok ;
} }
void CvsPluginPrivate::filelogCurrentFile() void CvsPluginPrivate::filelogCurrentFile()
@@ -1023,22 +1005,20 @@ void CvsPluginPrivate::filelog(const FilePath &workingDir,
// no need for temp file // no need for temp file
const QString id = VcsBaseEditor::getTitleId(workingDir, QStringList(file)); const QString id = VcsBaseEditor::getTitleId(workingDir, QStringList(file));
const QString source = VcsBaseEditor::getSource(workingDir, file); const QString source = VcsBaseEditor::getSource(workingDir, file);
QStringList args; const auto response = runCvs(workingDir, {"log", file}, RunFlags::None, codec);
args << QLatin1String("log"); if (response.result() != ProcessResult::FinishedWithSuccess)
args.append(file);
const CvsResponse response = runCvs(workingDir, args, RunFlags::None, codec);
if (response.result != CvsResponse::Ok)
return; return;
// Re-use an existing view if possible to support // Re-use an existing view if possible to support
// the common usage pattern of continuously changing and diffing a file // the common usage pattern of continuously changing and diffing a file
const QString tag = VcsBaseEditor::editorTag(LogOutput, workingDir.toString(), QStringList(file)); const QString tag = VcsBaseEditor::editorTag(LogOutput, workingDir.toString(), QStringList(file));
if (IEditor *editor = VcsBaseEditor::locateEditorByTag(tag)) { if (IEditor *editor = VcsBaseEditor::locateEditorByTag(tag)) {
editor->document()->setContents(response.stdOut.toUtf8()); editor->document()->setContents(response.cleanedStdOut().toUtf8());
EditorManager::activateEditor(editor); EditorManager::activateEditor(editor);
} else { } else {
const QString title = QString::fromLatin1("cvs log %1").arg(id); const QString title = QString::fromLatin1("cvs log %1").arg(id);
IEditor *newEditor = showOutputInEditor(title, response.stdOut, logEditorParameters.id, source, codec); IEditor *newEditor = showOutputInEditor(title, response.cleanedStdOut(),
logEditorParameters.id, source, codec);
VcsBaseEditor::tagEditor(newEditor, tag); VcsBaseEditor::tagEditor(newEditor, tag);
if (enableAnnotationContextMenu) if (enableAnnotationContextMenu)
VcsBaseEditor::getVcsBaseEditor(newEditor)->setFileLogAnnotateEnabled(true); VcsBaseEditor::getVcsBaseEditor(newEditor)->setFileLogAnnotateEnabled(true);
@@ -1049,7 +1029,7 @@ void CvsPluginPrivate::updateDirectory()
{ {
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return); QTC_ASSERT(state.hasFile(), return);
update(state.currentFileDirectory(), QString()); update(state.currentFileDirectory(), {});
} }
void CvsPluginPrivate::updateProject() void CvsPluginPrivate::updateProject()
@@ -1061,12 +1041,11 @@ void CvsPluginPrivate::updateProject()
bool CvsPluginPrivate::update(const FilePath &topLevel, const QString &file) bool CvsPluginPrivate::update(const FilePath &topLevel, const QString &file)
{ {
QStringList args(QLatin1String("update")); QStringList args{"update", "-dR"};
args.push_back(QLatin1String("-dR"));
if (!file.isEmpty()) if (!file.isEmpty())
args.append(file); args.append(file);
const auto response = runCvs(topLevel, args, RunFlags::ShowStdOut, nullptr, 10); const auto response = runCvs(topLevel, args, RunFlags::ShowStdOut, nullptr, 10);
const bool ok = response.result == CvsResponse::Ok; const bool ok = response.result() == ProcessResult::FinishedWithSuccess;
if (ok) if (ok)
emit repositoryChanged(topLevel); emit repositoryChanged(topLevel);
return ok; return ok;
@@ -1108,23 +1087,22 @@ void CvsPluginPrivate::vcsAnnotate(const FilePath &workingDirectory, const QStri
bool CvsPluginPrivate::edit(const FilePath &topLevel, const QStringList &files) bool CvsPluginPrivate::edit(const FilePath &topLevel, const QStringList &files)
{ {
QStringList args(QLatin1String("edit")); const QStringList args{"edit"};
args.append(files); const auto response = runCvs(topLevel, args + files, RunFlags::ShowStdOut);
const auto response = runCvs(topLevel, args, RunFlags::ShowStdOut); return response.result() == ProcessResult::FinishedWithSuccess;
return response.result == CvsResponse::Ok;
} }
bool CvsPluginPrivate::diffCheckModified(const FilePath &topLevel, const QStringList &files, bool *modified) bool CvsPluginPrivate::diffCheckModified(const FilePath &topLevel, const QStringList &files,
bool *modified)
{ {
// Quick check for modified files using diff // Quick check for modified files using diff
*modified = false; *modified = false;
QStringList args(QLatin1String("-q")); const QStringList args{"-q", "diff"};
args << QLatin1String("diff"); const auto result = runCvs(topLevel, args + files).result();
args.append(files); if (result != ProcessResult::FinishedWithSuccess && result != ProcessResult::FinishedWithError)
const CvsResponse response = runCvs(topLevel, args);
if (response.result == CvsResponse::OtherError)
return false; return false;
*modified = response.result == CvsResponse::NonNullExitCode;
*modified = result == ProcessResult::FinishedWithError;
return true; return true;
} }
@@ -1142,14 +1120,13 @@ bool CvsPluginPrivate::unedit(const FilePath &topLevel, const QStringList &files
return false; return false;
} }
QStringList args(QLatin1String("unedit")); QStringList args{"unedit"};
// Note: Option '-y' to force 'yes'-answer to CVS' 'undo change' prompt, // Note: Option '-y' to force 'yes'-answer to CVS' 'undo change' prompt,
// exists in CVSNT only as of 6.8.2010. Standard CVS will otherwise prompt // exists in CVSNT only as of 6.8.2010. Standard CVS will otherwise prompt
if (modified) if (modified)
args.append(QLatin1String("-y")); args.append(QLatin1String("-y"));
args.append(files); const auto response = runCvs(topLevel, args + files, RunFlags::ShowStdOut);
const auto response = runCvs(topLevel, args, RunFlags::ShowStdOut); return response.result() == ProcessResult::FinishedWithSuccess;
return response.result == CvsResponse::Ok;
} }
void CvsPluginPrivate::annotate(const FilePath &workingDir, const QString &file, void CvsPluginPrivate::annotate(const FilePath &workingDir, const QString &file,
@@ -1160,13 +1137,12 @@ void CvsPluginPrivate::annotate(const FilePath &workingDir, const QString &file,
QTextCodec *codec = VcsBaseEditor::getCodec(workingDir, files); QTextCodec *codec = VcsBaseEditor::getCodec(workingDir, files);
const QString id = VcsBaseEditor::getTitleId(workingDir, files, revision); const QString id = VcsBaseEditor::getTitleId(workingDir, files, revision);
const QString source = VcsBaseEditor::getSource(workingDir, file); const QString source = VcsBaseEditor::getSource(workingDir, file);
QStringList args; QStringList args{"annotate"};
args << QLatin1String("annotate");
if (!revision.isEmpty()) if (!revision.isEmpty())
args << QLatin1String("-r") << revision; args << "-r" << revision;
args << file; args << file;
const CvsResponse response = runCvs(workingDir, args, RunFlags::None, codec); const auto response = runCvs(workingDir, args, RunFlags::None, codec);
if (response.result != CvsResponse::Ok) if (response.result() != ProcessResult::FinishedWithSuccess)
return; return;
// Re-use an existing view if possible to support // Re-use an existing view if possible to support
@@ -1176,12 +1152,13 @@ void CvsPluginPrivate::annotate(const FilePath &workingDir, const QString &file,
const QString tag = VcsBaseEditor::editorTag(AnnotateOutput, workingDir.toString(), QStringList(file), revision); const QString tag = VcsBaseEditor::editorTag(AnnotateOutput, workingDir.toString(), QStringList(file), revision);
if (IEditor *editor = VcsBaseEditor::locateEditorByTag(tag)) { if (IEditor *editor = VcsBaseEditor::locateEditorByTag(tag)) {
editor->document()->setContents(response.stdOut.toUtf8()); editor->document()->setContents(response.cleanedStdOut().toUtf8());
VcsBaseEditor::gotoLineOfEditor(editor, lineNumber); VcsBaseEditor::gotoLineOfEditor(editor, lineNumber);
EditorManager::activateEditor(editor); EditorManager::activateEditor(editor);
} else { } else {
const QString title = QString::fromLatin1("cvs annotate %1").arg(id); const QString title = QString::fromLatin1("cvs annotate %1").arg(id);
IEditor *newEditor = showOutputInEditor(title, response.stdOut, annotateEditorParameters.id, source, codec); IEditor *newEditor = showOutputInEditor(title, response.cleanedStdOut(),
annotateEditorParameters.id, source, codec);
VcsBaseEditor::tagEditor(newEditor, tag); VcsBaseEditor::tagEditor(newEditor, tag);
VcsBaseEditor::gotoLineOfEditor(newEditor, lineNumber); VcsBaseEditor::gotoLineOfEditor(newEditor, lineNumber);
} }
@@ -1189,13 +1166,15 @@ void CvsPluginPrivate::annotate(const FilePath &workingDir, const QString &file,
bool CvsPluginPrivate::status(const FilePath &topLevel, const QString &file, const QString &title) bool CvsPluginPrivate::status(const FilePath &topLevel, const QString &file, const QString &title)
{ {
QStringList args(QLatin1String("status")); QStringList args{"status"};
if (!file.isEmpty()) if (!file.isEmpty())
args.append(file); args.append(file);
const CvsResponse response = runCvs(topLevel, args); const auto response = runCvs(topLevel, args);
const bool ok = response.result == CvsResponse::Ok; const bool ok = response.result() == ProcessResult::FinishedWithSuccess;
if (ok) if (ok) {
showOutputInEditor(title, response.stdOut, commandLogEditorParameters.id, topLevel.toString(), nullptr); showOutputInEditor(title, response.cleanedStdOut(), commandLogEditorParameters.id,
topLevel.toString(), nullptr);
}
return ok; return ok;
} }
@@ -1224,14 +1203,14 @@ void CvsPluginPrivate::statusRepository()
{ {
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
status(state.topLevel(), QString(), Tr::tr("Repository status")); status(state.topLevel(), {}, Tr::tr("Repository status"));
} }
void CvsPluginPrivate::updateRepository() void CvsPluginPrivate::updateRepository()
{ {
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
update(state.topLevel(), QString()); update(state.topLevel(), {});
} }
@@ -1247,8 +1226,8 @@ bool CvsPluginPrivate::describe(const QString &file, const QString &changeNr, QS
return describe(toplevel, QDir(toplevel.toString()).relativeFilePath(file), changeNr, errorMessage); return describe(toplevel, QDir(toplevel.toString()).relativeFilePath(file), changeNr, errorMessage);
} }
bool CvsPluginPrivate::describe(const FilePath &toplevel, const QString &file, const bool CvsPluginPrivate::describe(const FilePath &toplevel, const QString &file,
QString &changeNr, QString *errorMessage) const QString &changeNr, QString *errorMessage)
{ {
// In CVS, revisions of files are normally unrelated, there is // In CVS, revisions of files are normally unrelated, there is
@@ -1263,14 +1242,12 @@ bool CvsPluginPrivate::describe(const FilePath &toplevel, const QString &file, c
return false; return false;
} }
// Run log to obtain commit id and details // Run log to obtain commit id and details
QStringList args; const auto logResponse = runCvs(toplevel, {"log", QString("-r%1").arg(changeNr), file});
args << QLatin1String("log") << (QLatin1String("-r") + changeNr) << file; if (logResponse.result() != ProcessResult::FinishedWithSuccess) {
const CvsResponse logResponse = runCvs(toplevel, args); *errorMessage = logResponse.exitMessage();
if (logResponse.result != CvsResponse::Ok) {
*errorMessage = logResponse.message;
return false; return false;
} }
const QList<CvsLogEntry> fileLog = parseLogEntries(logResponse.stdOut); const QList<CvsLogEntry> fileLog = parseLogEntries(logResponse.cleanedStdOut());
if (fileLog.empty() || fileLog.front().revisions.empty()) { if (fileLog.empty() || fileLog.front().revisions.empty()) {
*errorMessage = Tr::tr("Parsing of the log output failed."); *errorMessage = Tr::tr("Parsing of the log output failed.");
return false; return false;
@@ -1283,16 +1260,15 @@ bool CvsPluginPrivate::describe(const FilePath &toplevel, const QString &file, c
const QString dateS = fileLog.front().revisions.front().date; const QString dateS = fileLog.front().revisions.front().date;
const QDate date = QDate::fromString(dateS, Qt::ISODate); const QDate date = QDate::fromString(dateS, Qt::ISODate);
const QString nextDayS = date.addDays(1).toString(Qt::ISODate); const QString nextDayS = date.addDays(1).toString(Qt::ISODate);
args.clear(); const QStringList args{"log", "-d", dateS + '<' + nextDayS};
args << QLatin1String("log") << QLatin1String("-d") << (dateS + QLatin1Char('<') + nextDayS); const auto repoLogResponse = runCvs(toplevel, args, RunFlags::None, nullptr, 10);
if (repoLogResponse.result() != ProcessResult::FinishedWithSuccess) {
const CvsResponse repoLogResponse = runCvs(toplevel, args, RunFlags::None, nullptr, 10); *errorMessage = repoLogResponse.exitMessage();
if (repoLogResponse.result != CvsResponse::Ok) {
*errorMessage = repoLogResponse.message;
return false; return false;
} }
// Describe all files found, pass on dir to obtain correct absolute paths. // Describe all files found, pass on dir to obtain correct absolute paths.
const QList<CvsLogEntry> repoEntries = parseLogEntries(repoLogResponse.stdOut, QString(), commitId); const QList<CvsLogEntry> repoEntries = parseLogEntries(repoLogResponse.cleanedStdOut(),
{}, commitId);
if (repoEntries.empty()) { if (repoEntries.empty()) {
*errorMessage = Tr::tr("Could not find commits of id \"%1\" on %2.").arg(commitId, dateS); *errorMessage = Tr::tr("Could not find commits of id \"%1\" on %2.").arg(commitId, dateS);
return false; return false;
@@ -1320,38 +1296,35 @@ bool CvsPluginPrivate::describe(const FilePath &repositoryPath,
if (!codec) if (!codec)
codec = VcsBaseEditor::getCodec(repositoryPath, QStringList(it->file)); codec = VcsBaseEditor::getCodec(repositoryPath, QStringList(it->file));
// Run log // Run log
QStringList args(QLatin1String("log")); const QStringList args{"log", "-r", it->revisions.front().revision, it->file};
args << (QLatin1String("-r") + it->revisions.front().revision) << it->file; const auto logResponse = runCvs(repositoryPath, args);
const CvsResponse logResponse = runCvs(repositoryPath, args); if (logResponse.result() != ProcessResult::FinishedWithSuccess) {
if (logResponse.result != CvsResponse::Ok) { *errorMessage = logResponse.exitMessage();
*errorMessage = logResponse.message;
return false; return false;
} }
output += logResponse.stdOut; output += logResponse.cleanedStdOut();
} }
// Collect diffs relative to repository // Collect diffs relative to repository
for (QList<CvsLogEntry>::iterator it = entries.begin(); it != lend; ++it) { for (QList<CvsLogEntry>::iterator it = entries.begin(); it != lend; ++it) {
const QString &revision = it->revisions.front().revision; const QString &revision = it->revisions.front().revision;
if (!isFirstRevision(revision)) { if (!isFirstRevision(revision)) {
const QString previousRev = previousRevision(revision); const QStringList args{"diff", m_settings.diffOptions.value(),
QStringList args(QLatin1String("diff")); "-r", previousRevision(revision),
args << m_settings.diffOptions.value() "-r", it->revisions.front().revision, it->file};
<< QLatin1String("-r") << previousRev << QLatin1String("-r") const auto diffResponse = runCvs(repositoryPath, args, RunFlags::None, codec);
<< it->revisions.front().revision << it->file; switch (diffResponse.result()) {
const CvsResponse diffResponse = runCvs(repositoryPath, args, RunFlags::None, codec); case ProcessResult::FinishedWithSuccess:
switch (diffResponse.result) { case ProcessResult::FinishedWithError: // Diff exit code != 0
case CvsResponse::Ok: if (diffResponse.cleanedStdOut().isEmpty()) {
case CvsResponse::NonNullExitCode: // Diff exit code != 0 *errorMessage = diffResponse.exitMessage();
if (diffResponse.stdOut.isEmpty()) {
*errorMessage = diffResponse.message;
return false; // Something else failed. return false; // Something else failed.
} }
break; break;
case CvsResponse::OtherError: default:
*errorMessage = diffResponse.message; *errorMessage = diffResponse.exitMessage();
return false; return false;
} }
output += fixDiffOutput(diffResponse.stdOut); output += fixDiffOutput(diffResponse.cleanedStdOut());
} }
} }
@@ -1364,7 +1337,8 @@ bool CvsPluginPrivate::describe(const FilePath &repositoryPath,
setDiffBaseDirectory(editor, repositoryPath); setDiffBaseDirectory(editor, repositoryPath);
} else { } else {
const QString title = QString::fromLatin1("cvs describe %1").arg(commitId); const QString title = QString::fromLatin1("cvs describe %1").arg(commitId);
IEditor *newEditor = showOutputInEditor(title, output, diffEditorParameters.id, entries.front().file, codec); IEditor *newEditor = showOutputInEditor(title, output, diffEditorParameters.id,
entries.front().file, codec);
VcsBaseEditor::tagEditor(newEditor, commitId); VcsBaseEditor::tagEditor(newEditor, commitId);
setDiffBaseDirectory(newEditor, repositoryPath); setDiffBaseDirectory(newEditor, repositoryPath);
} }
@@ -1380,44 +1354,18 @@ void CvsPluginPrivate::commitFromEditor()
// Run CVS. At this point, file arguments must be relative to // Run CVS. At this point, file arguments must be relative to
// the working directory (see above). // the working directory (see above).
CvsResponse CvsPluginPrivate::runCvs(const FilePath &workingDirectory, CommandResult CvsPluginPrivate::runCvs(const FilePath &workingDirectory,
const QStringList &arguments, const QStringList &arguments, RunFlags flags,
RunFlags flags, QTextCodec *outputCodec, int timeoutMultiplier) const
QTextCodec *outputCodec,
int timeoutMultiplier) const
{ {
const FilePath executable = m_settings.binaryPath.filePath(); const FilePath executable = m_settings.binaryPath.filePath();
CvsResponse response; if (executable.isEmpty())
if (executable.isEmpty()) { return CommandResult(ProcessResult::StartFailed, Tr::tr("No CVS executable specified."));
response.result = CvsResponse::OtherError;
response.message = Tr::tr("No CVS executable specified.");
return response;
}
const int timeoutS = m_settings.timeout.value() * timeoutMultiplier; const int timeoutS = m_settings.timeout.value() * timeoutMultiplier;
const CommandResult result = m_client->vcsSynchronousExec(workingDirectory, return m_client->vcsSynchronousExec(workingDirectory,
{executable, m_settings.addOptions(arguments)}, {executable, m_settings.addOptions(arguments)},
flags, timeoutS, outputCodec); flags, timeoutS, outputCodec);
response.result = CvsResponse::OtherError;
response.stdErr = result.cleanedStdErr();
response.stdOut = result.cleanedStdOut();
switch (result.result()) {
case ProcessResult::FinishedWithSuccess:
response.result = CvsResponse::Ok;
break;
case ProcessResult::FinishedWithError:
response.result = CvsResponse::NonNullExitCode;
break;
case ProcessResult::TerminatedAbnormally:
case ProcessResult::StartFailed:
case ProcessResult::Hang:
break;
}
if (response.result != CvsResponse::Ok)
response.message = result.exitMessage();
return response;
} }
IEditor *CvsPluginPrivate::showOutputInEditor(const QString& title, const QString &output, IEditor *CvsPluginPrivate::showOutputInEditor(const QString& title, const QString &output,
@@ -1442,18 +1390,14 @@ IEditor *CvsPluginPrivate::showOutputInEditor(const QString& title, const QStrin
bool CvsPluginPrivate::vcsAdd(const FilePath &workingDir, const QString &rawFileName) bool CvsPluginPrivate::vcsAdd(const FilePath &workingDir, const QString &rawFileName)
{ {
QStringList args; const auto response = runCvs(workingDir, {"add", rawFileName}, RunFlags::ShowStdOut);
args << QLatin1String("add") << rawFileName; return response.result() == ProcessResult::FinishedWithSuccess;
const auto response = runCvs(workingDir, args, RunFlags::ShowStdOut);
return response.result == CvsResponse::Ok;
} }
bool CvsPluginPrivate::vcsDelete(const FilePath &workingDir, const QString &rawFileName) bool CvsPluginPrivate::vcsDelete(const FilePath &workingDir, const QString &rawFileName)
{ {
QStringList args; const auto response = runCvs(workingDir, {"remove", "-f", rawFileName}, RunFlags::ShowStdOut);
args << QLatin1String("remove") << QLatin1String("-f") << rawFileName; return response.result() == ProcessResult::FinishedWithSuccess;
const auto response = runCvs(workingDir, args, RunFlags::ShowStdOut);
return response.result == CvsResponse::Ok;
} }
/* CVS has a "CVS" directory in each directory it manages. The top level /* CVS has a "CVS" directory in each directory it manages. The top level
@@ -1489,12 +1433,10 @@ bool CvsPluginPrivate::managesDirectory(const FilePath &directory, FilePath *top
bool CvsPluginPrivate::managesFile(const FilePath &workingDirectory, const QString &fileName) const bool CvsPluginPrivate::managesFile(const FilePath &workingDirectory, const QString &fileName) const
{ {
QStringList args; const auto response = runCvs(workingDirectory, {"status", fileName});
args << QLatin1String("status") << fileName; if (response.result() != ProcessResult::FinishedWithSuccess)
const CvsResponse response = runCvs(workingDirectory, args);
if (response.result != CvsResponse::Ok)
return false; return false;
return !response.stdOut.contains(QLatin1String("Status: Unknown")); return !response.cleanedStdOut().contains(QLatin1String("Status: Unknown"));
} }
bool CvsPluginPrivate::checkCVSDirectory(const QDir &directory) const bool CvsPluginPrivate::checkCVSDirectory(const QDir &directory) const