summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2014-02-09 00:26:38 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-02-10 19:49:53 (GMT)
commit7e2e4b37d3d57a95a525ba1a18224ba04f858768 (patch)
tree4f4db8edbe17b887b4c641c34a59c824a16f5a68 /dir.c
parent16402b992e0332d2ac68106f4488b47175bf0a13 (diff)
downloadgit-7e2e4b37d3d57a95a525ba1a18224ba04f858768.zip
git-7e2e4b37d3d57a95a525ba1a18224ba04f858768.tar.gz
git-7e2e4b37d3d57a95a525ba1a18224ba04f858768.tar.bz2
dir: ignore trailing spaces in exclude patterns
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/dir.c b/dir.c
index 065491b..f6743b3 100644
--- a/dir.c
+++ b/dir.c
@@ -463,20 +463,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,
@@ -530,7 +533,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++;