forked from qt-creator/qt-creator
Fix revno detection in bzr log
Avoid false-positives when looking for changes under cursor in log view. Change-Id: Ic0f9c105747ee2c1792b372f9cb3757017633861 Reviewed-by: Hugues Delorme <delorme.hugues@fougsys.fr>
This commit is contained in:
committed by
Hugues Delorme
parent
1e7a0d3f65
commit
acd49da492
@@ -40,7 +40,7 @@ BazaarAnnotationHighlighter::BazaarAnnotationHighlighter(const ChangeNumbers &ch
|
|||||||
const QColor &bg,
|
const QColor &bg,
|
||||||
QTextDocument *document)
|
QTextDocument *document)
|
||||||
: VcsBase::BaseAnnotationHighlighter(changeNumbers, bg, document),
|
: VcsBase::BaseAnnotationHighlighter(changeNumbers, bg, document),
|
||||||
m_changeset(QLatin1String(Constants::CHANGESET_ID))
|
m_changeset(QLatin1String(Constants::ANNOTATE_CHANGESET_ID))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -55,6 +55,7 @@ using namespace Bazaar;
|
|||||||
|
|
||||||
BazaarEditor::BazaarEditor(const VcsBase::VcsBaseEditorParameters *type, QWidget *parent)
|
BazaarEditor::BazaarEditor(const VcsBase::VcsBaseEditorParameters *type, QWidget *parent)
|
||||||
: VcsBase::VcsBaseEditorWidget(type, parent),
|
: VcsBase::VcsBaseEditorWidget(type, parent),
|
||||||
|
m_changesetId(QLatin1String(Constants::CHANGESET_ID)),
|
||||||
m_exactChangesetId(QLatin1String(Constants::CHANGESET_ID_EXACT)),
|
m_exactChangesetId(QLatin1String(Constants::CHANGESET_ID_EXACT)),
|
||||||
m_diffFileId(QLatin1String("^=== [a-z]+ [a-z]+ '(.*)'\\s*"))
|
m_diffFileId(QLatin1String("^=== [a-z]+ [a-z]+ '(.*)'\\s*"))
|
||||||
{
|
{
|
||||||
@@ -86,12 +87,30 @@ QSet<QString> BazaarEditor::annotationChanges() const
|
|||||||
|
|
||||||
QString BazaarEditor::changeUnderCursor(const QTextCursor &cursorIn) const
|
QString BazaarEditor::changeUnderCursor(const QTextCursor &cursorIn) const
|
||||||
{
|
{
|
||||||
|
// The test is done in two steps: first we check if the line contains a
|
||||||
|
// changesetId. Then we check if the cursor is over the changesetId itself
|
||||||
|
// and not over "revno" or another part of the line.
|
||||||
|
// The two steps are necessary because matching only for the changesetId
|
||||||
|
// leads to many false-positives (a regex like "[0-9]+" matches a lot of text).
|
||||||
|
const int cursorCol = cursorIn.columnNumber();
|
||||||
QTextCursor cursor = cursorIn;
|
QTextCursor cursor = cursorIn;
|
||||||
cursor.select(QTextCursor::WordUnderCursor);
|
cursor.select(QTextCursor::LineUnderCursor);
|
||||||
if (cursor.hasSelection()) {
|
if (cursor.hasSelection()) {
|
||||||
const QString change = cursor.selectedText();
|
const QString line = cursor.selectedText();
|
||||||
if (m_exactChangesetId.exactMatch(change))
|
const int start = m_changesetId.indexIn(line);
|
||||||
return change;
|
if (start > -1) {
|
||||||
|
const QString match = m_changesetId.cap(0);
|
||||||
|
const int stop = start + match.length();
|
||||||
|
if (start <= cursorCol && cursorCol <= stop) {
|
||||||
|
cursor = cursorIn;
|
||||||
|
cursor.select(QTextCursor::WordUnderCursor);
|
||||||
|
if (cursor.hasSelection()) {
|
||||||
|
const QString change = cursor.selectedText();
|
||||||
|
if (m_exactChangesetId.exactMatch(change))
|
||||||
|
return change;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
@@ -54,6 +54,7 @@ private:
|
|||||||
virtual VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes, const QColor &bg) const;
|
virtual VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes, const QColor &bg) const;
|
||||||
virtual QString fileNameFromDiffSpecification(const QTextBlock &diffFileSpec) const;
|
virtual QString fileNameFromDiffSpecification(const QTextBlock &diffFileSpec) const;
|
||||||
|
|
||||||
|
const QRegExp m_changesetId;
|
||||||
const QRegExp m_exactChangesetId;
|
const QRegExp m_exactChangesetId;
|
||||||
const QRegExp m_diffFileId;
|
const QRegExp m_diffFileId;
|
||||||
};
|
};
|
||||||
|
@@ -41,8 +41,13 @@ const char BAZAARREPO[] = ".bzr";
|
|||||||
const char BAZAARDEFAULT[] = "bzr";
|
const char BAZAARDEFAULT[] = "bzr";
|
||||||
|
|
||||||
// Changeset identifiers
|
// Changeset identifiers
|
||||||
const char CHANGESET_ID[] = "([0-9]+)"; // match and capture
|
const char CHANGESET_ID[] = "^("
|
||||||
const char CHANGESET_ID_EXACT[] = "[0-9]+"; // match
|
"revno: [.0-9]+" // detailed
|
||||||
|
"| +[.0-9]+" // short
|
||||||
|
"|[.0-9]+: " // line
|
||||||
|
")";
|
||||||
|
const char CHANGESET_ID_EXACT[] = "([.0-9]+)";
|
||||||
|
const char ANNOTATE_CHANGESET_ID[] = "([.0-9]+)";
|
||||||
|
|
||||||
// Base editor parameters
|
// Base editor parameters
|
||||||
const char COMMANDLOG_ID[] = "Bazaar Command Log Editor";
|
const char COMMANDLOG_ID[] = "Bazaar Command Log Editor";
|
||||||
|
Reference in New Issue
Block a user