mirror of
https://github.com/git/git.git
synced 2024-11-23 18:05:29 +08:00
utf8-bom: introduce skip_utf8_bom() helper
With the recent change to ignore the UTF8 BOM at the beginning of .gitignore files, we now have two codepaths that do such a skipping (the other one is for reading the configuration files). Introduce utf8_bom[] constant string and skip_utf8_bom() helper and teach .gitignore code how to use it. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
cb0abea870
commit
dde843e737
9
dir.c
9
dir.c
@ -12,6 +12,7 @@
|
|||||||
#include "refs.h"
|
#include "refs.h"
|
||||||
#include "wildmatch.h"
|
#include "wildmatch.h"
|
||||||
#include "pathspec.h"
|
#include "pathspec.h"
|
||||||
|
#include "utf8.h"
|
||||||
|
|
||||||
struct path_simplify {
|
struct path_simplify {
|
||||||
int len;
|
int len;
|
||||||
@ -538,7 +539,6 @@ int add_excludes_from_file_to_list(const char *fname,
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
int fd, i, lineno = 1;
|
int fd, i, lineno = 1;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
static const unsigned char *utf8_bom = (unsigned char *) "\xef\xbb\xbf";
|
|
||||||
char *buf, *entry;
|
char *buf, *entry;
|
||||||
|
|
||||||
fd = open(fname, O_RDONLY);
|
fd = open(fname, O_RDONLY);
|
||||||
@ -576,10 +576,9 @@ int add_excludes_from_file_to_list(const char *fname,
|
|||||||
|
|
||||||
el->filebuf = buf;
|
el->filebuf = buf;
|
||||||
|
|
||||||
if (size >= 3 && !memcmp(buf, utf8_bom, 3)) {
|
if (skip_utf8_bom(&buf, size))
|
||||||
buf += 3;
|
size -= buf - el->filebuf;
|
||||||
size -= 3;
|
|
||||||
}
|
|
||||||
entry = buf;
|
entry = buf;
|
||||||
|
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
|
11
utf8.c
11
utf8.c
@ -633,3 +633,14 @@ int is_hfs_dotgit(const char *path)
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char utf8_bom[] = "\357\273\277";
|
||||||
|
|
||||||
|
int skip_utf8_bom(char **text, size_t len)
|
||||||
|
{
|
||||||
|
if (len < strlen(utf8_bom) ||
|
||||||
|
memcmp(*text, utf8_bom, strlen(utf8_bom)))
|
||||||
|
return 0;
|
||||||
|
*text += strlen(utf8_bom);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
3
utf8.h
3
utf8.h
@ -13,6 +13,9 @@ int same_encoding(const char *, const char *);
|
|||||||
__attribute__((format (printf, 2, 3)))
|
__attribute__((format (printf, 2, 3)))
|
||||||
int utf8_fprintf(FILE *, const char *, ...);
|
int utf8_fprintf(FILE *, const char *, ...);
|
||||||
|
|
||||||
|
extern const char utf8_bom[];
|
||||||
|
extern int skip_utf8_bom(char **, size_t);
|
||||||
|
|
||||||
void strbuf_add_wrapped_text(struct strbuf *buf,
|
void strbuf_add_wrapped_text(struct strbuf *buf,
|
||||||
const char *text, int indent, int indent2, int width);
|
const char *text, int indent, int indent2, int width);
|
||||||
void strbuf_add_wrapped_bytes(struct strbuf *buf, const char *data, int len,
|
void strbuf_add_wrapped_bytes(struct strbuf *buf, const char *data, int len,
|
||||||
|
Loading…
Reference in New Issue
Block a user