X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=config.c;h=b8d289d21789b5017579d90b7894db8ebee4c47a;hb=1689c5de8730ea334535337a341db3c7a21ad002;hp=1e066c71e0fbc4b172ef548663e660e636d6a916;hpb=e75bf76f5462af4185d8260f6feecf24dd24a516;p=git.git diff --git a/config.c b/config.c index 1e066c71e..b8d289d21 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; @@ -255,7 +274,7 @@ static int parse_unit_factor(const char *end, unsigned long *val) return 0; } -int git_parse_long(const char *value, long *ret) +static int git_parse_long(const char *value, long *ret) { if (value && *value) { char *end; @@ -291,7 +310,7 @@ static void die_bad_config(const char *name) int git_config_int(const char *name, const char *value) { - long ret; + long ret = 0; if (!git_parse_long(value, &ret)) die_bad_config(name); return ret; @@ -341,6 +360,10 @@ static int git_default_core_config(const char *var, const char *value) trust_executable_bit = git_config_bool(var, value); return 0; } + if (!strcmp(var, "core.trustctime")) { + trust_ctime = git_config_bool(var, value); + return 0; + } if (!strcmp(var, "core.quotepath")) { quote_path_fully = git_config_bool(var, value); @@ -730,9 +753,8 @@ static int store_write_section(int fd, const char* key) { const char *dot; int i, success; - struct strbuf sb; + struct strbuf sb = STRBUF_INIT; - strbuf_init(&sb, 0); dot = memchr(key, '.', store.baselen); if (dot) { strbuf_addf(&sb, "[%.*s \"", (int)(dot - key), key); @@ -757,7 +779,7 @@ static int store_write_pair(int fd, const char* key, const char* value) int i, success; int length = strlen(key + store.baselen + 1); const char *quote = ""; - struct strbuf sb; + struct strbuf sb = STRBUF_INIT; /* * Check to see if the value needs to be surrounded with a dq pair. @@ -774,7 +796,6 @@ static int store_write_pair(int fd, const char* key, const char* value) if (i && value[i - 1] == ' ') quote = "\""; - strbuf_init(&sb, 0); strbuf_addf(&sb, "\t%.*s = %s", length, key + store.baselen + 1, quote);