Move Git-specific logic from DiffEditor to Git

Change-Id: I29466c26a51844bb975ac3ecb68adf708021aa67
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
Orgad Shaneh
2017-05-18 23:08:11 +03:00
committed by Orgad Shaneh
parent 744285c3fc
commit a4a146b3cb
3 changed files with 27 additions and 38 deletions

View File

@@ -106,11 +106,8 @@ void DiffEditorController::setDescription(const QString &description)
m_document->setDescription(description);
}
void DiffEditorController::informationForCommitReceived(const QString &output)
void DiffEditorController::branchesReceived(const QString &branches)
{
// TODO: Git specific code...
const QString branches = prepareBranchesForCommit(output);
QString tmp = m_document->description();
tmp.replace(QLatin1String(Constants::EXPAND_BRANCHES), branches);
m_document->setDescription(tmp);
@@ -123,35 +120,6 @@ void DiffEditorController::requestMoreInformation()
emit requestInformationForCommit(rev);
}
QString DiffEditorController::prepareBranchesForCommit(const QString &output)
{
// TODO: More git-specific code...
QString moreBranches;
QString branches;
QStringList res;
foreach (const QString &branch, output.split(QLatin1Char('\n'))) {
const QString b = branch.mid(2).trimmed();
if (!b.isEmpty())
res << b;
}
const int branchCount = res.count();
// If there are more than 20 branches, list first 10 followed by a hint
if (branchCount > 20) {
const int leave = 10;
//: Displayed after the untranslated message "Branches: branch1, branch2 'and %n more'"
// in git show.
moreBranches = QLatin1Char(' ') + tr("and %n more", 0, branchCount - leave);
res.erase(res.begin() + leave, res.end());
}
branches = QLatin1String("Branches: ");
if (res.isEmpty())
branches += tr("<None>");
else
branches += res.join(QLatin1String(", ")) + moreBranches;
return branches;
}
/**
* @brief Force the lines of context to the given number.
*

View File

@@ -59,7 +59,7 @@ public:
const QString &displayName);
static DiffEditorController *controller(Core::IDocument *document);
void informationForCommitReceived(const QString &output);
void branchesReceived(const QString &branches);
signals:
void chunkActionsRequested(QMenu *menu, bool isValid);
@@ -83,8 +83,6 @@ private:
void requestMoreInformation();
void requestChunkActions(QMenu *menu, int diffFileIndex, int chunkIndex);
QString prepareBranchesForCommit(const QString &output);
Internal::DiffEditorDocument *const m_document;
bool m_isReloading;

View File

@@ -1425,8 +1425,31 @@ void GitClient::branchesForCommit(const QString &revision)
VcsCommand *command = vcsExec(
workingDirectory, {"branch", noColorOption, "-a", "--contains", revision}, nullptr,
false, 0, workingDirectory);
connect(command, &VcsCommand::stdOutText, controller,
&DiffEditorController::informationForCommitReceived);
connect(command, &VcsCommand::stdOutText, controller, [controller](const QString &text) {
QString moreBranches;
QStringList res;
for (const QString &branch : text.split('\n')) {
const QString b = branch.mid(2).trimmed();
if (!b.isEmpty())
res << b;
}
const int branchCount = res.count();
// If there are more than 20 branches, list first 10 followed by a hint
if (branchCount > 20) {
const int leave = 10;
//: Displayed after the untranslated message "Branches: branch1, branch2 'and %n more'"
// in git show.
moreBranches = ' ' + tr("and %n more", 0, branchCount - leave);
res.erase(res.begin() + leave, res.end());
}
QString branches = "Branches: ";
if (res.isEmpty())
branches += tr("<None>");
else
branches += res.join(", ") + moreBranches;
controller->branchesReceived(branches);
});
}
bool GitClient::isRemoteCommit(const QString &workingDirectory, const QString &commit)