Commit 5d96fe8828505db852671175d5895dfd275f3d06

Carlos Martín Nieto 2014-01-14T15:33:29

refs: changes from feedback Change the name to _matching() intead of _if(), and force _set_target() to be a conditional update. If the user doesn't care about the old value, they should use git_reference_create().

diff --git a/include/git2/refs.h b/include/git2/refs.h
index 296fcb6..7262294 100644
--- a/include/git2/refs.h
+++ b/include/git2/refs.h
@@ -184,7 +184,7 @@ GIT_EXTERN(int) git_reference_create(git_reference **out, git_repository *repo, 
  * @param old_id The old value which the reference should have
  * @return 0 on success, GIT_EEXISTS, GIT_EINVALIDSPEC or an error code
  */
-GIT_EXTERN(int) git_reference_create_if(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const git_signature *signature, const char *log_message, const git_oid *old_id);
+GIT_EXTERN(int) git_reference_create_matching(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const git_signature *signature, const char *log_message, const git_oid *old_id);
 
 /**
  * Get the OID pointed to by a direct reference.
diff --git a/src/refs.c b/src/refs.c
index a5492cf..007fdf3 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -407,19 +407,7 @@ static int log_signature(git_signature **out, git_repository *repo)
 	return 0;
 }
 
-int git_reference_create(
-	git_reference **ref_out,
-	git_repository *repo,
-	const char *name,
-	const git_oid *id,
-	int force,
-	const git_signature *signature,
-	const char *log_message)
-{
-        return git_reference_create_if(ref_out, repo, name, id, force, signature, log_message, NULL);
-}
-
-int git_reference_create_if(
+int git_reference_create_matching(
 	git_reference **ref_out,
 	git_repository *repo,
 	const char *name,
@@ -428,6 +416,7 @@ int git_reference_create_if(
 	const git_signature *signature,
 	const char *log_message,
 	const git_oid *old_id)
+
 {
 	int error;
 	git_signature *who = NULL;
@@ -448,6 +437,18 @@ int git_reference_create_if(
 	return error;
 }
 
+int git_reference_create(
+	git_reference **ref_out,
+	git_repository *repo,
+	const char *name,
+	const git_oid *id,
+	int force,
+	const git_signature *signature,
+	const char *log_message)
+{
+        return git_reference_create_matching(ref_out, repo, name, id, force, signature, log_message, NULL);
+}
+
 int git_reference_symbolic_create(
 	git_reference **ref_out,
 	git_repository *repo,
@@ -485,13 +486,12 @@ static int ensure_is_an_updatable_direct_reference(git_reference *ref)
 	return -1;
 }
 
-int git_reference_set_target_if(
+int git_reference_set_target(
 	git_reference **out,
 	git_reference *ref,
 	const git_oid *id,
 	const git_signature *signature,
-	const char *log_message,
-        const git_oid *old_id)
+	const char *log_message)
 {
 	int error;
 	git_repository *repo;
@@ -503,7 +503,7 @@ int git_reference_set_target_if(
 	if ((error = ensure_is_an_updatable_direct_reference(ref)) < 0)
 		return error;
 
-	return git_reference_create_if(out, repo, ref->name, id, 1, signature, log_message, old_id);
+	return git_reference_create_matching(out, repo, ref->name, id, 1, signature, log_message, &ref->target.oid);
 }
 
 static int ensure_is_an_updatable_symbolic_reference(git_reference *ref)
@@ -515,16 +515,6 @@ static int ensure_is_an_updatable_symbolic_reference(git_reference *ref)
 	return -1;
 }
 
-int git_reference_set_target(
-	git_reference **out,
-	git_reference *ref,
-	const git_oid *id,
-	const git_signature *signature,
-	const char *log_message)
-{
-        return git_reference_set_target_if(out, ref, id, signature, log_message, NULL);
-}
-
 int git_reference_symbolic_set_target(
 	git_reference **out,
 	git_reference *ref,