Commit 97f3462ae699fae370cfa410ed58eb869ae6b276

Edward Thomson 2014-03-18T13:14:09

git_merge_status -> git_merge_analysis

diff --git a/include/git2/merge.h b/include/git2/merge.h
index a4432ee..2cb8df3 100644
--- a/include/git2/merge.h
+++ b/include/git2/merge.h
@@ -235,41 +235,44 @@ GIT_EXTERN(int) git_merge_init_options(
 	int version);
 
 /**
- * The results of `git_merge_status` indicate the state of a merge scenario.
+ * The results of `git_merge_analysis` indicate the merge opportunities.
  */
 typedef enum {
+	/** No merge is possible.  (Unused.) */
+	GIT_MERGE_ANALYSIS_NONE = 0,
+
 	/**
 	 * A "normal" merge; both HEAD and the given merge input have diverged
 	 * from their common ancestor.  The divergent commits must be merged.
 	 */
-	GIT_MERGE_STATUS_NORMAL = 0,
+	GIT_MERGE_ANALYSIS_NORMAL = (1 << 0),
 
 	/**
 	 * The repository is already up-to-date and no merge needs to be
 	 * performed.  The given merge input already exists as a parent of HEAD.
 	 */
-	GIT_MERGE_STATUS_UP_TO_DATE = (1 << 0),
+	GIT_MERGE_ANALYSIS_UP_TO_DATE = (1 << 1),
 
 	/**
 	 * The given merge input is a fast-forward from HEAD and no merge
 	 * needs to be performed.  Instead, the client can check out the
 	 * given merge input.
 	 */
-	GIT_MERGE_STATUS_FASTFORWARD = (1 << 1),
-} git_merge_status_t;
+	GIT_MERGE_ANALYSIS_FASTFORWARD = (1 << 2),
+} git_merge_analysis_t;
 
 /**
- * Determine the status of the merge between the given branch(es) and the
- * HEAD of the repository.
+ * Analyzes the given branch(es) and determines the opportunities for
+ * merging them into the HEAD of the repository.
  *
- * @param status_out status enumeration that the result is written into
+ * @param analysis_out analysis enumeration that the result is written into
  * @param repo the repository to merge
  * @param their_heads the heads to merge into
  * @param their_heads_len the number of heads to merge
  * @return 0 on success or error code
  */
-GIT_EXTERN(int) git_merge_status(
-	git_merge_status_t *status_out,
+GIT_EXTERN(int) git_merge_analysis(
+	git_merge_analysis_t *analysis_out,
 	git_repository *repo,
 	const git_merge_head **their_heads,
 	size_t their_heads_len);
diff --git a/src/merge.c b/src/merge.c
index 66b8be6..6b416a3 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -2517,8 +2517,8 @@ done:
 	return error;
 }
 
-int git_merge_status(
-	git_merge_status_t *out,
+int git_merge_analysis(
+	git_merge_analysis_t *out,
 	git_repository *repo,
 	const git_merge_head **their_heads,
 	size_t their_heads_len)
@@ -2528,7 +2528,7 @@ int git_merge_status(
 
 	assert(out && repo && their_heads);
 
-	*out = GIT_MERGE_STATUS_NORMAL;
+	*out = GIT_MERGE_ANALYSIS_NORMAL;
 
 	if ((error = merge_heads(&ancestor_head, &our_head, repo, their_heads, their_heads_len)) < 0)
 		goto done;
@@ -2536,11 +2536,11 @@ int git_merge_status(
 	if (their_heads_len == 1 && ancestor_head != NULL) {
 		/* We're up-to-date if we're trying to merge our own common ancestor. */
 		if (git_oid_equal(&ancestor_head->oid, &their_heads[0]->oid))
-			*out = GIT_MERGE_STATUS_UP_TO_DATE;
+			*out = GIT_MERGE_ANALYSIS_UP_TO_DATE;
 
 		/* We're fastforwardable if we're our own common ancestor. */
 		else if (git_oid_equal(&ancestor_head->oid, &our_head->oid))
-			*out = GIT_MERGE_STATUS_FASTFORWARD;
+			*out = GIT_MERGE_ANALYSIS_FASTFORWARD | GIT_MERGE_ANALYSIS_NORMAL;
 	}
 
 done:
diff --git a/tests/merge/workdir/analysis.c b/tests/merge/workdir/analysis.c
new file mode 100644
index 0000000..6a4b86d
--- /dev/null
+++ b/tests/merge/workdir/analysis.c
@@ -0,0 +1,90 @@
+#include "clar_libgit2.h"
+#include "git2/repository.h"
+#include "git2/merge.h"
+#include "git2/sys/index.h"
+#include "merge.h"
+#include "../merge_helpers.h"
+#include "refs.h"
+
+static git_repository *repo;
+static git_index *repo_index;
+
+#define TEST_REPO_PATH "merge-resolve"
+#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
+
+#define UPTODATE_BRANCH			"master"
+#define PREVIOUS_BRANCH			"previous"
+
+#define FASTFORWARD_BRANCH		"ff_branch"
+#define FASTFORWARD_ID			"fd89f8cffb663ac89095a0f9764902e93ceaca6a"
+
+#define NOFASTFORWARD_BRANCH	"branch"
+#define NOFASTFORWARD_ID		"7cb63eed597130ba4abb87b3e544b85021905520"
+
+
+// Fixture setup and teardown
+void test_merge_workdir_analysis__initialize(void)
+{
+	repo = cl_git_sandbox_init(TEST_REPO_PATH);
+	git_repository_index(&repo_index, repo);
+}
+
+void test_merge_workdir_analysis__cleanup(void)
+{
+	git_index_free(repo_index);
+	cl_git_sandbox_cleanup();
+}
+
+static git_merge_analysis_t analysis_from_branch(const char *branchname)
+{
+	git_buf refname = GIT_BUF_INIT;
+	git_reference *their_ref;
+	git_merge_head *their_heads[1];
+	git_merge_analysis_t analysis;
+
+	git_buf_printf(&refname, "%s%s", GIT_REFS_HEADS_DIR, branchname);
+
+	cl_git_pass(git_reference_lookup(&their_ref, repo, git_buf_cstr(&refname)));
+	cl_git_pass(git_merge_head_from_ref(&their_heads[0], repo, their_ref));
+
+	cl_git_pass(git_merge_analysis(&analysis, repo, their_heads, 1));
+
+	git_buf_free(&refname);
+	git_merge_head_free(their_heads[0]);
+	git_reference_free(their_ref);
+
+	return analysis;
+}
+
+void test_merge_workdir_analysis__fastforward(void)
+{
+	git_merge_analysis_t analysis;
+
+	analysis = analysis_from_branch(FASTFORWARD_BRANCH);
+	cl_assert_equal_i(GIT_MERGE_ANALYSIS_FASTFORWARD, (analysis & GIT_MERGE_ANALYSIS_FASTFORWARD));
+	cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, (analysis & GIT_MERGE_ANALYSIS_NORMAL));
+}
+
+void test_merge_workdir_analysis__no_fastforward(void)
+{
+	git_merge_analysis_t analysis;
+
+	analysis = analysis_from_branch(NOFASTFORWARD_BRANCH);
+	cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, analysis);
+}
+
+void test_merge_workdir_analysis__uptodate(void)
+{
+	git_merge_analysis_t analysis;
+
+	analysis = analysis_from_branch(UPTODATE_BRANCH);
+	cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, analysis);
+}
+
+void test_merge_workdir_analysis__uptodate_merging_prev_commit(void)
+{
+	git_merge_analysis_t analysis;
+
+	analysis = analysis_from_branch(PREVIOUS_BRANCH);
+	cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, analysis);
+}
diff --git a/tests/merge/workdir/status.c b/tests/merge/workdir/status.c
deleted file mode 100644
index 589299e..0000000
--- a/tests/merge/workdir/status.c
+++ /dev/null
@@ -1,89 +0,0 @@
-#include "clar_libgit2.h"
-#include "git2/repository.h"
-#include "git2/merge.h"
-#include "git2/sys/index.h"
-#include "merge.h"
-#include "../merge_helpers.h"
-#include "refs.h"
-
-static git_repository *repo;
-static git_index *repo_index;
-
-#define TEST_REPO_PATH "merge-resolve"
-#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
-
-#define UPTODATE_BRANCH			"master"
-#define PREVIOUS_BRANCH			"previous"
-
-#define FASTFORWARD_BRANCH		"ff_branch"
-#define FASTFORWARD_ID			"fd89f8cffb663ac89095a0f9764902e93ceaca6a"
-
-#define NOFASTFORWARD_BRANCH	"branch"
-#define NOFASTFORWARD_ID		"7cb63eed597130ba4abb87b3e544b85021905520"
-
-
-// Fixture setup and teardown
-void test_merge_workdir_status__initialize(void)
-{
-	repo = cl_git_sandbox_init(TEST_REPO_PATH);
-	git_repository_index(&repo_index, repo);
-}
-
-void test_merge_workdir_status__cleanup(void)
-{
-	git_index_free(repo_index);
-	cl_git_sandbox_cleanup();
-}
-
-static git_status_t status_from_branch(const char *branchname)
-{
-	git_buf refname = GIT_BUF_INIT;
-	git_reference *their_ref;
-	git_merge_head *their_heads[1];
-	git_status_t status;
-
-	git_buf_printf(&refname, "%s%s", GIT_REFS_HEADS_DIR, branchname);
-
-	cl_git_pass(git_reference_lookup(&their_ref, repo, git_buf_cstr(&refname)));
-	cl_git_pass(git_merge_head_from_ref(&their_heads[0], repo, their_ref));
-
-	cl_git_pass(git_merge_status(&status, repo, their_heads, 1));
-
-	git_buf_free(&refname);
-	git_merge_head_free(their_heads[0]);
-	git_reference_free(their_ref);
-
-	return status;
-}
-
-void test_merge_workdir_status__fastforward(void)
-{
-	git_merge_status_t status;
-
-	status = status_from_branch(FASTFORWARD_BRANCH);
-	cl_assert_equal_i(GIT_MERGE_STATUS_FASTFORWARD, status);
-}
-
-void test_merge_workdir_status__no_fastforward(void)
-{
-	git_merge_status_t status;
-
-	status = status_from_branch(NOFASTFORWARD_BRANCH);
-	cl_assert_equal_i(GIT_MERGE_STATUS_NORMAL, status);
-}
-
-void test_merge_workdir_status__uptodate(void)
-{
-	git_merge_status_t status;
-
-	status = status_from_branch(UPTODATE_BRANCH);
-	cl_assert_equal_i(GIT_MERGE_STATUS_UP_TO_DATE, status);
-}
-
-void test_merge_workdir_status__uptodate_merging_prev_commit(void)
-{
-	git_merge_status_t status;
-
-	status = status_from_branch(PREVIOUS_BRANCH);
-	cl_assert_equal_i(GIT_MERGE_STATUS_UP_TO_DATE, status);
-}