Commit 7d7f3059 by Edward Thomson

grafts: handle SHA256 graft files

parent 69592bde
...@@ -16,15 +16,20 @@ struct git_grafts { ...@@ -16,15 +16,20 @@ struct git_grafts {
/* Map of `git_commit_graft`s */ /* Map of `git_commit_graft`s */
git_oidmap *commits; git_oidmap *commits;
/* Type of object IDs */
git_oid_t oid_type;
/* File backing the graft. NULL if it's an in-memory graft */ /* File backing the graft. NULL if it's an in-memory graft */
char *path; char *path;
unsigned char path_checksum[GIT_HASH_SHA256_SIZE]; unsigned char path_checksum[GIT_HASH_SHA256_SIZE];
}; };
int git_grafts_new(git_grafts **out) int git_grafts_new(git_grafts **out, git_oid_t oid_type)
{ {
git_grafts *grafts; git_grafts *grafts;
GIT_ASSERT_ARG(out && oid_type);
grafts = git__calloc(1, sizeof(*grafts)); grafts = git__calloc(1, sizeof(*grafts));
GIT_ERROR_CHECK_ALLOC(grafts); GIT_ERROR_CHECK_ALLOC(grafts);
...@@ -33,19 +38,26 @@ int git_grafts_new(git_grafts **out) ...@@ -33,19 +38,26 @@ int git_grafts_new(git_grafts **out)
return -1; return -1;
} }
grafts->oid_type = oid_type;
*out = grafts; *out = grafts;
return 0; return 0;
} }
int git_grafts_from_file(git_grafts **out, const char *path) int git_grafts_from_file(
git_grafts **out,
const char *path,
git_oid_t oid_type)
{ {
git_grafts *grafts = NULL; git_grafts *grafts = NULL;
int error; int error;
GIT_ASSERT_ARG(path && oid_type);
if (*out) if (*out)
return git_grafts_refresh(*out); return git_grafts_refresh(*out);
if ((error = git_grafts_new(&grafts)) < 0) if ((error = git_grafts_new(&grafts, oid_type)) < 0)
goto error; goto error;
grafts->path = git__strdup(path); grafts->path = git__strdup(path);
...@@ -133,7 +145,7 @@ int git_grafts_parse(git_grafts *grafts, const char *buf, size_t len) ...@@ -133,7 +145,7 @@ int git_grafts_parse(git_grafts *grafts, const char *buf, size_t len)
for (; parser.remain_len; git_parse_advance_line(&parser)) { for (; parser.remain_len; git_parse_advance_line(&parser)) {
git_oid graft_oid; git_oid graft_oid;
if ((error = git_parse_advance_oid(&graft_oid, &parser, GIT_OID_SHA1)) < 0) { if ((error = git_parse_advance_oid(&graft_oid, &parser, grafts->oid_type)) < 0) {
git_error_set(GIT_ERROR_GRAFTS, "invalid graft OID at line %" PRIuZ, parser.line_num); git_error_set(GIT_ERROR_GRAFTS, "invalid graft OID at line %" PRIuZ, parser.line_num);
goto error; goto error;
} }
...@@ -143,7 +155,7 @@ int git_grafts_parse(git_grafts *grafts, const char *buf, size_t len) ...@@ -143,7 +155,7 @@ int git_grafts_parse(git_grafts *grafts, const char *buf, size_t len)
GIT_ERROR_CHECK_ALLOC(id); GIT_ERROR_CHECK_ALLOC(id);
if ((error = git_parse_advance_expected(&parser, " ", 1)) < 0 || if ((error = git_parse_advance_expected(&parser, " ", 1)) < 0 ||
(error = git_parse_advance_oid(id, &parser, GIT_OID_SHA1)) < 0) { (error = git_parse_advance_oid(id, &parser, grafts->oid_type)) < 0) {
git_error_set(GIT_ERROR_GRAFTS, "invalid parent OID at line %" PRIuZ, parser.line_num); git_error_set(GIT_ERROR_GRAFTS, "invalid parent OID at line %" PRIuZ, parser.line_num);
goto error; goto error;
} }
......
...@@ -19,13 +19,13 @@ typedef struct { ...@@ -19,13 +19,13 @@ typedef struct {
typedef struct git_grafts git_grafts; typedef struct git_grafts git_grafts;
int git_grafts_new(git_grafts **out); int git_grafts_new(git_grafts **out, git_oid_t oid_type);
int git_grafts_from_file(git_grafts **out, const char *path); int git_grafts_from_file(git_grafts **out, const char *path, git_oid_t oid_type);
void git_grafts_free(git_grafts *grafts); void git_grafts_free(git_grafts *grafts);
void git_grafts_clear(git_grafts *grafts); void git_grafts_clear(git_grafts *grafts);
int git_grafts_refresh(git_grafts *grafts); int git_grafts_refresh(git_grafts *grafts);
int git_grafts_parse(git_grafts *grafts, const char *content, size_t contentlen); int git_grafts_parse(git_grafts *grafts, const char *buf, size_t len);
int git_grafts_add(git_grafts *grafts, const git_oid *oid, git_array_oid_t parents); int git_grafts_add(git_grafts *grafts, const git_oid *oid, git_array_oid_t parents);
int git_grafts_remove(git_grafts *grafts, const git_oid *oid); int git_grafts_remove(git_grafts *grafts, const git_oid *oid);
int git_grafts_get(git_commit_graft **out, git_grafts *grafts, const git_oid *oid); int git_grafts_get(git_commit_graft **out, git_grafts *grafts, const git_oid *oid);
......
...@@ -852,13 +852,13 @@ static int load_grafts(git_repository *repo) ...@@ -852,13 +852,13 @@ static int load_grafts(git_repository *repo)
if ((error = git_repository__item_path(&path, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 || if ((error = git_repository__item_path(&path, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
(error = git_str_joinpath(&path, path.ptr, "grafts")) < 0 || (error = git_str_joinpath(&path, path.ptr, "grafts")) < 0 ||
(error = git_grafts_from_file(&repo->grafts, path.ptr)) < 0) (error = git_grafts_from_file(&repo->grafts, path.ptr, repo->oid_type)) < 0)
goto error; goto error;
git_str_clear(&path); git_str_clear(&path);
if ((error = git_str_joinpath(&path, repo->gitdir, "shallow")) < 0 || if ((error = git_str_joinpath(&path, repo->gitdir, "shallow")) < 0 ||
(error = git_grafts_from_file(&repo->shallow_grafts, path.ptr)) < 0) (error = git_grafts_from_file(&repo->shallow_grafts, path.ptr, repo->oid_type)) < 0)
goto error; goto error;
error: error:
......
...@@ -22,7 +22,7 @@ void test_grafts_basic__graft_add(void) ...@@ -22,7 +22,7 @@ void test_grafts_basic__graft_add(void)
git_commit_graft *graft; git_commit_graft *graft;
git_grafts *grafts; git_grafts *grafts;
cl_git_pass(git_grafts_new(&grafts)); cl_git_pass(git_grafts_new(&grafts, GIT_OID_SHA1));
cl_assert(oid1 = git_array_alloc(parents)); cl_assert(oid1 = git_array_alloc(parents));
cl_git_pass(git_oid__fromstr(&oid_src, "2f3053cbff8a4ca2f0666de364ddb734a28a31a9", GIT_OID_SHA1)); cl_git_pass(git_oid__fromstr(&oid_src, "2f3053cbff8a4ca2f0666de364ddb734a28a31a9", GIT_OID_SHA1));
......
...@@ -19,7 +19,7 @@ static git_grafts *grafts; ...@@ -19,7 +19,7 @@ static git_grafts *grafts;
void test_grafts_parse__initialize(void) void test_grafts_parse__initialize(void)
{ {
cl_git_pass(git_grafts_new(&grafts)); cl_git_pass(git_grafts_new(&grafts, GIT_OID_SHA1));
} }
void test_grafts_parse__cleanup(void) void test_grafts_parse__cleanup(void)
......
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