From b1d82efcc50bae26e40f5d9c73ebd788b9d6e950 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sun, 29 Jul 2012 20:40:27 +0200 Subject: [PATCH] Added unicode big-endian text file support to TortoiseGitBlame Signed-off-by: Sven Strickroth --- src/Changelog.txt | 2 +- src/TortoiseGitBlame/TortoiseGitBlameView.cpp | 31 ++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Changelog.txt b/src/Changelog.txt index 68a3d2342..c05cf5c7f 100644 --- a/src/Changelog.txt +++ b/src/Changelog.txt @@ -9,7 +9,7 @@ Released: unreleased * Allow users to store pushremote and pushbranch on push dialog for local branches * Fixed issue #1205: Add "Last modified" column to commit dialog * Fixed issue #1295: Browse Ref Dialog ref name order consider numbers in string - * Added unicode big-endian text file support to TortoiseMerge + * Added unicode big-endian text file support to TortoiseMerge and TortoiseGitBlame == Bug Fix == * Fixed issue #913: Merge does not cope with ambiguous tag and branch names diff --git a/src/TortoiseGitBlame/TortoiseGitBlameView.cpp b/src/TortoiseGitBlame/TortoiseGitBlameView.cpp index e9bf2b9c9..8f03af0b8 100644 --- a/src/TortoiseGitBlame/TortoiseGitBlameView.cpp +++ b/src/TortoiseGitBlame/TortoiseGitBlameView.cpp @@ -41,6 +41,11 @@ #define new DEBUG_NEW #endif +wchar_t WideCharSwap2(wchar_t nValue) +{ + return (((nValue>> 8)) | (nValue << 8)); +} + UINT CTortoiseGitBlameView::m_FindDialogMessage; // CTortoiseGitBlameView @@ -2452,6 +2457,13 @@ int CTortoiseGitBlameView::GetEncode(unsigned char *buff, int size, int *bomoffs return 1200; } + // check for UNICODE_BE does not work, because git blame produces two NUL chars in a row + if(type == CFileTextLines::BINARY && size > 2 && buff[0] == 0xFE && buff[1] == 0xFF) + { + *bomoffset = 2; + return 1201; + } + return GetACP(); } @@ -2531,7 +2543,24 @@ void CTortoiseGitBlameView::UpdateInfo(int Encode) encoding = GetEncode( &data[start+2], data.size() - start -2, &bomoffset); } { - if(encoding == 1200) + if(encoding == 1201) + { + CString strw; + int size = ((current - start -2 - bomoffset)/2); + TCHAR *buffer = strw.GetBuffer(size); + memcpy(buffer, &data[start + 2 + bomoffset],sizeof(TCHAR)*size); + // swap the bytes to little-endian order to get proper strings in wchar_t format + wchar_t * pSwapBuf = buffer; + for (DWORD i = 0; i