@@ -147,3 +147,45 @@ function commit(repo::GitRepo, msg::AbstractString;
147147 end
148148 return commit_id
149149end
150+
151+ """
152+ parentcount(c::GitCommit)
153+
154+ Get the number of parents of this commit.
155+
156+ See also [`parent`](@ref), [`parent_id`](@ref).
157+ """
158+ parentcount (c:: GitCommit ) =
159+ Int (ccall ((:git_commit_parentcount , :libgit2 ), Cuint, (Ptr{Cvoid},), c))
160+
161+ """
162+ parent(c::GitCommit, n)
163+
164+ Get the `n`-th (1-based) parent of the commit.
165+
166+ See also [`parentcount`](@ref), [`parent_id`](@ref).
167+ """
168+ function parent (c:: GitCommit , n)
169+ ptr_ref = Ref {Ptr{Cvoid}} ()
170+ @check ccall ((:git_commit_parent , :libgit2 ), Cint,
171+ (Ptr{Ptr{Cvoid}}, Ptr{Cvoid}, Cuint), ptr_ref, c, n - 1 )
172+ return GitCommit (c. owner, ptr_ref[])
173+ end
174+
175+ """
176+ parent_id(c::GitCommit, n)
177+
178+ Get the oid of the `n`-th (1-based) parent for a commit.
179+
180+ See also [`parentcount`](@ref), [`parent`](@ref).
181+ """
182+ function parent_id (c:: GitCommit , n)
183+ oid_ptr = ccall ((:git_commit_parent_id , :libgit2 ), Ptr{GitHash},
184+ (Ptr{Cvoid}, Cuint), c, n - 1 )
185+ if oid_ptr == C_NULL
186+ # 0-based indexing mimicking the error message from libgit2
187+ throw (GitError (Error. Invalid, Error. ENOTFOUND,
188+ " parent $(n - 1 ) does not exist" ))
189+ end
190+ return unsafe_load (oid_ptr)
191+ end
0 commit comments