aboutsummaryrefslogtreecommitdiffstats
path: root/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'config.c')
-rw-r--r--config.c45
1 files changed, 20 insertions, 25 deletions
diff --git a/config.c b/config.c
index b18b5617fc..8a2d0b7916 100644
--- a/config.c
+++ b/config.c
@@ -31,7 +31,7 @@
#include "hashmap.h"
#include "string-list.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "pager.h"
#include "path.h"
#include "utf8.h"
@@ -56,7 +56,6 @@ struct config_source {
} u;
enum config_origin_type origin_type;
const char *name;
- const char *path;
enum config_error_action default_error_action;
int linenr;
int eof;
@@ -173,14 +172,14 @@ static int handle_path_include(const struct key_value_info *kvi,
if (!is_absolute_path(path)) {
char *slash;
- if (!kvi || !kvi->path) {
+ if (!kvi || kvi->origin_type != CONFIG_ORIGIN_FILE) {
ret = error(_("relative config includes must come from files"));
goto cleanup;
}
- slash = find_last_dir_sep(kvi->path);
+ slash = find_last_dir_sep(kvi->filename);
if (slash)
- strbuf_add(&buf, kvi->path, slash - kvi->path + 1);
+ strbuf_add(&buf, kvi->filename, slash - kvi->filename + 1);
strbuf_addstr(&buf, path);
path = buf.buf;
}
@@ -224,11 +223,11 @@ static int prepare_include_condition_pattern(const struct key_value_info *kvi,
if (pat->buf[0] == '.' && is_dir_sep(pat->buf[1])) {
const char *slash;
- if (!kvi || !kvi->path)
+ if (!kvi || kvi->origin_type != CONFIG_ORIGIN_FILE)
return error(_("relative config include "
"conditionals must come from files"));
- strbuf_realpath(&path, kvi->path, 1);
+ strbuf_realpath(&path, kvi->filename, 1);
slash = find_last_dir_sep(path.buf);
if (!slash)
BUG("how is this possible?");
@@ -633,7 +632,6 @@ void kvi_from_param(struct key_value_info *out)
out->linenr = -1;
out->origin_type = CONFIG_ORIGIN_CMDLINE;
out->scope = CONFIG_SCOPE_COMMAND;
- out->path = NULL;
}
int git_config_parse_parameter(const char *text,
@@ -1036,7 +1034,6 @@ static void kvi_from_source(struct config_source *cs,
out->origin_type = cs->origin_type;
out->linenr = cs->linenr;
out->scope = scope;
- out->path = cs->path;
}
static int git_parse_source(struct config_source *cs, config_fn_t fn,
@@ -1537,9 +1534,11 @@ static int git_default_core_config(const char *var, const char *value,
!strcmp(var, "core.commentstring")) {
if (!value)
return config_error_nonbool(var);
- else if (!strcasecmp(value, "auto"))
+ else if (!strcasecmp(value, "auto")) {
auto_comment_line_char = 1;
- else if (value[0]) {
+ FREE_AND_NULL(comment_line_str_to_free);
+ comment_line_str = "#";
+ } else if (value[0]) {
if (strchr(value, '\n'))
return error(_("%s cannot contain newline"), var);
comment_line_str = value;
@@ -1595,11 +1594,6 @@ static int git_default_core_config(const char *var, const char *value,
return 0;
}
- if (!strcmp(var, "core.preloadindex")) {
- core_preload_index = git_config_bool(var, value);
- return 0;
- }
-
if (!strcmp(var, "core.createobject")) {
if (!value)
return config_error_nonbool(var);
@@ -1855,17 +1849,19 @@ static int do_config_from(struct config_source *top, config_fn_t fn,
static int do_config_from_file(config_fn_t fn,
const enum config_origin_type origin_type,
- const char *name, const char *path, FILE *f,
- void *data, enum config_scope scope,
+ const char *name, FILE *f, void *data,
+ enum config_scope scope,
const struct config_options *opts)
{
struct config_source top = CONFIG_SOURCE_INIT;
int ret;
+ if (origin_type == CONFIG_ORIGIN_FILE && (!name || !*name))
+ BUG("missing filename for CONFIG_ORIGIN_FILE");
+
top.u.file = f;
top.origin_type = origin_type;
top.name = name;
- top.path = path;
top.default_error_action = CONFIG_ERROR_DIE;
top.do_fgetc = config_file_fgetc;
top.do_ungetc = config_file_ungetc;
@@ -1880,8 +1876,8 @@ static int do_config_from_file(config_fn_t fn,
static int git_config_from_stdin(config_fn_t fn, void *data,
enum config_scope scope)
{
- return do_config_from_file(fn, CONFIG_ORIGIN_STDIN, "", NULL, stdin,
- data, scope, NULL);
+ return do_config_from_file(fn, CONFIG_ORIGIN_STDIN, "", stdin, data,
+ scope, NULL);
}
int git_config_from_file_with_options(config_fn_t fn, const char *filename,
@@ -1896,7 +1892,7 @@ int git_config_from_file_with_options(config_fn_t fn, const char *filename,
f = fopen_or_warn(filename, "r");
if (f) {
ret = do_config_from_file(fn, CONFIG_ORIGIN_FILE, filename,
- filename, f, data, scope, opts);
+ f, data, scope, opts);
fclose(f);
}
return ret;
@@ -1921,7 +1917,6 @@ int git_config_from_mem(config_fn_t fn,
top.u.buf.pos = 0;
top.origin_type = origin_type;
top.name = name;
- top.path = NULL;
top.default_error_action = CONFIG_ERROR_ERROR;
top.do_fgetc = config_buf_fgetc;
top.do_ungetc = config_buf_ungetc;
@@ -1942,7 +1937,7 @@ int git_config_from_blob_oid(config_fn_t fn,
unsigned long size;
int ret;
- buf = repo_read_object_file(repo, oid, &type, &size);
+ buf = odb_read_object(repo->objects, oid, &type, &size);
if (!buf)
return error(_("unable to load config blob object '%s'"), name);
if (type != OBJ_BLOB) {
@@ -2940,7 +2935,7 @@ static ssize_t write_pair(int fd, const char *key, const char *value,
if (value[0] == ' ')
quote = "\"";
for (i = 0; value[i]; i++)
- if (value[i] == ';' || value[i] == '#')
+ if (value[i] == ';' || value[i] == '#' || value[i] == '\r')
quote = "\"";
if (i && value[i - 1] == ' ')
quote = "\"";