Skip to content

Commit e86c5b6

Browse files
committed
Remove LibGit2 abuse of old iteration protocol
This can now just be a stateful iterator, like the rest of them in LibGit2.
1 parent 9d85f7f commit e86c5b6

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

stdlib/LibGit2/src/LibGit2.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ function rebase!(repo::GitRepo, upstream::AbstractString="", newbase::AbstractSt
829829
try
830830
rbs = GitRebase(repo, head_ann, upst_ann, onto=onto_ann)
831831
try
832-
while (rbs_op = next(rbs)) !== nothing
832+
for rbs_op in rbs
833833
commit(rbs, sig)
834834
end
835835
finish(rbs, sig)

stdlib/LibGit2/src/rebase.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ function Base.getindex(rb::GitRebase, i::Integer)
4545
return rb_op
4646
end
4747

48-
function Base.next(rb::GitRebase)
48+
function Base.iterate(rb::GitRebase, state=nothing)
4949
ensure_initialized()
5050
rb_op_ptr_ptr = Ref{Ptr{RebaseOperation}}(C_NULL)
5151
GC.@preserve rb begin
52-
try
53-
@check ccall((:git_rebase_next, :libgit2), Cint,
54-
(Ptr{Ptr{RebaseOperation}}, Ptr{Cvoid}),
55-
rb_op_ptr_ptr, rb.ptr)
56-
catch err
57-
err.code == Error.ITEROVER && return nothing
58-
rethrow(err)
52+
err = ccall((:git_rebase_next, :libgit2), Cint,
53+
(Ptr{Ptr{RebaseOperation}}, Ptr{Cvoid}),
54+
rb_op_ptr_ptr, rb.ptr)
55+
if err == Cint(Error.GIT_OK)
56+
return unsafe_load(rb_op_ptr_ptr[]), nothing
57+
elseif err == Cint(Error.ITEROVER)
58+
return nothing
59+
else
60+
throw(GitError(err))
5961
end
60-
rb_op_ptr = unsafe_load(rb_op_ptr_ptr[])
6162
end
62-
return rb_op_ptr
6363
end
6464

6565
function Base.show(io::IO, rb::GitRebase)

stdlib/LibGit2/test/libgit2.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,7 @@ mktempdir() do dir
16101610
rb = LibGit2.GitRebase(repo, head_ann, upst_ann)
16111611
@test_throws BoundsError rb[3]
16121612
@test_throws BoundsError rb[0]
1613-
rbo = next(rb)
1613+
rbo, _ = iterate(rb)
16141614
rbo_str = sprint(show, rbo)
16151615
@test rbo_str == "RebaseOperation($(string(rbo.id)))\nOperation type: REBASE_OPERATION_PICK\n"
16161616
rb_str = sprint(show, rb)

0 commit comments

Comments
 (0)