From 89e0a66f74c49098739c560cc140dbbc964bcea5 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint <Friedemann.Kleint@digia.com> Date: Tue, 19 Mar 2013 11:52:48 +0100 Subject: [PATCH] Git: Recognize SHA1s from 7 to 40 digits. Qt's grafts have 9-digit SHA1s which did not work with the previous 7-8/40 character limits. Change-Id: I3989405d00b575a6efb7dc6a467cbb24df9f3db5 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Tobias Hunger <tobias.hunger@digia.com> --- src/plugins/git/giteditor.cpp | 17 ++++++----------- src/plugins/git/giteditor.h | 3 +-- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/plugins/git/giteditor.cpp b/src/plugins/git/giteditor.cpp index fe2871ad89e..d5c9c2ac45a 100644 --- a/src/plugins/git/giteditor.cpp +++ b/src/plugins/git/giteditor.cpp @@ -51,8 +51,7 @@ #include <QTextEdit> #include <QTextBlock> -#define CHANGE_PATTERN_8C "[a-f0-9]{7,8}" -#define CHANGE_PATTERN_40C "[a-f0-9]{40,40}" +#define CHANGE_PATTERN "[a-f0-9]{7,40}" namespace Git { namespace Internal { @@ -61,11 +60,9 @@ namespace Internal { GitEditor::GitEditor(const VcsBase::VcsBaseEditorParameters *type, QWidget *parent) : VcsBase::VcsBaseEditorWidget(type, parent), - m_changeNumberPattern8(QLatin1String(CHANGE_PATTERN_8C)), - m_changeNumberPattern40(QLatin1String(CHANGE_PATTERN_40C)) + m_changeNumberPattern(QLatin1String(CHANGE_PATTERN)) { - QTC_ASSERT(m_changeNumberPattern8.isValid(), return); - QTC_ASSERT(m_changeNumberPattern40.isValid(), return); + QTC_ASSERT(m_changeNumberPattern.isValid(), return); /* Diff format: diff --git a/src/plugins/git/giteditor.cpp b/src/plugins/git/giteditor.cpp index 40997ff..4e49337 100644 @@ -85,11 +82,11 @@ QSet<QString> GitEditor::annotationChanges() const if (txt.isEmpty()) return changes; // Hunt for first change number in annotation: "<change>:" - QRegExp r(QLatin1String("^(" CHANGE_PATTERN_8C ") ")); + QRegExp r(QLatin1String("^(" CHANGE_PATTERN ") ")); QTC_ASSERT(r.isValid(), return changes); if (r.indexIn(txt) != -1) { changes.insert(r.cap(1)); - r.setPattern(QLatin1String("\n(" CHANGE_PATTERN_8C ") ")); + r.setPattern(QLatin1String("\n(" CHANGE_PATTERN ") ")); QTC_ASSERT(r.isValid(), return changes); int pos = 0; while ((pos = r.indexIn(txt, pos)) != -1) { @@ -108,9 +105,7 @@ QString GitEditor::changeUnderCursor(const QTextCursor &c) const if (!cursor.hasSelection()) return QString(); const QString change = cursor.selectedText(); - if (m_changeNumberPattern8.exactMatch(change)) - return change; - if (m_changeNumberPattern40.exactMatch(change)) + if (m_changeNumberPattern.exactMatch(change)) return change; return QString(); } diff --git a/src/plugins/git/giteditor.h b/src/plugins/git/giteditor.h index e101bfb8ad5..6af13790506 100644 --- a/src/plugins/git/giteditor.h +++ b/src/plugins/git/giteditor.h @@ -68,8 +68,7 @@ private: void addChangeActions(QMenu *menu, const QString &change); QString revisionSubject(const QTextBlock &inBlock) const; - mutable QRegExp m_changeNumberPattern8; - mutable QRegExp m_changeNumberPattern40; + mutable QRegExp m_changeNumberPattern; QString m_currentChange; }; -- GitLab