Re: [PATCH 0/1] gitignore: ignore comments on the same line as a pattern

2019-10-01 Thread Junio C Hamano
"Chris Zehner via GitGitGadget"  writes:

> Why make this change?
> =
>
> Add the ability to use # to put comments after ignore patterns. This is
> useful for documenting the reason for particular ignore patterns inclusion
> and structure.
>
> Right now a common convention in .gitignore files is to group patterns by
> similarity, using new lines beginning with one or more # characters as
> headings to explain these groupings. This works well when clarifying why
> broad classes of things are ignored, e.g. # build artifacts followed by
> several patterns.
>
> When leaving comments about a particular pattern it can be difficult to
> distinguish comments about a single patterns from comments used for file
> organization.

Not a good enough justification to break backward compatibility, I
would have to say.  If a single line is so tricky to deserve its own
comment, perhaps a group of lines can be separated with the next
group by a handful of blank lines for clarity (or the project can
adopt a convention that differentiates between comments on a group
and comments on an individual rule).


[PATCH 0/1] gitignore: ignore comments on the same line as a pattern

2019-10-01 Thread Chris Zehner via GitGitGadget
Why make this change?
=

Add the ability to use # to put comments after ignore patterns. This is
useful for documenting the reason for particular ignore patterns inclusion
and structure.

Right now a common convention in .gitignore files is to group patterns by
similarity, using new lines beginning with one or more # characters as
headings to explain these groupings. This works well when clarifying why
broad classes of things are ignored, e.g. # build artifacts followed by
several patterns.

When leaving comments about a particular pattern it can be difficult to
distinguish comments about a single patterns from comments used for file
organization.

Comments left after a pattern are unambiguously related to that line, and
that line only.

What should this change do?
===

The entirety of a string after a non-escaped #, including the #, is removed
from the pattern in a .gitignore file.

Why make the change this way?
=

I don't normally write C, so I probably overlooked more idiomatic ways to do
this. This is done similarly to the way trim_trailing_spaces removes
extraneous spaces from patterns.

Potentially this change could be combined with the existing code for
trim_trailing_spaces, but the logic is slightly different and it seems to me
that the difference in naming aids readability by making it clear what the
responsibilities are for each function.

How can we test this change works?
==

That's one area I'd like help with, please.

Test cases:

/pattern/to/match
# Existing comment
/pattern/with/comment # This comment is ignored
/pattern/with/\#octothorpe # \#octothorpe is ignored

I wasn't sure where the correct place to add these would be, I didn't see
(and potentially overlooked) any tests in /t/* that cover this
functionality. Would someone be willing to provide a pointer to the correct
place to add these tests?

Signed-off-by: Chris Zehner cbzeh...@gmail.com [cbzeh...@gmail.com]

Chris Zehner (1):
  gitignore: ignore comments on the same line as a pattern

 Documentation/gitignore.txt |  8 ++--
 dir.c   | 33 +
 2 files changed, 39 insertions(+), 2 deletions(-)


base-commit: bc12974a897308fd3254cf0cc90319078fe45eea
Published-As: 
https://github.com/gitgitgadget/git/releases/tag/pr-370%2Fcbzehner%2Fgitignore-pattern-comment-oneline-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git 
pr-370/cbzehner/gitignore-pattern-comment-oneline-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/370
-- 
gitgitgadget