make slash-rules more readable
From: Adam Nielsen <[email protected]>
gitignore.txt: make slash-rules more readable
Remove the addition it is removed for the purpose of the following description and make clear in which situations a trailing slash is used or not. Increase readability and make all paragraphs valid, even if they are not read in strict order.
Replace otherwise with the the concrete pattern that is considered in the paragraph to avoid confusion.
Add simple examples to point out the significant difference between using or not using a trailing slash.
--- Documentation/gitignore.txt | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
Documentation/gitignore.txt +13 -10
@@ -89,22 +89,25 @@ PATTERN FORMAT Put a backslash ("`\`") in front of the first "`!`" for patterns that begin with a literal "`!`", for example, "`\!important!.txt`". - - If the pattern ends with a slash, it is removed for the - purpose of the following description, but it would only find + - If the pattern ends with a slash "`/`", it would only find a match with a directory. In other words, `foo/` will match a directory `foo` and paths underneath it, but will not match a regular file or a symbolic link `foo` (this is consistent with the way how pathspec works in general in Git). - - If the pattern does not contain a slash '/', Git treats it as - a shell glob pattern and checks for a match against the - pathname relative to the location of the `.gitignore` file - (relative to the toplevel of the work tree if not from a - `.gitignore` file). + - If the pattern contains no slash "`/`" other then a trailing slash, + then the pattern will match in all directories. In other words, + `foo/` will match `/bar/foo/` and `foo` will match `/bar/bar/foo`. - - Otherwise, Git treats the pattern as a shell glob: "`*`" matches - anything except "`/`", "`?`" matches any one character except "`/`" - and "`[]`" matches one character in a selected range. See + - If the pattern contains a slash "`/`" other then a trailing slash, then + the pattern is always considered from the `.gitignore` file location. + In other words, `foo/bar` will match `/foo/bar` but not `/bar/foo/bar`. + + - The character "`*`" matches anything except a non trailing slash "`/`". + For example, "foo/*" matches "foo/test.json" and "foo/bar/" + but not "foo/bar/test.json". + The character "`?`" matches any one character except "`/`". + The character "`[]`" matches one character in a selected range. See fnmatch(3) and the FNM_PATHNAME flag for a more detailed description.
Signature · 1 line
2.17.1
"Dr. Adam Nielsen" <[email protected]> writes:
A few notes on the form.
Quoted 1 line
From: Adam Nielsen <[email protected]>
This "author" identity and the name-email on the Signed-off-by: line should match, at least for this project. I cannot tell which one is your preference, and I do not have any preference over your name either ;-), but please pick one and use it consistently.
Quoted 9 lines
gitignore.txt: make slash-rules more readable
Remove the addition
it is removed for the purpose of the following descriptionand make clear in which situations a trailing slash is used or not. Increase readability and make all paragraphs valid, even if they are not read in strict order.
Replaceotherwisewith the the concrete pattern that is considered in the paragraph to avoid confusion.
Add simple examples to point out the significant difference between using or not using a trailing slash.
These are overly long lines; we tend to fold long lines at around 70 char or so.
Quoted 11 lines
Signed-off-by Adam J. N. Nielsen <[email protected]>--- Documentation/gitignore.txt | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)Documentation/gitignore.txt +0
-0
Documentation/gitignore.txt PATTERN FORMAT · line 96
Quoted 10 lines
Documentation/gitignore.txt +1
-2@@ -89,22 +89,25 @@ PATTERN FORMAT Put a backslash ("`\`") in front of the first "`!`" for patterns that begin with a literal "`!`", for example, "`\!important!.txt`". - - If the pattern ends with a slash, it is removed for the - purpose of the following description, but it would only find + - If the pattern ends with a slash "`/`", it would only find a match with a directory. In other words, `foo/` will match a directory `foo` and paths underneath it, but will not match a regular file or a symbolic link `foo` (this is consistent with the way how pathspec works in general in Git).
I do like this change, even though I cannot bring myself backing it 100% immediately. The reason why I wrote it the way in the original was because I did not want to repeat "... but a slash at end, if exists, is exempt from this rule" over and over in the later bullet points, as it would be a maintenance burden when we have more bullet points and when we find a better phrasing to say "... but a slash at end if exists, is exempt from this rule".
The patch I am responding to bites the bullet and repeats the "the one at the end does not count", which may be slightly harder to maintain, but certainly makes it easier to read.
Documentation/gitignore.txt PATTERN FORMAT · line 98
Quoted 6 lines
Documentation/gitignore.txt +1
-5- - If the pattern does not contain a slash '/', Git treats it as - a shell glob pattern and checks for a match against the - pathname relative to the location of the `.gitignore` file - (relative to the toplevel of the work tree if not from a - `.gitignore` file). + - If the pattern contains no slash "`/`" other then a trailing slash,
While pretending to be a fresh reader and reading only this line made me wonder if the rule described in this bullet point applies only to a pattern that has a single slash at the end. I wonder if it is just me, or we can improve the phrasing so that it is clear that a pattern without any slash also is covered by this rule, not just a pattern that has all non-slash chars followed by a single slash.
Documentation/gitignore.txt PATTERN FORMAT · line 100
Quoted 2 lines
Documentation/gitignore.txt +2
-0+ then the pattern will match in all directories. In other words, + `foo/` will match `/bar/foo/` and `foo` will match `/bar/bar/foo`.
The half-technical "treats it as a shell glob pattern" from the original is gone, which I think is a good change. The examples may need to be improved, as it may not be clear to naive readers that with /bar/foo/, you meant that it is limited to a directory but not a file, and with /bar/bar/foo you meant both a directory and a file is fine. Perhaps
For example, 'frotz/' matches 'frotz', 'a/frotz', etc. that is a directory, but does not match if these are files. A pattern 'frotz' on the other hand matches these paths whether they are files or directories.
I also wonder if "in all directories" is clear enough that your "all" is limited to below the level the ignore pattern is defined for (i.e. "*.1" that appears in "Documentation/.gitignore" does not ignore "foo.1" at the top-level of the tree).
So I can tell that this patch is trying to address a problem in the original that is worth fixing, but I cannot say the result is good. At least not yet.
Documentation/gitignore.txt PATTERN FORMAT · line 102
Quoted 4 lines
Documentation/gitignore.txt +1
-3- - Otherwise, Git treats the pattern as a shell glob: "`*`" matches - anything except "`/`", "`?`" matches any one character except "`/`" - and "`[]`" matches one character in a selected range. See + - If the pattern contains a slash "`/`" other then a trailing slash, then
The same comment applies to this first line about the ambiguity of a pattern without any slash anywhere.
Documentation/gitignore.txt PATTERN FORMAT · line 104
Quoted 2 lines
Documentation/gitignore.txt +2
-0+ the pattern is always considered from the `.gitignore` file location. + In other words, `foo/bar` will match `/foo/bar` but not `/bar/foo/bar`.
Again, loss of the mention of "shell glob" is a good thing, as we still have a clue for those "in the know" at the end by mentioning fnmatch(3).
The example lacks one crucial description to be useful. The reader must be told where foo/bar came from. Was it in the .gitignore file at the top-level? A per-directory exclude file bar/.gitignore? Without making that clear, none of the "In other words" example makes much sense.
Also another issue common to previous example is that you are using absolute path notation "/bar/foo/", "/bar/foo/bar", etc. without explaining what you want it mean. I can guess that it does not refer to the root of the filesystem but you meant to refer to the top level of the working tree, but you are not writing documentation to help _me_ understand Git, so we should not rely on that "I can guess". I do not think an average first-time reader can.
Documentation/gitignore.txt PATTERN FORMAT · line 108
Quoted 3 lines
Documentation/gitignore.txt +3
-0+ - The character "`*`" matches anything except a non trailing slash "`/`". + For example, "foo/*" matches "foo/test.json" and "foo/bar/" + but not "foo/bar/test.json".
I think your writing out the trailing slash on the filesystem-entity side (i.e. things that are matched by patterns) is making the resulting description more distracting than necessary. Being able to mark a pattern with a trailing slash to "match only to directory" is one thing, but when the example talks about paths foo/test.json (presumably a regular file and not a directory) and foo/bar (presumably a directory), it shouldn't force users to mistakenly think that the matching engine first appends a slash after a directory we read from the filesystem before applying the pattern matching logic, which has a compensating hack to ignore trailing slash from the path when matching.
Once you write consistently that a path for a directory foo/bar is foo/bar, not foo/bar/, then this example would become much easier to write and read, I suspect.
An asterisk "*" matches anything except a slash. A pattern "foo/*", for example, matches "foo/test.json" (a regular file), "foo/bar" (a diretory), but it does not match "foo/bar/hello.c" (a regular file), as the asterisk in the patter does not match "bar/hello.c" which has a slash in it.
perhaps.
Documentation/gitignore.txt PATTERN FORMAT · line 110
Quoted 2 lines
Documentation/gitignore.txt +2
-0+ The character "`?`" matches any one character except "`/`". + The character "`[]`" matches one character in a selected range. See
Calling [] construct "the character" is blatantly wrong.
The range notation, e.g. [a-zA-Z], can be used to match one of the characters in a range.
perhaps. It still omits negation [!0-9] but it probably is OK to leave that for fnmatch(3), and you've done so by leaving these two lines from the original intact, which is good.
Documentation/gitignore.txt PATTERN FORMAT · line 112
Quoted 2 lines
Documentation/gitignore.txt +0
-0fnmatch(3) and the FNM_PATHNAME flag for a more detailed description.
Thanks.
Am Mo., 8. Apr. 2019 um 09:51 Uhr schrieb Junio C Hamano <[email protected]>:
Quoted 12 lines
"Adam Nielsen" <[email protected]> writes:
A few notes on the form.
Quoted 1 line
From: Adam Nielsen <[email protected]>
This "author" identity and the name-email on the Signed-off-by: line should match, at least for this project. I cannot tell which one is your preference, and I do not have any preference over your name either ;-), but please pick one and use it consistently.
Haha yes sorry. I had my struggles with this patch procedure and I will do better next time.
Quoted 10 lines
Quoted 9 lines
gitignore.txt: make slash-rules more readable
Remove the addition
it is removed for the purpose of the following descriptionand make clear in which situations a trailing slash is used or not. Increase readability and make all paragraphs valid, even if they are not read in strict order.
Replaceotherwisewith the the concrete pattern that is considered in the paragraph to avoid confusion.
Add simple examples to point out the significant difference between using or not using a trailing slash.
Quoted 2 lines
These are overly long lines; we tend to fold long lines at around 70 char or so.
Okay.
Quoted 26 lines
Quoted 12 lines
Signed-off-by Adam J. N. Nielsen <[email protected]>--- Documentation/gitignore.txt | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)Documentation/gitignore.txt +0
-0Documentation/gitignore.txt PATTERN FORMAT · line 96
Quoted 10 lines
Documentation/gitignore.txt +1
-2@@ -89,22 +89,25 @@ PATTERN FORMAT Put a backslash ("`\`") in front of the first "`!`" for patterns that begin with a literal "`!`", for example, "`\!important!.txt`". - - If the pattern ends with a slash, it is removed for the - purpose of the following description, but it would only find + - If the pattern ends with a slash "`/`", it would only find a match with a directory. In other words, `foo/` will match a directory `foo` and paths underneath it, but will not match a regular file or a symbolic link `foo` (this is consistent with the way how pathspec works in general in Git).I do like this change, even though I cannot bring myself backing it 100% immediately.
Quoted 3 lines
The reason why I wrote it the way in the original
was because I did not want to repeat "... but a slash at end, if exists, is exempt from this rule"
Yes, I can see why this makes sense. However, I find that this exception makes this paragraph hard to read. Also I think its ambiguous if "it" refers to the pattern or the slash. The first few times I read it,
I just didn't get it and was very intimidated by the paragraph.
Quoted 4 lines
over and over in the later bullet
points, as it would be a maintenance burden when we have more bullet points and when we find a better phrasing to say "... but a slash at end if exists, is exempt from this rule".
Yes, I agree. One should not repeat such a bloated exception rule over and over again.
Quoted 12 lines
The patch I am responding to bites the bullet and repeats the "the one at the end does not count", which may be slightly harder to maintain, but certainly makes it easier to read.
Documentation/gitignore.txt PATTERN FORMAT · line 98
Quoted 6 lines
Documentation/gitignore.txt +1
-5- - If the pattern does not contain a slash '/', Git treats it as - a shell glob pattern and checks for a match against the - pathname relative to the location of the `.gitignore` file - (relative to the toplevel of the work tree if not from a - `.gitignore` file). + - If the pattern contains no slash "`/`" other then a trailing slash,
Quoted 7 lines
While pretending to be a fresh reader and reading only this line made me wonder if the rule described in this bullet point applies only to a pattern that has a single slash at the end. I wonder if it is just me, or we can improve the phrasing so that it is clear that a pattern without any slash also is covered by this rule, not just a pattern that has all non-slash chars followed by a single slash.
I agree with you. How about we make up the word "intermediate slash" and explain it in an extra paragraph? This would make it less repetitive. Also it makes clear that the case without any slash is also covered. Perhaps
In the following we use the term **intermediate slash** to denote a slash "/" in a pattern that is not a trailing slash nor a leading slash.
For example the pattern /foo/bar, foo/bar and /foo/bar/
all contain
only one intermediate slash. The pattern foo/ does not contain an intermediate slash.
Then, instead of:
If the pattern contains no slash "/" other then a trailing slash,"
one could say:
If the pattern contains no intermediate slash "/",
Quoted 11 lines
Documentation/gitignore.txt PATTERN FORMAT · line 100
Quoted 3 lines
Documentation/gitignore.txt +2
-0+ then the pattern will match in all directories. In other words, + `foo/` will match `/bar/foo/` and `foo` will match `/bar/bar/foo`.The half-technical "treats it as a shell glob pattern" from the original is gone, which I think is a good change. The examples may need to be improved, as it may not be clear to naive readers that with /bar/foo/, you meant that it is limited to a directory but not a file, and with /bar/bar/foo you meant both a directory and a file is fine. Perhaps
Quoted 5 lines
For example, 'frotz/' matches 'frotz', 'a/frotz', etc. that is a directory, but does not match if these are files. A pattern 'frotz' on the other hand matches these paths whether they are files or directories.
Yes. This is so much better.
Quoted 4 lines
I also wonder if "in all directories" is clear enough that your "all" is limited to below the level the ignore pattern is defined for (i.e. "*.1" that appears in "
Documentation/.gitignore" does not ignore "foo.1" at the top-level of the tree).
Its mentioned at the start of the page that the pattern is always relative to the location of the .gitignore file. However, I see that since its said "in all directories" its necessary to restrict it again. How about
If the pattern contains no intermediate slash "/", the pattern will match in all directories at or below the .gitignore file, with infinite depth.
Quoted 5 lines
So I can tell that this patch is trying to address a problem in the original that is worth fixing, but I cannot say the result is good. At least not yet.
Quoted 7 lines
Documentation/gitignore.txt PATTERN FORMAT · line 102
Quoted 4 lines
Documentation/gitignore.txt +1
-3- - Otherwise, Git treats the pattern as a shell glob: "`*`" matches - anything except "`/`", "`?`" matches any one character except "`/`" - and "`[]`" matches one character in a selected range. See + - If the pattern contains a slash "`/`" other then a trailing slash, thenThe same comment applies to this first line about the ambiguity of a pattern without any slash anywhere.
This would now change with the above remarks to:
If the pattern contains an intermediate slash "/",
Quoted 14 lines
Documentation/gitignore.txt PATTERN FORMAT · line 104
Quoted 3 lines
Documentation/gitignore.txt +2
-0+ the pattern is always considered from the `.gitignore` file location. + In other words, `foo/bar` will match `/foo/bar` but not `/bar/foo/bar`.Again, loss of the mention of "shell glob" is a good thing, as we still have a clue for those "in the know" at the end by mentioning fnmatch(3).
The example lacks one crucial description to be useful. The reader must be told where foo/bar came from. Was it in the .gitignore file at the top-level? A per-directory exclude file bar/.gitignore? Without making that clear, none of the "In other words" example makes much sense.
Quoted 7 lines
Also another issue common to previous example is that you are using absolute path notation "/bar/foo/", "/bar/foo/bar", etc. without explaining what you want it mean. I can guess that it does not refer to the root of the filesystem but you meant to refer to the top level of the working tree, but you are not writing documentation to help _me_ understand Git, so we should not rely on that "I can guess". I do not think an average first-time reader can.
Maybe its shorter and clearer to write it like this:
If the pattern contains an intermediate slash "/", its equivalent to the same pattern starting with a leading slash. For example the pattern doc/read.txt is equivalent to /doc/read.txt.
If we do this, one would need to lift the "leading slash" paragraph up (The one starting with "A leading slash matches the beginning of the pathname. For example,...").
Note that since an intermediate slash is explicitly not a leading slash, it is not said that/bar/ and //bar/ are equivalent.
Quoted 21 lines
Documentation/gitignore.txt PATTERN FORMAT · line 108
Quoted 4 lines
Documentation/gitignore.txt +3
-0+ - The character "`*`" matches anything except a non trailing slash "`/`". + For example, "foo/*" matches "foo/test.json" and "foo/bar/" + but not "foo/bar/test.json".I think your writing out the trailing slash on the filesystem-entity side (i.e. things that are matched by patterns) is making the resulting description more distracting than necessary. Being able to mark a pattern with a trailing slash to "match only to directory" is one thing, but when the example talks about paths
foo/test.json(presumably a regular file and not a directory) and foo/bar (presumably a directory), it shouldn't force users to mistakenly think that the matching engine first appends a slash after a directory we read from the filesystem before applying the pattern matching logic, which has a compensating hack to ignore trailing slash from the path when matching.Once you write consistently that a path for a directory foo/bar is foo/bar, not foo/bar/, then this example would become much easier to write and read, I suspect.
Quoted 7 lines
An asterisk "
*" matches anything except a slash. A pattern "foo/*", for example, matches "foo/test.json" (a regular file), "foo/bar" (a diretory), but it does not match "foo/bar/hello.c" (a regular file), as the asterisk in the patter does not match "bar/hello.c" which has a slash in it.perhaps.
I agree, this is much better. Although I would leave out
Quoted 8 lines
"as the asterisk in the patter does not match "
bar/hello.c"
which has a slash in it."Documentation/gitignore.txt PATTERN FORMAT · line 110
Quoted 2 lines
Documentation/gitignore.txt +2
-0+ The character "`?`" matches any one character except "`/`". + The character "`[]`" matches one character in a selected range. SeeCalling
[]construct "the character" is blatantly wrong.
Yes, my bad.
Quoted 5 lines
The range notation, e.g.
[a-zA-Z], can be used to match one of the characters in a range.perhaps.
That is much better too.
Quoted 9 lines
It still omits negation [!0-9] but it probably is OK to leave that for fnmatch(3), and you've done so by leaving these two lines from the original intact, which is good.
Documentation/gitignore.txt PATTERN FORMAT · line 112
Quoted 2 lines
Documentation/gitignore.txt +0
-0fnmatch(3) and the FNM_PATHNAME flag for a more detailed description.Thanks.
Thank you for all your input. If you agree with my proposed changes, I would create a new patch merging all this together.
Am Mo., 8. Apr. 2019 um 09:51 Uhr schrieb Junio C Hamano <[email protected]>:
Quoted 172 lines
"Dr. Adam Nielsen" <[email protected]> writes:
A few notes on the form.
Quoted 1 line
From: Adam Nielsen <[email protected]>
This "author" identity and the name-email on the Signed-off-by: line should match, at least for this project. I cannot tell which one is your preference, and I do not have any preference over your name either ;-), but please pick one and use it consistently.
Quoted 9 lines
gitignore.txt: make slash-rules more readable
Remove the addition
it is removed for the purpose of the following descriptionand make clear in which situations a trailing slash is used or not. Increase readability and make all paragraphs valid, even if they are not read in strict order.
Replaceotherwisewith the the concrete pattern that is considered in the paragraph to avoid confusion.
Add simple examples to point out the significant difference between using or not using a trailing slash.These are overly long lines; we tend to fold long lines at around 70 char or so.
Quoted 11 lines
Signed-off-by Adam J. N. Nielsen <[email protected]>--- Documentation/gitignore.txt | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)Documentation/gitignore.txt +0
-0Documentation/gitignore.txt PATTERN FORMAT · line 96
Quoted 10 lines
Documentation/gitignore.txt +1
-2@@ -89,22 +89,25 @@ PATTERN FORMAT Put a backslash ("`\`") in front of the first "`!`" for patterns that begin with a literal "`!`", for example, "`\!important!.txt`". - - If the pattern ends with a slash, it is removed for the - purpose of the following description, but it would only find + - If the pattern ends with a slash "`/`", it would only find a match with a directory. In other words, `foo/` will match a directory `foo` and paths underneath it, but will not match a regular file or a symbolic link `foo` (this is consistent with the way how pathspec works in general in Git).I do like this change, even though I cannot bring myself backing it 100% immediately. The reason why I wrote it the way in the original was because I did not want to repeat "... but a slash at end, if exists, is exempt from this rule" over and over in the later bullet points, as it would be a maintenance burden when we have more bullet points and when we find a better phrasing to say "... but a slash at end if exists, is exempt from this rule".
The patch I am responding to bites the bullet and repeats the "the one at the end does not count", which may be slightly harder to maintain, but certainly makes it easier to read.
Documentation/gitignore.txt PATTERN FORMAT · line 98
Quoted 6 lines
Documentation/gitignore.txt +1
-5- - If the pattern does not contain a slash '/', Git treats it as - a shell glob pattern and checks for a match against the - pathname relative to the location of the `.gitignore` file - (relative to the toplevel of the work tree if not from a - `.gitignore` file). + - If the pattern contains no slash "`/`" other then a trailing slash,While pretending to be a fresh reader and reading only this line made me wonder if the rule described in this bullet point applies only to a pattern that has a single slash at the end. I wonder if it is just me, or we can improve the phrasing so that it is clear that a pattern without any slash also is covered by this rule, not just a pattern that has all non-slash chars followed by a single slash.
Documentation/gitignore.txt PATTERN FORMAT · line 100
Quoted 2 lines
Documentation/gitignore.txt +2
-0+ then the pattern will match in all directories. In other words, + `foo/` will match `/bar/foo/` and `foo` will match `/bar/bar/foo`.The half-technical "treats it as a shell glob pattern" from the original is gone, which I think is a good change. The examples may need to be improved, as it may not be clear to naive readers that with /bar/foo/, you meant that it is limited to a directory but not a file, and with /bar/bar/foo you meant both a directory and a file is fine. Perhaps
For example, 'frotz/' matches 'frotz', 'a/frotz', etc. that is a directory, but does not match if these are files. A pattern 'frotz' on the other hand matches these paths whether they are files or directories.
I also wonder if "in all directories" is clear enough that your "all" is limited to below the level the ignore pattern is defined for (i.e. "*.1" that appears in "
Documentation/.gitignore" does not ignore "foo.1" at the top-level of the tree).So I can tell that this patch is trying to address a problem in the original that is worth fixing, but I cannot say the result is good. At least not yet.
Documentation/gitignore.txt PATTERN FORMAT · line 102
Quoted 4 lines
Documentation/gitignore.txt +1
-3- - Otherwise, Git treats the pattern as a shell glob: "`*`" matches - anything except "`/`", "`?`" matches any one character except "`/`" - and "`[]`" matches one character in a selected range. See + - If the pattern contains a slash "`/`" other then a trailing slash, thenThe same comment applies to this first line about the ambiguity of a pattern without any slash anywhere.
Documentation/gitignore.txt PATTERN FORMAT · line 104
Quoted 2 lines
Documentation/gitignore.txt +2
-0+ the pattern is always considered from the `.gitignore` file location. + In other words, `foo/bar` will match `/foo/bar` but not `/bar/foo/bar`.Again, loss of the mention of "shell glob" is a good thing, as we still have a clue for those "in the know" at the end by mentioning fnmatch(3).
The example lacks one crucial description to be useful. The reader must be told where foo/bar came from. Was it in the .gitignore file at the top-level? A per-directory exclude file bar/.gitignore? Without making that clear, none of the "In other words" example makes much sense.
Also another issue common to previous example is that you are using absolute path notation "/bar/foo/", "/bar/foo/bar", etc. without explaining what you want it mean. I can guess that it does not refer to the root of the filesystem but you meant to refer to the top level of the working tree, but you are not writing documentation to help _me_ understand Git, so we should not rely on that "I can guess". I do not think an average first-time reader can.
Documentation/gitignore.txt PATTERN FORMAT · line 108
Quoted 3 lines
Documentation/gitignore.txt +3
-0+ - The character "`*`" matches anything except a non trailing slash "`/`". + For example, "foo/*" matches "foo/test.json" and "foo/bar/" + but not "foo/bar/test.json".I think your writing out the trailing slash on the filesystem-entity side (i.e. things that are matched by patterns) is making the resulting description more distracting than necessary. Being able to mark a pattern with a trailing slash to "match only to directory" is one thing, but when the example talks about paths
foo/test.json(presumably a regular file and not a directory) and foo/bar (presumably a directory), it shouldn't force users to mistakenly think that the matching engine first appends a slash after a directory we read from the filesystem before applying the pattern matching logic, which has a compensating hack to ignore trailing slash from the path when matching.Once you write consistently that a path for a directory foo/bar is foo/bar, not foo/bar/, then this example would become much easier to write and read, I suspect.
An asterisk "
*" matches anything except a slash. A pattern "foo/*", for example, matches "foo/test.json" (a regular file), "foo/bar" (a diretory), but it does not match "foo/bar/hello.c" (a regular file), as the asterisk in the patter does not match "bar/hello.c" which has a slash in it.perhaps.
Documentation/gitignore.txt PATTERN FORMAT · line 110
Quoted 2 lines
Documentation/gitignore.txt +2
-0+ The character "`?`" matches any one character except "`/`". + The character "`[]`" matches one character in a selected range. SeeCalling
[]construct "the character" is blatantly wrong.The range notation, e.g.
[a-zA-Z], can be used to match one of the characters in a range.perhaps. It still omits negation [!0-9] but it probably is OK to leave that for fnmatch(3), and you've done so by leaving these two lines from the original intact, which is good.
Documentation/gitignore.txt PATTERN FORMAT · line 112
Quoted 2 lines
Documentation/gitignore.txt +0
-0fnmatch(3) and the FNM_PATHNAME flag for a more detailed description.Thanks.
Signature · 19 lines
Dr. Adam Nielsen Administrator for IN/ICI/WHO IN: www.nlp-institutes.net ICI: www.coaching-institutes.net WHO: www.world-hypnosis.org
Quoted 2 lines · Dr. Adam Nielsen
I agree with you. How about we make up the word "intermediate slash" and explain it in an extra paragraph?
I am not sure if that is any better than "in the following, pretend that a slash at the end of a pattern does not exist", which is how the current description avoids repetition and aims for clarity. It probably is worse than than the current one if we need to introduce a new term that is otherwise not useful elsewhere---a new term adds to the cognitive load of readers.
Quoted 5 lines
Quoted 4 lines
I also wonder if "in all directories" is clear enough that your "all" is limited to below the level the ignore pattern is defined for (i.e. "*.1" that appears in "
Documentation/.gitignore" does not ignore "foo.1" at the top-level of the tree).
Quoted 8 lines
Its mentioned at the start of the page that the pattern is always relative to the location of the
.gitignorefile. However, I see that since its said "in all directories" its necessary to restrict it again. How aboutIf the pattern contains no intermediate slash "
/", the pattern will match in all directories at or below the.gitignorefile, with infinite depth.
It is unclear what "with infinite depth" means in this sentence. There is no depth-limit in the exclude mechanism, and I'd prefer not to confuse readers by making a casual mention of "depth" to imply as if there is some depth-based logic.
Also, as you defined "intermediate" as a slash that is neither leading nor trailing, the above paragraph says "/foo" matches any filesystem entity whose final path component is 'foo', e.g. a file 'foo' at the current level, a directory 'foo' in subdirectory 'dir' (i.e. 'dir/foo'), etc. I do not think you meant to say that (and this is why I do not like to introduce a new term---even its inventor cannot get it right).
Quoted 14 lines
Quoted 14 lines
So I can tell that this patch is trying to address a problem in the original that is worth fixing, but I cannot say the result is good. At least not yet.
...
Once you write consistently that a path for a directory foo/bar is foo/bar, not foo/bar/, then this example would become much easier to write and read, I suspect.An asterisk "
*" matches anything except a slash. A pattern "foo/*", for example, matches "foo/test.json" (a regular file), "foo/bar" (a diretory), but it does not match "foo/bar/hello.c" (a regular file), as the asterisk in the patter does not match "bar/hello.c" which has a slash in it.
Quoted 6 lines
Quoted 1 line
perhaps.
I agree, this is much better. Although I would leave out
Quoted 2 lines
"as the asterisk in the patter does not match "
bar/hello.c"
which has a slash in it."
I happen to think that the part is the more important half of that whole "example". By explaining why it does not match, it enforces "matches anything except a slash" we gave upfront.
Thanks. I think we are making progress...
Quoted 9 lines
Quoted 2 lines
I agree with you. How about we make up the word "intermediate slash" and explain it in an extra paragraph?
I am not sure if that is any better than "in the following, pretend that a slash at the end of a pattern does not exist", which is how the current description avoids repetition and aims for clarity. It probably is worse than than the current one if we need to introduce a new term that is otherwise not useful elsewhere---a new term adds to the cognitive load of readers.
The description "in the following, pretend that a slash at the end of a pattern does not exist"
is much better understandable then "it is removed for the purpose of the following description"
to me. However, I still think its better not to use it:
1. The following paragraphs may not be valid if you do not keep this
rule in mind.
This could happen, because one may not read the paragraphs in order, or its unclear if "in the following" is meant for all following
paragraphs or just this
paragraph, or one simply forgets it if one happens to check up a
specific paragraph
after some months or when returning from a break.
2. Forcing the user to be aware that "in the following pretend that
a slash at the end does not exist"
is at least for me a harder cognitive load then introducing a new term. Because for every new paragraph that I read, I have to check if
this rule applies.
3. If you jump between paragraphs, you always need to locate the rule and then check if the current paragraph is below or after that rule.
4. There are 7 paragraphs following this "specific rule" but only
the next paragraph
is using it. I think its also not needed for the paragraph where
it appears.
For the other 6 paragraphs one needs to unnecessary check if the rule is implicitly used anywhere.
5. For every paragraph that one may add in the future below that
rule, one needs to double check
if its compatible with this rule. So in terms of maintenance I
think its rather a downside.
If something is cumbersome to explain and appears often, I think its best to explain it once in detail
and refer to that instead of a bloated description. However, since this scenario only appears in two paragraphs,
a new term is maybe not justifiable. Thus, a cumbersome but complete description might be preferable.
Quoted 5 lines
Quoted 5 lines
Its mentioned at the start of the page that the pattern is always relative to the location of the
.gitignorefile. However, I see that since its said "in all directories" its necessary to restrict it again. How about
Quoted 8 lines
Quoted 3 lines
If the pattern contains no intermediate slash "
/", the pattern will match in all directories at or below the.gitignorefile, with infinite depth.It is unclear what "with infinite depth" means in this sentence. There is no depth-limit in the exclude mechanism, and I'd prefer not to confuse readers by making a casual mention of "depth" to imply as if there is some depth-based logic.
The description "infinite depth" is used in the current documentation in the paragraph
for /**. I thought its good to reuse something that has already been approved by the community.
I think it points out very well that we are not only looking at folders at the level of the .gitignore
file but all the folders below.
Quoted 5 lines
Also, as you defined "intermediate" as a slash that is neither leading nor trailing, the above paragraph says "/foo" matches any filesystem entity whose final path component is 'foo', e.g. a file 'foo' at the current level, a directory 'foo' in subdirectory 'dir' (i.e. 'dir/foo'), etc. I do not think you meant to say that (and
We could fix it by defining an intermediate slash as any slash that is not a trailing one.
But then one may just call it a "non-trailing" slash which is maybe self-explanatory enough.
Quoted 2 lines
this is why I do not like to introduce a new term---even its inventor cannot get it right).
Especially if someone invents a new thing, I would not expect that its perfect right from scratch.
However, I have to admit, the introduced term "intermediate" has its flaws. Maybe using "non-trailing" or a description is better.
Quoted 7 lines
Quoted 4 lines
I agree, this is much better. Although I would leave out
Quoted 2 lines
"as the asterisk in the patter does not match "
bar/hello.c"
which has a slash in it."I happen to think that the part is the more important half of that whole "example".
Alright.
To summarize: I would suggest to drop "it is removed for the purpose of the following description" because of the points
I made at the top and instead mention the necessary exceptions in the two relevant paragraphs. Here my new updated proposals:
If the pattern contains no slash "/" (except an optional trailing slash),
the pattern will match in all directories relative to the .gitignore file, with infinite depth. For example, frotz/ matches frotz and a/frotz that is a directory, but does not match if these are files. A pattern frotz on the other hand matches these paths whether they are files or directories.
I think this is better then my first proposal:
Quoted 9 lines
Quoted 1 line
+ - If the pattern contains no slash "
/" other then a trailing slash,While pretending to be a fresh reader and reading only this line made me wonder if the rule described in this bullet point applies only to a pattern that has a single slash at the end. I wonder if it is just me, or we can improve the phrasing so that it is clear that a pattern without any slash also is covered by this rule, not just a pattern that has all non-slash chars followed by a single slash.
The phrase "except an optional" and the example both point out that this rule works with and without trailing slash.
I kept "infinite depth" for the reasons explained above.
For the next paragraph I would suggest this:
If the pattern contains a non-trailing slash "/", it matches the beginning of the pathname. For example, the pattern doc/frotz/ matches doc/frotz that is a directory
but does not match a/doc/frotz.
Where I have taken it matches the beginning of the pathname from the paragraph of a leading slash.
The example uses a trailing slash, to emphasize that this rule works also with trailing slash, for the case
that the reader confuses the line with "If the pattern contains no trailing slash". Alternatively I would suggest:
If the pattern contains a slash "/" that is not a trailing slash,
it matches the beginning of the pathname. For example, the pattern doc/frotz/ matches doc/frotz that is a directory
but does not match a/doc/frotz.
This might be addressing the problem of my first proposal:
Quoted 4 lines
Quoted 1 line
+ - If the pattern contains a slash "
/" other then a trailing slash, thenThe same comment applies to this first line about the ambiguity of a pattern without any slash anywhere.
All the best,
Adam
Quoted 2 lines · Dr. Adam Nielsen
If the pattern contains no slash "
/"
(except an optional trailing slash),
That's perfect.
Quoted 2 lines
the pattern will match in all directories relative to the
.gitignorefile, with infinite depth.
Maybe it is just me but "in all directories relative to the file" does not say the same thing as
the pattern is matched against paths in the directory where the .gitignore file that has the pattern in it is in, and any of its subdirectories (recursively).
which I think is what we want to say. Especially, I do not think the phrasing implies the match is limited to the directory and its subdirectories, as it is unclear what the words "relative to" wanted to mean in that sentence.
Quoted 4 lines
For example,
frotz/matchesfrotzanda/frotzthat is a directory, but does not match if these are files. A patternfrotzon the other hand matches these paths whether they are files or directories.
Yeah this is good.
Quoted 4 lines
For the next paragraph I would suggest this:
If the pattern contains a non-trailing slash "
/", it matches the beginning of the pathname.
The reference of "it" in "it matches" is fuzzy; first I was confused as I thoguht it refers to the slash (which one? if the pattern has two or more slashes a/b/c).
A pattern with a non-trailing slash matches the beginning of the pathname
would mean the same thing without ambiguity, but I am not sure "matches the beginning of" is quite right.
A pattern doc/frotz that appears in v1.0/.gitignore file would match a file or directory v1.0/doc/frotz (pathnames in these example are all from the top level of the repository).
I think woe most important messages we need to deliver are
- a pattern without slash applies in a directory the pattern "appears in", or any of its subdirectories (recursively).
- a pattern with slash on the other hand is anchored at the directory the pattern "appears in" and does not apply to any of its subdirectories.
So with that in mind, perhaps
Unlike a pattern without a slash, a pattern with a non-trailing slash is matched against paths immediately in the directory the .gitignore file the pattern appears in is stored in, and does not get used in its subdirectories..
or something?
Quoted 3 lines
For example, the pattern
doc/frotz/matchesdoc/frotzthat is a directory
but does not matcha/doc/frotz.
Correct, almost.
For example, the pattern doc/frotz/ that appears in .gitignore at the top-level of the project matches doc/frotz directory (again, seen from the top-level), but not a/doc/frotz.
Also, a pattern "/doc" matches doc at the current level (i.e. the directory in which .gitignore file that the pattern was taken from is found) and not in any subdirectories. Is that clear in the proposed update?
Procedurally (I am writing to make sure we are on the same page for the technical correctness, so that I can let you take care of the ease of understanding of the end result---it is of no use if an easy to understand document describes incorrect behaviour ;-)
* A trailing slash is used *only* to mark that a pattern matches only against directories, and it is ignored by the actual pattern mac.thing logic. It also is ignored by the logic to determine if the pattern is anchored.
e.g. /foo-bar/ becomes /foo-bar but "must match dir" (aka "ends with a slash") is remembered.
* A leading slash is used *only* to mark that a pattern is "anchored" at the current level, and otherwise it is ignored by the actual pattern matching logic.
e.g. /foo-bar that used to be /foo-bar/ then becomes foo-bar but we also remember "must match here" (aka "had a slash in it").
* A slash in a pattern that is not ignored by the above two rules (i.e. your "intermediate slash") marks a pattern as "anchored", i.e. used to match against the paths relative to the current level only.
e.g. foo-bar that used to be /foo-bar that used to be /foo-bar/ thru the above processing, as well as foo/bar that was ignored by the above two rules, are both anchored to the current level, and they do not match a/foo-bar or a/foo/bar in our immediate subdirectory 'a'
Quoted 6 lines
the pattern is matched against paths in the directory where the
.gitignorefile that has the pattern in it is in, and any of its subdirectories (recursively).the pattern will match in all directories relative to the
.gitignorefile, with infinite depth.
I could not catch the difference between the meaning of both. However, I think "paths in the directory" and "directories relative to" are maybe both ambiguous.
Since a pattern without a non-trailing slash must always be a file name or a folder name, and does not have a leading slash, we could maybe just say it like this:
the pattern is matched against all files and folders (recursively) from the location of the .gitignore file.
---------
Quoted 4 lines
Unlike a pattern without a slash, a pattern with a non-trailing slash is matched against paths immediately in the directory the
.gitignorefile the pattern appears in is stored in, and does not get used in its subdirectories..
I think one can always assume that we talking about the relevant .gitignore file (where the pattern appears in).
Perhaps this covers it all?
A pattern with a non-trailing slash is always considered to begin at the .gitignore file location.
followed by your example
Quoted 4 lines
For example, the pattern
doc/frotz/that appears in.gitignoreat the top-level of the project matchesdoc/frotzdirectory (again, seen from the top-level), but nota/doc/frotz.
and maybe one more example
Note that the pattern doc/frotz and /doc/frotz are equivalent.
However /bar and bar are different. They both match the bar file or folder at the top level, but only the latter
will also match foo/bar
(when foo is at the top level).
This avoids the hustle with the ambiguous path, where it starts, and trailing or leading slashes. Together with the
two examples it seems to be a good compromise between accuracy and understandable.
The alternative would be to say
A pattern with a non-trailing slash is only matched against any path that begins in the directory of the .gitignore file.
While this is maybe clearer then saying "pattern [...] always considered to begin at` it is ambiguous about the slashes. So a very accuracy but maybe less understandable version would be something like this:
A pattern with a non-trailing slash is only matched against any path that begins in the directory of the .gitignore file. For example, if the .gitignore file is in folder doc the path to file bar/doc/a/foo that begins in doc is a/foo. A pattern that matches a path except for a leading slash or
trailing slash
is still considered a match. It is still valid however, that when a pattern ends with a slash, it would only find a
match with a directory.
---------
Quoted 4 lines
Also, a pattern "/doc" matches doc at the current level (i.e. the directory in which .gitignore file that the pattern was taken from is found) and not in any subdirectories. Is that clear in the proposed update?
Yes.
However, in the docs is already one paragraph solely dedicated for this case:
Quoted 2 lines
A leading slash matches the beginning of the pathname. For example, "/*.c" matches "
cat-file.c" but not "mozilla-sha1/sha1.c".
However, we have already a better and more in detail explained example in the new
proposal * paragraph and and the case with the leading slash is now a sub-case of A pattern with a non-trailing slash
so we might just get rid of the above paragraph?
----------
Thank you for explaining me how the algorithm works procedurally. It gave some inside of the origin of "If the pattern ends with a slash, it is removed for the purpose of the following description.."
---------
All the best,
Adam
I think its maybe hard to track all the changes that we have discussed so far. Should I create a new PATCH request including all the changes from the recent mails and then we continue the discussion from there?
Best regards,
Adam
Am Mi., 10. Apr. 2019 um 09:39 Uhr schrieb Dr. Adam Nielsen <[email protected]>:
Quoted 104 lines
Quoted 7 lines
the pattern is matched against paths in the directory where the
.gitignorefile that has the pattern in it is in, and any of its subdirectories (recursively).the pattern will match in all directories relative to the
.gitignorefile, with infinite depth.I could not catch the difference between the meaning of both. However, I think "paths in the directory" and "directories relative to" are maybe both ambiguous.
Since a pattern without a non-trailing slash must always be a file name or a folder name, and does not have a leading slash, we could maybe just say it like this:
the pattern is matched against all files and folders (recursively) from the location of the
.gitignorefile.
---------Quoted 4 lines
Unlike a pattern without a slash, a pattern with a non-trailing slash is matched against paths immediately in the directory the
.gitignorefile the pattern appears in is stored in, and does not get used in its subdirectories..I think one can always assume that we talking about the relevant
.gitignorefile (where the pattern appears in).Perhaps this covers it all?
A pattern with a non-trailing slash is always considered to begin at the
.gitignorefile location.followed by your example
Quoted 4 lines
For example, the pattern
doc/frotz/that appears in.gitignoreat the top-level of the project matchesdoc/frotzdirectory (again, seen from the top-level), but nota/doc/frotz.and maybe one more example
Note that the pattern
doc/frotzand/doc/frotzare equivalent.
However/barandbarare different. They both match thebarfile or folder at the top level, but only the latter
will also matchfoo/bar
(whenfoois at the top level).This avoids the hustle with the ambiguous path, where it starts, and trailing or leading slashes. Together with the
two examples it seems to be a good compromise between accuracy and understandable.The alternative would be to say
A pattern with a non-trailing slash is only matched against any path that begins in the directory of the
.gitignorefile.While this is maybe clearer then saying "pattern [...] always considered to begin at` it is ambiguous about the slashes. So a very accuracy but maybe less understandable version would be something like this:
A pattern with a non-trailing slash is only matched against any path that begins in the directory of the
.gitignorefile. For example, if the.gitignorefile is in folderdocthe path to filebar/doc/a/foothat begins indocisa/foo. A pattern that matches a path except for a leading slash or
trailing slash
is still considered a match. It is still valid however, that when a pattern ends with a slash, it would only find a
match with a directory.---------
Quoted 4 lines
Also, a pattern "/doc" matches doc at the current level (i.e. the directory in which .gitignore file that the pattern was taken from is found) and not in any subdirectories. Is that clear in the proposed update?
Yes.
However, in the docs is already one paragraph solely dedicated for this case:
Quoted 2 lines
A leading slash matches the beginning of the pathname. For example, "/*.c" matches "
cat-file.c" but not "mozilla-sha1/sha1.c".However, we have already a better and more in detail explained example in the new
proposal*paragraph and and the case with the leading slash is now a sub-case ofA pattern with a non-trailing slash
so we might just get rid of the above paragraph?
----------Thank you for explaining me how the algorithm works procedurally. It gave some inside of the origin of "If the pattern ends with a slash, it is removed for the purpose of the following description.."
---------All the best,
Adam