{"thread":{"id":"7640","subject":"[PATCH 2/3] Define 'crlf' attribute.","startedAt":"2007-04-13T09:01:36Z","lastAt":"2007-04-15T15:54:13Z","messageCount":2,"participants":["Junio C Hamano","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"39277","messageId":"7vps68d4wf.fsf@assigned-by-dhcp.cox.net","threadId":"7640","inReplyTo":null,"subject":"[PATCH 2/3] Define 'crlf' attribute.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-04-13T09:01:36Z","receivedAt":"2007-04-13T09:01:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This defines the semantics of 'crlf' attribute as an example.\nWhen a path has this attribute unset (i.e. '!crlf'), autocrlf\nline-end conversion is not applied.\n\nEventually we would want to let users to build a pipeline of\nprocessing to munge blob data to filesystem format (and in the\nother direction) based on combination of attributes, and at that\npoint the mechanism in convert_to_{git,working_tree}() that\nlooks at 'crlf' attribute needs to be enhanced.  Perhaps the\nexisting 'crlf' would become the first step in the input chain,\nand the last step in the output chain.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n attr.c          |   18 ++++++++++++++++++\n convert.c       |   49 ++++++++++++++++++++++++++++++++++++++++++-------\n t/t0020-crlf.sh |   24 ++++++++++++++++++++++++\n 3 files changed, 84 insertions(+), 7 deletions(-)\n\ndiff --git a/attr.c b/attr.c\nindex bdbc4a3..d35ae9e 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -299,3 +299,21 @@ int git_checkattr(const char *path, int num, struct git_attr_check *check)\n \t\trem = fill(path, pathlen, stk, check, num, rem);\n \treturn 0;\n }\n+\n+static void setup_binary_check(struct git_attr_check *check)\n+{\n+\tstatic struct git_attr *attr_binary;\n+\n+\tif (!attr_binary)\n+\t\tattr_binary = git_attr(\"binary\", 6);\n+\tcheck->attr = attr_binary;\n+}\n+\n+int git_path_is_binary(const char *path)\n+{\n+\tstruct git_attr_check attr_binary_check;\n+\n+\tsetup_binary_check(&attr_binary_check);\n+\treturn (!git_checkattr(path, 1, &attr_binary_check) &&\n+\t\t(0 < attr_binary_check.isset));\n+}\ndiff --git a/convert.c b/convert.c\nindex 898bfe3..20c744a 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -1,4 +1,6 @@\n #include \"cache.h\"\n+#include \"attr.h\"\n+\n /*\n  * convert.c - convert a file when checking it out and checking it in.\n  *\n@@ -72,17 +74,12 @@ static int is_binary(unsigned long size, struct text_stat *stats)\n \treturn 0;\n }\n \n-int convert_to_git(const char *path, char **bufp, unsigned long *sizep)\n+static int autocrlf_to_git(const char *path, char **bufp, unsigned long *sizep)\n {\n \tchar *buffer, *nbuf;\n \tunsigned long size, nsize;\n \tstruct text_stat stats;\n \n-\t/*\n-\t * FIXME! Other pluggable conversions should go here,\n-\t * based on filename patterns. Right now we just do the\n-\t * stupid auto-CRLF one.\n-\t */\n \tif (!auto_crlf)\n \t\treturn 0;\n \n@@ -128,7 +125,7 @@ int convert_to_git(const char *path, char **bufp, unsigned long *sizep)\n \treturn 1;\n }\n \n-int convert_to_working_tree(const char *path, char **bufp, unsigned long *sizep)\n+static int autocrlf_to_working_tree(const char *path, char **bufp, unsigned long *sizep)\n {\n \tchar *buffer, *nbuf;\n \tunsigned long size, nsize;\n@@ -184,3 +181,41 @@ int convert_to_working_tree(const char *path, char **bufp, unsigned long *sizep)\n \n \treturn 1;\n }\n+\n+static void setup_crlf_check(struct git_attr_check *check)\n+{\n+\tstatic struct git_attr *attr_crlf;\n+\n+\tif (!attr_crlf)\n+\t\tattr_crlf = git_attr(\"crlf\", 4);\n+\tcheck->attr = attr_crlf;\n+}\n+\n+static int git_path_is_binary(const char *path)\n+{\n+\tstruct git_attr_check attr_crlf_check;\n+\n+\tsetup_crlf_check(&attr_crlf_check);\n+\n+\t/*\n+\t * If crlf is not mentioned, default to autocrlf;\n+\t * disable autocrlf only when crlf attribute is explicitly\n+\t * unset.\n+\t */\n+\treturn (!git_checkattr(path, 1, &attr_crlf_check) &&\n+\t\t(0 == attr_crlf_check.isset));\n+}\n+\n+int convert_to_git(const char *path, char **bufp, unsigned long *sizep)\n+{\n+\tif (git_path_is_binary(path))\n+\t\treturn 0;\n+\treturn autocrlf_to_git(path, bufp, sizep);\n+}\n+\n+int convert_to_working_tree(const char *path, char **bufp, unsigned long *sizep)\n+{\n+\tif (git_path_is_binary(path))\n+\t\treturn 0;\n+\treturn autocrlf_to_working_tree(path, bufp, sizep);\n+}\ndiff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh\nindex 723b29a..600dcd3 100755\n--- a/t/t0020-crlf.sh\n+++ b/t/t0020-crlf.sh\n@@ -214,4 +214,28 @@ test_expect_success 'apply patch --index (autocrlf=true)' '\n \t}\n '\n \n+test_expect_success '.gitattributes says two is binary' '\n+\n+\techo \"two !crlf\" >.gitattributes &&\n+\trm -f tmp one dir/two &&\n+\tgit repo-config core.autocrlf true &&\n+\tgit read-tree --reset -u HEAD &&\n+\n+\tif remove_cr dir/two >/dev/null\n+\tthen\n+\t\techo \"Huh?\"\n+\t\tfalse\n+\telse\n+\t\t: happy\n+\tfi &&\n+\n+\tif remove_cr one >/dev/null\n+\tthen\n+\t\t: happy\n+\telse\n+\t\techo \"Huh?\"\n+\t\tfalse\n+\tfi\n+'\n+\n test_done\n-- \n1.5.1.1.784.g95e2\n"},{"id":"39374","messageId":"Pine.LNX.4.64.0704151141090.18846@racer.site","threadId":"7640","inReplyTo":"7vps68d4wf.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 2/3] Define 'crlf' attribute.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-04-15T15:54:13Z","receivedAt":"2007-04-15T15:54:13Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 13 Apr 2007, Junio C Hamano wrote:\n\n> diff --git a/attr.c b/attr.c\n> index bdbc4a3..d35ae9e 100644\n> --- a/attr.c\n> +++ b/attr.c\n> [...]\n> +\n> +int git_path_is_binary(const char *path)\n> +{\n> +\tstruct git_attr_check attr_binary_check;\n> +\n> +\tsetup_binary_check(&attr_binary_check);\n> +\treturn (!git_checkattr(path, 1, &attr_binary_check) &&\n> +\t\t(0 < attr_binary_check.isset));\n> +}\n\nThis function is not declared in a header file, and ...\n\n> diff --git a/convert.c b/convert.c\n> index 898bfe3..20c744a 100644\n> --- a/convert.c\n> +++ b/convert.c\n> [...]\n> +\n> +static int git_path_is_binary(const char *path)\n> +{\n> +\tstruct git_attr_check attr_crlf_check;\n> +\n> +\tsetup_crlf_check(&attr_crlf_check);\n> +\n> +\t/*\n> +\t * If crlf is not mentioned, default to autocrlf;\n> +\t * disable autocrlf only when crlf attribute is explicitly\n> +\t * unset.\n> +\t */\n> +\treturn (!git_checkattr(path, 1, &attr_crlf_check) &&\n> +\t\t(0 == attr_crlf_check.isset));\n> +}\n\n... here you have a function of the _same_ name, which does something \nsubtly different: it checks for \"crlf\" instead of \"binary\".\n\nPerhaps you wanted the change to attr.c at a later stage, and the function \nin convert.c should be renamed to \"path_wants_crlf()\"?\n\n[Reading 3/3 revealed that indeed, the 18 lines in attr.c were unwanted.]\n\nCiao,\nDscho\n"}]}