From: Junio C Hamano Date: Mon, 16 Jun 2014 17:07:16 +0000 (-0700) Subject: Merge branch 'jk/strbuf-tolower' X-Git-Tag: v2.1.0-rc0~123 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/b4bba8de115b6aa48103443cc81a3be7111095a9?ds=inline;hp=-c Merge branch 'jk/strbuf-tolower' * jk/strbuf-tolower: strbuf: add strbuf_tolower function --- b4bba8de115b6aa48103443cc81a3be7111095a9 diff --combined Documentation/technical/api-strbuf.txt index 4396be9dda,8480f8902d..50690186d3 --- a/Documentation/technical/api-strbuf.txt +++ b/Documentation/technical/api-strbuf.txt @@@ -121,19 -121,14 +121,23 @@@ Function * Related to the contents of the buffer +`strbuf_trim`:: + + Strip whitespace from the beginning and end of a string. + Equivalent to performing `strbuf_rtrim()` followed by `strbuf_ltrim()`. + `strbuf_rtrim`:: Strip whitespace from the end of a string. +`strbuf_ltrim`:: + + Strip whitespace from the beginning of a string. + + `strbuf_tolower`:: + + Lowercase each character in the buffer using `tolower`. + `strbuf_cmp`:: Compare two buffers. Returns an integer less than, equal to, or greater diff --combined config.c index 3c3e31448e,03ce5c6844..9319aa12f3 --- a/config.c +++ b/config.c @@@ -147,12 -147,6 +147,6 @@@ int git_config_include(const char *var return ret; } - static void lowercase(char *p) - { - for (; *p; p++) - *p = tolower(*p); - } - void git_config_push_parameter(const char *text) { struct strbuf env = STRBUF_INIT; @@@ -180,7 -174,7 +174,7 @@@ int git_config_parse_parameter(const ch strbuf_list_free(pair); return error("bogus config parameter: %s", text); } - lowercase(pair[0]->buf); + strbuf_tolower(pair[0]); if (fn(pair[0]->buf, pair[1] ? pair[1]->buf : NULL, data) < 0) { strbuf_list_free(pair); return -1; @@@ -826,16 -820,9 +820,16 @@@ static int git_default_core_config(cons if (!strcmp(var, "core.commentchar")) { const char *comment; int ret = git_config_string(&comment, var, value); - if (!ret) + if (ret) + return ret; + else if (!strcasecmp(comment, "auto")) + auto_comment_line_char = 1; + else if (comment[0] && !comment[1]) { comment_line_char = comment[0]; - return ret; + auto_comment_line_char = 0; + } else + return error("core.commentChar should only be one character"); + return 0; } if (!strcmp(var, "core.askpass")) @@@ -1643,13 -1630,6 +1637,13 @@@ int git_config_set_multivar_in_file(con MAP_PRIVATE, in_fd, 0); close(in_fd); + if (fchmod(fd, st.st_mode & 07777) < 0) { + error("fchmod on %s failed: %s", + lock->filename, strerror(errno)); + ret = CONFIG_NO_WRITE; + goto out_free; + } + if (store.seen == 0) store.seen = 1; @@@ -1798,7 -1778,6 +1792,7 @@@ int git_config_rename_section_in_file(c int out_fd; char buf[1024]; FILE *config_file; + struct stat st; if (new_name && !section_name_is_ok(new_name)) { ret = error("invalid section name: %s", new_name); @@@ -1820,14 -1799,6 +1814,14 @@@ goto unlock_and_out; } + fstat(fileno(config_file), &st); + + if (fchmod(out_fd, st.st_mode & 07777) < 0) { + ret = error("fchmod on %s failed: %s", + lock->filename, strerror(errno)); + goto out; + } + while (fgets(buf, sizeof(buf), config_file)) { int i; int length; diff --combined strbuf.c index f5d609a51f,1a673fc72e..c8217755e5 --- a/strbuf.c +++ b/strbuf.c @@@ -78,8 -78,15 +78,8 @@@ void strbuf_grow(struct strbuf *sb, siz void strbuf_trim(struct strbuf *sb) { - char *b = sb->buf; - while (sb->len > 0 && isspace((unsigned char)sb->buf[sb->len - 1])) - sb->len--; - while (sb->len > 0 && isspace(*b)) { - b++; - sb->len--; - } - memmove(sb->buf, b, sb->len); - sb->buf[sb->len] = '\0'; + strbuf_rtrim(sb); + strbuf_ltrim(sb); } void strbuf_rtrim(struct strbuf *sb) { @@@ -99,6 -106,13 +99,13 @@@ void strbuf_ltrim(struct strbuf *sb sb->buf[sb->len] = '\0'; } + void strbuf_tolower(struct strbuf *sb) + { + char *p = sb->buf, *end = sb->buf + sb->len; + for (; p < end; p++) + *p = tolower(*p); + } + struct strbuf **strbuf_split_buf(const char *str, size_t slen, int terminator, int max) { @@@ -563,16 -577,3 +570,16 @@@ int fprintf_ln(FILE *fp, const char *fm return -1; return ret + 1; } + +char *xstrdup_tolower(const char *string) +{ + char *result; + size_t len, i; + + len = strlen(string); + result = xmalloc(len + 1); + for (i = 0; i < len; i++) + result[i] = tolower(string[i]); + result[i] = '\0'; + return result; +} diff --combined strbuf.h index 4de7531c43,6b6f745e01..25328b9e81 --- a/strbuf.h +++ b/strbuf.h @@@ -45,6 -45,7 +45,7 @@@ static inline void strbuf_setlen(struc extern void strbuf_trim(struct strbuf *); extern void strbuf_rtrim(struct strbuf *); extern void strbuf_ltrim(struct strbuf *); + extern void strbuf_tolower(struct strbuf *sb); extern int strbuf_cmp(const struct strbuf *, const struct strbuf *); /* @@@ -183,6 -184,4 +184,6 @@@ extern int printf_ln(const char *fmt, . __attribute__((format (printf,2,3))) extern int fprintf_ln(FILE *fp, const char *fmt, ...); +char *xstrdup_tolower(const char *); + #endif /* STRBUF_H */