Skip to content

Commit 5463caa

Browse files
sahildua2305gitster
authored andcommitted
config: create a function to format section headers
Factor out the logic which creates section headers in the config file, e.g. the 'branch.foo' key will be turned into '[branch "foo"]'. This introduces no function changes, but is needed for a later change which adds support for copying branch sections in the config file. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Ramsay Jones <[email protected]> Signed-off-by: Sahil Dua <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 41dd433 commit 5463caa

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

config.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,10 +2169,10 @@ static int write_error(const char *filename)
21692169
return 4;
21702170
}
21712171

2172-
static int store_write_section(int fd, const char *key)
2172+
static struct strbuf store_create_section(const char *key)
21732173
{
21742174
const char *dot;
2175-
int i, success;
2175+
int i;
21762176
struct strbuf sb = STRBUF_INIT;
21772177

21782178
dot = memchr(key, '.', store.baselen);
@@ -2188,6 +2188,15 @@ static int store_write_section(int fd, const char *key)
21882188
strbuf_addf(&sb, "[%.*s]\n", store.baselen, key);
21892189
}
21902190

2191+
return sb;
2192+
}
2193+
2194+
static int store_write_section(int fd, const char *key)
2195+
{
2196+
int success;
2197+
2198+
struct strbuf sb = store_create_section(key);
2199+
21912200
success = write_in_full(fd, sb.buf, sb.len) == sb.len;
21922201
strbuf_release(&sb);
21932202

0 commit comments

Comments
 (0)