Skip to content

Commit d9bd4cb

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 634eb82 commit d9bd4cb

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

config.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,10 +2251,11 @@ static int write_error(const char *filename)
22512251
return 4;
22522252
}
22532253

2254-
static int store_write_section(int fd, const char *key)
2254+
static ssize_t write_section(int fd, const char *key)
22552255
{
22562256
const char *dot;
2257-
int i, success;
2257+
int i;
2258+
ssize_t ret;
22582259
struct strbuf sb = STRBUF_INIT;
22592260

22602261
dot = memchr(key, '.', store.baselen);
@@ -2270,15 +2271,16 @@ static int store_write_section(int fd, const char *key)
22702271
strbuf_addf(&sb, "[%.*s]\n", store.baselen, key);
22712272
}
22722273

2273-
success = write_in_full(fd, sb.buf, sb.len) == sb.len;
2274+
ret = write_in_full(fd, sb.buf, sb.len);
22742275
strbuf_release(&sb);
22752276

2276-
return success;
2277+
return ret;
22772278
}
22782279

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)
22802281
{
2281-
int i, success;
2282+
int i;
2283+
ssize_t ret;
22822284
int length = strlen(key + store.baselen + 1);
22832285
const char *quote = "";
22842286
struct strbuf sb = STRBUF_INIT;
@@ -2318,10 +2320,10 @@ static int store_write_pair(int fd, const char *key, const char *value)
23182320
}
23192321
strbuf_addf(&sb, "%s\n", quote);
23202322

2321-
success = write_in_full(fd, sb.buf, sb.len) == sb.len;
2323+
ret = write_in_full(fd, sb.buf, sb.len);
23222324
strbuf_release(&sb);
23232325

2324-
return success;
2326+
return ret;
23252327
}
23262328

23272329
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,
24512453
}
24522454

24532455
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)
24562458
goto write_err_out;
24572459
} else {
24582460
struct stat st;
@@ -2574,10 +2576,10 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
25742576
/* write the pair (value == NULL means unset) */
25752577
if (value != NULL) {
25762578
if (store.state == START) {
2577-
if (!store_write_section(fd, key))
2579+
if (write_section(fd, key) < 0)
25782580
goto write_err_out;
25792581
}
2580-
if (!store_write_pair(fd, key, value))
2582+
if (write_pair(fd, key, value) < 0)
25812583
goto write_err_out;
25822584
}
25832585

@@ -2770,7 +2772,7 @@ int git_config_rename_section_in_file(const char *config_filename,
27702772
continue;
27712773
}
27722774
store.baselen = strlen(new_name);
2773-
if (!store_write_section(out_fd, new_name)) {
2775+
if (write_section(out_fd, new_name) < 0) {
27742776
ret = write_error(get_lock_file_path(lock));
27752777
goto out;
27762778
}

0 commit comments

Comments
 (0)