Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does TortoiseHg think Resource.h is binary?

Using Visual Studio 2010. I have a resource.h file which TortoiseHg thinks is binary so it won't display a diff for it in the commit window. I can easily open the file in a text editor and see that it is plain text.

I saw a related question (Why does Mercurial think my SQL files are binary?) which suggests it has to do with file encoding. Indeed opening the file in Notepad++ says the file is in "UCS-2 Little Endian". How can I fix this? I, obviously, don't want to break some Visual Studio expectation.

like image 449
User Avatar asked Oct 06 '11 23:10

User


2 Answers

For display purposes only, Mercurial treats all files containing NUL bytes as binary due to long-standing UNIX convention. This is just about always right.. except for UTF-16 (formerly known as UCS-2).. where half your file is NUL bytes!

Internally, Mercurial treats all files as binary all the time, so this issue is only relevant for things like whether or not we try to display diffs.

So you have two options:

  • ignore it, Mercurial will work just fine
  • use an encoding other than UTF-16

Some web searched for "resource.h utf-16" suggest that VS2010 will be just fine if you save this file in UTF-8 or ASCII, which should be perfectly fine choices for C source code.

http://social.msdn.microsoft.com/Forums/en/vssetup/thread/aff0f96d-16e3-4801-a7a2-5032803c8d83

like image 105
mpm Avatar answered Nov 05 '22 12:11

mpm


Try explicitly converting / changing the encoding to UTF-8 / ASCII and see. You can do that from Notepad++'s Encoding menu ( choose Encode in UTF-8)

Visual Studio will work with the UTF-8 file just fine.

like image 42
manojlds Avatar answered Nov 05 '22 13:11

manojlds