diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-07-11 11:00:05 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-07-11 11:00:05 +0200 |
commit | 6e6da75fdb3c5d53c8df94d551aa9e6b9f4d8957 (patch) | |
tree | 5327e729a1ed571f19ed6909968027d9b33cf5e9 /src | |
parent | 54d350e05367a88874c291c6aa2c1801c5062031 (diff) | |
download | libgit2-6e6da75fdb3c5d53c8df94d551aa9e6b9f4d8957.tar.gz |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/config_file.c | 4 | ||||
-rw-r--r-- | src/config_mem.c | 2 | ||||
-rw-r--r-- | src/config_parse.c | 6 | ||||
-rw-r--r-- | src/config_parse.h | 2 |
4 files changed, 6 insertions, 8 deletions
diff --git a/src/config_file.c b/src/config_file.c index 8cadeba46..89da82967 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -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)); diff --git a/src/config_mem.c b/src/config_mem.c index c2ecfda12..b563a972e 100644 --- a/src/config_mem.c +++ b/src/config_mem.c @@ -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; diff --git a/src/config_parse.c b/src/config_parse.c index 6354f526b..bda1840fe 100644 --- a/src/config_parse.c +++ b/src/config_parse.c @@ -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); } diff --git a/src/config_parse.h b/src/config_parse.h index 3eef7d3cd..a25da9dd2 100644 --- a/src/config_parse.h +++ b/src/config_parse.h @@ -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; |