Skip to content

Commit 9accb8f

Browse files
committed
Update to libgit at 7064938, v0.10.0
2 current issues: 1. git_repository_close is not exposed 2. git_strarray_free is not exposed, so there's no way to free memory from listing references. These issues are fixed are the libgit2/development branch, but are not merged back into libgit2/master yet. Also, I removed the translation of the git_pack and git_revwalk structures because they changed almost completely, and the internal details aren't necessary for using the API.
1 parent ea2cc0a commit 9accb8f

File tree

7 files changed

+156
-419
lines changed

7 files changed

+156
-419
lines changed

LIBGIT2_sha

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# code based on github.com/libgit2/libgit2 sha:
2-
b760fbf539e1ce17ac2768da755834babf700b9a
1+
# code based on github.com/libgit2/libgit2 v0.10.0 sha:
2+
7064938bd5e7ef47bfd79a685a62c1e2649e2ce7

TestsFromLibGit2/t0402_details.pas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ procedure Test0402_details.query_details_test_0402;
6363
p := 0;
6464
while p < parents do
6565
begin
66-
parent := git_commit_parent(commit, p);
66+
must_pass(git_commit_parent(parent, commit, p));
6767
CheckTrue(parent <> nil, 'parent <> nil');
6868
CheckTrue(git_commit_author(parent) <> nil, 'git_commit_author(parent) <> nil'); // is it really a commit?
6969
Inc(p);
7070
end;
71-
CheckTrue(git_commit_parent(commit, parents) = nil, 'git_commit_parent(commit, parents) = nil');
71+
must_fail(git_commit_parent(parent, commit, parents));
7272
end;
7373

7474
git_repository_free(repo);

TestsFromLibGit2/t0501_walk.pas

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ procedure Test0501_walk.simple_walk_test_0501;
5151
commit_count = 6;
5252
result_bytes = 24;
5353

54-
function get_commit_index(commit: Pgit_commit): Integer;
54+
function get_commit_index(raw_oid: Pgit_oid): Integer;
5555
var
5656
i: Integer;
5757
oid: array[0..39] of AnsiChar;
5858
begin
59-
git_oid_fmt(oid, @commit.object_.id);
59+
git_oid_fmt(oid, raw_oid);
6060

6161
for i := 0 to commit_count - 1 do
6262
begin
@@ -71,27 +71,33 @@ procedure Test0501_walk.simple_walk_test_0501;
7171
end;
7272

7373

74-
function test_walk(walk: Pgit_revwalk; start_from: Pgit_commit;
74+
function test_walk(walk: Pgit_revwalk;
7575
flags: Integer; const possible_results: array of TArray6; results_count: Integer): Integer;
7676
var
77-
commit: Pgit_commit;
77+
oid: git_oid;
7878

7979
ret, i: Integer;
8080
result_array: array [0..commit_count-1] of Integer;
8181
begin
82+
git_revwalk_reset(walk);
8283
git_revwalk_sorting(walk, flags);
83-
git_revwalk_push(walk, start_from);
8484

8585
for i := 0 to commit_count - 1 do
8686
result_array[i] := -1;
8787

8888
i := 0;
89-
ret := git_revwalk_next(commit, walk);
89+
ret := git_revwalk_next(@oid, walk);
9090
while (ret = GIT_SUCCESS) do
9191
begin
92-
result_array[i] := get_commit_index(commit);
93-
ret := git_revwalk_next(commit, walk);
92+
result_array[i] := get_commit_index(@oid);
93+
(*{
94+
char str[41];
95+
git_oid_fmt(str, &oid);
96+
str[40] = 0;
97+
printf(" %d) %s\n", i, str);
98+
}*)
9499
Inc(i);
100+
ret := git_revwalk_next(@oid, walk);
95101
end;
96102

97103
for i := 0 to results_count - 1 do
@@ -110,38 +116,23 @@ procedure Test0501_walk.simple_walk_test_0501;
110116
id: git_oid;
111117
repo: Pgit_repository;
112118
walk: Pgit_revwalk;
113-
head: Pgit_commit;
114119
begin
115120
repo := nil;
116-
head := nil;
117121

118122
must_pass(git_repository_open(repo, REPOSITORY_FOLDER));
119123

120124
must_pass(git_revwalk_new(walk, repo));
121125

122126
git_oid_mkstr(@id, commit_head);
127+
git_revwalk_push(walk, @id);
123128

124-
must_pass(git_commit_lookup(head, repo, @id));
129+
must_pass(test_walk(walk, GIT_SORT_TIME, commit_sorting_time, 1));
125130

126-
must_pass(test_walk(walk, head,
127-
GIT_SORT_TIME,
128-
commit_sorting_time, 1)
129-
);
131+
must_pass(test_walk(walk, GIT_SORT_TOPOLOGICAL, commit_sorting_topo, 2));
130132

131-
must_pass(test_walk(walk, head,
132-
GIT_SORT_TOPOLOGICAL,
133-
commit_sorting_topo, 2)
134-
);
133+
must_pass(test_walk(walk, GIT_SORT_TIME or GIT_SORT_REVERSE, commit_sorting_time_reverse, 1));
135134

136-
must_pass(test_walk(walk, head,
137-
GIT_SORT_TIME or GIT_SORT_REVERSE,
138-
commit_sorting_time_reverse, 1)
139-
);
140-
141-
must_pass(test_walk(walk, head,
142-
GIT_SORT_TOPOLOGICAL or GIT_SORT_REVERSE,
143-
commit_sorting_topo_reverse, 2)
144-
);
135+
must_pass(test_walk(walk, GIT_SORT_TOPOLOGICAL or GIT_SORT_REVERSE, commit_sorting_topo_reverse, 2));
145136

146137
git_revwalk_free(walk);
147138
git_repository_free(repo);

TestsFromLibGit2/t0801_readtag.pas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ procedure Test0801_readtag.readtag_0801;
3333
CheckTrue(StrComp(git_tag_name(tag1), 'test') = 0);
3434
CheckTrue(git_tag_type(tag1) = GIT_OBJ_TAG);
3535

36-
tag2 := Pgit_tag(git_tag_target(tag1));
36+
must_pass(git_tag_target(Pgit_object(tag2), tag1));
3737
CheckTrue(tag2 <> nil);
3838

3939
CheckTrue(git_oid_cmp(@id2, git_tag_id(tag2)) = 0);
4040

41-
commit := Pgit_commit(git_tag_target(tag2));
41+
must_pass(git_tag_target(Pgit_object(commit), tag2));
4242
CheckTrue(commit <> nil);
4343

4444
CheckTrue(git_oid_cmp(@id_commit, git_commit_id(commit)) = 0);

TestsFromLibGit2/t10_refs.pas

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ Test10_refs_delete = class(TTestFromLibGit2)
4747
procedure delete_reference_deletes_both_packed_and_loose;
4848
end;
4949

50+
Test10_refs_list = class(TTestFromLibGit2)
51+
procedure list_all_the_references_in_our_test_repo;
52+
end;
53+
5054
implementation
5155

5256
const
@@ -616,6 +620,22 @@ procedure Test10_refs_delete.delete_reference_deletes_both_packed_and_loose;
616620
close_temp_repo(repo);
617621
end;
618622

623+
{ Test10_refs_list }
624+
625+
procedure Test10_refs_list.list_all_the_references_in_our_test_repo;
626+
var
627+
repo: Pgit_repository;
628+
ref_list: git_strarray;
629+
begin
630+
must_pass(git_repository_open(repo, REPOSITORY_FOLDER));
631+
must_pass(git_reference_listall(@ref_list, repo, GIT_REF_LISTALL));
632+
must_be_true(ref_list.count = 8); //* 8 refs in total if we include the packed ones */
633+
634+
// TODO : git_strarray_free not exposed, no way to free memory
635+
// git_strarray_free(ref_list);
636+
git_repository_free(repo);
637+
end;
638+
619639
initialization
620640
RegisterTest('From libgit2.t10-refs', Test10_refs_readtag.Suite);
621641
RegisterTest('From libgit2.t10-refs', Test10_refs_readsymref.Suite);
@@ -624,6 +644,7 @@ initialization
624644
RegisterTest('From libgit2.t10-refs', Test10_refs_packfile.Suite);
625645
RegisterTest('From libgit2.t10-refs', Test10_refs_rename.Suite);
626646
RegisterTest('From libgit2.t10-refs', Test10_refs_delete.Suite);
647+
RegisterTest('From libgit2.t10-refs', Test10_refs_list.Suite);
627648

628649
end.
629650

0 commit comments

Comments
 (0)