Skip to content

Commit 6e6da75

Browse files
committed
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.
1 parent 54d350e commit 6e6da75

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

src/config_file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ static int config_read_buffer(
889889
}
890890

891891
/* Initialize the reading position */
892-
reader.file = file;
892+
reader.path = file->path;
893893
git_parse_ctx_init(&reader.ctx, buf, buflen);
894894

895895
/* 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
11751175
struct write_data write_data;
11761176

11771177
memset(&reader, 0, sizeof(reader));
1178-
reader.file = &cfg->file;
1178+
reader.path = cfg->file.path;
11791179

11801180
if (cfg->locked) {
11811181
result = git_buf_puts(&contents, git_buf_cstr(&cfg->locked_content) == NULL ? "" : git_buf_cstr(&cfg->locked_content));

src/config_mem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static int config_memory_open(git_config_backend *backend, git_config_level_t le
8787
return 0;
8888

8989
git_parse_ctx_init(&reader.ctx, memory_backend->cfg.ptr, memory_backend->cfg.size);
90-
reader.file = NULL;
90+
reader.path = "in-memory";
9191
parse_data.entries = memory_backend->entries;
9292
parse_data.level = level;
9393

src/config_parse.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ const char *git_config_escaped = "\n\t\b\"\\";
1616

1717
static void set_parse_error(git_config_parser *reader, int col, const char *error_str)
1818
{
19-
const char *file = reader->file ? reader->file->path : "in-memory";
20-
2119
if (col)
2220
git_error_set(GIT_ERROR_CONFIG,
2321
"failed to parse config file: %s (in %s:%"PRIuZ", column %d)",
24-
error_str, file, reader->ctx.line_num, col);
22+
error_str, reader->path, reader->ctx.line_num, col);
2523
else
2624
git_error_set(GIT_ERROR_CONFIG,
2725
"failed to parse config file: %s (in %s:%"PRIuZ")",
28-
error_str, file, reader->ctx.line_num);
26+
error_str, reader->path, reader->ctx.line_num);
2927
}
3028

3129

src/config_parse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ typedef struct config_file {
2525
} git_config_file;
2626

2727
typedef struct {
28-
git_config_file *file;
28+
const char *path;
2929
git_parse_ctx ctx;
3030
} git_config_parser;
3131

0 commit comments

Comments
 (0)