dgcor / DGEngine

An implementation of the Diablo 1 game engine
Other
243 stars 30 forks source link

Normalize line endings #7

Closed mewmew closed 8 years ago

mewmew commented 8 years ago

To facilitate contributions from developers working on different platforms, one thing to consider is the normalization of line endings.

TL;DR: Windows uses a two character sequence for line endings (CRLF - Carriage Return, Line Feed), while Linux and Mac uses a one character sequence for line endings. In order to make this consistent, we may leverage git commit hooks to normalize line endings for us. See further details below.

(Copied more or less verbatim from quixotic-cynic/open-diablo-editor#1)

GitHub suggests that the line feed character (LF, 0x0A, '\n') should be used instead of the carriage return, line feed character sequence (CRLF, 0x0D, 0x0A, "\r\n").

The reason for this is that Window, Linux and Mac all uses different character sequences to signal line endings. CRLF on Windows, CR on Mac and LF on Linux. Fortunately, git may be configured to automatically change these line endings to a uniform format (LF was chosen for this) on commit. This way, all three operating systems may use their line endings locally, while the code repository uses a single format for line endings.

To configure Git to automatically convert CRLF on Windows to LF, before commits; simply run the following command:

# Configure Git on Windows to properly handle line endings
git config --global core.autocrlf true

As the repository already contains code which has CRLF line endings instead of LF line endings, it has to be resubmitted; as explained by the following Stack Overflow answer: http://stackoverflow.com/a/1889699

The gist of which is summarized below:

# Remove everything from the index
$ git rm --cached -r .

# Re-add all the deleted files to the index
# You should get lots of messages like: "warning: CRLF will be replaced by LF in <file>."
$ git diff --cached --name-only -z | xargs -0 git add

# Commit
$ git commit -m "Fix CRLF"
mewmew commented 8 years ago

Also, http://adaptivepatchwork.com/2012/03/01/mind-the-end-of-your-line/ may be worth a read for some backgroud.

ghost commented 8 years ago

I am aware of this you mention. I develop on Windows, hence why every file is CRLF. I will look into this later on.

mewmew commented 8 years ago

I will look into this later on.

Thanks! It will make it much easier for Linux users to contribute to the project.

ghost commented 8 years ago

It's done.

mewmew commented 8 years ago

It's done.

Wonderful! Thanks. I'll close this issue as it has been resolved by commit 67121f951d4fef467c3450b574e586547af491c1.