summaryrefslogtreecommitdiff
path: root/src/notes.c
diff options
context:
space:
mode:
authorMichael Schubert <schu@schu.io>2012-04-29 18:42:42 +0200
committerMichael Schubert <schu@schu.io>2012-05-03 22:31:29 +0200
commitcaea5e543379c053de5eec45b8f5a0e83c07e3fe (patch)
tree8809ce6a805b0257bbfc726143ade0390e6b4414 /src/notes.c
parent76873c09053e210c7f739b1cda39cffd6ab865e0 (diff)
downloadlibgit2-caea5e543379c053de5eec45b8f5a0e83c07e3fe.tar.gz
notes: honor core.notesRef
Setting core.notesRef allows to change the default notes reference used by Git. Check if set before using GIT_NOTES_DEFAULT_REF. Fixes #649.
Diffstat (limited to 'src/notes.c')
-rw-r--r--src/notes.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/notes.c b/src/notes.c
index 05c70c643..9e6722e75 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -9,6 +9,7 @@
#include "git2.h"
#include "refs.h"
+#include "config.h"
static int find_subtree(git_tree **subtree, const git_oid *root,
git_repository *repo, const char *target, int *fanout)
@@ -262,6 +263,25 @@ static int note_remove(git_repository *repo,
return error;
}
+static int note_get_default_ref(const char **out, git_repository *repo)
+{
+ int error;
+ git_config *cfg;
+
+ *out = NULL;
+
+ if (git_repository_config__weakptr(&cfg, repo) < 0)
+ return -1;
+
+ error = git_config_get_string(cfg, "core.notesRef", out);
+ if (error == GIT_ENOTFOUND) {
+ *out = GIT_NOTES_DEFAULT_REF;
+ return 0;
+ }
+
+ return error;
+}
+
int git_note_read(git_note **out, git_repository *repo,
const char *notes_ref, const git_oid *oid)
{
@@ -273,8 +293,11 @@ int git_note_read(git_note **out, git_repository *repo,
*out = NULL;
- if (!notes_ref)
- notes_ref = GIT_NOTES_DEFAULT_REF;
+ if (!notes_ref) {
+ error = note_get_default_ref(&notes_ref, repo);
+ if (error < 0)
+ return error;
+ }
error = git_reference_lookup(&ref, repo, notes_ref);
if (error < 0)
@@ -314,8 +337,11 @@ int git_note_create(
git_commit *commit = NULL;
git_reference *ref;
- if (!notes_ref)
- notes_ref = GIT_NOTES_DEFAULT_REF;
+ if (!notes_ref) {
+ error = note_get_default_ref(&notes_ref, repo);
+ if (error < 0)
+ return error;
+ }
error = git_reference_lookup(&ref, repo, notes_ref);
if (error < 0 && error != GIT_ENOTFOUND)
@@ -359,8 +385,11 @@ int git_note_remove(git_repository *repo, const char *notes_ref,
git_commit *commit;
git_reference *ref;
- if (!notes_ref)
- notes_ref = GIT_NOTES_DEFAULT_REF;
+ if (!notes_ref) {
+ error = note_get_default_ref(&notes_ref, repo);
+ if (error < 0)
+ return error;
+ }
error = git_reference_lookup(&ref, repo, notes_ref);
if (error < 0)