{"thread":{"id":"35830","subject":"[PATCH 0/2] Ignore trailing spaces in .gitignore","startedAt":"2014-02-08T08:10:02Z","lastAt":"2014-02-10T05:04:13Z","messageCount":13,"participants":["Nguyễn Thái Ngọc Duy","Torsten Bögershausen","Jeff King","Duy Nguyen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"234495","messageId":"1391847004-22810-1-git-send-email-pclouds@gmail.com","threadId":"35830","inReplyTo":null,"subject":"[PATCH 0/2] Ignore trailing spaces in .gitignore","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-02-08T08:10:02Z","receivedAt":"2014-02-08T08:10:02Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Trailing spaces are invisible in most standard editors (*). \"git diff\"\ndoes show trailing spaces by default. But that does not help newly\nwritten .gitignore files. And trailing spaces are the source of\nfrustration when writing .gitignore.\n\nSo let's ignore them. Nobody sane would put a trailing space in file\nnames. But we could be careful and do it in two steps: warn first,\nthen ignore trailing spaces. Another option is merge two patches in\none and be done with it.\n\nPeople can still quote trailing spaces, which will not be ignored (and\nmuch more visible). Quoting comes with a cost of doing fnmatch(). But\nI won't optimize it until I see someone shows me they have a use case\nfor it.\n\n(*) either that or my coworkers keep pissing me off on purpose when\n    they never clean trailing spaces.\n\nNguyễn Thái Ngọc Duy (2):\n  dir: warn about trailing spaces in exclude pattern\n  dir: ignore trailing spaces in exclude patterns\n\n Documentation/gitignore.txt | 3 +++\n dir.c                       | 9 +++++++++\n 2 files changed, 12 insertions(+)\n\n-- \n1.8.5.2.240.g8478abd\n"},{"id":"234496","messageId":"1391847004-22810-2-git-send-email-pclouds@gmail.com","threadId":"35830","inReplyTo":"1391847004-22810-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 1/2] dir: warn about trailing spaces in exclude pattern","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-02-08T08:10:03Z","receivedAt":"2014-02-08T08:10:03Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n dir.c | 11 +++++++++++\n 1 file changed, 11 insertions(+)\n\ndiff --git a/dir.c b/dir.c\nindex b35b633..9edde44 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -491,6 +491,16 @@ void clear_exclude_list(struct exclude_list *el)\n \tel->filebuf = NULL;\n }\n \n+static void check_trailing_spaces(const char *fname, char *buf)\n+{\n+\tint len = strlen(buf);\n+\twhile (len && buf[len - 1] == ' ')\n+\t\tlen--;\n+\tif (buf[len] != '\\0')\n+\t\twarning(_(\"%s: trailing spaces in '%s'. Please quote them.\"),\n+\t\t\tfname, buf);\n+}\n+\n int add_excludes_from_file_to_list(const char *fname,\n \t\t\t\t   const char *base,\n \t\t\t\t   int baselen,\n@@ -542,6 +552,7 @@ int add_excludes_from_file_to_list(const char *fname,\n \t\tif (buf[i] == '\\n') {\n \t\t\tif (entry != buf + i && entry[0] != '#') {\n \t\t\t\tbuf[i - (i && buf[i-1] == '\\r')] = 0;\n+\t\t\t\tcheck_trailing_spaces(fname, entry);\n \t\t\t\tadd_exclude(entry, base, baselen, el, lineno);\n \t\t\t}\n \t\t\tlineno++;\n-- \n1.8.5.2.240.g8478abd\n"},{"id":"234497","messageId":"1391847004-22810-3-git-send-email-pclouds@gmail.com","threadId":"35830","inReplyTo":"1391847004-22810-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 2/2] dir: ignore trailing spaces in exclude patterns","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-02-08T08:10:04Z","receivedAt":"2014-02-08T08:10:04Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Documentation/gitignore.txt | 3 +++\n dir.c                       | 4 +---\n 2 files changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt\nindex b08d34d..8734c15 100644\n--- a/Documentation/gitignore.txt\n+++ b/Documentation/gitignore.txt\n@@ -77,6 +77,9 @@ PATTERN FORMAT\n    Put a backslash (\"`\\`\") in front of the first hash for patterns\n    that begin with a hash.\n \n+ - Trailing spaces are ignored unless they are quoted with backlash\n+   (\"`\\`\").\n+\n  - An optional prefix \"`!`\" which negates the pattern; any\n    matching file excluded by a previous pattern will become\n    included again. It is not possible to re-include a file if a parent\ndiff --git a/dir.c b/dir.c\nindex 9edde44..7dee5ca 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -496,9 +496,7 @@ static void check_trailing_spaces(const char *fname, char *buf)\n \tint len = strlen(buf);\n \twhile (len && buf[len - 1] == ' ')\n \t\tlen--;\n-\tif (buf[len] != '\\0')\n-\t\twarning(_(\"%s: trailing spaces in '%s'. Please quote them.\"),\n-\t\t\tfname, buf);\n+\tbuf[len] = '\\0';\n }\n \n int add_excludes_from_file_to_list(const char *fname,\n-- \n1.8.5.2.240.g8478abd\n"},{"id":"234507","messageId":"52F6404C.1080107@web.de","threadId":"35830","inReplyTo":"1391847004-22810-2-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 1/2] dir: warn about trailing spaces in exclude pattern","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2014-02-08T14:33:48Z","receivedAt":"2014-02-08T14:33:48Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On 2014-02-08 09.10, Nguyễn Thái Ngọc Duy wrote:\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  dir.c | 11 +++++++++++\n>  1 file changed, 11 insertions(+)\n> \n> diff --git a/dir.c b/dir.c\n> index b35b633..9edde44 100644\n> --- a/dir.c\n> +++ b/dir.c\n> @@ -491,6 +491,16 @@ void clear_exclude_list(struct exclude_list *el)\n>  \tel->filebuf = NULL;\n>  }\n>  \n> +static void check_trailing_spaces(const char *fname, char *buf)\n> +{\n> +\tint len = strlen(buf);\n> +\twhile (len && buf[len - 1] == ' ')\n> +\t\tlen--;\n> +\tif (buf[len] != '\\0')\nDo we need the while loop here, (when we only warn) ?\n\n> +\t\twarning(_(\"%s: trailing spaces in '%s'. Please quote them.\"),\n> +\t\t\tfname, buf);\n> +}\nThis is nice. However we can hint the user that there are 2 choices: \n\t\twarning(_(\"%s: trailing spaces in '%s'. Please remove them or quote them.\"),\n> +\n>  int add_excludes_from_file_to_list(const char *fname,\n>  \t\t\t\t   const char *base,\n>  \t\t\t\t   int baselen,\n> @@ -542,6 +552,7 @@ int add_excludes_from_file_to_list(const char *fname,\n>  \t\tif (buf[i] == '\\n') {\n>  \t\t\tif (entry != buf + i && entry[0] != '#') {\n>  \t\t\t\tbuf[i - (i && buf[i-1] == '\\r')] = 0;\n> +\t\t\t\tcheck_trailing_spaces(fname, entry);\n>  \t\t\t\tadd_exclude(entry, base, baselen, el, lineno);\n>  \t\t\t}\n>  \t\t\tlineno++;\n> \n"},{"id":"234509","messageId":"20140208164548.GA24600@sigill.intra.peff.net","threadId":"35830","inReplyTo":"1391847004-22810-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 0/2] Ignore trailing spaces in .gitignore","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-02-08T16:45:49Z","receivedAt":"2014-02-08T16:45:49Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Feb 08, 2014 at 03:10:02PM +0700, Nguyễn Thái Ngọc Duy wrote:\n\n> Trailing spaces are invisible in most standard editors (*). \"git diff\"\n> does show trailing spaces by default. But that does not help newly\n> written .gitignore files. And trailing spaces are the source of\n> frustration when writing .gitignore.\n\nI guess leading spaces are not as frustrating, but I wonder if it would\nbe more consistent to say that we soak up all whitespace. That is also a\nregression, but I agree that these are exceptional cases, and as long as\nwe provide an \"out\" for people to cover them via quoting, ignoring the\nwhitespace seems like a sane default.\n\n> People can still quote trailing spaces, which will not be ignored (and\n> much more visible). Quoting comes with a cost of doing fnmatch(). But\n> I won't optimize it until I see someone shows me they have a use case\n> for it.\n\nI naively expected that:\n\n  echo 'trailing\\ \\ ' >.gitignore\n\nwould count as quoting, but your patch doesn't handle that. It _does_\nseem to work currently (that is, the backslashes go away and we treat it\nliterally), but I am not sure if that is planned, or simply happens to\nwork.\n\nI guess by quoting you meant:\n\n  echo '\"trailing  \"' >.gitignore\n\nAnyway, here are some tests I wrote up while playing with this. They do\nnot pass with your current patch for the reasons above, but maybe they\nwill be useful to squash in (either after tweaking the tests, or\ntweaking the patch).\n\ndiff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh\nindex b4d98e6..4dde314 100755\n--- a/t/t0008-ignores.sh\n+++ b/t/t0008-ignores.sh\n@@ -775,4 +775,33 @@ test_expect_success PIPE 'streaming support for --stdin' '\n \techo \"$response\" | grep \"^::\ttwo\"\n '\n \n+############################################################################\n+#\n+# test whitespace handling\n+\n+test_expect_success 'leading/trailing whitespace is ignored' '\n+\tmkdir whitespace &&\n+\t>whitespace/leading &&\n+\t>whitespace/trailing &&\n+\t>whitespace/untracked &&\n+\t{\n+\t\techo \"    whitespace/leading\" &&\n+\t\techo \"whitespace/trailing   \"\n+\t} >ignore &&\n+\techo whitespace/untracked >expect &&\n+\tgit ls-files -o -X ignore whitespace >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'quoting allows trailing whitespace' '\n+\trm -rf whitespace &&\n+\tmkdir whitespace &&\n+\t>\"whitespace/trailing  \" &&\n+\t>whitespace/untracked &&\n+\techo \"whitespace/trailing\\\\ \\\\ \" >ignore &&\n+\techo whitespace/untracked >expect &&\n+\tgit ls-files -o -X ignore whitespace >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n"},{"id":"234535","messageId":"CACsJy8C_Lc+mcJxGc7S5AB47YKDrhmWPwZp2oxJ9Z1tONVT0kQ@mail.gmail.com","threadId":"35830","inReplyTo":"20140208164548.GA24600@sigill.intra.peff.net","subject":"Re: [PATCH 0/2] Ignore trailing spaces in .gitignore","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2014-02-08T23:48:18Z","receivedAt":"2014-02-08T23:48:18Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sat, Feb 8, 2014 at 11:45 PM, Jeff King <peff@peff.net> wrote:\n> On Sat, Feb 08, 2014 at 03:10:02PM +0700, Nguyễn Thái Ngọc Duy wrote:\n>\n>> Trailing spaces are invisible in most standard editors (*). \"git diff\"\n>> does show trailing spaces by default. But that does not help newly\n>> written .gitignore files. And trailing spaces are the source of\n>> frustration when writing .gitignore.\n>\n> I guess leading spaces are not as frustrating, but I wonder if it would\n> be more consistent to say that we soak up all whitespace. That is also a\n> regression, but I agree that these are exceptional cases, and as long as\n> we provide an \"out\" for people to cover them via quoting, ignoring the\n> whitespace seems like a sane default.\n\nHm...\n\n>\n>> People can still quote trailing spaces, which will not be ignored (and\n>> much more visible). Quoting comes with a cost of doing fnmatch(). But\n>> I won't optimize it until I see someone shows me they have a use case\n>> for it.\n>\n> I naively expected that:\n>\n>   echo 'trailing\\ \\ ' >.gitignore\n>\n> would count as quoting, but your patch doesn't handle that. It _does_\n> seem to work currently (that is, the backslashes go away and we treat it\n> literally), but I am not sure if that is planned, or simply happens to\n> work.\n\nNo that's what I had in mind. But yeah my patches are flawed.\n\n>\n> I guess by quoting you meant:\n>\n>   echo '\"trailing  \"' >.gitignore\n\nThis makes \" special. If we follow shell convention then things\nbetween \"..\" should be literal (e.g. \"*\" is no longer a wildcard). We\ndon't support it yet. So I rather go with backslash as it adds less\ncode.\n\n>\n> Anyway, here are some tests I wrote up while playing with this. They do\n> not pass with your current patch for the reasons above, but maybe they\n> will be useful to squash in (either after tweaking the tests, or\n> tweaking the patch).\n>\n> diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh\n> index b4d98e6..4dde314 100755\n> --- a/t/t0008-ignores.sh\n> +++ b/t/t0008-ignores.sh\n> @@ -775,4 +775,33 @@ test_expect_success PIPE 'streaming support for --stdin' '\n>         echo \"$response\" | grep \"^::    two\"\n>  '\n>\n> +############################################################################\n> +#\n> +# test whitespace handling\n> +\n> +test_expect_success 'leading/trailing whitespace is ignored' '\n> +       mkdir whitespace &&\n> +       >whitespace/leading &&\n> +       >whitespace/trailing &&\n> +       >whitespace/untracked &&\n> +       {\n> +               echo \"    whitespace/leading\" &&\n> +               echo \"whitespace/trailing   \"\n> +       } >ignore &&\n> +       echo whitespace/untracked >expect &&\n> +       git ls-files -o -X ignore whitespace >actual &&\n> +       test_cmp expect actual\n> +'\n> +\n> +test_expect_success 'quoting allows trailing whitespace' '\n> +       rm -rf whitespace &&\n> +       mkdir whitespace &&\n> +       >\"whitespace/trailing  \" &&\n> +       >whitespace/untracked &&\n> +       echo \"whitespace/trailing\\\\ \\\\ \" >ignore &&\n> +       echo whitespace/untracked >expect &&\n> +       git ls-files -o -X ignore whitespace >actual &&\n> +       test_cmp expect actual\n> +'\n> +\n>  test_done\n\n\n\n-- \nDuy\n"},{"id":"234536","messageId":"1391905598-19198-1-git-send-email-pclouds@gmail.com","threadId":"35830","inReplyTo":"1391847004-22810-1-git-send-email-pclouds@gmail.com","subject":"[PATCH v2 0/2] Ignore trailing spaces in .gitignore","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-02-09T00:26:36Z","receivedAt":"2014-02-09T00:26:36Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This reroll now respects backslash quoting. Thanks Jeff and Torsten\nfor the comments.\n\nNguyễn Thái Ngọc Duy (2):\n  dir: warn about trailing spaces in exclude patterns\n  dir: ignore trailing spaces in exclude patterns\n\n Documentation/gitignore.txt |  3 +++\n dir.c                       | 20 ++++++++++++++++++++\n t/t0008-ignores.sh          | 31 +++++++++++++++++++++++++++++++\n 3 files changed, 54 insertions(+)\n\n-- \n1.8.5.2.240.g8478abd\n"},{"id":"234538","messageId":"1391905598-19198-2-git-send-email-pclouds@gmail.com","threadId":"35830","inReplyTo":"1391905598-19198-1-git-send-email-pclouds@gmail.com","subject":"[PATCH v2 1/2] dir: warn about trailing spaces in exclude patterns","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-02-09T00:26:37Z","receivedAt":"2014-02-09T00:26:37Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n dir.c              | 17 +++++++++++++++++\n t/t0008-ignores.sh | 31 +++++++++++++++++++++++++++++++\n 2 files changed, 48 insertions(+)\n\ndiff --git a/dir.c b/dir.c\nindex b35b633..6162209 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -491,6 +491,22 @@ void clear_exclude_list(struct exclude_list *el)\n \tel->filebuf = NULL;\n }\n \n+static void check_trailing_spaces(const char *fname, char *buf)\n+{\n+\tint i, last_space = -1, len = strlen(buf);\n+\tfor (i = 0; i < len; i++)\n+\t\tif (buf[i] == '\\\\')\n+\t\t\ti++;\n+\t\telse if (buf[i] == ' ')\n+\t\t\tlast_space = i;\n+\t\telse\n+\t\t\tlast_space = -1;\n+\n+\tif (last_space == len - 1)\n+\t\twarning(_(\"%s: trailing spaces in '%s'. Please quote or remove them.\"),\n+\t\t\tfname, buf);\n+}\n+\n int add_excludes_from_file_to_list(const char *fname,\n \t\t\t\t   const char *base,\n \t\t\t\t   int baselen,\n@@ -542,6 +558,7 @@ int add_excludes_from_file_to_list(const char *fname,\n \t\tif (buf[i] == '\\n') {\n \t\t\tif (entry != buf + i && entry[0] != '#') {\n \t\t\t\tbuf[i - (i && buf[i-1] == '\\r')] = 0;\n+\t\t\t\tcheck_trailing_spaces(fname, entry);\n \t\t\t\tadd_exclude(entry, base, baselen, el, lineno);\n \t\t\t}\n \t\t\tlineno++;\ndiff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh\nindex b4d98e6..9e1d64c 100755\n--- a/t/t0008-ignores.sh\n+++ b/t/t0008-ignores.sh\n@@ -775,4 +775,35 @@ test_expect_success PIPE 'streaming support for --stdin' '\n \techo \"$response\" | grep \"^::\ttwo\"\n '\n \n+############################################################################\n+#\n+# test whitespace handling\n+\n+test_expect_success 'trailing whitespace is warned' '\n+\tmkdir whitespace &&\n+\t>whitespace/trailing &&\n+\t>whitespace/untracked &&\n+\techo \"whitespace/trailing   \" >ignore &&\n+\tcat >expect <<EOF &&\n+whitespace/trailing\n+whitespace/untracked\n+EOF\n+\tgit ls-files -o -X ignore whitespace >actual 2>err &&\n+\tgrep \"ignore:.*'\\''whitespace/trailing   '\\''\" err &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'quoting allows trailing whitespace' '\n+\trm -rf whitespace &&\n+\tmkdir whitespace &&\n+\t>\"whitespace/trailing  \" &&\n+\t>whitespace/untracked &&\n+\techo \"whitespace/trailing\\\\ \\\\ \" >ignore &&\n+\techo whitespace/untracked >expect &&\n+\t: >err.expect &&\n+\tgit ls-files -o -X ignore whitespace >actual 2>err &&\n+\ttest_cmp expect actual &&\n+\ttest_cmp err.expect err\n+'\n+\n test_done\n-- \n1.8.5.2.240.g8478abd\n"},{"id":"234537","messageId":"1391905598-19198-3-git-send-email-pclouds@gmail.com","threadId":"35830","inReplyTo":"1391905598-19198-1-git-send-email-pclouds@gmail.com","subject":"[PATCH v2 2/2] dir: ignore trailing spaces in exclude patterns","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-02-09T00:26:38Z","receivedAt":"2014-02-09T00:26:38Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Documentation/gitignore.txt |  3 +++\n dir.c                       | 21 ++++++++++++---------\n t/t0008-ignores.sh          |  8 ++++----\n 3 files changed, 19 insertions(+), 13 deletions(-)\n\ndiff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt\nindex b08d34d..8734c15 100644\n--- a/Documentation/gitignore.txt\n+++ b/Documentation/gitignore.txt\n@@ -77,6 +77,9 @@ PATTERN FORMAT\n    Put a backslash (\"`\\`\") in front of the first hash for patterns\n    that begin with a hash.\n \n+ - Trailing spaces are ignored unless they are quoted with backlash\n+   (\"`\\`\").\n+\n  - An optional prefix \"`!`\" which negates the pattern; any\n    matching file excluded by a previous pattern will become\n    included again. It is not possible to re-include a file if a parent\ndiff --git a/dir.c b/dir.c\nindex 6162209..70076b5 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -491,20 +491,23 @@ void clear_exclude_list(struct exclude_list *el)\n \tel->filebuf = NULL;\n }\n \n-static void check_trailing_spaces(const char *fname, char *buf)\n+static void trim_trailing_spaces(char *buf)\n {\n-\tint i, last_space = -1, len = strlen(buf);\n+\tint i, last_space = -1, nr_spaces, len = strlen(buf);\n \tfor (i = 0; i < len; i++)\n \t\tif (buf[i] == '\\\\')\n \t\t\ti++;\n-\t\telse if (buf[i] == ' ')\n-\t\t\tlast_space = i;\n-\t\telse\n+\t\telse if (buf[i] == ' ') {\n+\t\t\tif (last_space == -1) {\n+\t\t\t\tlast_space = i;\n+\t\t\t\tnr_spaces = 1;\n+\t\t\t} else\n+\t\t\t\tnr_spaces++;\n+\t\t} else\n \t\t\tlast_space = -1;\n \n-\tif (last_space == len - 1)\n-\t\twarning(_(\"%s: trailing spaces in '%s'. Please quote or remove them.\"),\n-\t\t\tfname, buf);\n+\tif (last_space != -1 && last_space + nr_spaces == len)\n+\t\tbuf[last_space] = '\\0';\n }\n \n int add_excludes_from_file_to_list(const char *fname,\n@@ -558,7 +561,7 @@ int add_excludes_from_file_to_list(const char *fname,\n \t\tif (buf[i] == '\\n') {\n \t\t\tif (entry != buf + i && entry[0] != '#') {\n \t\t\t\tbuf[i - (i && buf[i-1] == '\\r')] = 0;\n-\t\t\t\tcheck_trailing_spaces(fname, entry);\n+\t\t\t\ttrim_trailing_spaces(entry);\n \t\t\t\tadd_exclude(entry, base, baselen, el, lineno);\n \t\t\t}\n \t\t\tlineno++;\ndiff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh\nindex 9e1d64c..bbaf6b5 100755\n--- a/t/t0008-ignores.sh\n+++ b/t/t0008-ignores.sh\n@@ -779,18 +779,18 @@ test_expect_success PIPE 'streaming support for --stdin' '\n #\n # test whitespace handling\n \n-test_expect_success 'trailing whitespace is warned' '\n+test_expect_success 'trailing whitespace is ignored' '\n \tmkdir whitespace &&\n \t>whitespace/trailing &&\n \t>whitespace/untracked &&\n \techo \"whitespace/trailing   \" >ignore &&\n \tcat >expect <<EOF &&\n-whitespace/trailing\n whitespace/untracked\n EOF\n+\t: >err.expect &&\n \tgit ls-files -o -X ignore whitespace >actual 2>err &&\n-\tgrep \"ignore:.*'\\''whitespace/trailing   '\\''\" err &&\n-\ttest_cmp expect actual\n+\ttest_cmp expect actual &&\n+\ttest_cmp err.expect err\n '\n \n test_expect_success 'quoting allows trailing whitespace' '\n-- \n1.8.5.2.240.g8478abd\n"},{"id":"234566","messageId":"20140210011859.GB12773@sigill.intra.peff.net","threadId":"35830","inReplyTo":"CACsJy8C_Lc+mcJxGc7S5AB47YKDrhmWPwZp2oxJ9Z1tONVT0kQ@mail.gmail.com","subject":"Re: [PATCH 0/2] Ignore trailing spaces in .gitignore","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-02-10T01:19:02Z","receivedAt":"2014-02-10T01:19:02Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Feb 09, 2014 at 06:48:18AM +0700, Duy Nguyen wrote:\n\n> > I guess by quoting you meant:\n> >\n> >   echo '\"trailing  \"' >.gitignore\n> \n> This makes \" special. If we follow shell convention then things\n> between \"..\" should be literal (e.g. \"*\" is no longer a wildcard). We\n> don't support it yet. So I rather go with backslash as it adds less\n> code.\n\nFor some reason I was thinking that we already handled double-quotes\nhere (as we do in other places where quoting is optional). But it looks\nlike we don't currently, so yeah, I don't think it is worth adding due\nto the potential confusion.\n\nBackslash-escaping was what I had originally assumed you meant, and it\nwas, so we are all on the same page (the patch was just broken. ;) ).\n\n-Peff\n"},{"id":"234567","messageId":"7vd2iv8vbo.fsf@alter.siamese.dyndns.org","threadId":"35830","inReplyTo":"1391847004-22810-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 0/2] Ignore trailing spaces in .gitignore","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-02-10T04:07:07Z","receivedAt":"2014-02-10T04:07:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> Trailing spaces are invisible in most standard editors (*). \"git diff\"\n> does show trailing spaces by default. But that does not help newly\n> written .gitignore files. And trailing spaces are the source of\n> frustration when writing .gitignore.\n>\n> So let's ignore them. Nobody sane would put a trailing space in file\n> names. But we could be careful and do it in two steps: warn first,\n> then ignore trailing spaces. Another option is merge two patches in\n> one and be done with it.\n>\n> People can still quote trailing spaces, which will not be ignored (and\n> much more visible). Quoting comes with a cost of doing fnmatch(). But\n\nHmph, sorry but I fail to see why we need to incur cost for\nfnmatch().  We read and parse the file and keep them as internal\nstrings, so your unquoting (and complaining the unquoted trailng\nspaces) can be done at the parse time, while keeping the trailing\nspaces the user explicitly told us to keep by quoting in the\ninternal string that we eventually feed fnmatch() with _after_\nunquoting, no?\n\nPuzzled...\n"},{"id":"234568","messageId":"CACsJy8AZbi89gsM_MWzPe+95y+MqjtFpiFZE8ai1JMtzwiLTQg@mail.gmail.com","threadId":"35830","inReplyTo":"7vd2iv8vbo.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 0/2] Ignore trailing spaces in .gitignore","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2014-02-10T04:29:17Z","receivedAt":"2014-02-10T04:29:17Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Feb 10, 2014 at 11:07 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n>\n>> Trailing spaces are invisible in most standard editors (*). \"git diff\"\n>> does show trailing spaces by default. But that does not help newly\n>> written .gitignore files. And trailing spaces are the source of\n>> frustration when writing .gitignore.\n>>\n>> So let's ignore them. Nobody sane would put a trailing space in file\n>> names. But we could be careful and do it in two steps: warn first,\n>> then ignore trailing spaces. Another option is merge two patches in\n>> one and be done with it.\n>>\n>> People can still quote trailing spaces, which will not be ignored (and\n>> much more visible). Quoting comes with a cost of doing fnmatch(). But\n>\n> Hmph, sorry but I fail to see why we need to incur cost for\n> fnmatch().  We read and parse the file and keep them as internal\n> strings, so your unquoting (and complaining the unquoted trailng\n> spaces) can be done at the parse time, while keeping the trailing\n> spaces the user explicitly told us to keep by quoting in the\n> internal string that we eventually feed fnmatch() with _after_\n> unquoting, no?\n\nThat's the optimization in the \"but\" sentence. Another (off topic)\nopt. we could do is make \"*.[ch]\" behave more like \"*.c\", where we\njust try to match the tail part.\n-- \nDuy\n"},{"id":"234569","messageId":"7vfvnrlfsi.fsf@alter.siamese.dyndns.org","threadId":"35830","inReplyTo":"7vd2iv8vbo.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 0/2] Ignore trailing spaces in .gitignore","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-02-10T05:04:13Z","receivedAt":"2014-02-10T05:04:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n>\n>> Trailing spaces are invisible in most standard editors (*). \"git diff\"\n>> does show trailing spaces by default. But that does not help newly\n>> written .gitignore files. And trailing spaces are the source of\n>> frustration when writing .gitignore.\n>>\n>> So let's ignore them. Nobody sane would put a trailing space in file\n>> names. But we could be careful and do it in two steps: warn first,\n>> then ignore trailing spaces. Another option is merge two patches in\n>> one and be done with it.\n>>\n>> People can still quote trailing spaces, which will not be ignored (and\n>> much more visible). Quoting comes with a cost of doing fnmatch(). But\n>\n> Hmph, sorry but I fail to see why we need to incur cost for\n> fnmatch().  We read and parse the file and keep them as internal\n> strings, so your unquoting (and complaining the unquoted trailng\n> spaces) can be done at the parse time, while keeping the trailing\n> spaces the user explicitly told us to keep by quoting in the\n> internal string that we eventually feed fnmatch() with _after_\n> unquoting, no?\n>\n> Puzzled...\n\nHeh, silly me. Yes, we _could_ parse and strip \"\\ \" into \" \" if we\nwanted to, but we can just give \"\\ \" and let fnmatch(3) do its\nthing, and that is the right thing to do for a rare corner case like\nthis (i.e. deliberate trailing spaces).\n\nSo I think I understand your reasoning, and I agree with it.\n"}]}