Re: [PATCH 1/2] dir: warn about trailing spaces in exclude pattern
From: Torsten Bögershausen <hidden>
Date: 2016-06-15 22:59:52
On 2014-02-08 09.10, Nguyễn Thái Ngọc Duy wrote:
quoted hunk ↗ jump to hunk
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted> --- dir.c | 11 +++++++++++ 1 file changed, 11 insertions(+)diff --git a/dir.c b/dir.c index b35b633..9edde44 100644 --- a/dir.c +++ b/dir.c@@ -491,6 +491,16 @@ void clear_exclude_list(struct exclude_list *el) el->filebuf = NULL; } +static void check_trailing_spaces(const char *fname, char *buf) +{ + int len = strlen(buf); + while (len && buf[len - 1] == ' ') + len--; + if (buf[len] != '\0')
Do we need the while loop here, (when we only warn) ?
+ warning(_("%s: trailing spaces in '%s'. Please quote them."),
+ fname, buf);
+}This is nice. However we can hint the user that there are 2 choices:
warning(_("%s: trailing spaces in '%s'. Please remove them or quote them."),quoted hunk ↗ jump to hunk
+ int add_excludes_from_file_to_list(const char *fname, const char *base, int baselen,@@ -542,6 +552,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); add_exclude(entry, base, baselen, el, lineno); } lineno++;