Commit 6e6da75f by Patrick Steinhardt

config_parse: remove use of `git_config_file`

The config parser code needs to keep track of the current parsed
file's name so that we are able to provide proper error messages
to the user. Right now, we do that by storing a `git_config_file`
in the parser structure, but as that is a specific backend and
the parser aims to be generic, it is a layering violation.

Switch over to use a simple string to fix that.
parent 54d350e0
......@@ -889,7 +889,7 @@ static int config_read_buffer(
}
/* Initialize the reading position */
reader.file = file;
reader.path = file->path;
git_parse_ctx_init(&reader.ctx, buf, buflen);
/* If the file is empty, there's nothing for us to do */
......@@ -1175,7 +1175,7 @@ static int config_write(diskfile_backend *cfg, const char *orig_key, const char
struct write_data write_data;
memset(&reader, 0, sizeof(reader));
reader.file = &cfg->file;
reader.path = cfg->file.path;
if (cfg->locked) {
result = git_buf_puts(&contents, git_buf_cstr(&cfg->locked_content) == NULL ? "" : git_buf_cstr(&cfg->locked_content));
......
......@@ -87,7 +87,7 @@ static int config_memory_open(git_config_backend *backend, git_config_level_t le
return 0;
git_parse_ctx_init(&reader.ctx, memory_backend->cfg.ptr, memory_backend->cfg.size);
reader.file = NULL;
reader.path = "in-memory";
parse_data.entries = memory_backend->entries;
parse_data.level = level;
......
......@@ -16,16 +16,14 @@ const char *git_config_escaped = "\n\t\b\"\\";
static void set_parse_error(git_config_parser *reader, int col, const char *error_str)
{
const char *file = reader->file ? reader->file->path : "in-memory";
if (col)
git_error_set(GIT_ERROR_CONFIG,
"failed to parse config file: %s (in %s:%"PRIuZ", column %d)",
error_str, file, reader->ctx.line_num, col);
error_str, reader->path, reader->ctx.line_num, col);
else
git_error_set(GIT_ERROR_CONFIG,
"failed to parse config file: %s (in %s:%"PRIuZ")",
error_str, file, reader->ctx.line_num);
error_str, reader->path, reader->ctx.line_num);
}
......
......@@ -25,7 +25,7 @@ typedef struct config_file {
} git_config_file;
typedef struct {
git_config_file *file;
const char *path;
git_parse_ctx ctx;
} git_config_parser;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment