summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@elego.de>2015-04-16 14:05:12 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-04-16 17:17:04 (GMT)
commit245e1c196dab226675a02a8caca5a83373f5e4d4 (patch)
tree16a1586a6baed9c7d4203f6a5f9ce5c8efc876c7 /dir.c
parentfdf96a20acf96a6ac538df8113b2aafd6ed71d50 (diff)
downloadgit-245e1c196dab226675a02a8caca5a83373f5e4d4.zip
git-245e1c196dab226675a02a8caca5a83373f5e4d4.tar.gz
git-245e1c196dab226675a02a8caca5a83373f5e4d4.tar.bz2
dir: allow a BOM at the beginning of exclude files
Some text editors like Notepad or LibreOffice write an UTF-8 BOM in order to indicate that the file is Unicode text rather than whatever the current locale would indicate. If someone uses such an editor to edit a gitignore file, we are left with those three bytes at the beginning of the file. If we do not skip them, we will attempt to match a filename with the BOM as prefix, which won't match the files the user is expecting. Signed-off-by: Carlos Martín Nieto <cmn@elego.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/dir.c b/dir.c
index 3f7a025..10c1f90 100644
--- a/dir.c
+++ b/dir.c
@@ -538,6 +538,7 @@ int add_excludes_from_file_to_list(const char *fname,
struct stat st;
int fd, i, lineno = 1;
size_t size = 0;
+ static const unsigned char *utf8_bom = (unsigned char *) "\xef\xbb\xbf";
char *buf, *entry;
fd = open(fname, O_RDONLY);
@@ -574,7 +575,12 @@ int add_excludes_from_file_to_list(const char *fname,
}
el->filebuf = buf;
- entry = buf;
+
+ if (size >= 3 && !memcmp(buf, utf8_bom, 3))
+ entry = buf + 3;
+ else
+ entry = buf;
+
for (i = 0; i < size; i++) {
if (buf[i] == '\n') {
if (entry != buf + i && entry[0] != '#') {