Skip to content

Commit 7d7f305

Browse files
committed
grafts: handle SHA256 graft files
1 parent 69592bd commit 7d7f305

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

src/libgit2/grafts.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,20 @@ struct git_grafts {
1616
/* Map of `git_commit_graft`s */
1717
git_oidmap *commits;
1818

19+
/* Type of object IDs */
20+
git_oid_t oid_type;
21+
1922
/* File backing the graft. NULL if it's an in-memory graft */
2023
char *path;
2124
unsigned char path_checksum[GIT_HASH_SHA256_SIZE];
2225
};
2326

24-
int git_grafts_new(git_grafts **out)
27+
int git_grafts_new(git_grafts **out, git_oid_t oid_type)
2528
{
2629
git_grafts *grafts;
2730

31+
GIT_ASSERT_ARG(out && oid_type);
32+
2833
grafts = git__calloc(1, sizeof(*grafts));
2934
GIT_ERROR_CHECK_ALLOC(grafts);
3035

@@ -33,19 +38,26 @@ int git_grafts_new(git_grafts **out)
3338
return -1;
3439
}
3540

41+
grafts->oid_type = oid_type;
42+
3643
*out = grafts;
3744
return 0;
3845
}
3946

40-
int git_grafts_from_file(git_grafts **out, const char *path)
47+
int git_grafts_from_file(
48+
git_grafts **out,
49+
const char *path,
50+
git_oid_t oid_type)
4151
{
4252
git_grafts *grafts = NULL;
4353
int error;
4454

55+
GIT_ASSERT_ARG(path && oid_type);
56+
4557
if (*out)
4658
return git_grafts_refresh(*out);
4759

48-
if ((error = git_grafts_new(&grafts)) < 0)
60+
if ((error = git_grafts_new(&grafts, oid_type)) < 0)
4961
goto error;
5062

5163
grafts->path = git__strdup(path);
@@ -133,7 +145,7 @@ int git_grafts_parse(git_grafts *grafts, const char *buf, size_t len)
133145
for (; parser.remain_len; git_parse_advance_line(&parser)) {
134146
git_oid graft_oid;
135147

136-
if ((error = git_parse_advance_oid(&graft_oid, &parser, GIT_OID_SHA1)) < 0) {
148+
if ((error = git_parse_advance_oid(&graft_oid, &parser, grafts->oid_type)) < 0) {
137149
git_error_set(GIT_ERROR_GRAFTS, "invalid graft OID at line %" PRIuZ, parser.line_num);
138150
goto error;
139151
}
@@ -143,7 +155,7 @@ int git_grafts_parse(git_grafts *grafts, const char *buf, size_t len)
143155
GIT_ERROR_CHECK_ALLOC(id);
144156

145157
if ((error = git_parse_advance_expected(&parser, " ", 1)) < 0 ||
146-
(error = git_parse_advance_oid(id, &parser, GIT_OID_SHA1)) < 0) {
158+
(error = git_parse_advance_oid(id, &parser, grafts->oid_type)) < 0) {
147159
git_error_set(GIT_ERROR_GRAFTS, "invalid parent OID at line %" PRIuZ, parser.line_num);
148160
goto error;
149161
}

src/libgit2/grafts.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ typedef struct {
1919

2020
typedef struct git_grafts git_grafts;
2121

22-
int git_grafts_new(git_grafts **out);
23-
int git_grafts_from_file(git_grafts **out, const char *path);
22+
int git_grafts_new(git_grafts **out, git_oid_t oid_type);
23+
int git_grafts_from_file(git_grafts **out, const char *path, git_oid_t oid_type);
2424
void git_grafts_free(git_grafts *grafts);
2525
void git_grafts_clear(git_grafts *grafts);
2626

2727
int git_grafts_refresh(git_grafts *grafts);
28-
int git_grafts_parse(git_grafts *grafts, const char *content, size_t contentlen);
28+
int git_grafts_parse(git_grafts *grafts, const char *buf, size_t len);
2929
int git_grafts_add(git_grafts *grafts, const git_oid *oid, git_array_oid_t parents);
3030
int git_grafts_remove(git_grafts *grafts, const git_oid *oid);
3131
int git_grafts_get(git_commit_graft **out, git_grafts *grafts, const git_oid *oid);

src/libgit2/repository.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,13 +852,13 @@ static int load_grafts(git_repository *repo)
852852

853853
if ((error = git_repository__item_path(&path, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
854854
(error = git_str_joinpath(&path, path.ptr, "grafts")) < 0 ||
855-
(error = git_grafts_from_file(&repo->grafts, path.ptr)) < 0)
855+
(error = git_grafts_from_file(&repo->grafts, path.ptr, repo->oid_type)) < 0)
856856
goto error;
857857

858858
git_str_clear(&path);
859859

860860
if ((error = git_str_joinpath(&path, repo->gitdir, "shallow")) < 0 ||
861-
(error = git_grafts_from_file(&repo->shallow_grafts, path.ptr)) < 0)
861+
(error = git_grafts_from_file(&repo->shallow_grafts, path.ptr, repo->oid_type)) < 0)
862862
goto error;
863863

864864
error:

tests/libgit2/grafts/basic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void test_grafts_basic__graft_add(void)
2222
git_commit_graft *graft;
2323
git_grafts *grafts;
2424

25-
cl_git_pass(git_grafts_new(&grafts));
25+
cl_git_pass(git_grafts_new(&grafts, GIT_OID_SHA1));
2626

2727
cl_assert(oid1 = git_array_alloc(parents));
2828
cl_git_pass(git_oid__fromstr(&oid_src, "2f3053cbff8a4ca2f0666de364ddb734a28a31a9", GIT_OID_SHA1));

tests/libgit2/grafts/parse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static git_grafts *grafts;
1919

2020
void test_grafts_parse__initialize(void)
2121
{
22-
cl_git_pass(git_grafts_new(&grafts));
22+
cl_git_pass(git_grafts_new(&grafts, GIT_OID_SHA1));
2323
}
2424

2525
void test_grafts_parse__cleanup(void)

0 commit comments

Comments
 (0)