{"thread":{"id":"23845","subject":"[PATCH v5 0/4] EOL conversion series, take 5","startedAt":"2010-05-19T20:43:08Z","lastAt":"2010-05-19T20:43:12Z","messageCount":5,"participants":["Eyvind Bernhardsen"],"isPatch":true,"patchVersion":5,"patchTotal":4},"messages":[{"id":"141920","messageId":"cover.1274301351.git.eyvind.bernhardsen@gmail.com","threadId":"23845","inReplyTo":null,"subject":"[PATCH v5 0/4] EOL conversion series, take 5","fromName":"Eyvind Bernhardsen","fromEmail":"eyvind.bernhardsen@gmail.com","sentAt":"2010-05-19T20:43:08Z","receivedAt":"2010-05-19T20:43:08Z","isPatch":true,"sender":{"key":"eyvind.bernhardsen@gmail.com","avatar":"https://avatars.githubusercontent.com/u/106762?v=4"},"body":"This is a resend of the latest crlf fix/rename series, including the\nfinal \"add core.eol\" config variable patch and some minor fixes to the\ntests.  I didn't include Finn Arne's \"safe autocrlf\" patch this time,\nbut it is still required.\n-- \nEyvind\n\n\nEyvind Bernhardsen (4):\n  Add tests for per-repository eol normalization\n  Add per-repository eol normalization\n  Rename the \"crlf\" attribute \"text\"\n  Add \"core.eol\" config variable\n\n Documentation/config.txt        |   28 +++++--\n Documentation/git-cvsserver.txt |   13 +--\n Documentation/gitattributes.txt |  167 +++++++++++++++++++++++++++++++--------\n Makefile                        |    3 +\n attr.c                          |    2 +-\n cache.h                         |   22 +++++-\n config.c                        |   18 ++++-\n convert.c                       |  148 ++++++++++++++++++++++++++---------\n environment.c                   |    3 +-\n git-cvsserver.perl              |   13 ++-\n t/t0025-crlf-auto.sh            |  155 ++++++++++++++++++++++++++++++++++++\n t/t0026-eol-config.sh           |   83 +++++++++++++++++++\n 12 files changed, 562 insertions(+), 93 deletions(-)\n create mode 100755 t/t0025-crlf-auto.sh\n create mode 100755 t/t0026-eol-config.sh\n"},{"id":"141922","messageId":"5d98ce018581830f7ae14a3abfe96800487b803e.1274301351.git.eyvind.bernhardsen@gmail.com","threadId":"23845","inReplyTo":"cover.1274301351.git.eyvind.bernhardsen@gmail.com","subject":"[PATCH v5 1/4] Add tests for per-repository eol normalization","fromName":"Eyvind Bernhardsen","fromEmail":"eyvind.bernhardsen@gmail.com","sentAt":"2010-05-19T20:43:09Z","receivedAt":"2010-05-19T20:43:09Z","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 |  142 ++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 142 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..2c98338\n--- /dev/null\n+++ b/t/t0025-crlf-auto.sh\n@@ -0,0 +1,142 @@\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+\tthree=`git rev-parse HEAD:three` &&\n+\n+\techo happy.\n+'\n+\n+test_expect_success 'default settings cause no changes' '\n+\n+\trm -f .gitattributes tmp one two three &&\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+\tthreediff=`git diff three` &&\n+\ttest -z \"$onediff\" -a -z \"$twodiff\" -a -z \"$threediff\"\n+'\n+\n+test_expect_failure 'crlf=true causes a CRLF file to be normalized' '\n+\n+\trm -f .gitattributes tmp one two three &&\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 three &&\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 three &&\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 three &&\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 three &&\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+\tthreediff=`git diff three` &&\n+\ttest -z \"$onediff\" -a -z \"$twodiff\" -a -z \"$threediff\"\n+'\n+\n+test_expect_failure 'crlf=auto, autocrlf=true _does_ normalize CRLF 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+\thas_cr one &&\n+\thas_cr two &&\n+\tonediff=`git diff one` &&\n+\ttwodiff=`git diff two` &&\n+\tthreediff=`git diff three` &&\n+\ttest -z \"$onediff\" -a -n \"$twodiff\" -a -z \"$threediff\"\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.gc3ee8\n"},{"id":"141921","messageId":"57d9db59805b4e1d0241e4cde4d514a4dd8a7829.1274301351.git.eyvind.bernhardsen@gmail.com","threadId":"23845","inReplyTo":"cover.1274301351.git.eyvind.bernhardsen@gmail.com","subject":"[PATCH v5 2/4] Add per-repository eol normalization","fromName":"Eyvind Bernhardsen","fromEmail":"eyvind.bernhardsen@gmail.com","sentAt":"2010-05-19T20:43:10Z","receivedAt":"2010-05-19T20:43:10Z","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 |  152 ++++++++++++++++++++++++++++++--------\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, 222 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..076f313 100644\n--- a/Documentation/gitattributes.txt\n+++ b/Documentation/gitattributes.txt\n@@ -95,50 +95,138 @@ 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+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+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+------------------------\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-If the configuration variable `core.autocrlf` is false, no\n-conversion is done.\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-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+-------------------------------------------------\n+$ echo \"* crlf=auto\" >>.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-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+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 2c98338..2781f15 100755\n--- a/t/t0025-crlf-auto.sh\n+++ b/t/t0025-crlf-auto.sh\n@@ -39,7 +39,7 @@ test_expect_success 'default settings cause no changes' '\n \ttest -z \"$onediff\" -a -z \"$twodiff\" -a -z \"$threediff\"\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 three &&\n \techo \"two crlf\" > .gitattributes &&\n@@ -51,7 +51,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 three &&\n \tgit config core.autocrlf false &&\n@@ -63,7 +63,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 three &&\n \tgit config core.autocrlf input &&\n@@ -75,7 +75,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 three &&\n \tgit config core.autocrlf true &&\n@@ -101,7 +101,7 @@ test_expect_success 'autocrlf=true does not normalize CRLF files' '\n \ttest -z \"$onediff\" -a -z \"$twodiff\" -a -z \"$threediff\"\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 three &&\n \tgit config core.autocrlf true &&\n@@ -128,7 +128,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.gc3ee8\n"},{"id":"141924","messageId":"4f6e9addf23d26c32d6d4ad8c1e68054e71932f3.1274301351.git.eyvind.bernhardsen@gmail.com","threadId":"23845","inReplyTo":"cover.1274301351.git.eyvind.bernhardsen@gmail.com","subject":"[PATCH v5 3/4] Rename the \"crlf\" attribute \"text\"","fromName":"Eyvind Bernhardsen","fromEmail":"eyvind.bernhardsen@gmail.com","sentAt":"2010-05-19T20:43:11Z","receivedAt":"2010-05-19T20:43:11Z","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 076f313..f091f08 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 $ 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@@ -215,17 +226,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@@ -311,11 +322,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@@ -719,7 +730,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@@ -732,7 +743,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@@ -743,7 +754,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 2781f15..f5f67a6 100755\n--- a/t/t0025-crlf-auto.sh\n+++ b/t/t0025-crlf-auto.sh\n@@ -41,6 +41,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 three &&\n \techo \"two crlf\" > .gitattributes &&\n \tgit read-tree --reset -u HEAD &&\n@@ -51,6 +52,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 three &&\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 three &&\n@@ -101,11 +114,11 @@ test_expect_success 'autocrlf=true does not normalize CRLF files' '\n \ttest -z \"$onediff\" -a -z \"$twodiff\" -a -z \"$threediff\"\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 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 \thas_cr one &&\n@@ -116,11 +129,11 @@ test_expect_success 'crlf=auto, autocrlf=true _does_ normalize CRLF files' '\n \ttest -z \"$onediff\" -a -n \"$twodiff\" -a -z \"$threediff\"\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.gc3ee8\n"},{"id":"141923","messageId":"828287a3eae726102cb6d0d7dbb74526180f9983.1274301351.git.eyvind.bernhardsen@gmail.com","threadId":"23845","inReplyTo":"cover.1274301351.git.eyvind.bernhardsen@gmail.com","subject":"[PATCH v5 4/4] Add \"core.eol\" config variable","fromName":"Eyvind Bernhardsen","fromEmail":"eyvind.bernhardsen@gmail.com","sentAt":"2010-05-19T20:43:12Z","receivedAt":"2010-05-19T20:43:12Z","isPatch":true,"sender":{"key":"eyvind.bernhardsen@gmail.com","avatar":"https://avatars.githubusercontent.com/u/106762?v=4"},"body":"Introduce a new configuration variable, \"core.eol\", that allows the user\nto set which line endings to use for end-of-line-normalized files in the\nworking directory.  It defaults to \"native\", which means CRLF on Windows\nand LF everywhere else.\n\nFor backwards compatibility, \"core.autocrlf\" will override core.eol if\ncore.eol is left unset.  This means that\n\n[core]\n\tautocrlf = true\n\nwill give CRLFs in the working directory even on platforms with LF as\ntheir native line ending.\n\nIf core.eol is set explicitly (including setting it to \"native\"), it\nwill override core.autocrlf so that\n\n[core]\n        autocrlf = true\n        eol = lf\n\nnormalizes all files that look like text, but does not put CRLFs in the\nworking directory.\n\nSigned-off-by: Eyvind Bernhardsen <eyvind.bernhardsen@gmail.com>\n---\n Documentation/config.txt        |    8 ++++\n Documentation/gitattributes.txt |    6 ++-\n Makefile                        |    3 +\n cache.h                         |   13 ++++++\n config.c                        |   16 +++++++\n convert.c                       |   56 +++++++++++++++++---------\n environment.c                   |    1 +\n t/t0026-eol-config.sh           |   83 +++++++++++++++++++++++++++++++++++++++\n 8 files changed, 166 insertions(+), 20 deletions(-)\n create mode 100755 t/t0026-eol-config.sh\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 207351b..7cc15a4 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -207,6 +207,14 @@ core.autocrlf::\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.eol::\n+\tSets the line ending type to use in the working directory for\n+\tfiles that have the `text` property set.  Alternatives are\n+\t'lf', 'crlf' and 'native', which uses the platform's native\n+\tline ending.  The default value is `native`.  See\n+\tlinkgit:gitattributes[5] for more information on end-of-line\n+\tconversion.\n+\n core.safecrlf::\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\ndiff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt\nindex f091f08..be1f160 100644\n--- a/Documentation/gitattributes.txt\n+++ b/Documentation/gitattributes.txt\n@@ -207,7 +207,11 @@ attribute to \"auto\" for _all_ files.\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+normalized (LF) line endings in the repository.  The `core.eol`\n+configuration variable controls which line endings git will use for\n+normalized files in your working directory; the default is to use the\n+native line ending for your platform, or CRLF if `core.autocrlf` is\n+set.\n \n NOTE: When `text=auto` normalization is enabled in an existing\n repository, any text files containing CRLFs should be normalized.  If\ndiff --git a/Makefile b/Makefile\nindex 910f471..419532e 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -224,6 +224,8 @@ all::\n #\n # Define CHECK_HEADER_DEPENDENCIES to check for problems in the hard-coded\n # dependency rules.\n+#\n+# Define NATIVE_CRLF if your platform uses CRLF for line endings.\n \n GIT-VERSION-FILE: FORCE\n \t@$(SHELL_PATH) ./GIT-VERSION-GEN\n@@ -989,6 +991,7 @@ ifeq ($(uname_S),Windows)\n \tNO_CURL = YesPlease\n \tNO_PYTHON = YesPlease\n \tBLK_SHA1 = YesPlease\n+\tNATIVE_CRLF = YesPlease\n \n \tCC = compat/vcbuild/scripts/clink.pl\n \tAR = compat/vcbuild/scripts/lib.pl\ndiff --git a/cache.h b/cache.h\nindex d1f669e..ac6bfbd 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -568,6 +568,19 @@ enum auto_crlf {\n \n extern enum auto_crlf auto_crlf;\n \n+enum eol {\n+\tEOL_UNSET,\n+\tEOL_CRLF,\n+\tEOL_LF,\n+#ifdef NATIVE_CRLF\n+\tEOL_NATIVE = EOL_CRLF\n+#else\n+\tEOL_NATIVE = EOL_LF\n+#endif\n+};\n+\n+extern enum eol eol;\n+\n enum branch_track {\n \tBRANCH_TRACK_UNSPECIFIED = -1,\n \tBRANCH_TRACK_NEVER = 0,\ndiff --git a/config.c b/config.c\nindex b60a1ff..1479ee6 100644\n--- a/config.c\n+++ b/config.c\n@@ -461,6 +461,8 @@ 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\tif (eol == EOL_CRLF)\n+\t\t\t\treturn error(\"core.autocrlf=input conflicts with core.eol=crlf\");\n \t\t\tauto_crlf = AUTO_CRLF_INPUT;\n \t\t\treturn 0;\n \t\t}\n@@ -477,6 +479,20 @@ static int git_default_core_config(const char *var, const char *value)\n \t\treturn 0;\n \t}\n \n+\tif (!strcmp(var, \"core.eol\")) {\n+\t\tif (value && !strcasecmp(value, \"lf\"))\n+\t\t\teol = EOL_LF;\n+\t\telse if (value && !strcasecmp(value, \"crlf\"))\n+\t\t\teol = EOL_CRLF;\n+\t\telse if (value && !strcasecmp(value, \"native\"))\n+\t\t\teol = EOL_NATIVE;\n+\t\telse\n+\t\t\teol = EOL_UNSET;\n+\t\tif (eol == EOL_CRLF && auto_crlf == AUTO_CRLF_INPUT)\n+\t\t\treturn error(\"core.autocrlf=input conflicts with core.eol=crlf\");\n+\t\treturn 0;\n+\t}\n+\n \tif (!strcmp(var, \"core.notesref\")) {\n \t\tnotes_ref_name = xstrdup(value);\n \t\treturn 0;\ndiff --git a/convert.c b/convert.c\nindex a309e07..9f4ee81 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -20,12 +20,6 @@ enum action {\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 \tunsigned nul, cr, lf, crlf;\n@@ -99,14 +93,40 @@ static int is_binary(unsigned long size, struct text_stat *stats)\n \treturn 0;\n }\n \n+static enum eol get_output_conversion(enum action action) {\n+\tswitch (action) {\n+\tcase CRLF_BINARY:\n+\t\treturn EOL_UNSET;\n+\tcase CRLF_CRLF:\n+\t\treturn EOL_CRLF;\n+\tcase CRLF_INPUT:\n+\t\treturn EOL_LF;\n+\tcase CRLF_GUESS:\n+\t\tif (auto_crlf == AUTO_CRLF_FALSE)\n+\t\t\treturn EOL_UNSET;\n+\t\t/* fall through */\n+\tcase CRLF_TEXT:\n+\tcase CRLF_AUTO:\n+\t\tif (eol == EOL_UNSET) {\n+\t\t\tif (auto_crlf == AUTO_CRLF_FALSE)\n+\t\t\t\treturn EOL_NATIVE;\n+\t\t\telse if (auto_crlf == AUTO_CRLF_TRUE)\n+\t\t\t\treturn EOL_CRLF;\n+\t\t\telse\n+\t\t\t\treturn EOL_LF;\n+\t\t} else {\n+\t\t\treturn eol;\n+\t\t}\n+\t}\n+}\n+\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 ||\n-\t    (action == CRLF_GUESS && auto_crlf == AUTO_CRLF_INPUT)) {\n+\tif (get_output_conversion(action) == EOL_LF) {\n \t\t/*\n \t\t * CRLFs would not be restored by checkout:\n \t\t * check if we'd remove CRLFs\n@@ -117,8 +137,7 @@ static void check_safe_crlf(const char *path, enum action 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 (action == CRLF_CRLF ||\n-\t\t   (action == CRLF_GUESS && auto_crlf == AUTO_CRLF_TRUE)) {\n+\t} else if (get_output_conversion(action) == EOL_CRLF) {\n \t\t/*\n \t\t * CRLFs would be added by checkout:\n \t\t * check if we have \"naked\" LFs\n@@ -244,11 +263,10 @@ static int crlf_to_worktree(const char *path, const char *src, size_t len,\n \tchar *to_free = NULL;\n \tstruct text_stat stats;\n \n-\tif ((action == CRLF_BINARY) || (action == CRLF_INPUT) ||\n-\t    (action != CRLF_CRLF && auto_crlf != AUTO_CRLF_TRUE))\n+\tif (!len)\n \t\treturn 0;\n \n-\tif (!len)\n+\tif (get_output_conversion(action) != EOL_CRLF)\n \t\treturn 0;\n \n \tgather_stats(src, len, &stats);\n@@ -670,7 +688,7 @@ int convert_to_git(const char *path, const char *src, size_t len,\n {\n \tstruct git_attr_check check[5];\n \tenum action action = CRLF_GUESS;\n-\tenum eol eol = EOL_UNSET;\n+\tenum eol eol_attr = EOL_UNSET;\n \tint ident = 0, ret = 0;\n \tconst char *filter = NULL;\n \n@@ -682,7 +700,7 @@ int convert_to_git(const char *path, const char *src, size_t len,\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+\t\teol_attr = git_path_check_eol(path, check + 3);\n \t\tif (drv && drv->clean)\n \t\t\tfilter = drv->clean;\n \t}\n@@ -692,7 +710,7 @@ 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-\taction = determine_action(action, eol);\n+\taction = determine_action(action, eol_attr);\n \tret |= crlf_to_git(path, src, len, dst, action, checksafe);\n \tif (ret) {\n \t\tsrc = dst->buf;\n@@ -705,7 +723,7 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, struc\n {\n \tstruct git_attr_check check[5];\n \tenum action action = CRLF_GUESS;\n-\tenum eol eol = EOL_UNSET;\n+\tenum eol eol_attr = EOL_UNSET;\n \tint ident = 0, ret = 0;\n \tconst char *filter = NULL;\n \n@@ -717,7 +735,7 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, struc\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+\t\teol_attr = git_path_check_eol(path, check + 3);\n \t\tif (drv && drv->smudge)\n \t\t\tfilter = drv->smudge;\n \t}\n@@ -727,7 +745,7 @@ 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-\taction = determine_action(action, eol);\n+\taction = determine_action(action, eol_attr);\n \tret |= crlf_to_worktree(path, src, len, dst, action);\n \tif (ret) {\n \t\tsrc = dst->buf;\ndiff --git a/environment.c b/environment.c\nindex db4a5e9..83d38d3 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -40,6 +40,7 @@ const char *editor_program;\n const char *excludes_file;\n enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;\n int read_replace_refs = 1;\n+enum eol eol = EOL_UNSET;\n enum safe_crlf safe_crlf = SAFE_CRLF_WARN;\n unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;\n enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;\ndiff --git a/t/t0026-eol-config.sh b/t/t0026-eol-config.sh\nnew file mode 100755\nindex 0000000..5b6c297\n--- /dev/null\n+++ b/t/t0026-eol-config.sh\n@@ -0,0 +1,83 @@\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+\techo \"one text\" > .gitattributes\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; done >two &&\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+\techo happy.\n+'\n+\n+test_expect_success 'eol=lf puts LFs in normalized file' '\n+\n+\trm -f .gitattributes tmp one two &&\n+\tgit config core.eol lf &&\n+\tgit read-tree --reset -u HEAD &&\n+\n+\t! has_cr one &&\n+\t! has_cr two &&\n+\tonediff=`git diff one` &&\n+\ttwodiff=`git diff two` &&\n+\ttest -z \"$onediff\" -a -z \"$twodiff\"\n+'\n+\n+test_expect_success 'eol=crlf puts CRLFs in normalized file' '\n+\n+\trm -f .gitattributes tmp one two &&\n+\tgit config core.eol crlf &&\n+\tgit read-tree --reset -u HEAD &&\n+\n+\thas_cr one &&\n+\t! has_cr two &&\n+\tonediff=`git diff one` &&\n+\ttwodiff=`git diff two` &&\n+\ttest -z \"$onediff\" -a -z \"$twodiff\"\n+'\n+\n+test_expect_success 'eol=lf overrides autocrlf=true' '\n+\n+\trm -f .gitattributes tmp one two &&\n+\tgit config core.eol lf &&\n+\tgit config core.autocrlf true &&\n+\tgit read-tree --reset -u HEAD &&\n+\n+\t! has_cr one &&\n+\t! has_cr two &&\n+\tonediff=`git diff one` &&\n+\ttwodiff=`git diff two` &&\n+\ttest -z \"$onediff\" -a -z \"$twodiff\"\n+'\n+\n+test_expect_success 'autocrlf=true overrides unset eol' '\n+\n+\trm -f .gitattributes tmp one two &&\n+\tgit config --unset-all core.eol &&\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_done\n-- \n1.7.1.5.gc3ee8\n"}]}