summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti <vicent@github.com>2014-08-28 16:33:53 +0200
committerVicent Marti <vicent@github.com>2014-08-28 16:33:53 +0200
commitd99c8ca1783cfd04869e88f8707c036fc6053a05 (patch)
tree3d0be8ec9a6517716898fb358e617a8773c1b047
parent69db89342712f47ee84d9368823ec294a0db1c65 (diff)
parent05f0d0c1190f0a3922d48d9f35c6ef6f3c2048a7 (diff)
downloadlibgit2-d99c8ca1783cfd04869e88f8707c036fc6053a05.tar.gz
Merge pull request #2539 from libgit2/cmn/ahead-behind-order
Fix ahead-behind results
-rw-r--r--src/graph.c4
-rw-r--r--tests/revwalk/mergebase.c36
2 files changed, 20 insertions, 20 deletions
diff --git a/src/graph.c b/src/graph.c
index 1c264d997..8accd808c 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -124,9 +124,9 @@ static int ahead_behind(git_commit_list_node *one, git_commit_list_node *two,
(commit->flags & (PARENT1 | PARENT2)) == (PARENT1 | PARENT2))
continue;
else if (commit->flags & PARENT1)
- (*behind)++;
- else if (commit->flags & PARENT2)
(*ahead)++;
+ else if (commit->flags & PARENT2)
+ (*behind)++;
for (i = 0; i < commit->out_degree; i++) {
git_commit_list_node *p = commit->parents[i];
diff --git a/tests/revwalk/mergebase.c b/tests/revwalk/mergebase.c
index 2c7184fc7..8f1f6ef21 100644
--- a/tests/revwalk/mergebase.c
+++ b/tests/revwalk/mergebase.c
@@ -33,12 +33,12 @@ void test_revwalk_mergebase__single1(void)
cl_assert_equal_oid(&expected, &result);
cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &one, &two));
- cl_assert_equal_sz(ahead, 2);
- cl_assert_equal_sz(behind, 1);
+ cl_assert_equal_sz(ahead, 1);
+ cl_assert_equal_sz(behind, 2);
cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &two, &one));
- cl_assert_equal_sz(ahead, 1);
- cl_assert_equal_sz(behind, 2);
+ cl_assert_equal_sz(ahead, 2);
+ cl_assert_equal_sz(behind, 1);
}
void test_revwalk_mergebase__single2(void)
@@ -54,12 +54,12 @@ void test_revwalk_mergebase__single2(void)
cl_assert_equal_oid(&expected, &result);
cl_git_pass(git_graph_ahead_behind( &ahead, &behind, _repo, &one, &two));
- cl_assert_equal_sz(ahead, 4);
- cl_assert_equal_sz(behind, 1);
-
- cl_git_pass(git_graph_ahead_behind( &ahead, &behind, _repo, &two, &one));
cl_assert_equal_sz(ahead, 1);
cl_assert_equal_sz(behind, 4);
+
+ cl_git_pass(git_graph_ahead_behind( &ahead, &behind, _repo, &two, &one));
+ cl_assert_equal_sz(ahead, 4);
+ cl_assert_equal_sz(behind, 1);
}
void test_revwalk_mergebase__merged_branch(void)
@@ -78,12 +78,12 @@ void test_revwalk_mergebase__merged_branch(void)
cl_assert_equal_oid(&expected, &result);
cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &one, &two));
- cl_assert_equal_sz(ahead, 0);
- cl_assert_equal_sz(behind, 3);
-
- cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &two, &one));
cl_assert_equal_sz(ahead, 3);
cl_assert_equal_sz(behind, 0);
+
+ cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &two, &one));
+ cl_assert_equal_sz(ahead, 0);
+ cl_assert_equal_sz(behind, 3);
}
void test_revwalk_mergebase__two_way_merge(void)
@@ -95,13 +95,13 @@ void test_revwalk_mergebase__two_way_merge(void)
cl_git_pass(git_oid_fromstr(&two, "a953a018c5b10b20c86e69fef55ebc8ad4c5a417"));
cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo2, &one, &two));
- cl_assert_equal_sz(ahead, 2);
- cl_assert_equal_sz(behind, 8);
+ cl_assert_equal_sz(ahead, 8);
+ cl_assert_equal_sz(behind, 2);
cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo2, &two, &one));
- cl_assert_equal_sz(ahead, 8);
- cl_assert_equal_sz(behind, 2);
+ cl_assert_equal_sz(ahead, 2);
+ cl_assert_equal_sz(behind, 8);
}
void test_revwalk_mergebase__no_common_ancestor_returns_ENOTFOUND(void)
@@ -119,8 +119,8 @@ void test_revwalk_mergebase__no_common_ancestor_returns_ENOTFOUND(void)
cl_assert_equal_i(GIT_ENOTFOUND, error);
cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &one, &two));
- cl_assert_equal_sz(2, ahead);
- cl_assert_equal_sz(4, behind);
+ cl_assert_equal_sz(4, ahead);
+ cl_assert_equal_sz(2, behind);
}
void test_revwalk_mergebase__prefer_youngest_merge_base(void)