forked from qt-creator/qt-creator
Git: Return Result<CommitData> from readDataFromCommit
... and rename it to 'enrichCommitData', which is I think since it already takes a partially CommitData struct as input (previously via non-const ref) Change-Id: I53a3a224f27d6fc934a9469c3dc44d86c24f4351 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -2688,22 +2688,20 @@ static QByteArray shiftLogLine(QByteArray &logText)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GitClient::readDataFromCommit(const FilePath &repoDirectory, const QString &commit,
|
Result<CommitData> GitClient::enrichCommitData(const FilePath &repoDirectory,
|
||||||
CommitData &commitData, QString *errorMessage,
|
const QString &commit,
|
||||||
QString *commitTemplate)
|
const CommitData &commitDataIn)
|
||||||
{
|
{
|
||||||
// Get commit data as "hash<lf>author<lf>email<lf>message".
|
// Get commit data as "hash<lf>author<lf>email<lf>message".
|
||||||
const QStringList arguments = {"log", "--max-count=1", "--pretty=format:%h\n%aN\n%aE\n%B", commit};
|
const QStringList arguments = {"log", "--max-count=1", "--pretty=format:%h\n%aN\n%aE\n%B", commit};
|
||||||
const CommandResult result = vcsSynchronousExec(repoDirectory, arguments, RunFlags::NoOutput);
|
const CommandResult result = vcsSynchronousExec(repoDirectory, arguments, RunFlags::NoOutput);
|
||||||
|
|
||||||
if (result.result() != ProcessResult::FinishedWithSuccess) {
|
if (result.result() != ProcessResult::FinishedWithSuccess) {
|
||||||
if (errorMessage) {
|
return ResultError(Tr::tr("Cannot retrieve last commit data of repository \"%1\".")
|
||||||
*errorMessage = Tr::tr("Cannot retrieve last commit data of repository \"%1\".")
|
.arg(repoDirectory.toUserOutput()));
|
||||||
.arg(repoDirectory.toUserOutput());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CommitData commitData = commitDataIn;
|
||||||
QTextCodec *authorCodec = HostOsInfo::isWindowsHost()
|
QTextCodec *authorCodec = HostOsInfo::isWindowsHost()
|
||||||
? QTextCodec::codecForName("UTF-8")
|
? QTextCodec::codecForName("UTF-8")
|
||||||
: commitData.commitEncoding;
|
: commitData.commitEncoding;
|
||||||
@@ -2711,9 +2709,8 @@ bool GitClient::readDataFromCommit(const FilePath &repoDirectory, const QString
|
|||||||
commitData.amendHash = QLatin1String(shiftLogLine(stdOut));
|
commitData.amendHash = QLatin1String(shiftLogLine(stdOut));
|
||||||
commitData.panelData.author = authorCodec->toUnicode(shiftLogLine(stdOut));
|
commitData.panelData.author = authorCodec->toUnicode(shiftLogLine(stdOut));
|
||||||
commitData.panelData.email = authorCodec->toUnicode(shiftLogLine(stdOut));
|
commitData.panelData.email = authorCodec->toUnicode(shiftLogLine(stdOut));
|
||||||
if (commitTemplate)
|
commitData.commitTemplate = commitData.commitEncoding->toUnicode(stdOut);
|
||||||
*commitTemplate = commitData.commitEncoding->toUnicode(stdOut);
|
return commitData;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Author GitClient::parseAuthor(const QString &authorInfo)
|
Author GitClient::parseAuthor(const QString &authorInfo)
|
||||||
@@ -2815,16 +2812,20 @@ Result<CommitData> GitClient::getCommitData(CommitType commitType, const FilePat
|
|||||||
// Get the commit template or the last commit message
|
// Get the commit template or the last commit message
|
||||||
switch (commitData.commitType) {
|
switch (commitData.commitType) {
|
||||||
case AmendCommit: {
|
case AmendCommit: {
|
||||||
if (!readDataFromCommit(repoDirectory, HEAD, commitData, &errorMessage,
|
if (const Result<CommitData> res = enrichCommitData(repoDirectory, HEAD, commitData))
|
||||||
&commitData.commitTemplate))
|
commitData = res.value();
|
||||||
return ResultError(errorMessage);
|
else
|
||||||
|
return ResultError(res.error());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SimpleCommit: {
|
case SimpleCommit: {
|
||||||
bool authorFromCherryPick = false;
|
bool authorFromCherryPick = false;
|
||||||
// For cherry-picked commit, read author data from the commit (but template from MERGE_MSG)
|
// For cherry-picked commit, read author data from the commit (but template from MERGE_MSG)
|
||||||
if (gitDir.pathAppended(CHERRY_PICK_HEAD).exists()) {
|
if (gitDir.pathAppended(CHERRY_PICK_HEAD).exists()) {
|
||||||
authorFromCherryPick = readDataFromCommit(repoDirectory, CHERRY_PICK_HEAD, commitData);
|
if (const Result<CommitData> res = enrichCommitData(repoDirectory, CHERRY_PICK_HEAD, commitData)) {
|
||||||
|
authorFromCherryPick = true;
|
||||||
|
commitData = res.value();
|
||||||
|
}
|
||||||
commitData.amendHash.clear();
|
commitData.amendHash.clear();
|
||||||
}
|
}
|
||||||
if (!authorFromCherryPick) {
|
if (!authorFromCherryPick) {
|
||||||
|
@@ -299,9 +299,9 @@ public:
|
|||||||
void setConfigValue(const Utils::FilePath &workingDirectory, const QString &configVar,
|
void setConfigValue(const Utils::FilePath &workingDirectory, const QString &configVar,
|
||||||
const QString &value) const;
|
const QString &value) const;
|
||||||
|
|
||||||
bool readDataFromCommit(const Utils::FilePath &repoDirectory, const QString &commit,
|
Utils::Result<CommitData> enrichCommitData(const Utils::FilePath &repoDirectory,
|
||||||
CommitData &commitData, QString *errorMessage = nullptr,
|
const QString &commit,
|
||||||
QString *commitTemplate = nullptr);
|
const CommitData &commitDataIn);
|
||||||
Utils::Result<CommitData> getCommitData(CommitType commitType,
|
Utils::Result<CommitData> getCommitData(CommitType commitType,
|
||||||
const Utils::FilePath &workingDirectory);
|
const Utils::FilePath &workingDirectory);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user