From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: "Carlos Martín Nieto" <cmn@elego.de>, "Jeff King" <peff@peff.net>
Subject: [PATCH 1/3] utf8-bom: introduce skip_utf8_bom() helper
Date: Thu, 16 Apr 2015 10:52:52 -0700 [thread overview]
Message-ID: <1429206774-10087-2-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1429206774-10087-1-git-send-email-gitster@pobox.com>
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>
---
dir.c | 8 +++-----
utf8.c | 11 +++++++++++
utf8.h | 3 +++
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/dir.c b/dir.c
index 10c1f90..9e04a23 100644
--- a/dir.c
+++ b/dir.c
@@ -12,6 +12,7 @@
#include "refs.h"
#include "wildmatch.h"
#include "pathspec.h"
+#include "utf8.h"
struct path_simplify {
int len;
@@ -538,7 +539,6 @@ 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);
@@ -576,10 +576,8 @@ int add_excludes_from_file_to_list(const char *fname,
el->filebuf = buf;
- if (size >= 3 && !memcmp(buf, utf8_bom, 3))
- entry = buf + 3;
- else
- entry = buf;
+ entry = buf;
+ skip_utf8_bom(&entry, size);
for (i = 0; i < size; i++) {
if (buf[i] == '\n') {
diff --git a/utf8.c b/utf8.c
index 520fbb4..28e6d76 100644
--- a/utf8.c
+++ b/utf8.c
@@ -633,3 +633,14 @@ int is_hfs_dotgit(const char *path)
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;
+}
diff --git a/utf8.h b/utf8.h
index e4d9183..e7b2aa4 100644
--- a/utf8.h
+++ b/utf8.h
@@ -13,6 +13,9 @@ int same_encoding(const char *, const char *);
__attribute__((format (printf, 2, 3)))
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,
const char *text, int indent, int indent2, int width);
void strbuf_add_wrapped_bytes(struct strbuf *buf, const char *data, int len,
--
2.4.0-rc2-171-g98ddf7f
next prev parent reply other threads:[~2015-04-16 17:53 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-16 14:05 [PATCH] dir: allow a BOM at the beginning of exclude files Carlos Martín Nieto
2015-04-16 15:03 ` Johannes Schindelin
2015-04-16 15:09 ` Carlos Martín Nieto
2015-04-16 15:10 ` Carlos Martín Nieto
2015-04-16 15:39 ` Junio C Hamano
2015-04-16 15:55 ` Jeff King
2015-04-16 17:16 ` Junio C Hamano
2015-04-16 17:52 ` [PATCH 0/3] UTF8 BOM follow-up Junio C Hamano
2015-04-16 17:52 ` Junio C Hamano [this message]
2015-04-16 18:14 ` [PATCH 1/3] utf8-bom: introduce skip_utf8_bom() helper Jeff King
2015-04-16 18:23 ` Junio C Hamano
2015-04-16 17:52 ` [PATCH 2/3] config: use utf8_bom[] from utf.[ch] in git_parse_source() Junio C Hamano
2015-04-16 17:52 ` [PATCH 3/3] attr: skip UTF8 BOM at the beginning of the input file Junio C Hamano
2015-04-16 18:27 ` [PATCH] dir: allow a BOM at the beginning of exclude files Carlos Martín Nieto
2015-04-16 18:39 ` [PATCH v2 0/4] UTF8 BOM follow-up Junio C Hamano
2015-04-16 18:39 ` [PATCH v2 1/4] add_excludes_from_file: clarify the bom skipping logic Junio C Hamano
2015-04-16 18:39 ` [PATCH v2 2/4] utf8-bom: introduce skip_utf8_bom() helper Junio C Hamano
2015-04-16 18:39 ` [PATCH v2 3/4] config: use utf8_bom[] from utf.[ch] in git_parse_source() Junio C Hamano
2015-04-16 18:39 ` [PATCH v2 4/4] attr: skip UTF8 BOM at the beginning of the input file Junio C Hamano
2015-04-16 19:26 ` [PATCH v2 0/4] UTF8 BOM follow-up Jeff King
2015-04-17 22:44 ` Karsten Blees
2015-04-20 21:50 ` Junio C Hamano
2015-04-16 16:08 ` [PATCH] dir: allow a BOM at the beginning of exclude files Johannes Schindelin
2015-04-16 16:10 ` Torsten Bögershausen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1429206774-10087-2-git-send-email-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=cmn@elego.de \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.