mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-06 17:20:22 +00:00
commit: simplify and correct refcounting in nth_gen_ancestor
We can make use of git_object_dup to use refcounting instead of pointer comparison to make sure we don't free the caller's object. This also lets us simplify the case for '~0' which is now just an assignment instead of looking up the object we have at hand.
This commit is contained in:
parent
5187b609ba
commit
7c1ee212b7
15
src/commit.c
15
src/commit.c
@ -455,18 +455,17 @@ int git_commit_nth_gen_ancestor(
|
|||||||
|
|
||||||
assert(ancestor && commit);
|
assert(ancestor && commit);
|
||||||
|
|
||||||
current = (git_commit *)commit;
|
if (git_object_dup((git_object **) ¤t, (git_object *) commit) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0) {
|
||||||
return git_commit_lookup(
|
*ancestor = current;
|
||||||
ancestor,
|
return 0;
|
||||||
commit->object.repo,
|
}
|
||||||
git_object_id((const git_object *)commit));
|
|
||||||
|
|
||||||
while (n--) {
|
while (n--) {
|
||||||
error = git_commit_parent(&parent, (git_commit *)current, 0);
|
error = git_commit_parent(&parent, current, 0);
|
||||||
|
|
||||||
if (current != commit)
|
|
||||||
git_commit_free(current);
|
git_commit_free(current);
|
||||||
|
|
||||||
if (error < 0)
|
if (error < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user