config: flip return value of store_write_*()

The store_write_section() and store_write_pairs() functions are basically high-level wrappers around write(). But their return values are flipped from our usual convention, using "1" for success and "0" for failure. Let's flip them to follow the usual write() conventions and update all callers. As these are local to config.c, it's unlikely that we'd have new callers in any topics in flight (which would be silently broken by our change). But just to be on the safe side, let's rename them to just write_section() and write_pairs(). That also accentuates their relationship with write(). Signed-off-by: Jeff King <peff@peff.net> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 13, 2017 at 13:17 UTC d9bd4cbb9cce9f872cc4427d1c27a62c6768b12a
1 file changed +15 -13
config.c
+15 -13
@@ -2251,10 +2251,11 @@ static int write_error(const char *filename)
2251 return 4;
2252 }
2253
2254 -static int store_write_section(int fd, const char *key)
2254 +static ssize_t write_section(int fd, const char *key)
2255 {
2256 const char *dot;
2257 - int i, success;
2257 + int i;
2258 + ssize_t ret;
2259 struct strbuf sb = STRBUF_INIT;
2260
2261 dot = memchr(key, '.', store.baselen);
@@ -2270,15 +2271,16 @@ static int store_write_section(int fd, const char *key)
2271 strbuf_addf(&sb, "[%.*s]\n", store.baselen, key);
2272 }
2273
2273 - success = write_in_full(fd, sb.buf, sb.len) == sb.len;
2274 + ret = write_in_full(fd, sb.buf, sb.len);
2275 strbuf_release(&sb);
2276
2276 - return success;
2277 + return ret;
2278 }
2279
2279 -static int store_write_pair(int fd, const char *key, const char *value)
2280 +static ssize_t write_pair(int fd, const char *key, const char *value)
2281 {
2281 - int i, success;
2282 + int i;
2283 + ssize_t ret;
2284 int length = strlen(key + store.baselen + 1);
2285 const char *quote = "";
2286 struct strbuf sb = STRBUF_INIT;
@@ -2318,10 +2320,10 @@ static int store_write_pair(int fd, const char *key, const char *value)
2320 }
2321 strbuf_addf(&sb, "%s\n", quote);
2322
2321 - success = write_in_full(fd, sb.buf, sb.len) == sb.len;
2323 + ret = write_in_full(fd, sb.buf, sb.len);
2324 strbuf_release(&sb);
2325
2324 - return success;
2326 + return ret;
2327 }
2328
2329 static ssize_t find_beginning_of_line(const char *contents, size_t size,
@@ -2451,8 +2453,8 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
2453 }
2454
2455 store.key = (char *)key;
2454 - if (!store_write_section(fd, key) ||
2455 - !store_write_pair(fd, key, value))
2456 + if (write_section(fd, key) < 0 ||
2457 + write_pair(fd, key, value) < 0)
2458 goto write_err_out;
2459 } else {
2460 struct stat st;
@@ -2574,10 +2576,10 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
2576 /* write the pair (value == NULL means unset) */
2577 if (value != NULL) {
2578 if (store.state == START) {
2577 - if (!store_write_section(fd, key))
2579 + if (write_section(fd, key) < 0)
2580 goto write_err_out;
2581 }
2580 - if (!store_write_pair(fd, key, value))
2582 + if (write_pair(fd, key, value) < 0)
2583 goto write_err_out;
2584 }
2585
@@ -2770,7 +2772,7 @@ int git_config_rename_section_in_file(const char *config_filename,
2772 continue;
2773 }
2774 store.baselen = strlen(new_name);
2773 - if (!store_write_section(out_fd, new_name)) {
2775 + if (write_section(out_fd, new_name) < 0) {
2776 ret = write_error(get_lock_file_path(lock));
2777 goto out;
2778 }