From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 2/2] dir: ignore trailing spaces in exclude patterns
Date: Sun, 9 Feb 2014 07:26:38 +0700 [thread overview]
Message-ID: <1391905598-19198-3-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1391905598-19198-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
Documentation/gitignore.txt | 3 +++
dir.c | 21 ++++++++++++---------
t/t0008-ignores.sh | 8 ++++----
3 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index b08d34d..8734c15 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -77,6 +77,9 @@ PATTERN FORMAT
Put a backslash ("`\`") in front of the first hash for patterns
that begin with a hash.
+ - Trailing spaces are ignored unless they are quoted with backlash
+ ("`\`").
+
- An optional prefix "`!`" which negates the pattern; any
matching file excluded by a previous pattern will become
included again. It is not possible to re-include a file if a parent
diff --git a/dir.c b/dir.c
index 6162209..70076b5 100644
--- a/dir.c
+++ b/dir.c
@@ -491,20 +491,23 @@ void clear_exclude_list(struct exclude_list *el)
el->filebuf = NULL;
}
-static void check_trailing_spaces(const char *fname, char *buf)
+static void trim_trailing_spaces(char *buf)
{
- int i, last_space = -1, len = strlen(buf);
+ int i, last_space = -1, nr_spaces, len = strlen(buf);
for (i = 0; i < len; i++)
if (buf[i] == '\\')
i++;
- else if (buf[i] == ' ')
- last_space = i;
- else
+ else if (buf[i] == ' ') {
+ if (last_space == -1) {
+ last_space = i;
+ nr_spaces = 1;
+ } else
+ nr_spaces++;
+ } else
last_space = -1;
- if (last_space == len - 1)
- warning(_("%s: trailing spaces in '%s'. Please quote or remove them."),
- fname, buf);
+ if (last_space != -1 && last_space + nr_spaces == len)
+ buf[last_space] = '\0';
}
int add_excludes_from_file_to_list(const char *fname,
@@ -558,7 +561,7 @@ int add_excludes_from_file_to_list(const char *fname,
if (buf[i] == '\n') {
if (entry != buf + i && entry[0] != '#') {
buf[i - (i && buf[i-1] == '\r')] = 0;
- check_trailing_spaces(fname, entry);
+ trim_trailing_spaces(entry);
add_exclude(entry, base, baselen, el, lineno);
}
lineno++;
diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh
index 9e1d64c..bbaf6b5 100755
--- a/t/t0008-ignores.sh
+++ b/t/t0008-ignores.sh
@@ -779,18 +779,18 @@ test_expect_success PIPE 'streaming support for --stdin' '
#
# test whitespace handling
-test_expect_success 'trailing whitespace is warned' '
+test_expect_success 'trailing whitespace is ignored' '
mkdir whitespace &&
>whitespace/trailing &&
>whitespace/untracked &&
echo "whitespace/trailing " >ignore &&
cat >expect <<EOF &&
-whitespace/trailing
whitespace/untracked
EOF
+ : >err.expect &&
git ls-files -o -X ignore whitespace >actual 2>err &&
- grep "ignore:.*'\''whitespace/trailing '\''" err &&
- test_cmp expect actual
+ test_cmp expect actual &&
+ test_cmp err.expect err
'
test_expect_success 'quoting allows trailing whitespace' '
--
1.8.5.2.240.g8478abd
next prev parent reply other threads:[~2014-02-09 0:27 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-08 8:10 [PATCH 0/2] Ignore trailing spaces in .gitignore Nguyễn Thái Ngọc Duy
2014-02-08 8:10 ` [PATCH 1/2] dir: warn about trailing spaces in exclude pattern Nguyễn Thái Ngọc Duy
2014-02-08 14:33 ` Torsten Bögershausen
2014-02-08 8:10 ` [PATCH 2/2] dir: ignore trailing spaces in exclude patterns Nguyễn Thái Ngọc Duy
2014-02-08 16:45 ` [PATCH 0/2] Ignore trailing spaces in .gitignore Jeff King
2014-02-08 23:48 ` Duy Nguyen
2014-02-10 1:19 ` Jeff King
2014-02-09 0:26 ` [PATCH v2 " Nguyễn Thái Ngọc Duy
2014-02-09 0:26 ` [PATCH v2 1/2] dir: warn about trailing spaces in exclude patterns Nguyễn Thái Ngọc Duy
2014-02-09 0:26 ` Nguyễn Thái Ngọc Duy [this message]
2014-02-10 4:07 ` [PATCH 0/2] Ignore trailing spaces in .gitignore Junio C Hamano
2014-02-10 4:29 ` Duy Nguyen
2014-02-10 5:04 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1391905598-19198-3-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).