Git: Extend show output on diff editor

Change-Id: I51d3d0af96b28ec56bedaac163f9ce72158d8dc2
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Orgad Shaneh
2013-08-27 22:21:15 +03:00
committed by Orgad Shaneh
parent 0865e9eb27
commit 9f2110f8a1
3 changed files with 39 additions and 27 deletions

View File

@@ -273,8 +273,10 @@ void GitDiffHandler::slotShowDescriptionReceived(const QString &description)
if (m_editor.isNull()) if (m_editor.isNull())
return; return;
DiffEditor::DiffShowEditor *editor = qobject_cast<DiffEditor::DiffShowEditor *>(m_editor); DiffEditor::DiffShowEditor *editor = qobject_cast<DiffEditor::DiffShowEditor *>(m_editor);
if (editor) if (editor) {
editor->setDescription(description); editor->setDescription(GitPlugin::instance()->gitClient()->
extendedShowDescription(m_workingDirectory, description));
}
collectFilesList(QStringList() collectFilesList(QStringList()
<< m_requestedRevisionRange.begin.id << m_requestedRevisionRange.begin.id
@@ -2554,6 +2556,34 @@ void GitClient::continuePreviousGitCommand(const QString &workingDirectory,
} }
} }
QString GitClient::extendedShowDescription(const QString &workingDirectory, const QString &text)
{
if (!text.startsWith(QLatin1String("commit ")))
return text;
QString modText = text;
QString precedes, follows;
int lastHeaderLine = modText.indexOf(QLatin1String("\n\n")) + 1;
const QString commit = modText.mid(7, 8);
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 = 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'));
return modText;
}
// Quietly retrieve branch list of remote repository URL // Quietly retrieve branch list of remote repository URL
// //
// The branch HEAD is pointing to is always returned first. // The branch HEAD is pointing to is always returned first.

View File

@@ -302,6 +302,8 @@ public:
void continuePreviousGitCommand(const QString &workingDirectory, const QString &msgBoxTitle, QString msgBoxText, void continuePreviousGitCommand(const QString &workingDirectory, const QString &msgBoxTitle, QString msgBoxText,
const QString &buttonName, const QString &gitCommand, bool requireChanges = true); const QString &buttonName, const QString &gitCommand, bool requireChanges = true);
QString extendedShowDescription(const QString &workingDirectory, const QString &text);
void launchGitK(const QString &workingDirectory, const QString &fileName); void launchGitK(const QString &workingDirectory, const QString &fileName);
void launchGitK(const QString &workingDirectory) { launchGitK(workingDirectory, QString()); } void launchGitK(const QString &workingDirectory) { launchGitK(workingDirectory, QString()); }
bool launchGitGui(const QString &workingDirectory); bool launchGitGui(const QString &workingDirectory);

View File

@@ -183,32 +183,12 @@ void GitEditor::setPlainTextFiltered(const QString &text)
break; break;
} }
case VcsBase::DiffOutput: { case VcsBase::DiffOutput: {
if (modText.isEmpty()) if (modText.isEmpty()) {
modText = QLatin1String("No difference to HEAD"); modText = QLatin1String("No difference to HEAD");
} else {
const QFileInfo fi(source()); const QFileInfo fi(source());
const QString workingDirectory = fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath(); const QString workingDirectory = fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath();
QString precedes, follows; modText = plugin->gitClient()->extendedShowDescription(workingDirectory, modText);
if (modText.startsWith(QLatin1String("commit "))) { // show
int lastHeaderLine = modText.indexOf(QLatin1String("\n\n")) + 1;
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; break;
} }