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
@@ -85,6 +85,7 @@ public:
|
||||
QStringList unstagedFileNames(const QString &stateFilter = QString()) const;
|
||||
|
||||
QString amendSHA1;
|
||||
QString commitEncoding;
|
||||
GitSubmitEditorPanelInfo panelInfo;
|
||||
GitSubmitEditorPanelData panelData;
|
||||
|
||||
|
||||
@@ -1632,6 +1632,7 @@ bool GitClient::getCommitData(const QString &workingDirectory,
|
||||
|
||||
commitData->panelData.author = readConfigValue(workingDirectory, QLatin1String("user.name"));
|
||||
commitData->panelData.email = readConfigValue(workingDirectory, QLatin1String("user.email"));
|
||||
commitData->commitEncoding = readConfigValue(workingDirectory, QLatin1String("i18n.commitEncoding"));
|
||||
|
||||
// Get the commit template or the last commit message
|
||||
if (amend) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -60,6 +60,9 @@ public:
|
||||
signals:
|
||||
void diff(const QStringList &unstagedFiles, const QStringList &stagedFiles);
|
||||
|
||||
protected:
|
||||
virtual QByteArray fileContents() const;
|
||||
|
||||
private slots:
|
||||
void slotDiffSelected(const QStringList &);
|
||||
|
||||
@@ -67,6 +70,7 @@ private:
|
||||
inline GitSubmitEditorWidget *submitEditorWidget();
|
||||
|
||||
VCSBase::SubmitFileModel *m_model;
|
||||
QString m_commitEncoding;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user