Skip to content

Commit dccebdd

Browse files
committed
Finally formalise our defacto line-ending policy
Historically, we've not automatically enforced how git tracks line endings, but there are many, many commits that "undo" unintended CRLFs getting into history. `git log --pretty=oneline --grep=CRLF` shows nearly 100 commits involving reverts of CRLF making its way into the index and then history. As far as I can tell, there are none the other way round except for specific cases like `.bat` files or tests for parsers that need to accept such sequences. Of note, one of the earliest of those listed in that output is: ``` commit 9795860 Author: NAKAMURA Takumi <[email protected]> Date: Thu Feb 3 11:41:27 2011 +0000 cmake/*: Add svn:eol-style=native and fix CRLF. llvm-svn: 124793 ``` ...which introduced such a defacto policy for subversion. With old versions of git, it's been a bit of a crap-shoot whether enforcing storing line endings in the history will upset checkouts on machines where such line endings are the norm. Indeed many users have enforced that git checks out the working copy according to a global or per-user config via core crlf, or core autocrlf. For ~8 years now[1], however, git has supported the ability to "do as the Romans do" on checkout, but internally store subsets of text files with line-endings specified via a system of patterns in the `.gitattributes` file. Since we now have this ability, and we've been specifying attributes for various binary files, I think it makes sense to rid us of all that work converting things "back", and just let git handle the local checkout. Thus the new toplevel policy here is * text=auto In simple terms this means "unless otherwise specified, convert all files considered "text" files to LF in the project history, but check them out as expected on the local machine. What is "expected on the local machine" is dependent on configuration and default. For those files in the repository that *do* need CRLF endings, I've adopted a policy of `eol=crlf` which means that git will store them in history with LF, but regardless of user config, they'll be checked out in tree with CRLF. Finally, existing files have been "corrected" in history via `git add --renormalize .` End users should *not* need to adjust their local git config or workflow. [1]: git 2.10 was released with fixed support for fine-grained line-ending tracking that respects user-config *and* repo policy. This can be considered the point at which git will respect both the user's local working tree preference *and* the history as specified by the maintainers. See https://github.com/git/git/blob/master/Documentation/RelNotes/2.10.0.txt#L248 for the release note.
1 parent 8c60efe commit dccebdd

File tree

7 files changed

+23
-0
lines changed

7 files changed

+23
-0
lines changed

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Checkout as native, commit as LF except in specific circumstances
2+
* text=auto
3+
*.bat text eol=crlf
4+
*.rc text eol=crlf
5+
*.sln text eol=crlf
6+
*.natvis text eol=crlf
7+
18
libcxx/src/**/*.cpp merge=libcxx-reformat
29
libcxx/include/**/*.h merge=libcxx-reformat
310

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
input-mirror.test text eol=crlf
2+
too_large.test text eol=crlf
3+
protocol.test text eol=crlf

clang/test/.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FixIt/fixit-newline-style.c text eol=crlf
2+
Frontend/system-header-line-directive-ms-lineendings.c text eol=crlf
3+
Frontend/rewrite-includes-mixed-eol-crlf.* text eol=crlf
4+
clang/test/Frontend/rewrite-includes-mixed-eol-lf.h text eolf=lf

llvm/docs/TestingGuide.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,12 @@ Best practices for regression tests
360360
- Try to give values (including variables, blocks and functions) meaningful
361361
names, and avoid retaining complex names generated by the optimization
362362
pipeline (such as ``%foo.0.0.0.0.0.0``).
363+
- If your tests depend on specific input file encodings, beware of line-ending
364+
issues across different platforms, and in the project's history. Before you
365+
commit tests that depend on explicit encodings, consider adding filetype or
366+
specific line-ending annotations to a `<.gitattributes
367+
https://git-scm.com/docs/gitattributes#_effects>`_ file in the appropriate
368+
directory in the repository.
363369

364370
Extra files
365371
-----------

llvm/test/FileCheck/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dos-style-eol.txt text eol=crlf
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mri-crlf.mri text eol=crlf
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.dos text eol=crlf

0 commit comments

Comments
 (0)