Question

We primarily develop our PHP application on a Windows environment and have stored our text source files in PC / ANSI.

However now, a developer is joining us who uses a Mac platform and we're running into issues creating 'patches' on his machine. When he makes any changes and does:

svn diff > patchfile.patch

he generates a patch file that indicates that each and every line of the source code file has been modified (which isnt the case obviously).

I tried saving a test ANSI file as:

PC / UTF-8 (using UTFCast Express which I writes the BOM by default)
PC / UTF-8 (using Notepad++ "Encoding > Convert to UTF-8" - which writes the BOM)

As well as:

PC / UTF-8 (using Notepad++ "Encoding > Convert to UTF-8 without BOM")
PC / UTF-8 (using Notepad++ "Encoding > Encode in UTF-8 without BOM")

For ALL of these cases, whenever he makes a change and does an svn diff > patchfile.patch, it outputs all the lines as if all the lines have been changed!

[we tried doing "svn diff -x -p > patchfile.patch" for the last 3 as well - no difference]

Incidentally, the files generated with the last two options continue to show up as ANSI on my PC machine. Both do not seem to modify the file at all and doing an 'fc' (file comparison) from the DOS prompt does not reveal any difference.

What encoding should I be using for cross-platform development?

Was it helpful?

Solution

Not a character encoding issue, but a line-ending issue. Windows uses CR-LF (13/10), Macs now use (unix style) LF only (10).

Set the subversion property svn:eol-style=native on the relevant files to make it work properly.

OTHER TIPS

Windows uses the uses the "\r\n" (newline/carriage return) line ending.

OS/X uses unix "\n" characters.

Previous OS9 used "\r".

I'm not sure why you would want UTF-8 character encoding for source code unless you have been doing that all along for all your files, especially if you're all english language speakers for the project.

Your mac dev should try and set his editor to use PC line endings, to be compatible with the rest of you. Often editors will sense the right line endings and use the right ones for existing files, but for files that are created new, they may be set to use their OS default.

You can experiment with flip which is a cross platform command line tool that will convert line ending characters from one os to another.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top