From 6a337561c5336f638fe8dbed2a54e7c1bb8fde8d Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Sun, 25 Nov 2012 15:22:25 +0200 Subject: [PATCH] Git: Show Precedes/Follows tags on Show editor Known limitation: Commit that has a tag shows its own tag on Precedes field Change-Id: I533e48b4bb5d57809d8e9f12fa7db5d8706f7372 Reviewed-by: Tobias Hunger --- src/plugins/git/gitclient.cpp | 31 +++++++++++++++++++++++++++++++ src/plugins/git/gitclient.h | 2 ++ src/plugins/git/giteditor.cpp | 29 +++++++++++++++++++++++++---- 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index 8bf8ae41bc1..ddd5f534bd9 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -1156,6 +1156,37 @@ QString GitClient::synchronousTopRevision(const QString &workingDirectory, QStri return revision; } +void GitClient::synchronousTagsForCommit(const QString &workingDirectory, const QString &revision, + QByteArray &precedes, QByteArray &follows) +{ + QStringList arguments; + QByteArray parents; + arguments << QLatin1String("describe") << QLatin1String("--contains") << revision; + fullySynchronousGit(workingDirectory, arguments, &precedes); + int tilde = precedes.indexOf('~'); + if (tilde != -1) + precedes.truncate(tilde); + else + precedes = precedes.trimmed(); + + arguments.clear(); + arguments << QLatin1String("log") << QLatin1String("-n1") << QLatin1String("--pretty=format:%P") << revision; + fullySynchronousGit(workingDirectory, arguments, &parents); + foreach (const QByteArray &p, parents.split(' ')) { + QByteArray pf; + arguments.clear(); + arguments << QLatin1String("describe") << QLatin1String("--tags") + << QLatin1String("--abbrev=0") << QLatin1String(p); + fullySynchronousGit(workingDirectory, arguments, &pf); + pf.truncate(pf.lastIndexOf('\n')); + if (!pf.isEmpty()) { + if (!follows.isEmpty()) + follows += ", "; + follows += pf; + } + } +} + // Format an entry in a one-liner for selection list using git log. QString GitClient::synchronousShortDescription(const QString &workingDirectory, const QString &revision, const QString &format) diff --git a/src/plugins/git/gitclient.h b/src/plugins/git/gitclient.h index 21179d8dd4c..a52ee2040a2 100644 --- a/src/plugins/git/gitclient.h +++ b/src/plugins/git/gitclient.h @@ -163,6 +163,8 @@ public: const QString &format); QString synchronousBranch(const QString &workingDirectory); QString synchronousTopRevision(const QString &workingDirectory, QString *errorMessage = 0); + void synchronousTagsForCommit(const QString &workingDirectory, const QString &revision, + QByteArray &precedes, QByteArray &follows); bool cloneRepository(const QString &directory, const QByteArray &url); QString vcsGetRepositoryURL(const QString &directory); diff --git a/src/plugins/git/giteditor.cpp b/src/plugins/git/giteditor.cpp index 5879d036b27..874efafa036 100644 --- a/src/plugins/git/giteditor.cpp +++ b/src/plugins/git/giteditor.cpp @@ -207,11 +207,32 @@ static QByteArray removeAnnotationDate(const QByteArray &b) void GitEditor::setPlainTextDataFiltered(const QByteArray &a) { QByteArray array = a; + GitPlugin *plugin = GitPlugin::instance(); // If desired, filter out the date from annotation - const bool omitAnnotationDate = contentType() == VcsBase::AnnotateOutput - && GitPlugin::instance()->settings().boolValue(GitSettings::omitAnnotationDateKey); - if (omitAnnotationDate) - array = removeAnnotationDate(a); + switch (contentType()) + { + case VcsBase::AnnotateOutput: { + const bool omitAnnotationDate = plugin->settings().boolValue(GitSettings::omitAnnotationDateKey); + if (omitAnnotationDate) + array = removeAnnotationDate(a); + break; + } + case VcsBase::DiffOutput: { + const QFileInfo fi(source()); + const QString workingDirectory = fi.absolutePath(); + QByteArray precedes, follows; + if (array.startsWith("commit ")) { // show + int lastHeaderLine = array.indexOf("\n\n") + 1; + plugin->gitClient()->synchronousTagsForCommit(workingDirectory, QLatin1String(array.mid(7, 8)), precedes, follows); + if (!precedes.isEmpty()) + array.insert(lastHeaderLine, "Precedes: " + precedes + '\n'); + if (!follows.isEmpty()) + array.insert(lastHeaderLine, "Follows: " + follows + '\n'); + } + break; + } + } + setPlainTextData(array); }