From: Finn Arne Gangstad <hidden> Date: 2016-06-15 22:46:08
If you had an exclude-pattern with a backslash in it, e.g. "\#foo",
this would not work, since git would do a strcmp of the exclude pattern
and the filename. Only wildcard patterns were matched with fnmatch,
which does the right thing with backslashes. We now also treat all patterns
containing backslashes as wildcards.
De-escaping the pattern while reading the .gitignore file is error prone,
since that would break patterns with both backslashes and wildcards.
E.g. "\\*.c" would be translated to "\*.c" before fnmatch got it,
and would change the meaning of the rule dramatically.
Signed-off-by: Finn Arne Gangstad <redacted>
---
dir.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:46:08
Hi,
On Tue, 10 Feb 2009, Finn Arne Gangstad wrote:
If you had an exclude-pattern with a backslash in it, e.g. "\#foo",
this would not work, since git would do a strcmp of the exclude pattern
and the filename. Only wildcard patterns were matched with fnmatch,
which does the right thing with backslashes. We now also treat all patterns
containing backslashes as wildcards.
De-escaping the pattern while reading the .gitignore file is error prone,
since that would break patterns with both backslashes and wildcards.
E.g. "\\*.c" would be translated to "\*.c" before fnmatch got it,
and would change the meaning of the rule dramatically.
I am not sure I understand (maybe a test case would help, but that test
case would have to be disabled on Windows, I guess):
You mean that '\#abc' would match '\#abc', but '\#abc*' would not?
Ciao,
Dscho
From: Finn Arne Gangstad <hidden> Date: 2016-06-15 22:46:08
On Tue, Feb 10, 2009 at 01:56:36PM +0100, Johannes Schindelin wrote:
Hi,
On Tue, 10 Feb 2009, Finn Arne Gangstad wrote:
quoted
If you had an exclude-pattern with a backslash in it, e.g. "\#foo",
this would not work, since git would do a strcmp of the exclude pattern
and the filename. Only wildcard patterns were matched with fnmatch,
which does the right thing with backslashes. We now also treat all patterns
containing backslashes as wildcards.
De-escaping the pattern while reading the .gitignore file is error prone,
since that would break patterns with both backslashes and wildcards.
E.g. "\\*.c" would be translated to "\*.c" before fnmatch got it,
and would change the meaning of the rule dramatically.
I am not sure I understand (maybe a test case would help, but that test
case would have to be disabled on Windows, I guess):
You mean that '\#abc' would match '\#abc', but '\#abc*' would not?
Currently, \#abc does not match a file named #abc, but \#abc* does.
With the patch, both will match.
- Finn Arne
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:46:08
Hi,
On Tue, 10 Feb 2009, Finn Arne Gangstad wrote:
On Tue, Feb 10, 2009 at 01:56:36PM +0100, Johannes Schindelin wrote:
quoted
Hi,
On Tue, 10 Feb 2009, Finn Arne Gangstad wrote:
quoted
If you had an exclude-pattern with a backslash in it, e.g. "\#foo",
this would not work, since git would do a strcmp of the exclude pattern
and the filename. Only wildcard patterns were matched with fnmatch,
which does the right thing with backslashes. We now also treat all patterns
containing backslashes as wildcards.
De-escaping the pattern while reading the .gitignore file is error prone,
since that would break patterns with both backslashes and wildcards.
E.g. "\\*.c" would be translated to "\*.c" before fnmatch got it,
and would change the meaning of the rule dramatically.
I am not sure I understand (maybe a test case would help, but that test
case would have to be disabled on Windows, I guess):
You mean that '\#abc' would match '\#abc', but '\#abc*' would not?
Currently, \#abc does not match a file named #abc, but \#abc* does.
With the patch, both will match.
Ah, so I was wrong, and the test case would not have to be disabled on
Windows.
Thanks,
Dscho
From: Finn Arne Gangstad <hidden> Date: 2016-06-15 22:46:08
"\" was treated differently in exclude rules depending on whether a
wildcard match was done. For wildcard rules, "\" was de-escaped in
fnmatch, but this was not done for other rules since they used strcmp
instead. A file named "#foo" would not be excluded by "\#foo", but would
be excluded by "\#foo*".
We now treat all rules with "\" as wildcard rules.
Another solution could be to de-escape all non-wildcard rules as we
read them, but we would have to do the de-escaping exactly as fnmatch
does it to avoid inconsistencies.
Signed-off-by: Finn Arne Gangstad <redacted>
---
dir.c | 2 +-
t/t3003-ls-files-others-escaped-excludes.sh | 37 +++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 1 deletions(-)
create mode 100755 t/t3003-ls-files-others-escaped-excludes.sh
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:46:08
Hi,
On Tue, 10 Feb 2009, Finn Arne Gangstad wrote:
"\" was treated differently in exclude rules depending on whether a
wildcard match was done. For wildcard rules, "\" was de-escaped in
fnmatch, but this was not done for other rules since they used strcmp
instead. A file named "#foo" would not be excluded by "\#foo", but would
be excluded by "\#foo*".
We now treat all rules with "\" as wildcard rules.
Another solution could be to de-escape all non-wildcard rules as we
read them, but we would have to do the de-escaping exactly as fnmatch
does it to avoid inconsistencies.
Signed-off-by: Finn Arne Gangstad <redacted>
---
dir.c | 2 +-
t/t3003-ls-files-others-escaped-excludes.sh | 37 +++++++++++++++++++++++++++
@@ -0,0 +1,37 @@+#!/bin/sh+#+# Copyright (c) 2009 Finn Arne Gangstad+#++test_description='gitls-files--otherswithescapedexcludes++Thistesttestsexclusionpatternswith\ inthemandmakessurethey+aretreatedcorrectlyandidenticallybothfornormalandwildcardrules.+'++../test-lib.sh++touch\#ignore1&&
In other tests, we avoid 'touch' (IIRC it is not available everywhere or
some such), and we write ': > \#ignore1' instead.
BTW we do not need the # in the name, it could be any letter, right?
(Just for my understanding, not as a request to change it.)
From: Finn Arne Gangstad <hidden> Date: 2016-06-15 22:46:08
On Tue, Feb 10, 2009 at 03:27:43PM +0100, Johannes Schindelin wrote:
quoted
+
+. ./test-lib.sh
+
+touch \#ignore1 &&
In other tests, we avoid 'touch' (IIRC it is not available everywhere or
some such), and we write ': > \#ignore1' instead.
Will fix it up after seeing if there are some other comments.
BTW we do not need the # in the name, it could be any letter, right?
(Just for my understanding, not as a request to change it.)
So far I have only had to use \ in exclusion rules starting with #,
since they would otherwise be interpreted as comments, but it could be
any character that \ would not change the meaning of. I am not sure
what fnmatch would do with \t, \r and \n for example.
quoted
+cat >.gitignore <<EOF
You probably want to use \EOF here.
I am curious, does it matter? Most of the tests use EOF and not \EOF.
- Finn Arne