summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-01-14 15:33:29 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2014-02-05 12:07:56 +0100
commit5d96fe8828505db852671175d5895dfd275f3d06 (patch)
tree947f3d4f070248e067dcf3988b984ecfa325c15a
parent9b148098e6802f9dd797471fc4f20cfc58a846b4 (diff)
downloadlibgit2-5d96fe8828505db852671175d5895dfd275f3d06.tar.gz
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().
-rw-r--r--include/git2/refs.h2
-rw-r--r--src/refs.c44
2 files changed, 18 insertions, 28 deletions
diff --git a/include/git2/refs.h b/include/git2/refs.h
index 296fcb67d..72622948b 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 a5492cf91..007fdf353 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,