forked from qt-creator/qt-creator
Optionally shorten git blame output by removing date+line number.
This commit is contained in:
@@ -493,7 +493,7 @@ GitCommand *GitClient::createCommand(const QString &workingDirectory,
|
||||
}
|
||||
} else {
|
||||
QTC_ASSERT(editor, /**/);
|
||||
connect(command, SIGNAL(outputData(QByteArray)), editor, SLOT(setPlainTextData(QByteArray)));
|
||||
connect(command, SIGNAL(outputData(QByteArray)), editor, SLOT(setPlainTextDataFiltered(QByteArray)));
|
||||
}
|
||||
|
||||
if (outputWindow)
|
||||
|
@@ -33,6 +33,7 @@
|
||||
#include "gitclient.h"
|
||||
#include "gitconstants.h"
|
||||
#include "gitplugin.h"
|
||||
#include <QtCore/QTextCodec>
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -141,5 +142,47 @@ QString GitEditor::fileNameFromDiffSpecification(const QTextBlock &inBlock) cons
|
||||
return QString();
|
||||
}
|
||||
|
||||
/* Remove the date specification from annotation, which is tabular:
|
||||
\code
|
||||
8ca887aa (author YYYY-MM-DD HH:MM:SS <offset> <line>)<content>
|
||||
\endcode */
|
||||
|
||||
static void removeAnnotationDate(QString *s)
|
||||
{
|
||||
if (s->isEmpty())
|
||||
return;
|
||||
// Get position of date (including blank) and the ')'
|
||||
const QRegExp isoDatePattern(QLatin1String(" \\d{4}-\\d{2}-\\d{2}"));
|
||||
Q_ASSERT(isoDatePattern.isValid());
|
||||
const int datePos = s->indexOf(isoDatePattern);
|
||||
const int parenPos = datePos == -1 ? -1 : s->indexOf(QLatin1Char(')'));
|
||||
if (parenPos == -1)
|
||||
return;
|
||||
// In all lines, remove the bit from datePos .. parenPos;
|
||||
const int dateLength = parenPos - datePos;
|
||||
const QChar newLine = QLatin1Char('\n');
|
||||
for (int pos = 0; pos < s->size(); ) {
|
||||
if (pos + parenPos >s->size()) // Should not happen
|
||||
break;
|
||||
s->remove(pos + datePos, dateLength);
|
||||
const int nextLinePos = s->indexOf(newLine, pos + datePos);
|
||||
pos = nextLinePos == -1 ? s->size() : nextLinePos + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void GitEditor::setPlainTextDataFiltered(const QByteArray &a)
|
||||
{
|
||||
// If desired, filter out the date from annotation
|
||||
const bool omitAnnotationDate = contentType() == VCSBase::AnnotateOutput
|
||||
&& GitPlugin::instance()->settings().omitAnnotationDate;
|
||||
if (omitAnnotationDate) {
|
||||
QString text = codec()->toUnicode(a);
|
||||
removeAnnotationDate(&text);
|
||||
setPlainText(text);
|
||||
} else {
|
||||
setPlainTextData(a);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Git
|
||||
|
@@ -47,6 +47,9 @@ public:
|
||||
explicit GitEditor(const VCSBase::VCSBaseEditorParameters *type,
|
||||
QWidget *parent);
|
||||
|
||||
public slots:
|
||||
void setPlainTextDataFiltered(const QByteArray &a);
|
||||
|
||||
private:
|
||||
virtual QSet<QString> annotationChanges() const;
|
||||
virtual QString changeUnderCursor(const QTextCursor &) const;
|
||||
|
@@ -42,6 +42,7 @@ static const char *pathKeyC = "Path";
|
||||
static const char *logCountKeyC = "LogCount";
|
||||
static const char *timeoutKeyC = "TimeOut";
|
||||
static const char *promptToSubmitKeyC = "PromptForSubmit";
|
||||
static const char *omitAnnotationDateKeyC = "OmitAnnotationDate";
|
||||
|
||||
enum { defaultLogCount = 10 , defaultTimeOut = 30};
|
||||
|
||||
@@ -52,7 +53,8 @@ GitSettings::GitSettings() :
|
||||
adoptPath(false),
|
||||
logCount(defaultLogCount),
|
||||
timeout(defaultTimeOut),
|
||||
promptToSubmit(true)
|
||||
promptToSubmit(true),
|
||||
omitAnnotationDate(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -64,6 +66,7 @@ void GitSettings::fromSettings(QSettings *settings)
|
||||
logCount = settings->value(QLatin1String(logCountKeyC), defaultLogCount).toInt();
|
||||
timeout = settings->value(QLatin1String(timeoutKeyC), defaultTimeOut).toInt();
|
||||
promptToSubmit = settings->value(QLatin1String(promptToSubmitKeyC), true).toBool();
|
||||
omitAnnotationDate = settings->value(QLatin1String(omitAnnotationDateKeyC), false).toBool();
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
@@ -75,13 +78,15 @@ void GitSettings::toSettings(QSettings *settings) const
|
||||
settings->setValue(QLatin1String(logCountKeyC), logCount);
|
||||
settings->setValue(QLatin1String(timeoutKeyC), timeout);
|
||||
settings->setValue(QLatin1String(promptToSubmitKeyC), promptToSubmit);
|
||||
settings->setValue(QLatin1String(omitAnnotationDateKeyC), omitAnnotationDate);
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
bool GitSettings::equals(const GitSettings &s) const
|
||||
{
|
||||
return adoptPath == s.adoptPath && path == s.path && logCount == s.logCount
|
||||
&& timeout == s.timeout && promptToSubmit == s.promptToSubmit;
|
||||
&& timeout == s.timeout && promptToSubmit == s.promptToSubmit
|
||||
&& omitAnnotationDate == s.omitAnnotationDate;
|
||||
}
|
||||
|
||||
QString GitSettings::gitBinaryPath(bool *ok, QString *errorMessage) const
|
||||
|
@@ -56,6 +56,7 @@ struct GitSettings
|
||||
int logCount;
|
||||
int timeout;
|
||||
bool promptToSubmit;
|
||||
bool omitAnnotationDate;
|
||||
};
|
||||
|
||||
inline bool operator==(const GitSettings &p1, const GitSettings &p2)
|
||||
|
@@ -55,6 +55,7 @@ GitSettings SettingsPageWidget::settings() const
|
||||
rc.logCount = m_ui.logCountSpinBox->value();
|
||||
rc.timeout = m_ui.timeoutSpinBox->value();
|
||||
rc.promptToSubmit = m_ui.promptToSubmitCheckBox->isChecked();
|
||||
rc.omitAnnotationDate = m_ui.omitAnnotationDataCheckBox->isChecked();
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -65,6 +66,7 @@ void SettingsPageWidget::setSettings(const GitSettings &s)
|
||||
m_ui.logCountSpinBox->setValue(s.logCount);
|
||||
m_ui.timeoutSpinBox->setValue(s.timeout);
|
||||
m_ui.promptToSubmitCheckBox->setChecked(s.promptToSubmit);
|
||||
m_ui.omitAnnotationDataCheckBox->setChecked(s.omitAnnotationDate);
|
||||
}
|
||||
|
||||
void SettingsPageWidget::setSystemPath()
|
||||
|
@@ -111,6 +111,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="omitAnnotationDataCheckBox">
|
||||
<property name="text">
|
||||
<string>Omit date from annotation output</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
Reference in New Issue
Block a user