1

How do you save MFC resource scripts containing symbol characters in Git so that merging works?

We have been using UTF-16 for the resource scripts (.rc) in our MFC application so that we can store strings with symbols in our resources. We have recently migrated to Git and these files are now treated as binary for merging. There is no obvious way to change to UTF-8: the editor sets the legacy code page without a byte order mark and the scripts refuse to compile with one.

A typical script looks like this: note that the Visual Studio editor mechanically adds the #pragma code_page(1252) line if the file is saved as UTF-8 and the symbol is treated as a sequence of bytes.

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
///////////////////////////////////////////////////////////////////////////    //
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (United Kingdom) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
#pragma code_page(1252)

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE 
BEGIN
    "resource.h\0"
END

2 TEXTINCLUDE 
BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
END

3 TEXTINCLUDE 
BEGIN
    "#define _AFX_NO_SPLITTER_RESOURCES\r\n"
    "#define _AFX_NO_OLE_RESOURCES\r\n"
    "#define _AFX_NO_TRACKER_RESOURCES\r\n"
    "#define _AFX_NO_PROPERTY_RESOURCES\r\n"
    "\r\n"
    "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)\r\n"
    "#ifdef _WIN32\r\n"
    "LANGUAGE 9, 2\r\n"
    "#endif //_WIN32\r\n"
    "#include ""res\\test.rc2""  // non-Microsoft Visual C++ edited resources\r\n"
    "#include ""afxres.rc""         // Standard components\r\n"
    "#endif\r\n"
    "\0"
END

#endif    // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// String Table
//

STRINGTABLE
BEGIN
    IDS_ALPHA               "α"
END

#endif    // English (United Kingdom) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
#ifdef _WIN32
LANGUAGE 9, 2
#endif //_WIN32
#include "res\test.rc2"  // non-Microsoft Visual C++ edited resources
#include "afxres.rc"         // Standard components
#endif

/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED
  • [Can I make git recognize a UTF-16 file as text?](https://stackoverflow.com/questions/777949/can-i-make-git-recognize-a-utf-16-file-as-text) – user7860670 Jan 07 '19 at 10:07
  • See VTT's link, and look into setting up a *merge driver* for these files. Merge drivers work a lot like the diff drivers. I understand the theory behind them but have not implemented one in practice. – torek Jan 07 '19 at 14:44
  • https://git-scm.com/docs/gitattributes#_code_working_tree_encoding_code check this option. I have not tried it – max630 Jan 08 '19 at 12:40

0 Answers0