From 9605244f6d73aced9ec33eea105030ae23eea896 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 11 Nov 2014 16:27:23 +0100 Subject: DiffEditor: Save description along with diff. Save complete, git-applicable patch when saving the result of for example 'git show'. Strips some Creator-specific tags off the description and reformats the description such that it is accepted by git. Change-Id: I739d85a7263f97e2149a2794974ba026f2eca067 Reviewed-by: Orgad Shaneh --- src/plugins/diffeditor/diffeditorcontroller.cpp | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/plugins/diffeditor/diffeditorcontroller.cpp') diff --git a/src/plugins/diffeditor/diffeditorcontroller.cpp b/src/plugins/diffeditor/diffeditorcontroller.cpp index 5aeb8d2705..f59a012b1e 100644 --- a/src/plugins/diffeditor/diffeditorcontroller.cpp +++ b/src/plugins/diffeditor/diffeditorcontroller.cpp @@ -102,6 +102,44 @@ bool DiffEditorController::isIgnoreWhitespace() const return m_ignoreWhitespace; } +// ### fixme: git-specific handling should be done in the git plugin: +// Remove unexpanded branches and follows-tag, clear indentation +// and create E-mail +static void formatGitDescription(QString *description) +{ + QString result; + result.reserve(description->size()); + foreach (QString line, description->split(QLatin1Char('\n'))) { + if (line.startsWith(QLatin1String("commit ")) + || line.startsWith(QLatin1String("Branches: "))) { + continue; + } + if (line.startsWith(QLatin1String("Author: "))) + line.replace(0, 8, QStringLiteral("From: ")); + else if (line.startsWith(QLatin1String(" "))) + line.remove(0, 4); + result.append(line); + result.append(QLatin1Char('\n')); + } + *description = result; +} + +QString DiffEditorController::contents() const +{ + QString result = m_description; + const int formattingOptions = DiffUtils::GitFormat; + if (formattingOptions & DiffUtils::GitFormat) + formatGitDescription(&result); + + const QString diff = DiffUtils::makePatch(diffFiles(), formattingOptions); + if (!diff.isEmpty()) { + if (!result.isEmpty()) + result += QLatin1Char('\n'); + result += diff; + } + return result; +} + QString DiffEditorController::makePatch(bool revert, bool addPrefix) const { if (m_diffFileIndex < 0 || m_chunkIndex < 0) -- cgit v1.2.1