Adapt to upstream changes

Do some cleanup.

Change-Id: Ibbd9406d202bd6fa0eaf47ecd81f656578407634
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2022-10-06 18:59:29 +02:00
parent 9cea8ab213
commit 7ffdada4a3

View File

@@ -57,8 +57,7 @@ using namespace VcsBase;
namespace Fossil { namespace Fossil {
namespace Internal { namespace Internal {
const unsigned s_pullFlags = VcsCommand::ShowStdOut | VcsCommand::ShowSuccessMessage; const RunFlags s_pullFlags = RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage;
// Parameter widget controlling whitespace diff mode, associated with a parameter // Parameter widget controlling whitespace diff mode, associated with a parameter
class FossilDiffConfig : public VcsBaseEditorConfig class FossilDiffConfig : public VcsBaseEditorConfig
@@ -265,9 +264,7 @@ unsigned int FossilClient::synchronousBinaryVersion() const
if (settings().binaryPath.value().isEmpty()) if (settings().binaryPath.value().isEmpty())
return 0; return 0;
QStringList args("version"); const CommandResult result = vcsSynchronousExec({}, QStringList{"version"});
const CommandResult result = vcsSynchronousExec(FilePath(), args);
if (result.result() != ProcessResult::FinishedWithSuccess) if (result.result() != ProcessResult::FinishedWithSuccess)
return 0; return 0;
@@ -315,7 +312,8 @@ BranchInfo FossilClient::synchronousCurrentBranch(const FilePath &workingDirecto
if (!currentBranch.isCurrent()) { if (!currentBranch.isCurrent()) {
// If not available from open branches, request it from the list of closed branches. // If not available from open branches, request it from the list of closed branches.
const CommandResult result = vcsSynchronousExec(workingDirectory, {"branch", "list", "--closed"}); const CommandResult result = vcsSynchronousExec(workingDirectory,
{"branch", "list", "--closed"});
if (result.result() != ProcessResult::FinishedWithSuccess) if (result.result() != ProcessResult::FinishedWithSuccess)
return BranchInfo(); return BranchInfo();
@@ -334,12 +332,12 @@ QList<BranchInfo> FossilClient::synchronousBranchQuery(const FilePath &workingDi
// Sort the list by branch name. // Sort the list by branch name.
if (workingDirectory.isEmpty()) if (workingDirectory.isEmpty())
return QList<BranchInfo>(); return {};
// First get list of open branches // First get list of open branches
CommandResult result = vcsSynchronousExec(workingDirectory, {"branch", "list"}); CommandResult result = vcsSynchronousExec(workingDirectory, {"branch", "list"});
if (result.result() != ProcessResult::FinishedWithSuccess) if (result.result() != ProcessResult::FinishedWithSuccess)
return QList<BranchInfo>(); return {};
QString output = sanitizeFossilOutput(result.cleanedStdOut()); QString output = sanitizeFossilOutput(result.cleanedStdOut());
QList<BranchInfo> branches = branchListFromOutput(output); QList<BranchInfo> branches = branchListFromOutput(output);
@@ -347,7 +345,7 @@ QList<BranchInfo> FossilClient::synchronousBranchQuery(const FilePath &workingDi
// Append a list of closed branches. // Append a list of closed branches.
result = vcsSynchronousExec(workingDirectory, {"branch", "list", "--closed"}); result = vcsSynchronousExec(workingDirectory, {"branch", "list", "--closed"});
if (result.result() != ProcessResult::FinishedWithSuccess) if (result.result() != ProcessResult::FinishedWithSuccess)
return QList<BranchInfo>(); return {};
output = sanitizeFossilOutput(result.cleanedStdOut()); output = sanitizeFossilOutput(result.cleanedStdOut());
branches.append(branchListFromOutput(output, BranchInfo::Closed)); branches.append(branchListFromOutput(output, BranchInfo::Closed));
@@ -363,13 +361,13 @@ QStringList FossilClient::parseRevisionCommentLine(const QString &commentLine)
const QRegularExpression commentRx("^comment:\\s+(.*)\\s\\(user:\\s(.*)\\)$", const QRegularExpression commentRx("^comment:\\s+(.*)\\s\\(user:\\s(.*)\\)$",
QRegularExpression::CaseInsensitiveOption); QRegularExpression::CaseInsensitiveOption);
QTC_ASSERT(commentRx.isValid(), return QStringList()); QTC_ASSERT(commentRx.isValid(), return {});
const QRegularExpressionMatch match = commentRx.match(commentLine); const QRegularExpressionMatch match = commentRx.match(commentLine);
if (!match.hasMatch()) if (!match.hasMatch())
return QStringList(); return {};
return QStringList({match.captured(1), match.captured(2)}); return {match.captured(1), match.captured(2)};
} }
RevisionInfo FossilClient::synchronousRevisionQuery(const FilePath &workingDirectory, RevisionInfo FossilClient::synchronousRevisionQuery(const FilePath &workingDirectory,
@@ -386,7 +384,7 @@ RevisionInfo FossilClient::synchronousRevisionQuery(const FilePath &workingDirec
args << id; args << id;
const CommandResult result = vcsSynchronousExec(workingDirectory, args, const CommandResult result = vcsSynchronousExec(workingDirectory, args,
VcsCommand::SuppressCommandLogging); RunFlags::SuppressCommandLogging);
if (result.result() != ProcessResult::FinishedWithSuccess) if (result.result() != ProcessResult::FinishedWithSuccess)
return RevisionInfo(); return RevisionInfo();
@@ -442,41 +440,33 @@ QStringList FossilClient::synchronousTagQuery(const FilePath &workingDirectory,
// Tag list includes branch names. // Tag list includes branch names.
if (workingDirectory.isEmpty()) if (workingDirectory.isEmpty())
return QStringList(); return {};
QStringList args({"tag", "list"}); QStringList args({"tag", "list"});
if (!id.isEmpty()) if (!id.isEmpty())
args << id; args << id;
const CommandResult result = vcsSynchronousExec(workingDirectory, args); const CommandResult result = vcsSynchronousExec(workingDirectory, args);
if (result.result() != ProcessResult::FinishedWithSuccess) if (result.result() != ProcessResult::FinishedWithSuccess)
return QStringList(); return {};
const QString output = sanitizeFossilOutput(result.cleanedStdOut()); return sanitizeFossilOutput(result.cleanedStdOut()).split('\n', Qt::SkipEmptyParts);
return output.split('\n', Qt::SkipEmptyParts);
} }
RepositorySettings FossilClient::synchronousSettingsQuery(const FilePath &workingDirectory) RepositorySettings FossilClient::synchronousSettingsQuery(const FilePath &workingDirectory)
{ {
if (workingDirectory.isEmpty()) if (workingDirectory.isEmpty())
return RepositorySettings(); return {};
const CommandResult result = vcsSynchronousExec(workingDirectory, QStringList{"settings"});
if (result.result() != ProcessResult::FinishedWithSuccess)
return {};
const QString output = sanitizeFossilOutput(result.cleanedStdOut());
RepositorySettings repoSettings; RepositorySettings repoSettings;
repoSettings.user = synchronousUserDefaultQuery(workingDirectory); repoSettings.user = synchronousUserDefaultQuery(workingDirectory);
if (repoSettings.user.isEmpty()) if (repoSettings.user.isEmpty())
repoSettings.user = settings().userName.value(); repoSettings.user = settings().userName.value();
const QStringList args("settings");
const CommandResult result = vcsSynchronousExec(workingDirectory, args);
if (result.result() != ProcessResult::FinishedWithSuccess)
return RepositorySettings();
const QString output = sanitizeFossilOutput(result.cleanedStdOut());
for (const QString &line : output.split('\n', Qt::SkipEmptyParts)) { for (const QString &line : output.split('\n', Qt::SkipEmptyParts)) {
// parse settings line: // parse settings line:
// <property> <(local|global)> <value> // <property> <(local|global)> <value>
@@ -507,8 +497,8 @@ RepositorySettings FossilClient::synchronousSettingsQuery(const FilePath &workin
return repoSettings; return repoSettings;
} }
bool FossilClient::synchronousSetSetting(const FilePath &workingDirectory, bool FossilClient::synchronousSetSetting(const FilePath &workingDirectory, const QString &property,
const QString &property, const QString &value, bool isGlobal) const QString &value, bool isGlobal)
{ {
// set a repository property to the given value // set a repository property to the given value
// if no value is given, unset the property // if no value is given, unset the property
@@ -529,7 +519,6 @@ bool FossilClient::synchronousSetSetting(const FilePath &workingDirectory,
== ProcessResult::FinishedWithSuccess; == ProcessResult::FinishedWithSuccess;
} }
bool FossilClient::synchronousConfigureRepository(const FilePath &workingDirectory, const RepositorySettings &newSettings, bool FossilClient::synchronousConfigureRepository(const FilePath &workingDirectory, const RepositorySettings &newSettings,
const RepositorySettings &currentSettings) const RepositorySettings &currentSettings)
{ {
@@ -577,17 +566,13 @@ bool FossilClient::synchronousConfigureRepository(const FilePath &workingDirecto
QString FossilClient::synchronousUserDefaultQuery(const FilePath &workingDirectory) QString FossilClient::synchronousUserDefaultQuery(const FilePath &workingDirectory)
{ {
if (workingDirectory.isEmpty()) if (workingDirectory.isEmpty())
return QString(); return {};
const QStringList args({"user", "default"}); const CommandResult result = vcsSynchronousExec(workingDirectory, {"user", "default"});
const CommandResult result = vcsSynchronousExec(workingDirectory, args);
if (result.result() != ProcessResult::FinishedWithSuccess) if (result.result() != ProcessResult::FinishedWithSuccess)
return QString(); return {};
QString output = sanitizeFossilOutput(result.cleanedStdOut()); return sanitizeFossilOutput(result.cleanedStdOut()).trimmed();
return output.trimmed();
} }
bool FossilClient::synchronousSetUserDefault(const FilePath &workingDirectory, const QString &userName) bool FossilClient::synchronousSetUserDefault(const FilePath &workingDirectory, const QString &userName)
@@ -604,19 +589,16 @@ bool FossilClient::synchronousSetUserDefault(const FilePath &workingDirectory, c
QString FossilClient::synchronousGetRepositoryURL(const FilePath &workingDirectory) QString FossilClient::synchronousGetRepositoryURL(const FilePath &workingDirectory)
{ {
if (workingDirectory.isEmpty()) if (workingDirectory.isEmpty())
return QString(); return {};
const QStringList args("remote-url"); const CommandResult result = vcsSynchronousExec(workingDirectory, QStringList{"remote-url"});
const CommandResult result = vcsSynchronousExec(workingDirectory, args);
if (result.result() != ProcessResult::FinishedWithSuccess) if (result.result() != ProcessResult::FinishedWithSuccess)
return QString(); return {};
const QString output = sanitizeFossilOutput(result.cleanedStdOut()).trimmed(); const QString output = sanitizeFossilOutput(result.cleanedStdOut()).trimmed();
// Fossil returns "off" when no remote-url is set. // Fossil returns "off" when no remote-url is set.
if (output.isEmpty() || output.toLower() == "off") if (output.toLower() == "off")
return QString(); return {};
return output; return output;
} }
@@ -624,13 +606,13 @@ QString FossilClient::synchronousGetRepositoryURL(const FilePath &workingDirecto
QString FossilClient::synchronousTopic(const FilePath &workingDirectory) QString FossilClient::synchronousTopic(const FilePath &workingDirectory)
{ {
if (workingDirectory.isEmpty()) if (workingDirectory.isEmpty())
return QString(); return {};
// return current branch name // return current branch name
const BranchInfo branchInfo = synchronousCurrentBranch(workingDirectory); const BranchInfo branchInfo = synchronousCurrentBranch(workingDirectory);
if (branchInfo.name().isEmpty()) if (branchInfo.name().isEmpty())
return QString(); return {};
return branchInfo.name(); return branchInfo.name();
} }
@@ -663,40 +645,24 @@ bool FossilClient::synchronousCreateRepository(const FilePath &workingDirectory,
CommandResult result = vcsSynchronousExec(workingDirectory, args); CommandResult result = vcsSynchronousExec(workingDirectory, args);
if (result.result() != ProcessResult::FinishedWithSuccess) if (result.result() != ProcessResult::FinishedWithSuccess)
return false; return false;
outputWindow->append(sanitizeFossilOutput(result.cleanedStdOut()));
QString output = sanitizeFossilOutput(result.cleanedStdOut());
outputWindow->append(output);
// check out the created repository file into the working directory // check out the created repository file into the working directory
result = vcsSynchronousExec(workingDirectory, {"open", repoFilePath.toUserOutput()});
args.clear();
output.clear();
args << "open" << repoFilePath.toUserOutput();
result = vcsSynchronousExec(workingDirectory, args);
if (result.result() != ProcessResult::FinishedWithSuccess) if (result.result() != ProcessResult::FinishedWithSuccess)
return false; return false;
outputWindow->append(sanitizeFossilOutput(result.cleanedStdOut()));
output = sanitizeFossilOutput(result.cleanedStdOut());
outputWindow->append(output);
// set user default to admin if specified // set user default to admin if specified
if (!adminUser.isEmpty()) { if (!adminUser.isEmpty()) {
args.clear(); result = vcsSynchronousExec(workingDirectory,
output.clear(); {"user", "default", adminUser, "--user", adminUser});
args << "user" << "default" << adminUser << "--user" << adminUser;
result = vcsSynchronousExec(workingDirectory, args);
if (result.result() != ProcessResult::FinishedWithSuccess) if (result.result() != ProcessResult::FinishedWithSuccess)
return false; return false;
outputWindow->append(sanitizeFossilOutput(result.cleanedStdOut()));
QString output = sanitizeFossilOutput(result.cleanedStdOut());
outputWindow->append(output);
} }
resetCachedVcsInfo(workingDirectory); resetCachedVcsInfo(workingDirectory);
return true; return true;
} }
@@ -833,8 +799,7 @@ FilePath FossilClient::findTopLevelForFile(const FilePath &file) const
bool FossilClient::managesFile(const FilePath &workingDirectory, const QString &fileName) const bool FossilClient::managesFile(const FilePath &workingDirectory, const QString &fileName) const
{ {
const QStringList args({"finfo", fileName}); const CommandResult result = vcsSynchronousExec(workingDirectory, {"finfo", fileName});
const CommandResult result = vcsSynchronousExec(workingDirectory, args);
if (result.result() != ProcessResult::FinishedWithSuccess) if (result.result() != ProcessResult::FinishedWithSuccess)
return false; return false;
QString output = sanitizeFossilOutput(result.cleanedStdOut()); QString output = sanitizeFossilOutput(result.cleanedStdOut());
@@ -1146,10 +1111,9 @@ QString FossilClient::vcsCommandString(VcsCommandTag cmd) const
// otherwise return baseclient command // otherwise return baseclient command
switch (cmd) { switch (cmd) {
case RemoveCommand: return QString("rm"); case RemoveCommand: return "rm";
case MoveCommand: return QString("mv"); case MoveCommand: return "mv";
case LogCommand: return QString("timeline"); case LogCommand: return "timeline";
default: return VcsBaseClient::vcsCommandString(cmd); default: return VcsBaseClient::vcsCommandString(cmd);
} }
} }
@@ -1164,7 +1128,7 @@ Id FossilClient::vcsEditorKind(VcsCommandTag cmd) const
case LogCommand: case LogCommand:
return Constants::FILELOG_ID; return Constants::FILELOG_ID;
default: default:
return Id(); return {};
} }
} }
@@ -1192,7 +1156,7 @@ FossilClient::StatusItem FossilClient::parseStatusLine(const QString &line) cons
int pos = line.indexOf(' '); int pos = line.indexOf(' ');
if (line.isEmpty() || pos < 1) if (line.isEmpty() || pos < 1)
return StatusItem(); return {};
QString label(line.left(pos)); QString label(line.left(pos));
QString flags; QString flags;
@@ -1230,7 +1194,7 @@ FossilClient::StatusItem FossilClient::parseStatusLine(const QString &line) cons
if (flags.isEmpty()) if (flags.isEmpty())
return StatusItem(); return {};
// adjust the position to the last space before the file name // adjust the position to the last space before the file name
for (int size = line.size(); (pos+1) < size && line[pos+1].isSpace(); ++pos) {} for (int size = line.size(); (pos+1) < size && line[pos+1].isSpace(); ++pos) {}