Git: Limit size of git blame output when using omit-date

* Do not use setPlainTextData on VCSBaseEditor only as that one implements
  the size limits on VCS output.

* Rework removal of date data from lines to limit copying

Change-Id: Ic1f507eb7bdabdb82b4a37a3d3e6f9381775b680
Reviewed-on: http://codereview.qt.nokia.com/780
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com>
This commit is contained in:
Tobias Hunger
2011-06-27 17:07:01 +02:00
parent d7ed0667e9
commit 3463a813c7

View File

@@ -147,41 +147,59 @@ QString GitEditor::fileNameFromDiffSpecification(const QTextBlock &inBlock) cons
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 void removeAnnotationDate(QString *s) static QByteArray removeAnnotationDate(const QByteArray &b)
{ {
if (s->isEmpty()) if (b.isEmpty())
return; return QByteArray();
// Get position of date (including blank) and the ')'
const QRegExp isoDatePattern(QLatin1String(" \\d{4}-\\d{2}-\\d{2}")); const int parenPos = b.indexOf(')');
Q_ASSERT(isoDatePattern.isValid());
const int datePos = s->indexOf(isoDatePattern);
const int parenPos = datePos == -1 ? -1 : s->indexOf(QLatin1Char(')'));
if (parenPos == -1) if (parenPos == -1)
return; return QByteArray(b);
// In all lines, remove the bit from datePos .. parenPos; int datePos = parenPos;
const int dateLength = parenPos - datePos;
const QChar newLine = QLatin1Char('\n'); // Go back from paren for 5 spaces: That is where the date starts.
for (int pos = 0; pos < s->size(); ) { int spaceCount = 0;
if (pos + parenPos >s->size()) // Should not happen for (int i = parenPos; i >= 0; --i) {
if (b.at(i) == ' ')
++spaceCount;
if (spaceCount == 5) {
datePos = i + 1;
break; break;
s->remove(pos + datePos, dateLength);
const int nextLinePos = s->indexOf(newLine, pos + datePos);
pos = nextLinePos == -1 ? s->size() : nextLinePos + 1;
} }
} }
if (datePos == 0)
return QByteArray(b);
// Copy over the parts that have not changed into a new byte array
Q_ASSERT(b.size() >= parenPos);
QByteArray result(b.constData(), datePos);
int prevPos = 0;
int pos = parenPos;
forever {
Q_ASSERT(prevPos < pos);
if (prevPos != 0)
result.append(b.constData() + prevPos, pos - prevPos);
prevPos = pos;
Q_ASSERT(prevPos != 0);
if (pos == b.size())
break;
pos = b.indexOf('\n', pos + 1);
if (pos == -1)
pos = b.size();
}
return result;
}
void GitEditor::setPlainTextDataFiltered(const QByteArray &a) void GitEditor::setPlainTextDataFiltered(const QByteArray &a)
{ {
QByteArray array = a;
// If desired, filter out the date from annotation // If desired, filter out the date from annotation
const bool omitAnnotationDate = contentType() == VCSBase::AnnotateOutput const bool omitAnnotationDate = contentType() == VCSBase::AnnotateOutput
&& GitPlugin::instance()->settings().omitAnnotationDate; && GitPlugin::instance()->settings().omitAnnotationDate;
if (omitAnnotationDate) { if (omitAnnotationDate)
QString text = codec()->toUnicode(a); array = removeAnnotationDate(a);
removeAnnotationDate(&text); setPlainTextData(array);
setPlainText(text);
} else {
setPlainTextData(a);
}
} }
void GitEditor::commandFinishedGotoLine(bool ok, int /* exitCode */, const QVariant &v) void GitEditor::commandFinishedGotoLine(bool ok, int /* exitCode */, const QVariant &v)