]> git.ipfire.org Git - thirdparty/git.git/blobdiff - dir.c
dir: allow a BOM at the beginning of exclude files
[thirdparty/git.git] / dir.c
diff --git a/dir.c b/dir.c
index fcb68729b1f559008e1797ff50f38acf81268d3d..10c1f903efc5ddff840782bae7a115b895a068a8 100644 (file)
--- 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] != '#') {
@@ -826,9 +832,9 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
        current = stk ? stk->baselen : -1;
        strbuf_setlen(&dir->basebuf, current < 0 ? 0 : current);
        while (current < baselen) {
-               struct exclude_stack *stk = xcalloc(1, sizeof(*stk));
                const char *cp;
 
+               stk = xcalloc(1, sizeof(*stk));
                if (current < 0) {
                        cp = base;
                        current = 0;
@@ -1507,12 +1513,16 @@ int dir_inside_of(const char *subdir, const char *dir)
 
 int is_inside_dir(const char *dir)
 {
-       char cwd[PATH_MAX];
+       char *cwd;
+       int rc;
+
        if (!dir)
                return 0;
-       if (!getcwd(cwd, sizeof(cwd)))
-               die_errno("can't find the current directory");
-       return dir_inside_of(cwd, dir) >= 0;
+
+       cwd = xgetcwd();
+       rc = (dir_inside_of(cwd, dir) >= 0);
+       free(cwd);
+       return rc;
 }
 
 int is_empty_dir(const char *path)