summaryrefslogtreecommitdiff
path: root/src/plugins/diffeditor/diffeditorcontroller.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2014-11-11 16:27:23 +0100
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2014-11-13 09:10:22 +0100
commit9605244f6d73aced9ec33eea105030ae23eea896 (patch)
treeec52b6659c211c36be2c07beecd09b1e2aef9132 /src/plugins/diffeditor/diffeditorcontroller.cpp
parente123f5a4d9ec164073d75fd926acadd9d4b2243b (diff)
downloadqt-creator-9605244f6d73aced9ec33eea105030ae23eea896.tar.gz
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 <orgads@gmail.com>
Diffstat (limited to 'src/plugins/diffeditor/diffeditorcontroller.cpp')
-rw-r--r--src/plugins/diffeditor/diffeditorcontroller.cpp38
1 files changed, 38 insertions, 0 deletions
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: <Expand>"))) {
+ 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)