Commit 08f97b50 authored by Yuchen Deng's avatar Yuchen Deng Committed by Tobias Hunger
Browse files

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: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent 58018411
......@@ -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
......
......@@ -58,7 +58,7 @@ PerforceSubmitEditorWidget *PerforceSubmitEditor::submitEditorWidget()
return static_cast<PerforceSubmitEditorWidget *>(widget());
}
QString PerforceSubmitEditor::fileContents() const
QByteArray PerforceSubmitEditor::fileContents() const
{
const_cast<PerforceSubmitEditor*>(this)->updateEntries();
QString text;
......@@ -70,7 +70,7 @@ QString PerforceSubmitEditor::fileContents() const
}
if (Perforce::Constants::debug)
qDebug() << Q_FUNC_INFO << text;
return text;
return text.toLocal8Bit();
}
bool PerforceSubmitEditor::setFileContents(const QString &contents)
......
......@@ -69,7 +69,7 @@ public:
static QString fileFromChangeLine(const QString &line);
protected:
virtual QString fileContents() const;
virtual QByteArray fileContents() const;
virtual bool setFileContents(const QString &contents);
private:
......
......@@ -456,7 +456,7 @@ bool VCSBaseSubmitEditor::save(QString *errorString, const QString &fileName, bo
{
const QString fName = fileName.isEmpty() ? d->m_file->fileName() : fileName;
Utils::FileSaver saver(fName, QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
saver.write(fileContents().toLocal8Bit());
saver.write(fileContents());
if (!saver.finalize(errorString))
return false;
if (autoSave)
......@@ -467,9 +467,9 @@ bool VCSBaseSubmitEditor::save(QString *errorString, const QString &fileName, bo
return true;
}
QString VCSBaseSubmitEditor::fileContents() const
QByteArray VCSBaseSubmitEditor::fileContents() const
{
return d->m_widget->descriptionText();
return d->m_widget->descriptionText().toLocal8Bit();
}
bool VCSBaseSubmitEditor::setFileContents(const QString &contents)
......@@ -616,7 +616,7 @@ bool VCSBaseSubmitEditor::runSubmitMessageCheckScript(const QString &checkScript
tempFilePattern += QDir::separator();
tempFilePattern += QLatin1String("msgXXXXXX.txt");
Utils::TempFileSaver saver(tempFilePattern);
saver.write(fileContents().toUtf8());
saver.write(fileContents());
if (!saver.finalize(errorMessage))
return false;
// Run check process
......
......@@ -170,7 +170,7 @@ protected:
/* These hooks allow for modifying the contents that goes to
* the file. The default implementation uses the text
* of the description editor. */
virtual QString fileContents() const;
virtual QByteArray fileContents() const;
virtual bool setFileContents(const QString &contents);
private:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment