aboutsummaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorSahil Dua <sahildua2305@gmail.com>2017-06-18 23:16:31 +0200
committerJunio C Hamano <gitster@pobox.com>2017-06-18 21:47:47 -0700
commit5463caab15fb795da2aab01827419b094146d1c4 (patch)
tree5225efd48f9d7373b34eacd437b11aac075f7c9d /config.c
parent41dd4330a1210003bd702ec4a9301ed68e60864d (diff)
downloadgit-5463caab15fb795da2aab01827419b094146d1c4.tar.gz
git-5463caab15fb795da2aab01827419b094146d1c4.tar.xz
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 <avarab@gmail.com> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com> Signed-off-by: Sahil Dua <sahildua2305@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r--config.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/config.c b/config.c
index 146cb3452..856e42e4d 100644
--- 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);