diff --git a/base/libgit2/callbacks.jl b/base/libgit2/callbacks.jl index 0ea20b7a0688c6..f46b232ce14353 100644 --- a/base/libgit2/callbacks.jl +++ b/base/libgit2/callbacks.jl @@ -14,7 +14,7 @@ function mirror_callback(remote::Ptr{Ptr{Void}}, repo_ptr::Ptr{Void}, err != 0 && return Cint(err) # And set the configuration option to true for the push command - config = GitConfig(GitRepo(repo_ptr)) + config = GitConfig(GitRepo(repo_ptr,false)) name_str = unsafe_string(name) err= try set!(config, "remote.$name_str.mirror", true) catch -1 diff --git a/base/libgit2/config.jl b/base/libgit2/config.jl index bdec33130fd13b..534025b043aa5b 100644 --- a/base/libgit2/config.jl +++ b/base/libgit2/config.jl @@ -16,11 +16,11 @@ function GitConfig(path::AbstractString, return cfg end -function GitConfig(r::GitRepo) +function GitConfig(repo::GitRepo) cfg_ptr_ptr = Ref{Ptr{Void}}(C_NULL) @check ccall((:git_repository_config, :libgit2), Cint, - (Ptr{Ptr{Void}}, Ptr{Void}), cfg_ptr_ptr, r.ptr) - return GitConfig(cfg_ptr_ptr[]) + (Ptr{Ptr{Void}}, Ptr{Void}), cfg_ptr_ptr, repo.ptr) + return GitConfig(repo, cfg_ptr_ptr[]) end function GitConfig(level::Consts.GIT_CONFIG = Consts.CONFIG_LEVEL_DEFAULT) diff --git a/base/libgit2/diff.jl b/base/libgit2/diff.jl index c580d734b66649..a1c5669bb8bdf2 100644 --- a/base/libgit2/diff.jl +++ b/base/libgit2/diff.jl @@ -20,7 +20,7 @@ function diff_tree(repo::GitRepo, tree::GitTree, pathspecs::AbstractString=""; c finally !emptypathspec && close(sa) end - return GitDiff(diff_ptr_ptr[]) + return GitDiff(repo, diff_ptr_ptr[]) end function diff_tree(repo::GitRepo, oldtree::GitTree, newtree::GitTree) @@ -28,7 +28,7 @@ function diff_tree(repo::GitRepo, oldtree::GitTree, newtree::GitTree) @check ccall((:git_diff_tree_to_tree, :libgit2), Cint, (Ptr{Ptr{Void}}, Ptr{Void}, Ptr{Void}, Ptr{Void}, Ptr{DiffOptionsStruct}), diff_ptr_ptr, repo.ptr, oldtree.ptr, newtree.ptr, C_NULL) - return GitDiff(diff_ptr_ptr[]) + return GitDiff(repo, diff_ptr_ptr[]) end function Base.count(diff::GitDiff) diff --git a/base/libgit2/index.jl b/base/libgit2/index.jl index 2a25e2cea87049..d9682b5d057c88 100644 --- a/base/libgit2/index.jl +++ b/base/libgit2/index.jl @@ -4,7 +4,7 @@ function GitIndex(repo::GitRepo) idx_ptr_ptr = Ref{Ptr{Void}}(C_NULL) @check ccall((:git_repository_index, :libgit2), Cint, (Ptr{Ptr{Void}}, Ptr{Void}), idx_ptr_ptr, repo.ptr) - return GitIndex(idx_ptr_ptr[]) + return GitIndex(repo, idx_ptr_ptr[]) end function read!(idx::GitIndex, force::Bool = false) @@ -25,9 +25,8 @@ function write_tree!(idx::GitIndex) end function owner(idx::GitIndex) - repo_ptr = ccall((:git_index_owner, :libgit2), Ptr{Void}, - (Ptr{Void},), idx.ptr) - return GitRepo(repo_ptr) + isnull(idx.nrepo) && throw(GitError(Error.Index, Error.ENOTFOUND, "Index does not have an owning repository.")) + return Base.get(idx.nrepo) end function read_tree!(idx::GitIndex, tree_id::Oid) diff --git a/base/libgit2/merge.jl b/base/libgit2/merge.jl index 054a856c73f309..2769572553d779 100644 --- a/base/libgit2/merge.jl +++ b/base/libgit2/merge.jl @@ -5,7 +5,7 @@ function GitAnnotated(repo::GitRepo, commit_id::Oid) @check ccall((:git_annotated_commit_lookup, :libgit2), Cint, (Ptr{Ptr{Void}}, Ptr{Void}, Ptr{Oid}), ann_ptr_ptr, repo.ptr, Ref(commit_id)) - return GitAnnotated(ann_ptr_ptr[]) + return GitAnnotated(repo, ann_ptr_ptr[]) end function GitAnnotated(repo::GitRepo, ref::GitReference) @@ -13,7 +13,7 @@ function GitAnnotated(repo::GitRepo, ref::GitReference) @check ccall((:git_annotated_commit_from_ref, :libgit2), Cint, (Ptr{Ptr{Void}}, Ptr{Void}, Ptr{Void}), ann_ref_ref, repo.ptr, ref.ptr) - return GitAnnotated(ann_ref_ref[]) + return GitAnnotated(repo, ann_ref_ref[]) end function GitAnnotated(repo::GitRepo, fh::FetchHead) @@ -21,7 +21,7 @@ function GitAnnotated(repo::GitRepo, fh::FetchHead) @check ccall((:git_annotated_commit_from_fetchhead, :libgit2), Cint, (Ptr{Ptr{Void}}, Ptr{Void}, Cstring, Cstring, Ptr{Oid}), ann_ref_ref, repo.ptr, fh.name, fh.url, Ref(fh.oid)) - return GitAnnotated(ann_ref_ref[]) + return GitAnnotated(repo, ann_ref_ref[]) end function GitAnnotated(repo::GitRepo, comittish::AbstractString) diff --git a/base/libgit2/rebase.jl b/base/libgit2/rebase.jl index cf6645693d57d8..8a80b7ca9afa69 100644 --- a/base/libgit2/rebase.jl +++ b/base/libgit2/rebase.jl @@ -9,7 +9,7 @@ function GitRebase(repo::GitRepo, branch::GitAnnotated, upstream::GitAnnotated; Ptr{Void}, Ptr{RebaseOptions}), rebase_ptr_ptr, repo.ptr, branch.ptr, upstream.ptr, isnull(onto) ? C_NULL : Base.get(onto).ptr, Ref(opts)) - return GitRebase(rebase_ptr_ptr[]) + return GitRebase(repo, rebase_ptr_ptr[]) end function Base.count(rb::GitRebase) diff --git a/base/libgit2/reference.jl b/base/libgit2/reference.jl index b3e7657d0e8806..744312c34d5a69 100644 --- a/base/libgit2/reference.jl +++ b/base/libgit2/reference.jl @@ -5,7 +5,7 @@ function GitReference(repo::GitRepo, refname::AbstractString) @check ccall((:git_reference_lookup, :libgit2), Cint, (Ptr{Ptr{Void}}, Ptr{Void}, Cstring), ref_ptr_ptr, repo.ptr, refname) - return GitReference(ref_ptr_ptr[]) + return GitReference(repo, ref_ptr_ptr[]) end function GitReference(repo::GitRepo, obj_oid::Oid, refname::AbstractString = Consts.HEAD_FILE; @@ -15,14 +15,14 @@ function GitReference(repo::GitRepo, obj_oid::Oid, refname::AbstractString = Con (Ptr{Ptr{Void}}, Ptr{Void}, Ptr{UInt8}, Ptr{Oid}, Cint, Cstring), ref_ptr_ptr, repo.ptr, refname, Ref(obj_oid), Cint(force), isempty(msg) ? C_NULL : msg) - return GitReference(ref_ptr_ptr[]) + return GitReference(repo, ref_ptr_ptr[]) end function head(repo::GitRepo) head_ptr_ptr = Ref{Ptr{Void}}(C_NULL) @check ccall((:git_repository_head, :libgit2), Cint, (Ptr{Ptr{Void}}, Ptr{Void}), head_ptr_ptr, repo.ptr) - return GitReference(head_ptr_ptr[]) + return GitReference(repo, head_ptr_ptr[]) end function shortname(ref::GitReference) @@ -96,11 +96,11 @@ function peel{T <: GitObject}(::Type{T}, ref::GitReference) return Oid() elseif err != Int(Error.GIT_OK) if obj_ptr_ptr[] != C_NULL - close(GitAnyObject(obj_ptr_ptr[])) + close(GitAnyObject(ref.repo, obj_ptr_ptr[])) end throw(Error.GitError(err)) end - return T(obj_ptr_ptr[]) + return T(ref.repo, obj_ptr_ptr[]) end function ref_list(repo::GitRepo) @@ -120,7 +120,7 @@ function create_branch(repo::GitRepo, @check ccall((:git_branch_create, :libgit2), Cint, (Ptr{Ptr{Void}}, Ptr{Void}, Cstring, Ptr{Void}, Cint), ref_ptr_ptr, repo.ptr, bname, commit_obj.ptr, Cint(force)) - return GitReference(ref_ptr_ptr[]) + return GitReference(repo, ref_ptr_ptr[]) end function delete_branch(branch::GitReference) @@ -146,11 +146,11 @@ function lookup_branch(repo::GitRepo, return nothing elseif err != Int(Error.GIT_OK) if ref_ptr_ptr[] != C_NULL - close(GitReference(ref_ptr_ptr[])) + close(GitReference(repo, ref_ptr_ptr[])) end throw(Error.GitError(err)) end - return GitReference(ref_ptr_ptr[]) + return GitReference(repo, ref_ptr_ptr[]) end function upstream(ref::GitReference) @@ -162,32 +162,28 @@ function upstream(ref::GitReference) return nothing elseif err != Int(Error.GIT_OK) if ref_ptr_ptr[] != C_NULL - close(GitReference(ref_ptr_ptr[])) + close(GitReference(ref.repo, ref_ptr_ptr[])) end throw(Error.GitError(err)) end - return GitReference(ref_ptr_ptr[]) + return GitReference(ref.repo, ref_ptr_ptr[]) end -function owner(ref::GitReference) - repo_ptr = ccall((:git_reference_owner, :libgit2), Ptr{Void}, - (Ptr{Void},), ref.ptr) - return GitRepo(repo_ptr) -end +owner(ref::GitReference) = ref.repo function target!(ref::GitReference, new_oid::Oid; msg::AbstractString="") ref_ptr_ptr = Ref{Ptr{Void}}(C_NULL) @check ccall((:git_reference_set_target, :libgit2), Cint, (Ptr{Ptr{Void}}, Ptr{Void}, Ptr{Oid}, Cstring), ref_ptr_ptr, ref.ptr, Ref(new_oid), isempty(msg) ? C_NULL : msg) - return GitReference(ref_ptr_ptr[]) + return GitReference(ref.repo, ref_ptr_ptr[]) end -function GitBranchIter(r::GitRepo, flags::Cint=Cint(Consts.BRANCH_LOCAL)) +function GitBranchIter(repo::GitRepo, flags::Cint=Cint(Consts.BRANCH_LOCAL)) bi_ptr = Ref{Ptr{Void}}(C_NULL) @check ccall((:git_branch_iterator_new, :libgit2), Cint, - (Ptr{Ptr{Void}}, Ptr{Void}, Cint), bi_ptr, r.ptr, flags) - return GitBranchIter(bi_ptr[]) + (Ptr{Ptr{Void}}, Ptr{Void}, Cint), bi_ptr, repo.ptr, flags) + return GitBranchIter(repo, bi_ptr[]) end function Base.start(bi::GitBranchIter) @@ -197,7 +193,7 @@ function Base.start(bi::GitBranchIter) (Ptr{Ptr{Void}}, Ptr{Cint}, Ptr{Void}), ref_ptr_ptr, btype, bi.ptr) err != Int(Error.GIT_OK) && return (nothing, -1, true) - return (GitReference(ref_ptr_ptr[]), btype[], false) + return (GitReference(bi.repo, ref_ptr_ptr[]), btype[], false) end Base.done(bi::GitBranchIter, state) = Bool(state[3]) @@ -209,7 +205,7 @@ function Base.next(bi::GitBranchIter, state) (Ptr{Ptr{Void}}, Ptr{Cint}, Ptr{Void}), ref_ptr_ptr, btype, bi.ptr) err != Int(Error.GIT_OK) && return (state[1:2], (nothing, -1, true)) - return (state[1:2], (GitReference(ref_ptr_ptr[]), btype[], false)) + return (state[1:2], (GitReference(bi.repo, ref_ptr_ptr[]), btype[], false)) end Base.iteratorsize(::Type{GitBranchIter}) = Base.SizeUnknown() diff --git a/base/libgit2/remote.jl b/base/libgit2/remote.jl index 2c298ee9c49f5d..16a342405b1e3f 100644 --- a/base/libgit2/remote.jl +++ b/base/libgit2/remote.jl @@ -5,7 +5,7 @@ function GitRemote(repo::GitRepo, rmt_name::AbstractString, rmt_url::AbstractStr @check ccall((:git_remote_create, :libgit2), Cint, (Ptr{Ptr{Void}}, Ptr{Void}, Cstring, Cstring), rmt_ptr_ptr, repo.ptr, rmt_name, rmt_url) - return GitRemote(rmt_ptr_ptr[]) + return GitRemote(repo, rmt_ptr_ptr[]) end function GitRemote(repo::GitRepo, rmt_name::AbstractString, rmt_url::AbstractString, fetch_spec::AbstractString) @@ -13,7 +13,7 @@ function GitRemote(repo::GitRepo, rmt_name::AbstractString, rmt_url::AbstractStr @check ccall((:git_remote_create_with_fetchspec, :libgit2), Cint, (Ptr{Ptr{Void}}, Ptr{Void}, Cstring, Cstring, Cstring), rmt_ptr_ptr, repo.ptr, rmt_name, rmt_url, fetch_spec) - return GitRemote(rmt_ptr_ptr[]) + return GitRemote(repo, rmt_ptr_ptr[]) end function GitRemoteAnon(repo::GitRepo, url::AbstractString) @@ -21,7 +21,7 @@ function GitRemoteAnon(repo::GitRepo, url::AbstractString) @check ccall((:git_remote_create_anonymous, :libgit2), Cint, (Ptr{Ptr{Void}}, Ptr{Void}, Cstring), rmt_ptr_ptr, repo.ptr, url) - return GitRemote(rmt_ptr_ptr[]) + return GitRemote(repo, rmt_ptr_ptr[]) end function get(::Type{GitRemote}, repo::GitRepo, rmt_name::AbstractString) @@ -29,7 +29,7 @@ function get(::Type{GitRemote}, repo::GitRepo, rmt_name::AbstractString) @check ccall((:git_remote_lookup, :libgit2), Cint, (Ptr{Ptr{Void}}, Ptr{Void}, Cstring), rmt_ptr_ptr, repo.ptr, rmt_name) - return GitRemote(rmt_ptr_ptr[]) + return GitRemote(repo, rmt_ptr_ptr[]) end function url(rmt::GitRemote) diff --git a/base/libgit2/repository.jl b/base/libgit2/repository.jl index bf51f3f51d3577..60fe43f0968c77 100644 --- a/base/libgit2/repository.jl +++ b/base/libgit2/repository.jl @@ -74,7 +74,7 @@ function revparse(repo::GitRepo, objname::AbstractString) err = ccall((:git_revparse_single, :libgit2), Cint, (Ptr{Ptr{Void}}, Ptr{Void}, Cstring), obj_ptr_ptr, repo.ptr, objname) err != 0 && return nothing - return GitAnyObject(obj_ptr_ptr[]) + return GitAnyObject(repo, obj_ptr_ptr[]) end """ Returns id of a found object """ @@ -86,7 +86,7 @@ function revparseid(repo::GitRepo, objname::AbstractString) return oid end -function get{T <: GitObject}(::Type{T}, r::GitRepo, oid::Oid, oid_size::Int=OID_HEXSZ) +function get{T <: GitObject}(::Type{T}, repo::GitRepo, oid::Oid, oid_size::Int=OID_HEXSZ) id_ptr = Ref(oid) obj_ptr_ptr = Ref{Ptr{Void}}(C_NULL) git_otype = getobjecttype(T) @@ -94,25 +94,25 @@ function get{T <: GitObject}(::Type{T}, r::GitRepo, oid::Oid, oid_size::Int=OID_ err = if oid_size != OID_HEXSZ ccall((:git_object_lookup_prefix, :libgit2), Cint, (Ptr{Ptr{Void}}, Ptr{Void}, Ptr{Oid}, Csize_t, Cint), - obj_ptr_ptr, r.ptr, id_ptr, Csize_t(oid_size), git_otype) + obj_ptr_ptr, repo.ptr, id_ptr, Csize_t(oid_size), git_otype) else ccall((:git_object_lookup, :libgit2), Cint, (Ptr{Ptr{Void}}, Ptr{Void}, Ptr{Oid}, Cint), - obj_ptr_ptr, r.ptr, id_ptr, git_otype) + obj_ptr_ptr, repo.ptr, id_ptr, git_otype) end if err == Int(Error.ENOTFOUND) return nothing elseif err != Int(Error.GIT_OK) if obj_ptr_ptr[] != C_NULL - close(GitAnyObject(obj_ptr_ptr[])) + close(GitAnyObject(repo, obj_ptr_ptr[])) end throw(Error.GitError(err)) end - return T(obj_ptr_ptr[]) + return T(repo, obj_ptr_ptr[]) end -function get{T <: GitObject}(::Type{T}, r::GitRepo, oid::AbstractString) - return get(T, r, Oid(oid), length(oid)) +function get{T <: GitObject}(::Type{T}, repo::GitRepo, oid::AbstractString) + return get(T, repo, Oid(oid), length(oid)) end function gitdir(repo::GitRepo) @@ -134,11 +134,11 @@ function peel(obj::GitObject, obj_type::Cint) return Oid() elseif err != Int(Error.GIT_OK) if peeled_ptr_ptr[] != C_NULL - close(GitAnyObject(peeled_ptr_ptr[])) + close(GitAnyObject(obj.repo, peeled_ptr_ptr[])) end throw(Error.GitError(err)) end - return git_otype(peeled_ptr_ptr[]) + return git_otype(obj.repo, peeled_ptr_ptr[]) end peel{T <: GitObject}(::Type{T}, obj::GitObject) = peel(obj, getobjecttype(T)) diff --git a/base/libgit2/status.jl b/base/libgit2/status.jl index 8adf8ede7c0bbc..889f609d9b25f5 100644 --- a/base/libgit2/status.jl +++ b/base/libgit2/status.jl @@ -5,7 +5,7 @@ function GitStatus(repo::GitRepo; status_opts=StatusOptions()) @check ccall((:git_status_list_new, :libgit2), Cint, (Ptr{Ptr{Void}}, Ptr{Void}, Ptr{StatusOptions}), stat_ptr_ptr, repo.ptr, Ref(status_opts)) - return GitStatus(stat_ptr_ptr[]) + return GitStatus(repo, stat_ptr_ptr[]) end function Base.length(status::GitStatus) diff --git a/base/libgit2/tree.jl b/base/libgit2/tree.jl index 321bd83708d2c6..a814840c98ea54 100644 --- a/base/libgit2/tree.jl +++ b/base/libgit2/tree.jl @@ -32,5 +32,5 @@ function object(repo::GitRepo, te::GitTreeEntry) @check ccall((:git_tree_entry_to_object, :libgit2), Cint, (Ptr{Ptr{Void}}, Ptr{Void}, Ref{Void}), obj_ptr_ptr, repo.ptr, te.ptr) - return GitAnyObject(obj_ptr_ptr[]) + return GitAnyObject(repo, obj_ptr_ptr[]) end diff --git a/base/libgit2/types.jl b/base/libgit2/types.jl index 7f31d778d4a521..961cf054180647 100644 --- a/base/libgit2/types.jl +++ b/base/libgit2/types.jl @@ -373,54 +373,100 @@ abstract AbstractGitObject Base.isempty(obj::AbstractGitObject) = (obj.ptr == C_NULL) abstract GitObject <: AbstractGitObject -function Base.close(obj::GitObject) - if obj.ptr != C_NULL - ccall((:git_object_free, :libgit2), Void, (Ptr{Void},), obj.ptr) - obj.ptr = C_NULL + +macro defclose(typ,cname) + quote end end -# Common types -for (typ, ref, sup, fnc) in ( - (:GitRemote, :Void, :AbstractGitObject, :(:git_remote_free)), - (:GitRevWalker, :Void, :AbstractGitObject, :(:git_revwalk_free)), - (:GitConfig, :Void, :AbstractGitObject, :(:git_config_free)), - (:GitReference, :Void, :AbstractGitObject, :(:git_reference_free)), - (:GitDiff, :Void, :AbstractGitObject, :(:git_diff_free)), - (:GitIndex, :Void, :AbstractGitObject, :(:git_index_free)), - (:GitRepo, :Void, :AbstractGitObject, :(:git_repository_free)), - (:GitAnnotated, :Void, :AbstractGitObject, :(:git_annotated_commit_free)), - (:GitRebase, :Void, :AbstractGitObject, :(:git_rebase_free)), - (:GitStatus, :Void, :AbstractGitObject, :(:git_status_list_free)), - (:GitBranchIter, :Void, :AbstractGitObject, :(:git_branch_iterator_free)), - (:GitTreeEntry, :Void, :AbstractGitObject, :(:git_tree_entry_free)), - (:GitSignature, :SignatureStruct, :AbstractGitObject, :(:git_signature_free)), - (:GitAnyObject, :Void, :GitObject, nothing), - (:GitCommit, :Void, :GitObject, nothing), - (:GitBlob, :Void, :GitObject, nothing), - (:GitTree, :Void, :GitObject, nothing), - (:GitTag, :Void, :GitObject, nothing) - ) - - @eval type $typ <: $sup - ptr::Ptr{$ref} - function $typ(ptr::Ptr{$ref}) - @assert ptr != C_NULL - obj = new(ptr) - finalizer(obj, Base.close) - return obj - end - end - if fnc !== nothing - @eval function Base.close(obj::$typ) - if obj.ptr != C_NULL - ccall(($fnc, :libgit2), Void, (Ptr{$ref},), obj.ptr) - obj.ptr = C_NULL +for (typ, reporef, sup, cname) in [ + (:GitRepo, nothing, :AbstractGitObject, :git_repository), + (:GitTreeEntry, nothing, :AbstractGitObject, :git_tree_entry), + (:GitConfig, :Nullable, :AbstractGitObject, :git_config), + (:GitIndex, :Nullable, :AbstractGitObject, :git_index), + (:GitRemote, :GitRepo, :AbstractGitObject, :git_remote), + (:GitRevWalker, :GitRepo, :AbstractGitObject, :git_revwalk), + (:GitReference, :GitRepo, :AbstractGitObject, :git_reference), + (:GitDiff, :GitRepo, :AbstractGitObject, :git_diff), + (:GitAnnotated, :GitRepo, :AbstractGitObject, :git_annotated_commit), + (:GitRebase, :GitRepo, :AbstractGitObject, :git_rebase), + (:GitStatus, :GitRepo, :AbstractGitObject, :git_status_list), + (:GitBranchIter, :GitRepo, :AbstractGitObject, :git_branch_iterator), + (:GitAnyObject, :GitRepo, :GitObject, :git_object), + (:GitCommit, :GitRepo, :GitObject, :git_commit), + (:GitBlob, :GitRepo, :GitObject, :git_blob), + (:GitTree, :GitRepo, :GitObject, :git_tree), + (:GitTag, :GitRepo, :GitObject, :git_tag)] + + if reporef == nothing + @eval type $typ <: $sup + ptr::Ptr{Void} + function $typ(ptr::Ptr{Void},fin=true) + @assert ptr != C_NULL + obj = new(ptr) + if fin + finalizer(obj, Base.close) + end + return obj + end + end + elseif reporef == :Nullable + @eval type $typ <: $sup + nrepo::Nullable{GitRepo} + ptr::Ptr{Void} + function $typ(repo::GitRepo, ptr::Ptr{Void}) + @assert ptr != C_NULL + obj = new(Nullable(repo), ptr) + finalizer(obj, Base.close) + return obj + end + function $typ(ptr::Ptr{Void}) + @assert ptr != C_NULL + obj = new(Nullable{GitRepo}(), ptr) + finalizer(obj, Base.close) + return obj + end + end + elseif reporef == :GitRepo + @eval type $typ <: $sup + repo::GitRepo + ptr::Ptr{Void} + function $typ(repo::GitRepo, ptr::Ptr{Void}) + @assert ptr != C_NULL + obj = new(repo, ptr) + finalizer(obj, Base.close) + return obj end end end + @eval function Base.close(obj::$typ) + if obj.ptr != C_NULL + ccall(($(string(cname, :_free)), :libgit2), Void, (Ptr{Void},), obj.ptr) + obj.ptr = C_NULL + end + end +end +""" + LibGit2.GitSignature + +This is a Julia wrapper around a pointer to a [`git_signature`](https://libgit2.github.com/libgit2/#HEAD/type/git_signature) object. +""" +type GitSignature <: AbstractGitObject + ptr::Ptr{SignatureStruct} + function GitSignature(ptr::Ptr{SignatureStruct}) + @assert ptr != C_NULL + obj = new(ptr) + finalizer(obj, Base.close) + return obj + end +end +function Base.close(obj::GitSignature) + if obj.ptr != C_NULL + ccall((:git_signature_free, :libgit2), Void, (Ptr{SignatureStruct},), obj.ptr) + obj.ptr = C_NULL + end end # Structure has the same layout as SignatureStruct diff --git a/base/libgit2/walker.jl b/base/libgit2/walker.jl index 1d564c3c406db7..fa878a414a4c68 100644 --- a/base/libgit2/walker.jl +++ b/base/libgit2/walker.jl @@ -1,10 +1,10 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -function GitRevWalker(r::GitRepo) +function GitRevWalker(repo::GitRepo) w_ptr = Ref{Ptr{Void}}(C_NULL) @check ccall((:git_revwalk_new, :libgit2), Cint, - (Ptr{Ptr{Void}}, Ptr{Void}), w_ptr, r.ptr) - return GitRevWalker(w_ptr[]) + (Ptr{Ptr{Void}}, Ptr{Void}), w_ptr, repo.ptr) + return GitRevWalker(repo, w_ptr[]) end function Base.start(w::GitRevWalker) @@ -48,11 +48,7 @@ function Base.sort!(w::GitRevWalker; by::Cint = Consts.SORT_NONE, rev::Bool=fals return w end -function repository(w::GitRevWalker) - ptr = ccall((:git_revwalk_repository, :libgit2), Ptr{Void}, (Ptr{Void},), w.ptr) - ptr != C_NULL && return GitRepo(ptr) - return nothing -end +repository(w::GitRevWalker) = w.repo function Base.map(f::Function, walker::GitRevWalker; oid::Oid=Oid(),