File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 1010#include "repository.h"
1111#include "filebuf.h"
1212#include "attrcache.h"
13+ #include "buf_text.h"
1314#include "git2/blob.h"
1415#include "git2/tree.h"
1516#include "blob.h"
@@ -108,9 +109,12 @@ int git_attr_file__load(
108109 int error = 0 ;
109110 git_blob * blob = NULL ;
110111 git_buf content = GIT_BUF_INIT ;
112+ const char * content_str ;
111113 git_attr_file * file ;
112114 struct stat st ;
113115 bool nonexistent = false;
116+ int bom_offset ;
117+ git_bom_t bom ;
114118
115119 * out = NULL ;
116120
@@ -159,13 +163,20 @@ int git_attr_file__load(
159163 if ((error = git_attr_file__new (& file , entry , source )) < 0 )
160164 goto cleanup ;
161165
166+ /* advance over a UTF8 BOM */
167+ content_str = git_buf_cstr (& content );
168+ bom_offset = git_buf_text_detect_bom (& bom , & content );
169+
170+ if (bom == GIT_BOM_UTF8 )
171+ content_str += bom_offset ;
172+
162173 /* store the key of the attr_reader; don't bother with cache
163174 * invalidation during the same attr reader session.
164175 */
165176 if (attr_session )
166177 file -> session_key = attr_session -> key ;
167178
168- if (parser && (error = parser (repo , file , git_buf_cstr ( & content ) )) < 0 ) {
179+ if (parser && (error = parser (repo , file , content_str )) < 0 ) {
169180 git_attr_file__free (file );
170181 goto cleanup ;
171182 }
You can’t perform that action at this time.
0 commit comments