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().
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
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,