config: create a function to format section headers
[gitweb.git] / config.c
index 146cb3452adab3115f15d30c2b0f9f5480344279..856e42e4d0ebc0ba46d39e92d271745d08fa6bf4 100644 (file)
--- a/config.c
+++ b/config.c
@@ -2169,10 +2169,10 @@ static int write_error(const char *filename)
        return 4;
 }
 
-static int store_write_section(int fd, const char *key)
+static struct strbuf store_create_section(const char *key)
 {
        const char *dot;
-       int i, success;
+       int i;
        struct strbuf sb = STRBUF_INIT;
 
        dot = memchr(key, '.', store.baselen);
@@ -2188,6 +2188,15 @@ static int store_write_section(int fd, const char *key)
                strbuf_addf(&sb, "[%.*s]\n", store.baselen, key);
        }
 
+       return sb;
+}
+
+static int store_write_section(int fd, const char *key)
+{
+       int success;
+
+       struct strbuf sb = store_create_section(key);
+
        success = write_in_full(fd, sb.buf, sb.len) == sb.len;
        strbuf_release(&sb);