Commit 7872981d authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

Git: Simplify commit message codec handling



Change-Id: I5f90d7f5a17ccbe8585efd8ac7f731440b10db61
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent a5a42c3f
......@@ -80,6 +80,7 @@ QDebug operator<<(QDebug d, const GitSubmitEditorPanelData &data)
CommitData::CommitData(CommitType type)
: commitType(type)
, commitEncoding(0)
, enablePush(false)
{
}
......
......@@ -111,7 +111,7 @@ public:
CommitType commitType;
QString amendSHA1;
QString commitEncoding;
QTextCodec *commitEncoding;
GitSubmitEditorPanelInfo panelInfo;
GitSubmitEditorPanelData panelData;
bool enablePush;
......
......@@ -424,8 +424,7 @@ void GitDiffHandler::collectShowDescription(const QString &id)
m_editorController->clear(m_waitMessage);
VcsBase::Command *command = new VcsBase::Command(m_gitPath, m_workingDirectory, m_processEnvironment);
const QString encoding = GitPlugin::instance()->gitClient()->commitEncoding(m_workingDirectory);
command->setCodec(QTextCodec::codecForName(encoding.toLocal8Bit()));
command->setCodec(GitPlugin::instance()->gitClient()->commitEncoding(m_workingDirectory));
connect(command, SIGNAL(output(QString)), this, SLOT(slotShowDescriptionReceived(QString)));
QStringList arguments;
arguments << QLatin1String("show") << QLatin1String("-s")
......@@ -3028,14 +3027,15 @@ QString GitClient::gitBinaryPath(bool *ok, QString *errorMessage) const
return settings()->gitBinaryPath(ok, errorMessage);
}
QString GitClient::commitEncoding(const QString &workingDirectory)
QTextCodec *GitClient::commitEncoding(const QString &workingDirectory)
{
QString encoding = readConfigValue(workingDirectory, QLatin1String("i18n.commitEncoding"));
if (!encoding.isEmpty())
return encoding;
QByteArray encoding = readConfigValue(workingDirectory, QLatin1String("i18n.commitEncoding"))
.toLocal8Bit();
// Set default commit encoding to 'UTF-8', when it's not set,
// to solve displaying error of commit log with non-latin characters.
return QLatin1String("UTF-8");
if (encoding.isEmpty())
encoding = "UTF-8";
return QTextCodec::codecForName(encoding);
}
bool GitClient::getCommitData(const QString &workingDirectory,
......@@ -3125,8 +3125,8 @@ bool GitClient::getCommitData(const QString &workingDirectory,
// Amend: get last commit data as "SHA1<tab>author<tab>email<tab>message".
QStringList args(QLatin1String("log"));
args << QLatin1String("--max-count=1") << QLatin1String("--pretty=format:%h\t%an\t%ae\t%B");
QTextCodec *codec = QTextCodec::codecForName(commitData.commitEncoding.toLocal8Bit());
const Utils::SynchronousProcessResponse sp = synchronousGit(repoDirectory, args, 0, codec);
const Utils::SynchronousProcessResponse sp = synchronousGit(repoDirectory, args, 0,
commitData.commitEncoding);
if (sp.result != Utils::SynchronousProcessResponse::Finished) {
*errorMessage = tr("Cannot retrieve last commit data of repository \"%1\".").arg(repoDirectory);
return false;
......
......@@ -285,7 +285,7 @@ public:
QString readConfigValue(const QString &workingDirectory, const QString &configVar) const;
QString commitEncoding(const QString &workingDirectory);
QTextCodec *commitEncoding(const QString &workingDirectory);
bool getCommitData(const QString &workingDirectory, QString *commitTemplate,
CommitData &commitData, QString *errorMessage);
......
......@@ -332,8 +332,7 @@ bool GitEditor::open(QString *errorString, const QString &fileName, const QStrin
QFileInfo fi(fileName);
const QString gitPath = fi.absolutePath();
setSource(gitPath);
const QString commitEncoding = GitPlugin::instance()->gitClient()->commitEncoding(gitPath);
baseTextDocument()->setCodec(QTextCodec::codecForName(commitEncoding.toLocal8Bit()));
baseTextDocument()->setCodec(GitPlugin::instance()->gitClient()->commitEncoding(gitPath));
}
return VcsBaseEditorWidget::open(errorString, fileName, realFileName);
}
......
......@@ -88,6 +88,7 @@ private:
GitSubmitEditor::GitSubmitEditor(const VcsBase::VcsBaseSubmitEditorParameters *parameters, QWidget *parent) :
VcsBaseSubmitEditor(parameters, new GitSubmitEditorWidget(parent)),
m_model(0),
m_commitEncoding(0),
m_commitType(SimpleCommit),
m_forceClose(false)
{
......@@ -202,13 +203,10 @@ QByteArray GitSubmitEditor::fileContents() const
{
const QString &text = 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);
}
// Do the encoding convert, When use user-defined encoding
// e.g. git config --global i18n.commitencoding utf-8
if (m_commitEncoding)
return m_commitEncoding->fromUnicode(text);
// Using utf-8 as the default encoding
return text.toUtf8();
......
......@@ -75,7 +75,7 @@ private:
inline const GitSubmitEditorWidget *submitEditorWidget() const;
VcsBase::SubmitFileModel *m_model;
QString m_commitEncoding;
QTextCodec *m_commitEncoding;
CommitType m_commitType;
QString m_amendSHA1;
bool m_forceClose;
......
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