forked from qt-creator/qt-creator
Git: List branches on show
Change-Id: Ie69a58efc7068c699abf0e3d396216d9809346f4 Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Petar Perisin <petar.perisin@gmail.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
51f69c8807
commit
0865e9eb27
@@ -1800,6 +1800,22 @@ void GitClient::synchronousTagsForCommit(const QString &workingDirectory, const
|
||||
}
|
||||
}
|
||||
|
||||
QStringList GitClient::synchronousBranchesForCommit(const QString &workingDirectory, const QString &revision)
|
||||
{
|
||||
QString output;
|
||||
QStringList arguments;
|
||||
arguments << QLatin1String(noColorOption) << QLatin1String("-a")
|
||||
<< QLatin1String("--contains") << revision;
|
||||
synchronousBranchCmd(workingDirectory, arguments, &output, 0);
|
||||
QStringList res;
|
||||
foreach (const QString &branch, output.split(QLatin1Char('\n'))) {
|
||||
const QString b = branch.mid(2).trimmed();
|
||||
if (!b.isEmpty())
|
||||
res << b;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool GitClient::isRemoteCommit(const QString &workingDirectory, const QString &commit)
|
||||
{
|
||||
QStringList arguments;
|
||||
@@ -1958,11 +1974,11 @@ bool GitClient::synchronousBranchCmd(const QString &workingDirectory, QStringLis
|
||||
QByteArray errorText;
|
||||
const bool rc = fullySynchronousGit(workingDirectory, branchArgs, &outputText, &errorText);
|
||||
*output = commandOutputFromLocal8Bit(outputText);
|
||||
if (!rc) {
|
||||
*errorMessage = msgCannotRun(QLatin1String("git branch"), workingDirectory, commandOutputFromLocal8Bit(errorText));
|
||||
return false;
|
||||
if (!rc && errorMessage) {
|
||||
*errorMessage = msgCannotRun(QLatin1String("git branch"), workingDirectory,
|
||||
commandOutputFromLocal8Bit(errorText));
|
||||
}
|
||||
return true;
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool GitClient::synchronousTagCmd(const QString &workingDirectory, QStringList tagArgs, QString *output, QString *errorMessage)
|
||||
|
||||
@@ -236,6 +236,8 @@ public:
|
||||
QString synchronousTopRevision(const QString &workingDirectory, QString *errorMessage = 0);
|
||||
void synchronousTagsForCommit(const QString &workingDirectory, const QString &revision,
|
||||
QString &precedes, QString &follows);
|
||||
QStringList synchronousBranchesForCommit(const QString &workingDirectory,
|
||||
const QString &revision);
|
||||
bool isRemoteCommit(const QString &workingDirectory, const QString &commit);
|
||||
|
||||
bool cloneRepository(const QString &directory, const QByteArray &url);
|
||||
|
||||
@@ -190,11 +190,25 @@ void GitEditor::setPlainTextFiltered(const QString &text)
|
||||
QString precedes, follows;
|
||||
if (modText.startsWith(QLatin1String("commit "))) { // show
|
||||
int lastHeaderLine = modText.indexOf(QLatin1String("\n\n")) + 1;
|
||||
plugin->gitClient()->synchronousTagsForCommit(workingDirectory, modText.mid(7, 8), precedes, follows);
|
||||
const QString commit = modText.mid(7, 8);
|
||||
plugin->gitClient()->synchronousTagsForCommit(workingDirectory, commit, precedes, follows);
|
||||
if (!precedes.isEmpty())
|
||||
modText.insert(lastHeaderLine, QLatin1String("Precedes: ") + precedes + QLatin1Char('\n'));
|
||||
if (!follows.isEmpty())
|
||||
modText.insert(lastHeaderLine, QLatin1String("Follows: ") + follows + QLatin1Char('\n'));
|
||||
QString moreBranches;
|
||||
QStringList branches = plugin->gitClient()->synchronousBranchesForCommit(
|
||||
workingDirectory, commit);
|
||||
const int branchCount = branches.count();
|
||||
// If there are more than 20 branches, list first 10 followed by a hint
|
||||
if (branchCount > 20) {
|
||||
const int leave = 10;
|
||||
moreBranches = tr(" and %1 more").arg(branchCount - leave);
|
||||
branches.erase(branches.begin() + leave, branches.end());
|
||||
}
|
||||
modText.insert(lastHeaderLine, QLatin1String("Branches: ")
|
||||
+ branches.join(QLatin1String(", ")) + moreBranches
|
||||
+ QLatin1Char('\n'));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user