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:
Aurélien Gâteau
2012-01-26 14:18:59 +01:00
committed by Hugues Delorme
parent 1e7a0d3f65
commit acd49da492
4 changed files with 32 additions and 7 deletions

View File

@@ -40,7 +40,7 @@ BazaarAnnotationHighlighter::BazaarAnnotationHighlighter(const ChangeNumbers &ch
const QColor &bg,
QTextDocument *document)
: VcsBase::BaseAnnotationHighlighter(changeNumbers, bg, document),
m_changeset(QLatin1String(Constants::CHANGESET_ID))
m_changeset(QLatin1String(Constants::ANNOTATE_CHANGESET_ID))
{
}

View File

@@ -55,6 +55,7 @@ using namespace Bazaar;
BazaarEditor::BazaarEditor(const VcsBase::VcsBaseEditorParameters *type, QWidget *parent)
: VcsBase::VcsBaseEditorWidget(type, parent),
m_changesetId(QLatin1String(Constants::CHANGESET_ID)),
m_exactChangesetId(QLatin1String(Constants::CHANGESET_ID_EXACT)),
m_diffFileId(QLatin1String("^=== [a-z]+ [a-z]+ '(.*)'\\s*"))
{
@@ -86,12 +87,30 @@ QSet<QString> BazaarEditor::annotationChanges() 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;
cursor.select(QTextCursor::WordUnderCursor);
cursor.select(QTextCursor::LineUnderCursor);
if (cursor.hasSelection()) {
const QString change = cursor.selectedText();
if (m_exactChangesetId.exactMatch(change))
return change;
const QString line = cursor.selectedText();
const int start = m_changesetId.indexIn(line);
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();
}

View File

@@ -54,6 +54,7 @@ private:
virtual VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes, const QColor &bg) const;
virtual QString fileNameFromDiffSpecification(const QTextBlock &diffFileSpec) const;
const QRegExp m_changesetId;
const QRegExp m_exactChangesetId;
const QRegExp m_diffFileId;
};

View File

@@ -41,8 +41,13 @@ const char BAZAARREPO[] = ".bzr";
const char BAZAARDEFAULT[] = "bzr";
// Changeset identifiers
const char CHANGESET_ID[] = "([0-9]+)"; // match and capture
const char CHANGESET_ID_EXACT[] = "[0-9]+"; // match
const char CHANGESET_ID[] = "^("
"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
const char COMMANDLOG_ID[] = "Bazaar Command Log Editor";