{"thread":{"id":"23801","subject":"[PATCH v4 0/4] End-of-line normalization, getting close?","startedAt":"2010-05-13T21:44:38Z","lastAt":"2010-05-13T21:44:42Z","messageCount":5,"participants":["Eyvind Bernhardsen"],"isPatch":true,"patchVersion":4,"patchTotal":4},"messages":[{"id":"141613","messageId":"cover.1273786317.git.eyvind.bernhardsen@gmail.com","threadId":"23801","inReplyTo":null,"subject":"[PATCH v4 0/4] End-of-line normalization, getting close?","fromName":"Eyvind Bernhardsen","fromEmail":"eyvind.bernhardsen@gmail.com","sentAt":"2010-05-13T21:44:38Z","receivedAt":"2010-05-13T21:44:38Z","isPatch":true,"sender":{"key":"eyvind.bernhardsen@gmail.com","avatar":"https://avatars.githubusercontent.com/u/106762?v=4"},"body":"Here's the latest series.  Linus's suggested attribute names were a\nlot saner than mine, so I've now split the \"crlf\" attribute into\n\"crlf\" and \"eol\", and the \"crlf\" attribute gets renamed to \"text\" in\nthe final commit.  I dropped the patch that renamed autocrlf.\n\ngit-cvsserver gets a bit more love in this round (particularly the\ndocumentation), so I think it should work as well as it did before.\nNot too happy with the logic duplication, though.\n\nPatch 1/4 is still \"safe autocrlf\" from Finn Arne, just for\nconvenience.\n\nAll in all, I think this looks pretty good now.\n-- \nEyvind\n\n\nEyvind Bernhardsen (3):\n  Add tests for per-repository eol normalization\n  Add per-repository eol normalization\n  Rename the \"crlf\" attribute \"text\"\n\nFinn Arne Gangstad (1):\n  autocrlf: Make it work also for un-normalized repositories\n\n Documentation/config.txt        |   20 +++--\n Documentation/git-cvsserver.txt |   13 +--\n Documentation/gitattributes.txt |  164 +++++++++++++++++++++++++++++++--------\n attr.c                          |    2 +-\n cache.h                         |    9 ++-\n config.c                        |    2 +-\n convert.c                       |  155 +++++++++++++++++++++++++++++++------\n environment.c                   |    2 +-\n git-cvsserver.perl              |   13 ++-\n t/t0020-crlf.sh                 |   52 ++++++++++++\n t/t0025-crlf-auto.sh            |  156 +++++++++++++++++++++++++++++++++++++\n 11 files changed, 507 insertions(+), 81 deletions(-)\n create mode 100755 t/t0025-crlf-auto.sh\n"},{"id":"141616","messageId":"4dc62dfef759eca02dd7debd833b25ac47956370.1273786317.git.eyvind.bernhardsen@gmail.com","threadId":"23801","inReplyTo":"cover.1273786317.git.eyvind.bernhardsen@gmail.com","subject":"[PATCH v4 1/4] autocrlf: Make it work also for un-normalized repositories","fromName":"Eyvind Bernhardsen","fromEmail":"eyvind.bernhardsen@gmail.com","sentAt":"2010-05-13T21:44:39Z","receivedAt":"2010-05-13T21:44:39Z","isPatch":true,"sender":{"key":"eyvind.bernhardsen@gmail.com","avatar":"https://avatars.githubusercontent.com/u/106762?v=4"},"body":"From: Finn Arne Gangstad <finnag@pvv.org>\n\nPreviously, autocrlf would only work well for normalized\nrepositories. Any text files that contained CRLF in the repository\nwould cause problems, and would be modified when handled with\ncore.autocrlf set.\n\nChange autocrlf to not do any conversions to files that in the\nrepository already contain a CR. git with autocrlf set will never\ncreate such a file, or change a LF only file to contain CRs, so the\n(new) assumption is that if a file contains a CR, it is intentional,\nand autocrlf should not change that.\n\nThe following sequence should now always be a NOP even with autocrlf\nset (assuming a clean working directory):\n\ngit checkout <something>\ntouch *\ngit add -A .    (will add nothing)\ngit commit      (nothing to commit)\n\nPreviously this would break for any text file containing a CR.\n\nSome of you may have been folowing Eyvind's excellent thread about\ntrying to make end-of-line translation in git a bit smoother.\n\nI decided to attack the problem from a different angle: Is it possible\nto make autocrlf behave non-destructively for all the previous problem cases?\n\nStealing the problem from Eyvind's initial mail (paraphrased and\nsummarized a bit):\n\n1. Setting autocrlf globally is a pain since autocrlf does not work well\n   with CRLF in the repo\n2. Setting it in individual repos is hard since you do it \"too late\"\n   (the clone will get it wrong)\n3. If someone checks in a file with CRLF later, you get into problems again\n4. If a repository once has contained CRLF, you can't tell autocrlf\n   at which commit everything is sane again\n5. autocrlf does needless work if you know that all your users want\n   the same EOL style.\n\nI belive that this patch makes autocrlf a safe (and good) default\nsetting for Windows, and this solves problems 1-4 (it solves 2 by being\nset by default, which is early enough for clone).\n\nI implemented it by looking for CR charactes in the index, and\naborting any conversion attempt if this is found.\n\nSigned-off-by: Finn Arne Gangstad <finag@pvv.org>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Eyvind Bernhardsen <eyvind.bernhardsen@gmail.com>\n---\n convert.c       |   49 +++++++++++++++++++++++++++++++++++++++++++++++++\n t/t0020-crlf.sh |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 101 insertions(+), 0 deletions(-)\n\ndiff --git a/convert.c b/convert.c\nindex 4f8fcb7..46622b0 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -120,6 +120,43 @@ static void check_safe_crlf(const char *path, int action,\n \t}\n }\n \n+static int has_cr_in_index(const char *path)\n+{\n+\tint pos, len;\n+\tunsigned long sz;\n+\tenum object_type type;\n+\tvoid *data;\n+\tint has_cr;\n+\tstruct index_state *istate = &the_index;\n+\n+\tlen = strlen(path);\n+\tpos = index_name_pos(istate, path, len);\n+\tif (pos < 0) {\n+\t\t/*\n+\t\t * We might be in the middle of a merge, in which\n+\t\t * case we would read stage #2 (ours).\n+\t\t */\n+\t\tint i;\n+\t\tfor (i = -pos - 1;\n+\t\t     (pos < 0 && i < istate->cache_nr &&\n+\t\t      !strcmp(istate->cache[i]->name, path));\n+\t\t     i++)\n+\t\t\tif (ce_stage(istate->cache[i]) == 2)\n+\t\t\t\tpos = i;\n+\t}\n+\tif (pos < 0)\n+\t\treturn 0;\n+\tdata = read_sha1_file(istate->cache[pos]->sha1, &type, &sz);\n+\tif (!data || type != OBJ_BLOB) {\n+\t\tfree(data);\n+\t\treturn 0;\n+\t}\n+\n+\thas_cr = memchr(data, '\\r', sz) != NULL;\n+\tfree(data);\n+\treturn has_cr;\n+}\n+\n static int crlf_to_git(const char *path, const char *src, size_t len,\n                        struct strbuf *buf, int action, enum safe_crlf checksafe)\n {\n@@ -145,6 +182,13 @@ static int crlf_to_git(const char *path, const char *src, size_t len,\n \t\t */\n \t\tif (is_binary(len, &stats))\n \t\t\treturn 0;\n+\n+\t\t/*\n+\t\t * If the file in the index has any CR in it, do not convert.\n+\t\t * This is the new safer autocrlf handling.\n+\t\t */\n+\t\tif (has_cr_in_index(path))\n+\t\t\treturn 0;\n \t}\n \n \tcheck_safe_crlf(path, action, &stats, checksafe);\n@@ -203,6 +247,11 @@ static int crlf_to_worktree(const char *path, const char *src, size_t len,\n \t\treturn 0;\n \n \tif (action == CRLF_GUESS) {\n+\t\t/* If we have any CR or CRLF line endings, we do not touch it */\n+\t\t/* This is the new safer autocrlf-handling */\n+\t\tif (stats.cr > 0 || stats.crlf > 0)\n+\t\t\treturn 0;\n+\n \t\t/* If we have any bare CR characters, we're not going to touch it */\n \t\tif (stats.cr != stats.crlf)\n \t\t\treturn 0;\ndiff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh\nindex c3e7e32..234a94f 100755\n--- a/t/t0020-crlf.sh\n+++ b/t/t0020-crlf.sh\n@@ -453,5 +453,57 @@ test_expect_success 'invalid .gitattributes (must not crash)' '\n \tgit diff\n \n '\n+# Some more tests here to add new autocrlf functionality.\n+# We want to have a known state here, so start a bit from scratch\n+\n+test_expect_success 'setting up for new autocrlf tests' '\n+\tgit config core.autocrlf false &&\n+\tgit config core.safecrlf false &&\n+\trm -rf .????* * &&\n+\tfor w in I am all LF; do echo $w; done >alllf &&\n+\tfor w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&\n+\tfor w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&\n+\tgit add -A . &&\n+\tgit commit -m \"alllf, allcrlf and mixed only\" &&\n+\tgit tag -a -m \"message\" autocrlf-checkpoint\n+'\n+\n+test_expect_success 'report no change after setting autocrlf' '\n+\tgit config core.autocrlf true &&\n+\ttouch * &&\n+\tgit diff --exit-code\n+'\n+\n+test_expect_success 'files are clean after checkout' '\n+\trm * &&\n+\tgit checkout -f &&\n+\tgit diff --exit-code\n+'\n+\n+cr_to_Q_no_NL () {\n+    tr '\\015' Q | tr -d '\\012'\n+}\n+\n+test_expect_success 'LF only file gets CRLF with autocrlf' '\n+\ttest \"$(cr_to_Q_no_NL < alllf)\" = \"IQamQallQLFQ\"\n+'\n+\n+test_expect_success 'Mixed file is still mixed with autocrlf' '\n+\ttest \"$(cr_to_Q_no_NL < mixed)\" = \"OhhereisCRLFQintext\"\n+'\n+\n+test_expect_success 'CRLF only file has CRLF with autocrlf' '\n+\ttest \"$(cr_to_Q_no_NL < allcrlf)\" = \"IQamQallQCRLFQ\"\n+'\n+\n+test_expect_success 'New CRLF file gets LF in repo' '\n+\ttr -d \"\\015\" < alllf | append_cr > alllf2 &&\n+\tgit add alllf2 &&\n+\tgit commit -m \"alllf2 added\" &&\n+\tgit config core.autocrlf false &&\n+\trm * &&\n+\tgit checkout -f &&\n+\ttest_cmp alllf alllf2\n+'\n \n test_done\n-- \n1.7.1.5.gd739a\n"},{"id":"141617","messageId":"c8aeeee8015650054265775aec5e67fd34b5bf21.1273786317.git.eyvind.bernhardsen@gmail.com","threadId":"23801","inReplyTo":"cover.1273786317.git.eyvind.bernhardsen@gmail.com","subject":"[PATCH v4 2/4] Add tests for per-repository eol normalization","fromName":"Eyvind Bernhardsen","fromEmail":"eyvind.bernhardsen@gmail.com","sentAt":"2010-05-13T21:44:40Z","receivedAt":"2010-05-13T21:44:40Z","isPatch":true,"sender":{"key":"eyvind.bernhardsen@gmail.com","avatar":"https://avatars.githubusercontent.com/u/106762?v=4"},"body":"Signed-off-by: Eyvind Bernhardsen <eyvind.bernhardsen@gmail.com>\n---\n t/t0025-crlf-auto.sh |  143 ++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 143 insertions(+), 0 deletions(-)\n create mode 100755 t/t0025-crlf-auto.sh\n\ndiff --git a/t/t0025-crlf-auto.sh b/t/t0025-crlf-auto.sh\nnew file mode 100755\nindex 0000000..360117c\n--- /dev/null\n+++ b/t/t0025-crlf-auto.sh\n@@ -0,0 +1,143 @@\n+#!/bin/sh\n+\n+test_description='CRLF conversion'\n+\n+. ./test-lib.sh\n+\n+has_cr() {\n+\ttr '\\015' Q <\"$1\" | grep Q >/dev/null\n+}\n+\n+test_expect_success setup '\n+\n+\tgit config core.autocrlf false &&\n+\n+\tfor w in Hello world how are you; do echo $w; done >one &&\n+\tfor w in I am very very fine thank you; do echo ${w}Q; done | q_to_cr >two &&\n+\tfor w in Oh here is a QNUL byte how alarming; do echo ${w}; done | q_to_nul >three &&\n+\tgit add . &&\n+\n+\tgit commit -m initial &&\n+\n+\tone=`git rev-parse HEAD:one` &&\n+\ttwo=`git rev-parse HEAD:two` &&\n+\n+\tfor w in Some extra lines here; do echo $w; done >>one &&\n+\tgit diff >patch.file &&\n+\tpatched=`git hash-object --stdin <one` &&\n+\tgit read-tree --reset -u HEAD &&\n+\n+\techo happy.\n+'\n+\n+test_expect_success 'default settings cause no changes' '\n+\n+\trm -f .gitattributes tmp one two &&\n+\tgit read-tree --reset -u HEAD &&\n+\n+\t! has_cr one &&\n+\thas_cr two &&\n+\tonediff=`git diff one` &&\n+\ttwodiff=`git diff two` &&\n+\ttest -z \"$onediff\" -a -z \"$twodiff\"\n+'\n+\n+test_expect_failure 'crlf=true causes a CRLF file to be normalized' '\n+\n+\trm -f .gitattributes tmp one two &&\n+\techo \"two crlf\" > .gitattributes &&\n+\tgit read-tree --reset -u HEAD &&\n+\n+\t# Note, \"normalized\" means that git will normalize it if added\n+\thas_cr two &&\n+\ttwodiff=`git diff two` &&\n+\ttest -n \"$twodiff\"\n+'\n+\n+test_expect_failure 'eol=crlf gives a normalized file CRLFs with autocrlf=false' '\n+\n+\trm -f .gitattributes tmp one two &&\n+\tgit config core.autocrlf false &&\n+\techo \"one eol=crlf\" > .gitattributes &&\n+\tgit read-tree --reset -u HEAD &&\n+\n+\thas_cr one &&\n+\tonediff=`git diff one` &&\n+\ttest -z \"$onediff\"\n+'\n+\n+test_expect_failure 'eol=crlf gives a normalized file CRLFs with autocrlf=input' '\n+\n+\trm -f .gitattributes tmp one two &&\n+\tgit config core.autocrlf input &&\n+\techo \"one eol=crlf\" > .gitattributes &&\n+\tgit read-tree --reset -u HEAD &&\n+\n+\thas_cr one &&\n+\tonediff=`git diff one` &&\n+\ttest -z \"$onediff\"\n+'\n+\n+test_expect_failure 'eol=lf gives a normalized file LFs with autocrlf=true' '\n+\n+\trm -f .gitattributes tmp one two &&\n+\tgit config core.autocrlf true &&\n+\techo \"one eol=lf\" > .gitattributes &&\n+\tgit read-tree --reset -u HEAD &&\n+\n+\t! has_cr one &&\n+\tonediff=`git diff one` &&\n+\ttest -z \"$onediff\"\n+'\n+\n+test_expect_success 'autocrlf=true does not normalize CRLF files' '\n+\n+\trm -f .gitattributes tmp one two &&\n+\tgit config core.autocrlf true &&\n+\tgit read-tree --reset -u HEAD &&\n+\n+\thas_cr one &&\n+\thas_cr two &&\n+\tonediff=`git diff one` &&\n+\ttwodiff=`git diff two` &&\n+\ttest -z \"$onediff\" -a -z \"$twodiff\"\n+'\n+\n+test_expect_failure 'crlf=auto, autocrlf=true _does_ normalize CRLF files' '\n+\n+\trm -f .gitattributes tmp one two &&\n+\tgit config core.autocrlf true &&\n+\techo \"* crlf=auto\" > .gitattributes &&\n+\tgit read-tree --reset -u HEAD &&\n+\n+\thas_cr one &&\n+\thas_cr two &&\n+\tonediff=`git diff one` &&\n+\ttwodiff=`git diff two` &&\n+\ttest -z \"$onediff\" -a -n \"$twodiff\"\n+'\n+\n+test_expect_success 'crlf=auto, autocrlf=true does not normalize binary files' '\n+\n+\trm -f .gitattributes tmp one two three &&\n+\tgit config core.autocrlf true &&\n+\techo \"* crlf=auto\" > .gitattributes &&\n+\tgit read-tree --reset -u HEAD &&\n+\n+\t! has_cr three &&\n+\tthreediff=`git diff three` &&\n+\ttest -z \"$threediff\"\n+'\n+\n+test_expect_failure 'eol=crlf _does_ normalize binary files' '\n+\n+\trm -f .gitattributes tmp one two three &&\n+\techo \"three eol=crlf\" > .gitattributes &&\n+\tgit read-tree --reset -u HEAD &&\n+\n+\thas_cr three &&\n+\tthreediff=`git diff three` &&\n+\ttest -z \"$threediff\"\n+'\n+\n+test_done\n-- \n1.7.1.5.gd739a\n"},{"id":"141615","messageId":"14989b79f1b7443fe3e9dbeebb238c6ccbc4e1a8.1273786317.git.eyvind.bernhardsen@gmail.com","threadId":"23801","inReplyTo":"cover.1273786317.git.eyvind.bernhardsen@gmail.com","subject":"[PATCH v4 3/4] Add per-repository eol normalization","fromName":"Eyvind Bernhardsen","fromEmail":"eyvind.bernhardsen@gmail.com","sentAt":"2010-05-13T21:44:41Z","receivedAt":"2010-05-13T21:44:41Z","isPatch":true,"sender":{"key":"eyvind.bernhardsen@gmail.com","avatar":"https://avatars.githubusercontent.com/u/106762?v=4"},"body":"Change the semantics of the \"crlf\" attribute so that it enables\nend-of-line normalization when it is set, regardless of \"core.autocrlf\".\n\nAdd a new setting for \"crlf\": \"auto\", which enables end-of-line\nconversion but does not override the automatic text file detection.\n\nAdd a new attribute \"eol\" with possible values \"crlf\" and \"lf\".  When\nset, this attribute enables normalization and forces git to use CRLF or\nLF line endings in the working directory, respectively.\n\nThe line ending style to be used for normalized text files in the\nworking directory is set using \"core.autocrlf\".  When it is set to\n\"true\", CRLFs are used in the working directory; when set to \"input\" or\n\"false\", LFs are used.\n\nSigned-off-by: Eyvind Bernhardsen <eyvind.bernhardsen@gmail.com>\n---\n Documentation/config.txt        |    4 +-\n Documentation/gitattributes.txt |  153 +++++++++++++++++++++++++++++++--------\n cache.h                         |    9 ++-\n config.c                        |    2 +-\n convert.c                       |  117 +++++++++++++++++++++---------\n environment.c                   |    2 +-\n t/t0025-crlf-auto.sh            |   12 ++--\n 7 files changed, 223 insertions(+), 76 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 92f851e..4d3c472 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -208,8 +208,8 @@ core.autocrlf::\n \tbased on the file's contents.  See linkgit:gitattributes[5].\n \n core.safecrlf::\n-\tIf true, makes git check if converting `CRLF` as controlled by\n-\t`core.autocrlf` is reversible.  Git will verify if a command\n+\tIf true, makes git check if converting `CRLF` is reversible when\n+\tend-of-line conversion is active.  Git will verify if a command\n \tmodifies a file in the work tree either directly or indirectly.\n \tFor example, committing a file followed by checking out the\n \tsame file should yield the original file in the work tree.  If\ndiff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt\nindex d892e64..c71d883 100644\n--- a/Documentation/gitattributes.txt\n+++ b/Documentation/gitattributes.txt\n@@ -95,50 +95,139 @@ repository upon 'git add' and 'git commit'.\n `crlf`\n ^^^^^^\n \n-This attribute controls the line-ending convention.\n+This attribute enables and controls end-of-line normalization.  When a\n+text file is normalized, its line endings are converted to LF in the\n+repository.  To control what line ending style is used in the working\n+directory, use the `eol` attribute for a single file and the\n+`core.autocrlf` configuration variable for all text files.\n \n Set::\n \n-\tSetting the `crlf` attribute on a path is meant to mark\n-\tthe path as a \"text\" file.  'core.autocrlf' conversion\n-\ttakes place without guessing the content type by\n-\tinspection.\n+\tSetting the `crlf` attribute on a path enables end-of-line\n+\tnormalization and marks the path as a text file.  End-of-line\n+\tconversion takes place without guessing the content type.\n \n Unset::\n \n \tUnsetting the `crlf` attribute on a path tells git not to\n \tattempt any end-of-line conversion upon checkin or checkout.\n \n+Set to string value \"auto\"::\n+\n+\tWhen `crlf` is set to \"auto\", the path is marked for automatic\n+\tend-of-line normalization.  If git decides that the content is\n+\ttext, its line endings are normalized to LF on checkin.\n+\n Unspecified::\n \n-\tUnspecified `crlf` attribute tells git to apply the\n-\t`core.autocrlf` conversion when the file content looks\n-\tlike text.\n+\tIf the `crlf` attribute is unspecified, git uses the `eol`\n+\tattribute and the `core.autocrlf` configuration variable to\n+\tdetermine if the file should be converted.\n \n-Set to string value \"input\"::\n+Any other value causes git to act as if `crlf` has been left\n+unspecified.\n \n-\tThis is similar to setting the attribute to `true`, but\n-\talso forces git to act as if `core.autocrlf` is set to\n-\t`input` for the path.\n+`eol`\n+^^^^^\n \n-Any other value set to `crlf` attribute is ignored and git acts\n-as if the attribute is left unspecified.\n+This attribute sets a specific line-ending style to be used in the\n+working directory.  It enables end-of-line normalization without any\n+content checks, similar to setting the `crlf` attribute.\n \n+Set to string value \"crlf\"::\n \n-The `core.autocrlf` conversion\n-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n+\tThis setting forces git to normalize line endings on checkin\n+\tand convert them to CRLF when the file is checked out,\n+\tregardless of `crlf` and `core.autocrlf`.\n+\n+Set to string value \"lf\"::\n+\n+\tThis setting forces git to normalize line endings to LF on\n+\tcheckin and prevents conversion to CRLF when the file is\n+\tchecked out, regardless of `crlf` and `core.autocrlf`.\n+\t`crlf=input` is a backwards compatibility alias for `eol=lf`.\n+\n+End-of-line conversion\n+^^^^^^^^^^^^^^^^^^^^^^\n \n-If the configuration variable `core.autocrlf` is false, no\n-conversion is done.\n+While git normally leaves file contents alone, it can be configured to\n+normalize line endings to LF in the repository and, optionally, to\n+convert them to CRLF when files are checked out.\n \n-When `core.autocrlf` is true, it means that the platform wants\n-CRLF line endings for files in the working tree, and you want to\n-convert them back to the normal LF line endings when checking\n-in to the repository.\n+Here is an example that will make git normalize .txt, .vcproj and .sh\n+files, ensure that .vcproj files have CRLF and .sh files have LF in\n+the working directory, and prevent .jpg files from being normalized\n+regardless of their content.\n \n-When `core.autocrlf` is set to \"input\", line endings are\n-converted to LF upon checkin, but there is no conversion done\n-upon checkout.\n+------------------------\n+*.txt\t\tcrlf\n+*.vcproj\teol=crlf\n+*.sh\t\teol=lf\n+*.jpg\t\t-crlf\n+------------------------\n+\n+Other source code management systems normalize all text files in their\n+repositories, and there are two ways to enable similar automatic\n+normalization in git.\n+\n+If you simply want to have CRLF line endings in your working directory\n+regardless of the repository you are working with, you can set the\n+config variable \"core.autocrlf\" without changing any attributes.\n+\n+------------------------\n+[core]\n+\tautocrlf = true\n+------------------------\n+\n+This does not force normalization of all text files, but does ensure\n+that text files that you introduce to the repository have their line\n+endings normalized to LF when they are added, and that files that are\n+already normalized in the repository stay normalized.  You can also\n+set `autocrlf` to \"input\" to have automatic normalization of new text\n+files without conversion to CRLF in the working directory.\n+\n+If you want to interoperate with a source code management system that\n+enforces end-of-line normalization, or you simply want all text files\n+in your repository to be normalized, you should instead set the `crlf`\n+attribute to \"auto\" for _all_ files.\n+\n+------------------------\n+*\tcrlf=auto\n+------------------------\n+\n+This ensures that all files that git considers to be text will have\n+normalized (LF) line endings in the repository.\n+\n+NOTE: When `crlf=auto` normalization is enabled in an existing\n+repository, any text files containing CRLFs should be normalized.  If\n+they are not they will be normalized the next time someone tries to\n+change them, causing unfortunate misattribution.  From a clean working\n+directory:\n+\n+-------------------------------------------------\n+$ echo \"* crlf=auto\" >>.gitattributes\n+                    # ...this should be the first line in .gitattributes\n+$ rm .git/index     # Remove the index to force git to\n+$ git reset         # re-scan the working directory\n+$ git status        # Show files that will be normalized\n+$ git add -u\n+$ git add .gitattributes\n+$ git commit -m \"Introduce end-of-line normalization\"\n+-------------------------------------------------\n+\n+If any files that should not be normalized show up in 'git status',\n+unset their `crlf` attribute before running 'git add -u'.\n+\n+------------------------\n+manual.pdf\t-crlf\n+------------------------\n+\n+Conversely, text files that git does not detect can have normalization\n+enabled manually.\n+\n+------------------------\n+weirdchars.txt\tcrlf\n+------------------------\n \n If `core.safecrlf` is set to \"true\" or \"warn\", git verifies if\n the conversion is reversible for the current setting of\ndiff --git a/cache.h b/cache.h\nindex 5eb0573..d1f669e 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -547,7 +547,6 @@ extern int core_compression_seen;\n extern size_t packed_git_window_size;\n extern size_t packed_git_limit;\n extern size_t delta_base_cache_limit;\n-extern int auto_crlf;\n extern int read_replace_refs;\n extern int fsync_object_files;\n extern int core_preload_index;\n@@ -561,6 +560,14 @@ enum safe_crlf {\n \n extern enum safe_crlf safe_crlf;\n \n+enum auto_crlf {\n+\tAUTO_CRLF_FALSE = 0,\n+\tAUTO_CRLF_TRUE = 1,\n+\tAUTO_CRLF_INPUT = -1,\n+};\n+\n+extern enum auto_crlf auto_crlf;\n+\n enum branch_track {\n \tBRANCH_TRACK_UNSPECIFIED = -1,\n \tBRANCH_TRACK_NEVER = 0,\ndiff --git a/config.c b/config.c\nindex 6963fbe..b60a1ff 100644\n--- a/config.c\n+++ b/config.c\n@@ -461,7 +461,7 @@ static int git_default_core_config(const char *var, const char *value)\n \n \tif (!strcmp(var, \"core.autocrlf\")) {\n \t\tif (value && !strcasecmp(value, \"input\")) {\n-\t\t\tauto_crlf = -1;\n+\t\t\tauto_crlf = AUTO_CRLF_INPUT;\n \t\t\treturn 0;\n \t\t}\n \t\tauto_crlf = git_config_bool(var, value);\ndiff --git a/convert.c b/convert.c\nindex 46622b0..98bc029 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -8,13 +8,23 @@\n  * This should use the pathname to decide on whether it wants to do some\n  * more interesting conversions (automatic gzip/unzip, general format\n  * conversions etc etc), but by default it just does automatic CRLF<->LF\n- * translation when the \"auto_crlf\" option is set.\n+ * translation when the \"crlf\" attribute or \"auto_crlf\" option is set.\n  */\n \n-#define CRLF_GUESS\t(-1)\n-#define CRLF_BINARY\t0\n-#define CRLF_TEXT\t1\n-#define CRLF_INPUT\t2\n+enum action {\n+\tCRLF_GUESS = -1,\n+\tCRLF_BINARY = 0,\n+\tCRLF_TEXT,\n+\tCRLF_INPUT,\n+\tCRLF_CRLF,\n+\tCRLF_AUTO,\n+};\n+\n+enum eol {\n+\tEOL_UNSET,\n+\tEOL_LF,\n+\tEOL_CRLF,\n+};\n \n struct text_stat {\n \t/* NUL, CR, LF and CRLF counts */\n@@ -89,13 +99,14 @@ static int is_binary(unsigned long size, struct text_stat *stats)\n \treturn 0;\n }\n \n-static void check_safe_crlf(const char *path, int action,\n+static void check_safe_crlf(const char *path, enum action action,\n                             struct text_stat *stats, enum safe_crlf checksafe)\n {\n \tif (!checksafe)\n \t\treturn;\n \n-\tif (action == CRLF_INPUT || auto_crlf <= 0) {\n+\tif (action == CRLF_INPUT ||\n+\t    (action == CRLF_GUESS && auto_crlf == AUTO_CRLF_INPUT)) {\n \t\t/*\n \t\t * CRLFs would not be restored by checkout:\n \t\t * check if we'd remove CRLFs\n@@ -106,7 +117,8 @@ static void check_safe_crlf(const char *path, int action,\n \t\t\telse /* i.e. SAFE_CRLF_FAIL */\n \t\t\t\tdie(\"CRLF would be replaced by LF in %s.\", path);\n \t\t}\n-\t} else if (auto_crlf > 0) {\n+\t} else if (action == CRLF_CRLF ||\n+\t\t   (action == CRLF_GUESS && auto_crlf == AUTO_CRLF_TRUE)) {\n \t\t/*\n \t\t * CRLFs would be added by checkout:\n \t\t * check if we have \"naked\" LFs\n@@ -158,17 +170,18 @@ static int has_cr_in_index(const char *path)\n }\n \n static int crlf_to_git(const char *path, const char *src, size_t len,\n-                       struct strbuf *buf, int action, enum safe_crlf checksafe)\n+\t\t       struct strbuf *buf, enum action action, enum safe_crlf checksafe)\n {\n \tstruct text_stat stats;\n \tchar *dst;\n \n-\tif ((action == CRLF_BINARY) || !auto_crlf || !len)\n+\tif (action == CRLF_BINARY ||\n+\t    (action == CRLF_GUESS && auto_crlf == AUTO_CRLF_FALSE) || !len)\n \t\treturn 0;\n \n \tgather_stats(src, len, &stats);\n \n-\tif (action == CRLF_GUESS) {\n+\tif (action == CRLF_AUTO || action == CRLF_GUESS) {\n \t\t/*\n \t\t * We're currently not going to even try to convert stuff\n \t\t * that has bare CR characters. Does anybody do that crazy\n@@ -183,12 +196,14 @@ static int crlf_to_git(const char *path, const char *src, size_t len,\n \t\tif (is_binary(len, &stats))\n \t\t\treturn 0;\n \n-\t\t/*\n-\t\t * If the file in the index has any CR in it, do not convert.\n-\t\t * This is the new safer autocrlf handling.\n-\t\t */\n-\t\tif (has_cr_in_index(path))\n-\t\t\treturn 0;\n+\t\tif (action == CRLF_GUESS) {\n+\t\t\t/*\n+\t\t\t * If the file in the index has any CR in it, do not convert.\n+\t\t\t * This is the new safer autocrlf handling.\n+\t\t\t */\n+\t\t\tif (has_cr_in_index(path))\n+\t\t\t\treturn 0;\n+\t\t}\n \t}\n \n \tcheck_safe_crlf(path, action, &stats, checksafe);\n@@ -201,7 +216,7 @@ static int crlf_to_git(const char *path, const char *src, size_t len,\n \tif (strbuf_avail(buf) + buf->len < len)\n \t\tstrbuf_grow(buf, len - buf->len);\n \tdst = buf->buf;\n-\tif (action == CRLF_GUESS) {\n+\tif (action == CRLF_AUTO || action == CRLF_GUESS) {\n \t\t/*\n \t\t * If we guessed, we already know we rejected a file with\n \t\t * lone CR, and we can strip a CR without looking at what\n@@ -224,13 +239,13 @@ static int crlf_to_git(const char *path, const char *src, size_t len,\n }\n \n static int crlf_to_worktree(const char *path, const char *src, size_t len,\n-                            struct strbuf *buf, int action)\n+\t\t\t    struct strbuf *buf, enum action action)\n {\n \tchar *to_free = NULL;\n \tstruct text_stat stats;\n \n \tif ((action == CRLF_BINARY) || (action == CRLF_INPUT) ||\n-\t    auto_crlf <= 0)\n+\t    (action != CRLF_CRLF && auto_crlf != AUTO_CRLF_TRUE))\n \t\treturn 0;\n \n \tif (!len)\n@@ -246,11 +261,13 @@ static int crlf_to_worktree(const char *path, const char *src, size_t len,\n \tif (stats.lf == stats.crlf)\n \t\treturn 0;\n \n-\tif (action == CRLF_GUESS) {\n-\t\t/* If we have any CR or CRLF line endings, we do not touch it */\n-\t\t/* This is the new safer autocrlf-handling */\n-\t\tif (stats.cr > 0 || stats.crlf > 0)\n-\t\t\treturn 0;\n+\tif (action == CRLF_AUTO || action == CRLF_GUESS) {\n+\t\tif (action == CRLF_GUESS) {\n+\t\t\t/* If we have any CR or CRLF line endings, we do not touch it */\n+\t\t\t/* This is the new safer autocrlf-handling */\n+\t\t\tif (stats.cr > 0 || stats.crlf > 0)\n+\t\t\t\treturn 0;\n+\t\t}\n \n \t\t/* If we have any bare CR characters, we're not going to touch it */\n \t\tif (stats.cr != stats.crlf)\n@@ -424,11 +441,13 @@ static int read_convert_config(const char *var, const char *value, void *cb)\n static void setup_convert_check(struct git_attr_check *check)\n {\n \tstatic struct git_attr *attr_crlf;\n+\tstatic struct git_attr *attr_eol;\n \tstatic struct git_attr *attr_ident;\n \tstatic struct git_attr *attr_filter;\n \n \tif (!attr_crlf) {\n \t\tattr_crlf = git_attr(\"crlf\");\n+\t\tattr_eol = git_attr(\"eol\");\n \t\tattr_ident = git_attr(\"ident\");\n \t\tattr_filter = git_attr(\"filter\");\n \t\tuser_convert_tail = &user_convert;\n@@ -437,6 +456,7 @@ static void setup_convert_check(struct git_attr_check *check)\n \tcheck[0].attr = attr_crlf;\n \tcheck[1].attr = attr_ident;\n \tcheck[2].attr = attr_filter;\n+\tcheck[3].attr = attr_eol;\n }\n \n static int count_ident(const char *cp, unsigned long size)\n@@ -593,9 +613,24 @@ static int git_path_check_crlf(const char *path, struct git_attr_check *check)\n \t\t;\n \telse if (!strcmp(value, \"input\"))\n \t\treturn CRLF_INPUT;\n+\telse if (!strcmp(value, \"auto\"))\n+\t\treturn CRLF_AUTO;\n \treturn CRLF_GUESS;\n }\n \n+static int git_path_check_eol(const char *path, struct git_attr_check *check)\n+{\n+\tconst char *value = check->value;\n+\n+\tif (ATTR_UNSET(value))\n+\t\t;\n+\telse if (!strcmp(value, \"lf\"))\n+\t\treturn EOL_LF;\n+\telse if (!strcmp(value, \"crlf\"))\n+\t\treturn EOL_CRLF;\n+\treturn EOL_UNSET;\n+}\n+\n static struct convert_driver *git_path_check_convert(const char *path,\n \t\t\t\t\t     struct git_attr_check *check)\n {\n@@ -617,20 +652,32 @@ static int git_path_check_ident(const char *path, struct git_attr_check *check)\n \treturn !!ATTR_TRUE(value);\n }\n \n+enum action determine_action(enum action crlf_attr, enum eol eol_attr) {\n+\tif (crlf_attr == CRLF_BINARY)\n+\t\treturn CRLF_BINARY;\n+\tif (eol_attr == EOL_LF)\n+\t\treturn CRLF_INPUT;\n+\tif (eol_attr == EOL_CRLF)\n+\t\treturn CRLF_CRLF;\n+\treturn crlf_attr;\n+}\n+\n int convert_to_git(const char *path, const char *src, size_t len,\n                    struct strbuf *dst, enum safe_crlf checksafe)\n {\n-\tstruct git_attr_check check[3];\n-\tint crlf = CRLF_GUESS;\n+\tstruct git_attr_check check[4];\n+\tenum action action = CRLF_GUESS;\n+\tenum eol eol = EOL_UNSET;\n \tint ident = 0, ret = 0;\n \tconst char *filter = NULL;\n \n \tsetup_convert_check(check);\n \tif (!git_checkattr(path, ARRAY_SIZE(check), check)) {\n \t\tstruct convert_driver *drv;\n-\t\tcrlf = git_path_check_crlf(path, check + 0);\n+\t\taction = git_path_check_crlf(path, check + 0);\n \t\tident = git_path_check_ident(path, check + 1);\n \t\tdrv = git_path_check_convert(path, check + 2);\n+\t\teol = git_path_check_eol(path, check + 3);\n \t\tif (drv && drv->clean)\n \t\t\tfilter = drv->clean;\n \t}\n@@ -640,7 +687,8 @@ int convert_to_git(const char *path, const char *src, size_t len,\n \t\tsrc = dst->buf;\n \t\tlen = dst->len;\n \t}\n-\tret |= crlf_to_git(path, src, len, dst, crlf, checksafe);\n+\taction = determine_action(action, eol);\n+\tret |= crlf_to_git(path, src, len, dst, action, checksafe);\n \tif (ret) {\n \t\tsrc = dst->buf;\n \t\tlen = dst->len;\n@@ -650,17 +698,19 @@ int convert_to_git(const char *path, const char *src, size_t len,\n \n int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst)\n {\n-\tstruct git_attr_check check[3];\n-\tint crlf = CRLF_GUESS;\n+\tstruct git_attr_check check[4];\n+\tenum action action = CRLF_GUESS;\n+\tenum eol eol = EOL_UNSET;\n \tint ident = 0, ret = 0;\n \tconst char *filter = NULL;\n \n \tsetup_convert_check(check);\n \tif (!git_checkattr(path, ARRAY_SIZE(check), check)) {\n \t\tstruct convert_driver *drv;\n-\t\tcrlf = git_path_check_crlf(path, check + 0);\n+\t\taction = git_path_check_crlf(path, check + 0);\n \t\tident = git_path_check_ident(path, check + 1);\n \t\tdrv = git_path_check_convert(path, check + 2);\n+\t\teol = git_path_check_eol(path, check + 3);\n \t\tif (drv && drv->smudge)\n \t\t\tfilter = drv->smudge;\n \t}\n@@ -670,7 +720,8 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, struc\n \t\tsrc = dst->buf;\n \t\tlen = dst->len;\n \t}\n-\tret |= crlf_to_worktree(path, src, len, dst, crlf);\n+\taction = determine_action(action, eol);\n+\tret |= crlf_to_worktree(path, src, len, dst, action);\n \tif (ret) {\n \t\tsrc = dst->buf;\n \t\tlen = dst->len;\ndiff --git a/environment.c b/environment.c\nindex 876c5e5..db4a5e9 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -38,7 +38,7 @@ const char *pager_program;\n int pager_use_color = 1;\n const char *editor_program;\n const char *excludes_file;\n-int auto_crlf = 0;\t/* 1: both ways, -1: only when adding git objects */\n+enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;\n int read_replace_refs = 1;\n enum safe_crlf safe_crlf = SAFE_CRLF_WARN;\n unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;\ndiff --git a/t/t0025-crlf-auto.sh b/t/t0025-crlf-auto.sh\nindex 360117c..44cb593 100755\n--- a/t/t0025-crlf-auto.sh\n+++ b/t/t0025-crlf-auto.sh\n@@ -42,7 +42,7 @@ test_expect_success 'default settings cause no changes' '\n \ttest -z \"$onediff\" -a -z \"$twodiff\"\n '\n \n-test_expect_failure 'crlf=true causes a CRLF file to be normalized' '\n+test_expect_success 'crlf=true causes a CRLF file to be normalized' '\n \n \trm -f .gitattributes tmp one two &&\n \techo \"two crlf\" > .gitattributes &&\n@@ -54,7 +54,7 @@ test_expect_failure 'crlf=true causes a CRLF file to be normalized' '\n \ttest -n \"$twodiff\"\n '\n \n-test_expect_failure 'eol=crlf gives a normalized file CRLFs with autocrlf=false' '\n+test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=false' '\n \n \trm -f .gitattributes tmp one two &&\n \tgit config core.autocrlf false &&\n@@ -66,7 +66,7 @@ test_expect_failure 'eol=crlf gives a normalized file CRLFs with autocrlf=false'\n \ttest -z \"$onediff\"\n '\n \n-test_expect_failure 'eol=crlf gives a normalized file CRLFs with autocrlf=input' '\n+test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=input' '\n \n \trm -f .gitattributes tmp one two &&\n \tgit config core.autocrlf input &&\n@@ -78,7 +78,7 @@ test_expect_failure 'eol=crlf gives a normalized file CRLFs with autocrlf=input'\n \ttest -z \"$onediff\"\n '\n \n-test_expect_failure 'eol=lf gives a normalized file LFs with autocrlf=true' '\n+test_expect_success 'eol=lf gives a normalized file LFs with autocrlf=true' '\n \n \trm -f .gitattributes tmp one two &&\n \tgit config core.autocrlf true &&\n@@ -103,7 +103,7 @@ test_expect_success 'autocrlf=true does not normalize CRLF files' '\n \ttest -z \"$onediff\" -a -z \"$twodiff\"\n '\n \n-test_expect_failure 'crlf=auto, autocrlf=true _does_ normalize CRLF files' '\n+test_expect_success 'crlf=auto, autocrlf=true _does_ normalize CRLF files' '\n \n \trm -f .gitattributes tmp one two &&\n \tgit config core.autocrlf true &&\n@@ -129,7 +129,7 @@ test_expect_success 'crlf=auto, autocrlf=true does not normalize binary files' '\n \ttest -z \"$threediff\"\n '\n \n-test_expect_failure 'eol=crlf _does_ normalize binary files' '\n+test_expect_success 'eol=crlf _does_ normalize binary files' '\n \n \trm -f .gitattributes tmp one two three &&\n \techo \"three eol=crlf\" > .gitattributes &&\n-- \n1.7.1.5.gd739a\n"},{"id":"141614","messageId":"51a3a3b5bc8736c40e488e01da2c5ac552c00b57.1273786317.git.eyvind.bernhardsen@gmail.com","threadId":"23801","inReplyTo":"cover.1273786317.git.eyvind.bernhardsen@gmail.com","subject":"[PATCH v4 4/4] Rename the \"crlf\" attribute \"text\"","fromName":"Eyvind Bernhardsen","fromEmail":"eyvind.bernhardsen@gmail.com","sentAt":"2010-05-13T21:44:42Z","receivedAt":"2010-05-13T21:44:42Z","isPatch":true,"sender":{"key":"eyvind.bernhardsen@gmail.com","avatar":"https://avatars.githubusercontent.com/u/106762?v=4"},"body":"As discussed on the list, \"crlf\" is not an optimal name.  Linus\nsuggested \"text\", which is much better.\n\nSigned-off-by: Eyvind Bernhardsen <eyvind.bernhardsen@gmail.com>\n---\n Documentation/config.txt        |   16 ++++++----\n Documentation/git-cvsserver.txt |   13 +++-----\n Documentation/gitattributes.txt |   59 +++++++++++++++++++++++----------------\n attr.c                          |    2 +-\n convert.c                       |   23 ++++++++++-----\n git-cvsserver.perl              |   13 ++++++--\n t/t0025-crlf-auto.sh            |   21 +++++++++++--\n 7 files changed, 91 insertions(+), 56 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 4d3c472..207351b 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -204,7 +204,7 @@ core.autocrlf::\n \treading from the work tree but files are written out to the work\n \ttree with `LF` at the end of lines.  A file is considered\n \t\"text\" (i.e. be subjected to the autocrlf mechanism) based on\n-\tthe file's `crlf` attribute, or if `crlf` is unspecified,\n+\tthe file's `text` attribute, or if `text` is unspecified,\n \tbased on the file's contents.  See linkgit:gitattributes[5].\n \n core.safecrlf::\n@@ -975,13 +975,15 @@ gitcvs.logfile::\n \tvarious stuff. See linkgit:git-cvsserver[1].\n \n gitcvs.usecrlfattr::\n-\tIf true, the server will look up the `crlf` attribute for\n-\tfiles to determine the '-k' modes to use. If `crlf` is set,\n-\tthe '-k' mode will be left blank, so cvs clients will\n-\ttreat it as text. If `crlf` is explicitly unset, the file\n+\tIf true, the server will look up the end-of-line conversion\n+\tattributes for files to determine the '-k' modes to use. If\n+\tthe attributes force git to treat a file as text,\n+\tthe '-k' mode will be left blank so cvs clients will\n+\ttreat it as text. If they suppress text conversion, the file\n \twill be set with '-kb' mode, which suppresses any newline munging\n-\tthe client might otherwise do. If `crlf` is not specified,\n-\tthen 'gitcvs.allbinary' is used. See linkgit:gitattributes[5].\n+\tthe client might otherwise do. If the attributes do not allow\n+\tthe file type to be determined, then 'gitcvs.allbinary' is\n+\tused. See linkgit:gitattributes[5].\n \n gitcvs.allbinary::\n \tThis is used if 'gitcvs.usecrlfattr' does not resolve\ndiff --git a/Documentation/git-cvsserver.txt b/Documentation/git-cvsserver.txt\nindex dbb053e..0864857 100644\n--- a/Documentation/git-cvsserver.txt\n+++ b/Documentation/git-cvsserver.txt\n@@ -340,16 +340,13 @@ By default the server leaves the '-k' mode blank for all files,\n which causes the cvs client to treat them as a text files, subject\n to crlf conversion on some platforms.\n \n-You can make the server use `crlf` attributes to set the '-k' modes\n-for files by setting the `gitcvs.usecrlfattr` config variable.\n-In this case, if `crlf` is explicitly unset ('-crlf'), then the\n-server will set '-kb' mode for binary files. If `crlf` is set,\n-then the '-k' mode will explicitly be left blank.  See\n-also linkgit:gitattributes[5] for more information about the `crlf`\n-attribute.\n+You can make the server use the end-of-line conversion attributes to\n+set the '-k' modes for files by setting the `gitcvs.usecrlfattr`\n+config variable.  See linkgit:gitattributes[5] for more information\n+about end-of-line conversion.\n \n Alternatively, if `gitcvs.usecrlfattr` config is not enabled\n-or if the `crlf` attribute is unspecified for a filename, then\n+or the attributes do not allow automatic detection for a filename, then\n the server uses the `gitcvs.allbinary` config for the default setting.\n If `gitcvs.allbinary` is set, then file not otherwise\n specified will default to '-kb' mode. Otherwise the '-k' mode\ndiff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt\nindex c71d883..25753b7 100644\n--- a/Documentation/gitattributes.txt\n+++ b/Documentation/gitattributes.txt\n@@ -92,7 +92,7 @@ such as 'git checkout' and 'git merge' run.  They also affect how\n git stores the contents you prepare in the working tree in the\n repository upon 'git add' and 'git commit'.\n \n-`crlf`\n+`text`\n ^^^^^^\n \n This attribute enables and controls end-of-line normalization.  When a\n@@ -103,28 +103,28 @@ directory, use the `eol` attribute for a single file and the\n \n Set::\n \n-\tSetting the `crlf` attribute on a path enables end-of-line\n+\tSetting the `text` attribute on a path enables end-of-line\n \tnormalization and marks the path as a text file.  End-of-line\n \tconversion takes place without guessing the content type.\n \n Unset::\n \n-\tUnsetting the `crlf` attribute on a path tells git not to\n+\tUnsetting the `text` attribute on a path tells git not to\n \tattempt any end-of-line conversion upon checkin or checkout.\n \n Set to string value \"auto\"::\n \n-\tWhen `crlf` is set to \"auto\", the path is marked for automatic\n+\tWhen `text` is set to \"auto\", the path is marked for automatic\n \tend-of-line normalization.  If git decides that the content is\n \ttext, its line endings are normalized to LF on checkin.\n \n Unspecified::\n \n-\tIf the `crlf` attribute is unspecified, git uses the `eol`\n+\tIf the `text` attribute is unspecified, git uses the `eol`\n \tattribute and the `core.autocrlf` configuration variable to\n \tdetermine if the file should be converted.\n \n-Any other value causes git to act as if `crlf` has been left\n+Any other value causes git to act as if `text` has been left\n unspecified.\n \n `eol`\n@@ -132,20 +132,31 @@ unspecified.\n \n This attribute sets a specific line-ending style to be used in the\n working directory.  It enables end-of-line normalization without any\n-content checks, similar to setting the `crlf` attribute.\n+content checks, similar to setting the `text` attribute.\n \n Set to string value \"crlf\"::\n \n \tThis setting forces git to normalize line endings on checkin\n \tand convert them to CRLF when the file is checked out,\n-\tregardless of `crlf` and `core.autocrlf`.\n+\tregardless of `text` and `core.autocrlf`.\n \n Set to string value \"lf\"::\n \n \tThis setting forces git to normalize line endings to LF on\n \tcheckin and prevents conversion to CRLF when the file is\n-\tchecked out, regardless of `crlf` and `core.autocrlf`.\n-\t`crlf=input` is a backwards compatibility alias for `eol=lf`.\n+\tchecked out, regardless of `text` and `core.autocrlf`.\n+\n+Backwards compatibility with `crlf` attribute\n+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n+\n+For backwards compatibility, the `crlf` attribute is interpreted as\n+follows:\n+\n+------------------------\n+crlf\t\ttext\n+-crlf\t\t-text\n+crlf=input\teol=lf\n+------------------------\n \n End-of-line conversion\n ^^^^^^^^^^^^^^^^^^^^^^\n@@ -160,10 +171,10 @@ the working directory, and prevent .jpg files from being normalized\n regardless of their content.\n \n ------------------------\n-*.txt\t\tcrlf\n+*.txt\t\ttext\n *.vcproj\teol=crlf\n *.sh\t\teol=lf\n-*.jpg\t\t-crlf\n+*.jpg\t\t-text\n ------------------------\n \n Other source code management systems normalize all text files in their\n@@ -188,24 +199,24 @@ files without conversion to CRLF in the working directory.\n \n If you want to interoperate with a source code management system that\n enforces end-of-line normalization, or you simply want all text files\n-in your repository to be normalized, you should instead set the `crlf`\n+in your repository to be normalized, you should instead set the `text`\n attribute to \"auto\" for _all_ files.\n \n ------------------------\n-*\tcrlf=auto\n+*\ttext=auto\n ------------------------\n \n This ensures that all files that git considers to be text will have\n normalized (LF) line endings in the repository.\n \n-NOTE: When `crlf=auto` normalization is enabled in an existing\n+NOTE: When `text=auto` normalization is enabled in an existing\n repository, any text files containing CRLFs should be normalized.  If\n they are not they will be normalized the next time someone tries to\n change them, causing unfortunate misattribution.  From a clean working\n directory:\n \n -------------------------------------------------\n-$ echo \"* crlf=auto\" >>.gitattributes\n+$ echo \"* text=auto\" >>.gitattributes\n                     # ...this should be the first line in .gitattributes\n $ rm .git/index     # Remove the index to force git to\n $ git reset         # re-scan the working directory\n@@ -216,17 +227,17 @@ $ git commit -m \"Introduce end-of-line normalization\"\n -------------------------------------------------\n \n If any files that should not be normalized show up in 'git status',\n-unset their `crlf` attribute before running 'git add -u'.\n+unset their `text` attribute before running 'git add -u'.\n \n ------------------------\n-manual.pdf\t-crlf\n+manual.pdf\t-text\n ------------------------\n \n Conversely, text files that git does not detect can have normalization\n enabled manually.\n \n ------------------------\n-weirdchars.txt\tcrlf\n+weirdchars.txt\ttext\n ------------------------\n \n If `core.safecrlf` is set to \"true\" or \"warn\", git verifies if\n@@ -312,11 +323,11 @@ Interaction between checkin/checkout attributes\n In the check-in codepath, the worktree file is first converted\n with `filter` driver (if specified and corresponding driver\n defined), then the result is processed with `ident` (if\n-specified), and then finally with `crlf` (again, if specified\n+specified), and then finally with `text` (again, if specified\n and applicable).\n \n In the check-out codepath, the blob content is first converted\n-with `crlf`, and then `ident` and fed to `filter`.\n+with `text`, and then `ident` and fed to `filter`.\n \n \n Generating diff text\n@@ -720,7 +731,7 @@ You do not want any end-of-line conversions applied to, nor textual diffs\n produced for, any binary file you track.  You would need to specify e.g.\n \n ------------\n-*.jpg -crlf -diff\n+*.jpg -text -diff\n ------------\n \n but that may become cumbersome, when you have many attributes.  Using\n@@ -733,7 +744,7 @@ the same time.  The system knows a built-in attribute macro, `binary`:\n \n which is equivalent to the above.  Note that the attribute macros can only\n be \"Set\" (see the above example that sets \"binary\" macro as if it were an\n-ordinary attribute --- setting it in turn unsets \"crlf\" and \"diff\").\n+ordinary attribute --- setting it in turn unsets \"text\" and \"diff\").\n \n \n DEFINING ATTRIBUTE MACROS\n@@ -744,7 +755,7 @@ at the toplevel (i.e. not in any subdirectory).  The built-in attribute\n macro \"binary\" is equivalent to:\n \n ------------\n-[attr]binary -diff -crlf\n+[attr]binary -diff -text\n ------------\n \n \ndiff --git a/attr.c b/attr.c\nindex f5346ed..bf00469 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -287,7 +287,7 @@ static void free_attr_elem(struct attr_stack *e)\n }\n \n static const char *builtin_attr[] = {\n-\t\"[attr]binary -diff -crlf\",\n+\t\"[attr]binary -diff -text\",\n \tNULL,\n };\n \ndiff --git a/convert.c b/convert.c\nindex 98bc029..a309e07 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -440,12 +440,14 @@ static int read_convert_config(const char *var, const char *value, void *cb)\n \n static void setup_convert_check(struct git_attr_check *check)\n {\n+\tstatic struct git_attr *attr_text;\n \tstatic struct git_attr *attr_crlf;\n \tstatic struct git_attr *attr_eol;\n \tstatic struct git_attr *attr_ident;\n \tstatic struct git_attr *attr_filter;\n \n-\tif (!attr_crlf) {\n+\tif (!attr_text) {\n+\t\tattr_text = git_attr(\"text\");\n \t\tattr_crlf = git_attr(\"crlf\");\n \t\tattr_eol = git_attr(\"eol\");\n \t\tattr_ident = git_attr(\"ident\");\n@@ -457,6 +459,7 @@ static void setup_convert_check(struct git_attr_check *check)\n \tcheck[1].attr = attr_ident;\n \tcheck[2].attr = attr_filter;\n \tcheck[3].attr = attr_eol;\n+\tcheck[4].attr = attr_text;\n }\n \n static int count_ident(const char *cp, unsigned long size)\n@@ -652,20 +655,20 @@ static int git_path_check_ident(const char *path, struct git_attr_check *check)\n \treturn !!ATTR_TRUE(value);\n }\n \n-enum action determine_action(enum action crlf_attr, enum eol eol_attr) {\n-\tif (crlf_attr == CRLF_BINARY)\n+enum action determine_action(enum action text_attr, enum eol eol_attr) {\n+\tif (text_attr == CRLF_BINARY)\n \t\treturn CRLF_BINARY;\n \tif (eol_attr == EOL_LF)\n \t\treturn CRLF_INPUT;\n \tif (eol_attr == EOL_CRLF)\n \t\treturn CRLF_CRLF;\n-\treturn crlf_attr;\n+\treturn text_attr;\n }\n \n int convert_to_git(const char *path, const char *src, size_t len,\n                    struct strbuf *dst, enum safe_crlf checksafe)\n {\n-\tstruct git_attr_check check[4];\n+\tstruct git_attr_check check[5];\n \tenum action action = CRLF_GUESS;\n \tenum eol eol = EOL_UNSET;\n \tint ident = 0, ret = 0;\n@@ -674,7 +677,9 @@ int convert_to_git(const char *path, const char *src, size_t len,\n \tsetup_convert_check(check);\n \tif (!git_checkattr(path, ARRAY_SIZE(check), check)) {\n \t\tstruct convert_driver *drv;\n-\t\taction = git_path_check_crlf(path, check + 0);\n+\t\taction = git_path_check_crlf(path, check + 4);\n+\t\tif (action == CRLF_GUESS)\n+\t\t\taction = git_path_check_crlf(path, check + 0);\n \t\tident = git_path_check_ident(path, check + 1);\n \t\tdrv = git_path_check_convert(path, check + 2);\n \t\teol = git_path_check_eol(path, check + 3);\n@@ -698,7 +703,7 @@ int convert_to_git(const char *path, const char *src, size_t len,\n \n int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst)\n {\n-\tstruct git_attr_check check[4];\n+\tstruct git_attr_check check[5];\n \tenum action action = CRLF_GUESS;\n \tenum eol eol = EOL_UNSET;\n \tint ident = 0, ret = 0;\n@@ -707,7 +712,9 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, struc\n \tsetup_convert_check(check);\n \tif (!git_checkattr(path, ARRAY_SIZE(check), check)) {\n \t\tstruct convert_driver *drv;\n-\t\taction = git_path_check_crlf(path, check + 0);\n+\t\taction = git_path_check_crlf(path, check + 4);\n+\t\tif (action == CRLF_GUESS)\n+\t\t\taction = git_path_check_crlf(path, check + 0);\n \t\tident = git_path_check_ident(path, check + 1);\n \t\tdrv = git_path_check_convert(path, check + 2);\n \t\teol = git_path_check_eol(path, check + 3);\ndiff --git a/git-cvsserver.perl b/git-cvsserver.perl\nindex 13751db..4e55041 100755\n--- a/git-cvsserver.perl\n+++ b/git-cvsserver.perl\n@@ -2369,15 +2369,20 @@ sub kopts_from_path\n     if ( defined ( $cfg->{gitcvs}{usecrlfattr} ) and\n          $cfg->{gitcvs}{usecrlfattr} =~ /\\s*(1|true|yes)\\s*$/i )\n     {\n-        my ($val) = check_attr( \"crlf\", $path );\n-        if ( $val eq \"set\" )\n+        my ($val) = check_attr( \"text\", $path );\n+        if ( $val eq \"unspecified\" )\n         {\n-            return \"\";\n+            $val = check_attr( \"crlf\", $path );\n         }\n-        elsif ( $val eq \"unset\" )\n+        if ( $val eq \"unset\" )\n         {\n             return \"-kb\"\n         }\n+        elsif ( check_attr( \"eol\", $path ) ne \"unspecified\" ||\n+                $val eq \"set\" || $val eq \"input\" )\n+        {\n+            return \"\";\n+        }\n         else\n         {\n             $log->info(\"Unrecognized check_attr crlf $path : $val\");\ndiff --git a/t/t0025-crlf-auto.sh b/t/t0025-crlf-auto.sh\nindex 44cb593..8b1a128 100755\n--- a/t/t0025-crlf-auto.sh\n+++ b/t/t0025-crlf-auto.sh\n@@ -44,6 +44,7 @@ test_expect_success 'default settings cause no changes' '\n \n test_expect_success 'crlf=true causes a CRLF file to be normalized' '\n \n+\t# Backwards compatibility check\n \trm -f .gitattributes tmp one two &&\n \techo \"two crlf\" > .gitattributes &&\n \tgit read-tree --reset -u HEAD &&\n@@ -54,6 +55,18 @@ test_expect_success 'crlf=true causes a CRLF file to be normalized' '\n \ttest -n \"$twodiff\"\n '\n \n+test_expect_success 'text=true causes a CRLF file to be normalized' '\n+\n+\trm -f .gitattributes tmp one two &&\n+\techo \"two text\" > .gitattributes &&\n+\tgit read-tree --reset -u HEAD &&\n+\n+\t# Note, \"normalized\" means that git will normalize it if added\n+\thas_cr two &&\n+\ttwodiff=`git diff two` &&\n+\ttest -n \"$twodiff\"\n+'\n+\n test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=false' '\n \n \trm -f .gitattributes tmp one two &&\n@@ -103,11 +116,11 @@ test_expect_success 'autocrlf=true does not normalize CRLF files' '\n \ttest -z \"$onediff\" -a -z \"$twodiff\"\n '\n \n-test_expect_success 'crlf=auto, autocrlf=true _does_ normalize CRLF files' '\n+test_expect_success 'text=auto, autocrlf=true _does_ normalize CRLF files' '\n \n \trm -f .gitattributes tmp one two &&\n \tgit config core.autocrlf true &&\n-\techo \"* crlf=auto\" > .gitattributes &&\n+\techo \"* text=auto\" > .gitattributes &&\n \tgit read-tree --reset -u HEAD &&\n \n \thas_cr one &&\n@@ -117,11 +130,11 @@ test_expect_success 'crlf=auto, autocrlf=true _does_ normalize CRLF files' '\n \ttest -z \"$onediff\" -a -n \"$twodiff\"\n '\n \n-test_expect_success 'crlf=auto, autocrlf=true does not normalize binary files' '\n+test_expect_success 'text=auto, autocrlf=true does not normalize binary files' '\n \n \trm -f .gitattributes tmp one two three &&\n \tgit config core.autocrlf true &&\n-\techo \"* crlf=auto\" > .gitattributes &&\n+\techo \"* text=auto\" > .gitattributes &&\n \tgit read-tree --reset -u HEAD &&\n \n \t! has_cr three &&\n-- \n1.7.1.5.gd739a\n"}]}