summaryrefslogtreecommitdiff
path: root/src/repository.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2020-05-12 11:30:27 +0200
committerPatrick Steinhardt <ps@pks.im>2020-06-27 14:33:58 +0200
commit05e286fba318d21147347a572b05b0d1dac79610 (patch)
treef2b88a018e06344c0a26016039b5f09b780cbd8b /src/repository.c
parent14a309ab384a8732f692e468ac56c0d1831fce2f (diff)
downloadlibgit2-05e286fba318d21147347a572b05b0d1dac79610.tar.gz
grafts: move parsing into grafts module
Parsing of grafts files is currently contained in the repository code. To make grafts-related logic more self-contained, move it into "grafts.c" instead.
Diffstat (limited to 'src/repository.c')
-rw-r--r--src/repository.c37
1 files changed, 1 insertions, 36 deletions
diff --git a/src/repository.c b/src/repository.c
index 4465d8e79..7721c3cd0 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -31,7 +31,6 @@
#include "annotated_commit.h"
#include "submodule.h"
#include "worktree.h"
-#include "parse.h"
#include "strmap.h"
@@ -582,10 +581,8 @@ out:
static int load_grafts(git_repository *repo)
{
- git_array_oid_t parents = GIT_ARRAY_INIT;
git_buf graft_path = GIT_BUF_INIT;
git_buf contents = GIT_BUF_INIT;
- git_parse_ctx parser;
int error, updated;
if ((error = git_repository_item_path(&graft_path, repo, GIT_REPOSITORY_ITEM_INFO)) < 0)
@@ -604,42 +601,10 @@ static int load_grafts(git_repository *repo)
goto cleanup;
}
- git_grafts_clear(repo->grafts);
-
- if ((error = git_parse_ctx_init(&parser, contents.ptr, contents.size)) < 0)
- goto cleanup;
-
- for (; parser.remain_len; git_parse_advance_line(&parser)) {
- const char *line_start = parser.line, *line_end = parser.line + parser.line_len;
- git_oid graft_oid;
-
- if (git_oid_fromstrn(&graft_oid, line_start, GIT_OID_HEXSZ) < 0)
- goto invalid_oid;
- line_start += GIT_OID_HEXSZ;
-
- while (line_start < line_end && *line_start == ' ') {
- git_oid *id = git_array_alloc(parents);
- GIT_ERROR_CHECK_ALLOC(id);
-
- if (git_oid_fromstrn(id, ++line_start, GIT_OID_HEXSZ) < 0)
- goto invalid_oid;
- line_start += GIT_OID_HEXSZ;
- }
-
- if ((error = git_grafts_add(repo->grafts, &graft_oid, parents)) < 0)
- goto cleanup;
-
- git_array_clear(parents);
- continue;
-
-invalid_oid:
- git_error_set(GIT_ERROR_REPOSITORY, "invalid OID at line %" PRIuZ, parser.line_num);
- error = -1;
+ if ((error = git_grafts_parse(repo->grafts, contents.ptr, contents.size)) < 0)
goto cleanup;
- }
cleanup:
- git_array_clear(parents);
git_buf_dispose(&contents);
git_buf_dispose(&graft_path);