i18n.commitEncoding is EVIL
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 35/100
Direção de pesquisa
Comece em NativeMethods.git_commit_message e Proxy.git_commit_message; depois, inspecione como Commit.Encoding é exposto e como Utf8NoCleanupMarshaler lida com o resultado nativo. Compare o comportamento com os três commits de exemplo usando as codificações default, gb2312 e cp936; está concluído quando as mensagens dos commits são decodificadas corretamente quando o Git declara uma codificação de página de código compatível.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Recently days I am researching i18n.commitEncoding, It's real an EVIL!!
First of all, I am a Chinese that OS language is en-us with Chinese(simplified) region. The commonly used encoding is GB2312(also GBK, code page 936).
The i18n.commitEncoding was defined in here that Character encoding the commit messages are stored in; git itself does not care per se, but this information is necessary.
OK, It's mean this config will affect the commit messages. but, I have find no any documents to define the format of encoding. I open the references window of Git GUI, and find the Default File Contents Encoding field. First item is System(cp936) of change menu, however, have an item Chinese Simplified (GB2312). They are equivalent in my first impression of two items.
I created a new repository then submit 3 commits with difference i18n.commitEncoding to test they. Both of they commit messages are four words Chinese, and i18n.commitEncoding followed by default, gb2312, cp936. (pushed to https://github.com/Aimeast/TestForFirst/commits/i18n)
git.execan display the second commitGit GUIcan display the first and third commitsGitHubcan display the first and second commits, third commit displayed as JapaneseLibGit2Sharpcan display the first and second commits (third commit not same with Github)
OK, the result real funny. I decompress objects files for digging.
- The first and second commits (e2266b and 38a2b0) were stored as
utf-8 - The third commit (bd9f62) was stored as
gb2312
After my analysis, git.exe can identify format start with cp and followed by code page number. So, we can explain why there is such result.
Now, let's into the issue. The code
// NativeMethods.git_commit_message
[DllImport(libgit2)]
[return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(Utf8NoCleanupMarshaler))]
internal static extern string git_commit_message(GitObjectSafeHandle commit);
It's always marshal as Utf-8 result in third commit message was messy code. So, I suggest that return raw data then decode string in Proxy.git_commit_message. But, the evil is .Net Framework not support some encoding which supported by git.exe.
Hereafter is my code for detect the encoding for a commit
public static Encoding CpAsEncoding(this Commit commit)
{
try
{
var encoding = commit.Encoding;
if (encoding.StartsWith("cp", StringComparison.OrdinalIgnoreCase))
return Encoding.GetEncoding(int.Parse(encoding.Substring(2)));
return Encoding.GetEncoding(encoding);
}
catch
{
return Encoding.UTF8;
}
}
Not perfect codes, but It's working.
- Linguagem predominante
- C#
- Estrelas
- 3.5k
- Forks
- 925
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de libgit2/libgit2sharp
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 52/100
libgit2/libgit2sharp#2193 · 2 comentários ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 38/100
libgit2/libgit2sharp#2192 · 1 comentário ·
-
Website is down Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 20/100
libgit2/libgit2sharp#2191 · 2 reações ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 68/100
libgit2/libgit2sharp#2189 · 1 reação ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 35/100
libgit2/libgit2sharp#2187 · 2 comentários ·
Todas as issues de libgit2/libgit2sharp
Issues semelhantes
-
bug
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 75/100
sillsdev/languageforge-lexbox#2665 ·
-
bug documentation frontend
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
azurenoops/spin_agent#975 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
SubtitleEdit/subtitleedit#15108 · 1 comentário ·