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 <tobias.hunger@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2015-07-07 08:57:36 +03:00
committed by Orgad Shaneh
parent 0898cde602
commit 1b6cc02725

View File

@@ -124,45 +124,46 @@ BaseAnnotationHighlighter *GitEditorWidget::createAnnotationHighlighter(const QS
8ca887aa (author YYYY-MM-DD HH:MM:SS <offset> <line>)<content> 8ca887aa (author YYYY-MM-DD HH:MM:SS <offset> <line>)<content>
\endcode */ \endcode */
static QString removeAnnotationDate(const QString &b) static QString sanitizeBlameOutput(const QString &b)
{ {
if (b.isEmpty()) if (b.isEmpty())
return b; return b;
const bool omitDate = GitPlugin::instance()->client()->settings().boolValue(
GitSettings::omitAnnotationDateKey);
const QChar space(QLatin1Char(' ')); const QChar space(QLatin1Char(' '));
const int parenPos = b.indexOf(QLatin1Char(')')); const int parenPos = b.indexOf(QLatin1Char(')'));
if (parenPos == -1) if (parenPos == -1)
return b; return b;
int datePos = parenPos;
int i = parenPos; int i = parenPos;
while (i >= 0 && b.at(i) != space) while (i >= 0 && b.at(i) != space)
--i; --i;
while (i >= 0 && b.at(i) == space) while (i >= 0 && b.at(i) == space)
--i; --i;
int spaceCount = 0; int stripPos = i + 1;
// i is now on timezone. Go back 3 spaces: That is where the date starts. if (omitDate) {
while (i >= 0) { int spaceCount = 0;
if (b.at(i) == space) // i is now on timezone. Go back 3 spaces: That is where the date starts.
++spaceCount; while (i >= 0) {
if (spaceCount == 3) { if (b.at(i) == space)
datePos = i; ++spaceCount;
break; 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 // Copy over the parts that have not changed into a new byte array
QString result; QString result;
QTC_ASSERT(b.size() >= parenPos, return result);
int prevPos = 0; int prevPos = 0;
int pos = b.indexOf(QLatin1Char('\n'), 0) + 1; int pos = b.indexOf(QLatin1Char('\n'), 0) + 1;
forever { forever {
QTC_CHECK(prevPos < pos); QTC_CHECK(prevPos < pos);
int afterParen = prevPos + parenPos; int afterParen = prevPos + parenPos;
result.append(b.mid(prevPos, datePos)); result.append(b.mid(prevPos, stripPos));
result.append(b.mid(afterParen, pos - afterParen)); result.append(b.mid(afterParen, pos - afterParen));
prevPos = pos; prevPos = pos;
QTC_CHECK(prevPos != 0); QTC_CHECK(prevPos != 0);
@@ -179,17 +180,12 @@ static QString removeAnnotationDate(const QString &b)
void GitEditorWidget::setPlainText(const QString &text) void GitEditorWidget::setPlainText(const QString &text)
{ {
QString modText = text; QString modText = text;
GitPlugin *plugin = GitPlugin::instance();
// If desired, filter out the date from annotation // If desired, filter out the date from annotation
switch (contentType()) switch (contentType())
{ {
case AnnotateOutput: { case AnnotateOutput:
const bool omitAnnotationDate modText = sanitizeBlameOutput(text);
= plugin->client()->settings().boolValue(GitSettings::omitAnnotationDateKey);
if (omitAnnotationDate)
modText = removeAnnotationDate(text);
break; break;
}
default: default:
break; break;
} }