vendor/libgit2/src/graph.c in rugged-0.19.0 vs vendor/libgit2/src/graph.c in rugged-0.21.0
- old
+ new
@@ -1,6 +1,5 @@
-
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
@@ -11,13 +10,13 @@
#include "git2/graph.h"
static int interesting(git_pqueue *list, git_commit_list *roots)
{
unsigned int i;
- /* element 0 isn't used - we need to start at 1 */
- for (i = 1; i < list->size; i++) {
- git_commit_list_node *commit = list->d[i];
+
+ for (i = 0; i < git_pqueue_size(list); i++) {
+ git_commit_list_node *commit = git_pqueue_get(list, i);
if ((commit->flags & STALE) == 0)
return 1;
}
while(roots) {
@@ -40,11 +39,11 @@
if (one == two) {
one->flags |= PARENT1 | PARENT2 | RESULT;
return 0;
}
- if (git_pqueue_init(&list, 2, git_commit_list_time_cmp) < 0)
+ if (git_pqueue_init(&list, 0, 2, git_commit_list_time_cmp) < 0)
return -1;
if (git_commit_list_parse(walk, one) < 0)
goto on_error;
one->flags |= PARENT1;
@@ -57,14 +56,13 @@
if (git_pqueue_insert(&list, two) < 0)
goto on_error;
/* as long as there are non-STALE commits */
while (interesting(&list, roots)) {
- git_commit_list_node *commit;
+ git_commit_list_node *commit = git_pqueue_pop(&list);
int flags;
- commit = git_pqueue_pop(&list);
if (commit == NULL)
break;
flags = commit->flags & (PARENT1 | PARENT2 | STALE);
if (flags == (PARENT1 | PARENT2)) {
@@ -108,21 +106,21 @@
static int ahead_behind(git_commit_list_node *one, git_commit_list_node *two,
size_t *ahead, size_t *behind)
{
git_commit_list_node *commit;
git_pqueue pq;
- int i;
+ int error = 0, i;
*ahead = 0;
*behind = 0;
- if (git_pqueue_init(&pq, 2, git_commit_list_time_cmp) < 0)
+ if (git_pqueue_init(&pq, 0, 2, git_commit_list_time_cmp) < 0)
return -1;
- if (git_pqueue_insert(&pq, one) < 0)
- goto on_error;
- if (git_pqueue_insert(&pq, two) < 0)
- goto on_error;
+ if ((error = git_pqueue_insert(&pq, one)) < 0 ||
+ (error = git_pqueue_insert(&pq, two)) < 0)
+ goto done;
+
while ((commit = git_pqueue_pop(&pq)) != NULL) {
if (commit->flags & RESULT ||
(commit->flags & (PARENT1 | PARENT2)) == (PARENT1 | PARENT2))
continue;
else if (commit->flags & PARENT1)
@@ -130,22 +128,19 @@
else if (commit->flags & PARENT2)
(*ahead)++;
for (i = 0; i < commit->out_degree; i++) {
git_commit_list_node *p = commit->parents[i];
- if (git_pqueue_insert(&pq, p) < 0)
- return -1;
+ if ((error = git_pqueue_insert(&pq, p)) < 0)
+ goto done;
}
commit->flags |= RESULT;
}
+done:
git_pqueue_free(&pq);
- return 0;
-
-on_error:
- git_pqueue_free(&pq);
- return -1;
+ return error;
}
int git_graph_ahead_behind(size_t *ahead, size_t *behind, git_repository *repo,
const git_oid *local, const git_oid *upstream)
{
@@ -173,6 +168,25 @@
return 0;
on_error:
git_revwalk_free(walk);
return -1;
+}
+
+int git_graph_descendant_of(git_repository *repo, const git_oid *commit, const git_oid *ancestor)
+{
+ git_oid merge_base;
+ int error;
+
+ if (git_oid_equal(commit, ancestor))
+ return 0;
+
+ error = git_merge_base(&merge_base, repo, commit, ancestor);
+ /* No merge-base found, it's not a descendant */
+ if (error == GIT_ENOTFOUND)
+ return 0;
+
+ if (error < 0)
+ return error;
+
+ return git_oid_equal(&merge_base, ancestor);
}