Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2013-11-10 19:41:41 +0400
committerVicent Marti <tanoku@gmail.com>2013-11-10 19:41:41 +0400
commita1d35ede189f6f3286102c53a499b5e486d86b79 (patch)
tree34ddd85010780d8d382bd3146f16780a851fbbe8 /src/config_file.c
parentb9cb72c28a937a887676a553fef8e21bbc7be3f0 (diff)
config_file: style
Diffstat (limited to 'src/config_file.c')
-rw-r--r--src/config_file.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/config_file.c b/src/config_file.c
index 25ebd1c97..15c8de49c 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -1178,20 +1178,22 @@ static int write_section(git_filebuf *file, const char *key)
return result;
}
-static int value_needs_surrounding_quote(const char *value)
+static const char *quotes_for_value(const char *value)
{
- const char *ptr = value;
- if (*value == ' ')
- return 1;
- while (*ptr) {
+ const char *ptr;
+
+ if (value[0] == ' ' || value[0] == '\0')
+ return "\"";
+
+ for (ptr = value; *ptr; ++ptr) {
if (*ptr == ';' || *ptr == '#')
- return 1;
- ++ptr;
+ return "\"";
}
- if (ptr != value && *(--ptr) == ' ')
- return 1;
- return 0;
+ if (ptr[-1] == ' ')
+ return "\"";
+
+ return "";
}
/*
@@ -1318,10 +1320,8 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
/* Then replace the variable. If the value is NULL, it
* means we want to delete it, so don't write anything. */
if (value != NULL) {
- if (value_needs_surrounding_quote(value))
- git_filebuf_printf(&file, "\t%s = \"%s\"\n", name, value);
- else
- git_filebuf_printf(&file, "\t%s = %s\n", name, value);
+ const char *q = quotes_for_value(value);
+ git_filebuf_printf(&file, "\t%s = %s%s%s\n", name, q, value, q);
}
/*
@@ -1362,6 +1362,8 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
if (preg_replaced) {
git_filebuf_printf(&file, "\n%s", write_start);
} else {
+ const char *q;
+
git_filebuf_write(&file, reader->buffer.ptr, reader->buffer.size);
/* And now if we just need to add a variable */
@@ -1381,10 +1383,8 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
if (reader->buffer.size > 0 && *(reader->buffer.ptr + reader->buffer.size - 1) != '\n')
git_filebuf_write(&file, "\n", 1);
- if (value_needs_surrounding_quote(value))
- git_filebuf_printf(&file, "\t%s = \"%s\"\n", name, value);
- else
- git_filebuf_printf(&file, "\t%s = %s\n", name, value);
+ q = quotes_for_value(value);
+ git_filebuf_printf(&file, "\t%s = %s%s%s\n", name, q, value, q);
}
}