Skip to content

Commit

Permalink
Remove LibGit2 abuse of old iteration protocol
Browse files Browse the repository at this point in the history
This can now just be a stateful iterator, like the rest of them
in LibGit2.
  • Loading branch information
Keno committed Aug 7, 2018
1 parent 9d85f7f commit e86c5b6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion stdlib/LibGit2/src/LibGit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ function rebase!(repo::GitRepo, upstream::AbstractString="", newbase::AbstractSt
try
rbs = GitRebase(repo, head_ann, upst_ann, onto=onto_ann)
try
while (rbs_op = next(rbs)) !== nothing
for rbs_op in rbs
commit(rbs, sig)
end
finish(rbs, sig)
Expand Down
20 changes: 10 additions & 10 deletions stdlib/LibGit2/src/rebase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ function Base.getindex(rb::GitRebase, i::Integer)
return rb_op
end

function Base.next(rb::GitRebase)
function Base.iterate(rb::GitRebase, state=nothing)
ensure_initialized()
rb_op_ptr_ptr = Ref{Ptr{RebaseOperation}}(C_NULL)
GC.@preserve rb begin
try
@check ccall((:git_rebase_next, :libgit2), Cint,
(Ptr{Ptr{RebaseOperation}}, Ptr{Cvoid}),
rb_op_ptr_ptr, rb.ptr)
catch err
err.code == Error.ITEROVER && return nothing
rethrow(err)
err = ccall((:git_rebase_next, :libgit2), Cint,
(Ptr{Ptr{RebaseOperation}}, Ptr{Cvoid}),
rb_op_ptr_ptr, rb.ptr)
if err == Cint(Error.GIT_OK)
return unsafe_load(rb_op_ptr_ptr[]), nothing
elseif err == Cint(Error.ITEROVER)
return nothing
else
throw(GitError(err))
end
rb_op_ptr = unsafe_load(rb_op_ptr_ptr[])
end
return rb_op_ptr
end

function Base.show(io::IO, rb::GitRebase)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/LibGit2/test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,7 @@ mktempdir() do dir
rb = LibGit2.GitRebase(repo, head_ann, upst_ann)
@test_throws BoundsError rb[3]
@test_throws BoundsError rb[0]
rbo = next(rb)
rbo, _ = iterate(rb)
rbo_str = sprint(show, rbo)
@test rbo_str == "RebaseOperation($(string(rbo.id)))\nOperation type: REBASE_OPERATION_PICK\n"
rb_str = sprint(show, rb)
Expand Down

0 comments on commit e86c5b6

Please sign in to comment.