summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-05-21 12:18:47 +0200
committerGitHub <noreply@github.com>2019-05-21 12:18:47 +0200
commit4aa36ff2c0fe2e7b29220737c757ffff99e00059 (patch)
tree23aa0cf89846bf448d4b74696c909ea0e77ed00a /src
parent6b9cc0290f8310c5ea43351077476e9601c29783 (diff)
parent133bcebad9af73395f1c1e09f85e7e980bd20744 (diff)
downloadlibgit2-4aa36ff2c0fe2e7b29220737c757ffff99e00059.tar.gz
Merge pull request #5075 from libgit2/ethomson/ignore_skip_bom
Skip UTF8 BOM in ignore files
Diffstat (limited to 'src')
-rw-r--r--src/attr_file.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/attr_file.c b/src/attr_file.c
index 8619647a3..ddd44703a 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -10,6 +10,7 @@
#include "repository.h"
#include "filebuf.h"
#include "attrcache.h"
+#include "buf_text.h"
#include "git2/blob.h"
#include "git2/tree.h"
#include "blob.h"
@@ -108,9 +109,12 @@ int git_attr_file__load(
int error = 0;
git_blob *blob = NULL;
git_buf content = GIT_BUF_INIT;
+ const char *content_str;
git_attr_file *file;
struct stat st;
bool nonexistent = false;
+ int bom_offset;
+ git_bom_t bom;
*out = NULL;
@@ -159,13 +163,20 @@ int git_attr_file__load(
if ((error = git_attr_file__new(&file, entry, source)) < 0)
goto cleanup;
+ /* advance over a UTF8 BOM */
+ content_str = git_buf_cstr(&content);
+ bom_offset = git_buf_text_detect_bom(&bom, &content);
+
+ if (bom == GIT_BOM_UTF8)
+ content_str += bom_offset;
+
/* store the key of the attr_reader; don't bother with cache
* invalidation during the same attr reader session.
*/
if (attr_session)
file->session_key = attr_session->key;
- if (parser && (error = parser(repo, file, git_buf_cstr(&content))) < 0) {
+ if (parser && (error = parser(repo, file, content_str)) < 0) {
git_attr_file__free(file);
goto cleanup;
}