forked from qt-creator/qt-creator
Git: Support user configured comment character
Task-number: QTCREATORBUG-28042 Change-Id: I96aea27434ba138637728a7fd7d1450e1eee260a Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
committed by
Orgad Shaneh
parent
a50afa486a
commit
45aa6a12c4
@@ -115,6 +115,7 @@ public:
|
|||||||
GitSubmitEditorPanelInfo panelInfo;
|
GitSubmitEditorPanelInfo panelInfo;
|
||||||
GitSubmitEditorPanelData panelData;
|
GitSubmitEditorPanelData panelData;
|
||||||
bool enablePush = false;
|
bool enablePush = false;
|
||||||
|
QChar commentChar;
|
||||||
|
|
||||||
QList<StateFilePair> files;
|
QList<StateFilePair> files;
|
||||||
|
|
||||||
|
@@ -2780,6 +2780,8 @@ bool GitClient::getCommitData(const FilePath &workingDirectory,
|
|||||||
*errorMessage = msgNoCommits(false);
|
*errorMessage = msgNoCommits(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
commitData.commentChar = commentChar(repoDirectory);
|
||||||
}
|
}
|
||||||
const StatusResult status = gitStatus(repoDirectory, ShowAll, &output, errorMessage);
|
const StatusResult status = gitStatus(repoDirectory, ShowAll, &output, errorMessage);
|
||||||
switch (status) {
|
switch (status) {
|
||||||
@@ -3550,6 +3552,12 @@ QString GitClient::readConfigValue(const FilePath &workingDirectory, const QStri
|
|||||||
return readOneLine(workingDirectory, {"config", configVar});
|
return readOneLine(workingDirectory, {"config", configVar});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QChar GitClient::commentChar(const Utils::FilePath &workingDirectory)
|
||||||
|
{
|
||||||
|
const QString commentChar = readConfigValue(workingDirectory, "core.commentChar");
|
||||||
|
return commentChar.isEmpty() ? QChar(Constants::DEFAULT_COMMENT_CHAR) : commentChar.at(0);
|
||||||
|
}
|
||||||
|
|
||||||
void GitClient::setConfigValue(const FilePath &workingDirectory, const QString &configVar,
|
void GitClient::setConfigValue(const FilePath &workingDirectory, const QString &configVar,
|
||||||
const QString &value) const
|
const QString &value) const
|
||||||
{
|
{
|
||||||
|
@@ -300,6 +300,7 @@ public:
|
|||||||
|
|
||||||
QString readGitVar(const Utils::FilePath &workingDirectory, const QString &configVar) const;
|
QString readGitVar(const Utils::FilePath &workingDirectory, const QString &configVar) const;
|
||||||
QString readConfigValue(const Utils::FilePath &workingDirectory, const QString &configVar) const;
|
QString readConfigValue(const Utils::FilePath &workingDirectory, const QString &configVar) const;
|
||||||
|
QChar commentChar(const Utils::FilePath &workingDirectory);
|
||||||
void setConfigValue(const Utils::FilePath &workingDirectory, const QString &configVar,
|
void setConfigValue(const Utils::FilePath &workingDirectory, const QString &configVar,
|
||||||
const QString &value) const;
|
const QString &value) const;
|
||||||
|
|
||||||
|
@@ -56,6 +56,7 @@ const int OBSOLETE_COMMIT_AGE_IN_DAYS = 90;
|
|||||||
const int MAX_OBSOLETE_COMMITS_TO_DISPLAY = 5;
|
const int MAX_OBSOLETE_COMMITS_TO_DISPLAY = 5;
|
||||||
|
|
||||||
const char EXPAND_BRANCHES[] = "Branches: <Expand>";
|
const char EXPAND_BRANCHES[] = "Branches: <Expand>";
|
||||||
|
const char DEFAULT_COMMENT_CHAR = '#';
|
||||||
|
|
||||||
} // namespace Constants
|
} // namespace Constants
|
||||||
} // namespace Git
|
} // namespace Git
|
||||||
|
@@ -269,10 +269,15 @@ void GitEditorWidget::init()
|
|||||||
{
|
{
|
||||||
VcsBaseEditorWidget::init();
|
VcsBaseEditorWidget::init();
|
||||||
Utils::Id editorId = textDocument()->id();
|
Utils::Id editorId = textDocument()->id();
|
||||||
if (editorId == Git::Constants::GIT_COMMIT_TEXT_EDITOR_ID)
|
const bool isCommitEditor = editorId == Git::Constants::GIT_COMMIT_TEXT_EDITOR_ID;
|
||||||
textDocument()->setSyntaxHighlighter(new GitSubmitHighlighter);
|
const bool isRebaseEditor = editorId == Git::Constants::GIT_REBASE_EDITOR_ID;
|
||||||
else if (editorId == Git::Constants::GIT_REBASE_EDITOR_ID)
|
if (!isCommitEditor && !isRebaseEditor)
|
||||||
textDocument()->setSyntaxHighlighter(new GitRebaseHighlighter);
|
return;
|
||||||
|
const QChar commentChar = GitClient::instance()->commentChar(FilePath::fromString(source()));
|
||||||
|
if (isCommitEditor)
|
||||||
|
textDocument()->setSyntaxHighlighter(new GitSubmitHighlighter(commentChar));
|
||||||
|
else if (isRebaseEditor)
|
||||||
|
textDocument()->setSyntaxHighlighter(new GitRebaseHighlighter(commentChar));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitEditorWidget::addDiffActions(QMenu *menu, const DiffChunk &chunk)
|
void GitEditorWidget::addDiffActions(QMenu *menu, const DiffChunk &chunk)
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
#include "gitconstants.h"
|
||||||
#include "githighlighters.h"
|
#include "githighlighters.h"
|
||||||
|
|
||||||
namespace Git {
|
namespace Git {
|
||||||
@@ -34,12 +35,12 @@ namespace Internal {
|
|||||||
|
|
||||||
static const char CHANGE_PATTERN[] = "\\b[a-f0-9]{7,40}\\b";
|
static const char CHANGE_PATTERN[] = "\\b[a-f0-9]{7,40}\\b";
|
||||||
|
|
||||||
GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) :
|
GitSubmitHighlighter::GitSubmitHighlighter(QChar commentChar, QTextEdit * parent) :
|
||||||
TextEditor::SyntaxHighlighter(parent),
|
TextEditor::SyntaxHighlighter(parent),
|
||||||
m_keywordPattern("^[\\w-]+:")
|
m_keywordPattern("^[\\w-]+:")
|
||||||
{
|
{
|
||||||
setDefaultTextFormatCategories();
|
setDefaultTextFormatCategories();
|
||||||
m_hashChar = '#';
|
m_commentChar = commentChar.isNull() ? QChar(Constants::DEFAULT_COMMENT_CHAR) : commentChar;
|
||||||
QTC_CHECK(m_keywordPattern.isValid());
|
QTC_CHECK(m_keywordPattern.isValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ void GitSubmitHighlighter::highlightBlock(const QString &text)
|
|||||||
state = Other;
|
state = Other;
|
||||||
setCurrentBlockState(state);
|
setCurrentBlockState(state);
|
||||||
return;
|
return;
|
||||||
} else if (text.startsWith(m_hashChar)) {
|
} else if (text.startsWith(m_commentChar)) {
|
||||||
setFormat(0, text.size(), formatForCategory(TextEditor::C_COMMENT));
|
setFormat(0, text.size(), formatForCategory(TextEditor::C_COMMENT));
|
||||||
setCurrentBlockState(state);
|
setCurrentBlockState(state);
|
||||||
return;
|
return;
|
||||||
@@ -83,6 +84,19 @@ void GitSubmitHighlighter::highlightBlock(const QString &text)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QChar GitSubmitHighlighter::commentChar() const
|
||||||
|
{
|
||||||
|
return m_commentChar;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GitSubmitHighlighter::setCommentChar(QChar commentChar)
|
||||||
|
{
|
||||||
|
if (m_commentChar == commentChar)
|
||||||
|
return;
|
||||||
|
m_commentChar = commentChar;
|
||||||
|
rehighlight();
|
||||||
|
}
|
||||||
|
|
||||||
GitRebaseHighlighter::RebaseAction::RebaseAction(const QString ®exp,
|
GitRebaseHighlighter::RebaseAction::RebaseAction(const QString ®exp,
|
||||||
const Format formatCategory)
|
const Format formatCategory)
|
||||||
: exp(regexp),
|
: exp(regexp),
|
||||||
@@ -117,9 +131,9 @@ static TextEditor::TextStyle styleForFormat(int format)
|
|||||||
return C_TEXT;
|
return C_TEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
GitRebaseHighlighter::GitRebaseHighlighter(QTextDocument *parent) :
|
GitRebaseHighlighter::GitRebaseHighlighter(QChar commentChar, QTextDocument *parent) :
|
||||||
TextEditor::SyntaxHighlighter(parent),
|
TextEditor::SyntaxHighlighter(parent),
|
||||||
m_hashChar('#'),
|
m_commentChar(commentChar),
|
||||||
m_changeNumberPattern(CHANGE_PATTERN)
|
m_changeNumberPattern(CHANGE_PATTERN)
|
||||||
{
|
{
|
||||||
setTextFormatCategories(Format_Count, styleForFormat);
|
setTextFormatCategories(Format_Count, styleForFormat);
|
||||||
@@ -139,7 +153,7 @@ GitRebaseHighlighter::GitRebaseHighlighter(QTextDocument *parent) :
|
|||||||
|
|
||||||
void GitRebaseHighlighter::highlightBlock(const QString &text)
|
void GitRebaseHighlighter::highlightBlock(const QString &text)
|
||||||
{
|
{
|
||||||
if (text.startsWith(m_hashChar)) {
|
if (text.startsWith(m_commentChar)) {
|
||||||
setFormat(0, text.size(), formatForCategory(Format_Comment));
|
setFormat(0, text.size(), formatForCategory(Format_Comment));
|
||||||
QRegularExpressionMatchIterator it = m_changeNumberPattern.globalMatch(text);
|
QRegularExpressionMatchIterator it = m_changeNumberPattern.globalMatch(text);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
|
@@ -56,13 +56,15 @@ enum Format {
|
|||||||
class GitSubmitHighlighter : public TextEditor::SyntaxHighlighter
|
class GitSubmitHighlighter : public TextEditor::SyntaxHighlighter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit GitSubmitHighlighter(QTextEdit *parent = nullptr);
|
explicit GitSubmitHighlighter(QChar commentChar = QChar(), QTextEdit *parent = nullptr);
|
||||||
void highlightBlock(const QString &text) override;
|
void highlightBlock(const QString &text) override;
|
||||||
|
QChar commentChar() const;
|
||||||
|
void setCommentChar(QChar commentChar);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum State { None = -1, Header, Other };
|
enum State { None = -1, Header, Other };
|
||||||
const QRegularExpression m_keywordPattern;
|
const QRegularExpression m_keywordPattern;
|
||||||
QChar m_hashChar;
|
QChar m_commentChar;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Highlighter for interactive rebase todo. Indicates comments as such
|
// Highlighter for interactive rebase todo. Indicates comments as such
|
||||||
@@ -70,7 +72,7 @@ private:
|
|||||||
class GitRebaseHighlighter : public TextEditor::SyntaxHighlighter
|
class GitRebaseHighlighter : public TextEditor::SyntaxHighlighter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit GitRebaseHighlighter(QTextDocument *parent = nullptr);
|
explicit GitRebaseHighlighter(QChar commentChar, QTextDocument *parent = nullptr);
|
||||||
void highlightBlock(const QString &text) override;
|
void highlightBlock(const QString &text) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -81,7 +83,7 @@ private:
|
|||||||
Format formatCategory;
|
Format formatCategory;
|
||||||
RebaseAction(const QString ®exp, const Format formatCategory);
|
RebaseAction(const QString ®exp, const Format formatCategory);
|
||||||
};
|
};
|
||||||
const QChar m_hashChar;
|
const QChar m_commentChar;
|
||||||
const QRegularExpression m_changeNumberPattern;
|
const QRegularExpression m_changeNumberPattern;
|
||||||
QList<RebaseAction> m_actions;
|
QList<RebaseAction> m_actions;
|
||||||
};
|
};
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include "gitsubmiteditorwidget.h"
|
#include "gitsubmiteditorwidget.h"
|
||||||
|
|
||||||
#include "commitdata.h"
|
#include "commitdata.h"
|
||||||
|
#include "gitconstants.h"
|
||||||
#include "githighlighters.h"
|
#include "githighlighters.h"
|
||||||
#include "logchangedialog.h"
|
#include "logchangedialog.h"
|
||||||
|
|
||||||
@@ -119,7 +120,7 @@ public:
|
|||||||
GitSubmitEditorWidget::GitSubmitEditorWidget() :
|
GitSubmitEditorWidget::GitSubmitEditorWidget() :
|
||||||
m_gitSubmitPanel(new GitSubmitPanel)
|
m_gitSubmitPanel(new GitSubmitPanel)
|
||||||
{
|
{
|
||||||
new GitSubmitHighlighter(descriptionEdit());
|
m_highlighter = new GitSubmitHighlighter(QChar(), descriptionEdit());
|
||||||
|
|
||||||
m_emailValidator = new QRegularExpressionValidator(QRegularExpression("[^@ ]+@[^@ ]+\\.[a-zA-Z]+"), this);
|
m_emailValidator = new QRegularExpressionValidator(QRegularExpression("[^@ ]+@[^@ ]+\\.[a-zA-Z]+"), this);
|
||||||
const QPixmap error = Utils::Icons::CRITICAL.pixmap();
|
const QPixmap error = Utils::Icons::CRITICAL.pixmap();
|
||||||
@@ -176,6 +177,10 @@ void GitSubmitEditorWidget::initialize(const FilePath &repository, const CommitD
|
|||||||
insertLeftWidget(logChangeGroupBox);
|
insertLeftWidget(logChangeGroupBox);
|
||||||
m_gitSubmitPanel->editGroup->hide();
|
m_gitSubmitPanel->editGroup->hide();
|
||||||
hideDescription();
|
hideDescription();
|
||||||
|
} else {
|
||||||
|
m_highlighter->setCommentChar(data.commentChar);
|
||||||
|
if (data.commentChar != Constants::DEFAULT_COMMENT_CHAR)
|
||||||
|
verifyDescription();
|
||||||
}
|
}
|
||||||
insertTopWidget(m_gitSubmitPanel);
|
insertTopWidget(m_gitSubmitPanel);
|
||||||
setPanelData(data.panelData);
|
setPanelData(data.panelData);
|
||||||
@@ -248,14 +253,14 @@ bool GitSubmitEditorWidget::canSubmit(QString *whyNot) const
|
|||||||
QString GitSubmitEditorWidget::cleanupDescription(const QString &input) const
|
QString GitSubmitEditorWidget::cleanupDescription(const QString &input) const
|
||||||
{
|
{
|
||||||
// We need to manually purge out comment lines starting with
|
// We need to manually purge out comment lines starting with
|
||||||
// hash '#' since git does not do that when using -F.
|
// the comment char (default hash '#') since git does not do that when using -F.
|
||||||
const QChar newLine = '\n';
|
const QChar newLine = '\n';
|
||||||
const QChar hash = '#';
|
const QChar commentChar = m_highlighter->commentChar();
|
||||||
QString message = input;
|
QString message = input;
|
||||||
for (int pos = 0; pos < message.size(); ) {
|
for (int pos = 0; pos < message.size(); ) {
|
||||||
const int newLinePos = message.indexOf(newLine, pos);
|
const int newLinePos = message.indexOf(newLine, pos);
|
||||||
const int startOfNextLine = newLinePos == -1 ? message.size() : newLinePos + 1;
|
const int startOfNextLine = newLinePos == -1 ? message.size() : newLinePos + 1;
|
||||||
if (message.at(pos) == hash)
|
if (message.at(pos) == commentChar)
|
||||||
message.remove(pos, startOfNextLine - pos);
|
message.remove(pos, startOfNextLine - pos);
|
||||||
else
|
else
|
||||||
pos = startOfNextLine;
|
pos = startOfNextLine;
|
||||||
|
@@ -44,6 +44,7 @@ namespace Internal {
|
|||||||
class GitSubmitPanel;
|
class GitSubmitPanel;
|
||||||
class GitSubmitEditorPanelInfo;
|
class GitSubmitEditorPanelInfo;
|
||||||
class GitSubmitEditorPanelData;
|
class GitSubmitEditorPanelData;
|
||||||
|
class GitSubmitHighlighter;
|
||||||
class LogChangeWidget;
|
class LogChangeWidget;
|
||||||
|
|
||||||
/* Submit editor widget with 2 additional panes:
|
/* Submit editor widget with 2 additional panes:
|
||||||
@@ -87,6 +88,7 @@ private:
|
|||||||
|
|
||||||
PushAction m_pushAction = NoPush;
|
PushAction m_pushAction = NoPush;
|
||||||
GitSubmitPanel *m_gitSubmitPanel;
|
GitSubmitPanel *m_gitSubmitPanel;
|
||||||
|
GitSubmitHighlighter *m_highlighter = nullptr;
|
||||||
LogChangeWidget *m_logChangeWidget = nullptr;
|
LogChangeWidget *m_logChangeWidget = nullptr;
|
||||||
QValidator *m_emailValidator;
|
QValidator *m_emailValidator;
|
||||||
QString m_originalAuthor;
|
QString m_originalAuthor;
|
||||||
|
@@ -118,9 +118,8 @@ protected:
|
|||||||
void insertLeftWidget(QWidget *w);
|
void insertLeftWidget(QWidget *w);
|
||||||
void addSubmitButtonMenu(QMenu *menu);
|
void addSubmitButtonMenu(QMenu *menu);
|
||||||
void hideDescription();
|
void hideDescription();
|
||||||
|
|
||||||
protected slots:
|
|
||||||
void descriptionTextChanged();
|
void descriptionTextChanged();
|
||||||
|
void verifyDescription();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateCheckAllComboBox();
|
void updateCheckAllComboBox();
|
||||||
@@ -138,7 +137,6 @@ private:
|
|||||||
int checkedFilesCount() const;
|
int checkedFilesCount() const;
|
||||||
void wrapDescription();
|
void wrapDescription();
|
||||||
void trimDescription();
|
void trimDescription();
|
||||||
void verifyDescription();
|
|
||||||
|
|
||||||
SubmitEditorWidgetPrivate *d;
|
SubmitEditorWidgetPrivate *d;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user