From 1b6cc02725fc8953e314902b23e09eb63d2d67d4 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Tue, 7 Jul 2015 08:57:36 +0300 Subject: [PATCH] Git: Strip line numbers from blame output The editor already has its own line numbers. Save a few chars for content. Change-Id: I83fa55140c09224cf0f2ec24ff2dac0baa64def1 Reviewed-by: Tobias Hunger --- src/plugins/git/giteditor.cpp | 40 ++++++++++++++++------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/plugins/git/giteditor.cpp b/src/plugins/git/giteditor.cpp index 3be3eee670f..944a9ba676d 100644 --- a/src/plugins/git/giteditor.cpp +++ b/src/plugins/git/giteditor.cpp @@ -124,45 +124,46 @@ BaseAnnotationHighlighter *GitEditorWidget::createAnnotationHighlighter(const QS 8ca887aa (author YYYY-MM-DD HH:MM:SS ) \endcode */ -static QString removeAnnotationDate(const QString &b) +static QString sanitizeBlameOutput(const QString &b) { if (b.isEmpty()) return b; + const bool omitDate = GitPlugin::instance()->client()->settings().boolValue( + GitSettings::omitAnnotationDateKey); const QChar space(QLatin1Char(' ')); const int parenPos = b.indexOf(QLatin1Char(')')); if (parenPos == -1) return b; - int datePos = parenPos; int i = parenPos; while (i >= 0 && b.at(i) != space) --i; while (i >= 0 && b.at(i) == space) --i; - int spaceCount = 0; - // i is now on timezone. Go back 3 spaces: That is where the date starts. - while (i >= 0) { - if (b.at(i) == space) - ++spaceCount; - if (spaceCount == 3) { - datePos = i; - break; + int stripPos = i + 1; + if (omitDate) { + int spaceCount = 0; + // i is now on timezone. Go back 3 spaces: That is where the date starts. + while (i >= 0) { + if (b.at(i) == space) + ++spaceCount; + if (spaceCount == 3) { + stripPos = i; + break; + } + --i; } - --i; } - if (datePos == 0) - return b; // Copy over the parts that have not changed into a new byte array QString result; - QTC_ASSERT(b.size() >= parenPos, return result); int prevPos = 0; int pos = b.indexOf(QLatin1Char('\n'), 0) + 1; forever { QTC_CHECK(prevPos < pos); int afterParen = prevPos + parenPos; - result.append(b.mid(prevPos, datePos)); + result.append(b.mid(prevPos, stripPos)); result.append(b.mid(afterParen, pos - afterParen)); prevPos = pos; QTC_CHECK(prevPos != 0); @@ -179,17 +180,12 @@ static QString removeAnnotationDate(const QString &b) void GitEditorWidget::setPlainText(const QString &text) { QString modText = text; - GitPlugin *plugin = GitPlugin::instance(); // If desired, filter out the date from annotation switch (contentType()) { - case AnnotateOutput: { - const bool omitAnnotationDate - = plugin->client()->settings().boolValue(GitSettings::omitAnnotationDateKey); - if (omitAnnotationDate) - modText = removeAnnotationDate(text); + case AnnotateOutput: + modText = sanitizeBlameOutput(text); break; - } default: break; }