From: Petr Baudis <pasky@suse.cz>
To: git@vger.kernel.org
To: git@vger.kernel.org
Cc: Petr Baudis <petr.baudis@novartis.com>
Subject: [PATCH] config.c: Tolerate UTF8 BOM at the beginning of config file
Date: Wed, 1 Oct 2008 22:13:02 +0200 [thread overview]
Message-ID: <1222891982-24193-1-git-send-email-pasky@suse.cz> (raw)
Unfortunately, the abomination of Windows Notepad likes to scatted
non-sensical UTF8 BOM marks across text files it edits. This is
especially troublesome when editing the Git configuration file,
and it does not appear to be particularly harmful to teach Git
to deal with this poo in the configfile.
Signed-off-by: Petr Baudis <petr.baudis@novartis.com>
---
config.c | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/config.c b/config.c
index 53f04a0..1d30120 100644
--- a/config.c
+++ b/config.c
@@ -205,8 +205,27 @@ static int git_parse_file(config_fn_t fn, void *data)
int baselen = 0;
static char var[MAXNAME];
+ /* U+FEFF Byte Order Mark in UTF8 */
+ static const unsigned char *utf8_bom = (unsigned char *) "\xef\xbb\xbf";
+ const unsigned char *bomptr = utf8_bom;
+
for (;;) {
int c = get_next_char();
+ if (bomptr && *bomptr) {
+ /* We are at the file beginning; skip UTF8-encoded BOM
+ * if present. Sane editors won't put this in on their
+ * own, but e.g. Windows Notepad will do it happily. */
+ if ((unsigned char) c == *bomptr) {
+ bomptr++;
+ continue;
+ } else {
+ /* Do not tolerate partial BOM. */
+ if (bomptr != utf8_bom)
+ break;
+ /* No BOM at file beginning. Cool. */
+ bomptr = NULL;
+ }
+ }
if (c == '\n') {
if (config_file_eof)
return 0;
--
tg: (9800c0d..) t/config/utf8-bom (depends on: vanilla/master)
reply other threads:[~2008-10-01 20:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1222891982-24193-1-git-send-email-pasky@suse.cz \
--to=pasky@suse.cz \
--cc=git@vger.kernel.org \
--cc=petr.baudis@novartis.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).