forked from qt-creator/qt-creator
Git: Support encoding convert of commit messages
We need read i18n.commitEncoding value, to write correct encoding of the commit file. In Windows OS, the default encoding is GBK, So we need convert to correct encoding of the commit messages. Change-Id: Id5f35745dba15da2c9ceb1266e0ea537cba7da73 Merge-request: 382 Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com>
This commit is contained in:
committed by
Tobias Hunger
parent
5801841130
commit
08f97b50d7
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QTextCodec>
|
||||
|
||||
namespace Git {
|
||||
namespace Internal {
|
||||
@@ -83,6 +84,8 @@ void GitSubmitEditor::setCommitData(const CommitData &d)
|
||||
submitEditorWidget()->setPanelData(d.panelData);
|
||||
submitEditorWidget()->setPanelInfo(d.panelInfo);
|
||||
|
||||
m_commitEncoding = d.commitEncoding;
|
||||
|
||||
m_model = new VCSBase::SubmitFileModel(this);
|
||||
addStateFileListToModel(d.stagedFiles, true, StagedFile, m_model);
|
||||
addStateFileListToModel(d.unstagedFiles, false, UnstagedFile, m_model);
|
||||
@@ -128,5 +131,21 @@ GitSubmitEditorPanelData GitSubmitEditor::panelData() const
|
||||
return const_cast<GitSubmitEditor*>(this)->submitEditorWidget()->panelData();
|
||||
}
|
||||
|
||||
QByteArray GitSubmitEditor::fileContents() const
|
||||
{
|
||||
const QString& text = const_cast<GitSubmitEditor*>(this)->submitEditorWidget()->descriptionText();
|
||||
|
||||
if (!m_commitEncoding.isEmpty()) {
|
||||
// Do the encoding convert, When use user-defined encoding
|
||||
// e.g. git config --global i18n.commitencoding utf-8
|
||||
QTextCodec *codec = QTextCodec::codecForName(m_commitEncoding.toLocal8Bit());
|
||||
if (codec)
|
||||
return codec->fromUnicode(text);
|
||||
}
|
||||
|
||||
// Using utf-8 as the default encoding
|
||||
return text.toUtf8();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Git
|
||||
|
||||
Reference in New Issue
Block a user