diff options
author | Vicent Martà <tanoku@gmail.com> | 2012-05-05 14:14:58 -0700 |
---|---|---|
committer | Vicent Martà <tanoku@gmail.com> | 2012-05-05 14:14:58 -0700 |
commit | d3a60dc24479a6077c21ecc3ae3e41b6d5557ff7 (patch) | |
tree | 62f370591854a5437889b81cfd0193318df1a401 /src | |
parent | 674a198599aa3a77b7edff3f864e3e8779059e36 (diff) | |
parent | 630c5a4a54bca28687f1c42117f830720f822fa6 (diff) | |
download | libgit2-d3a60dc24479a6077c21ecc3ae3e41b6d5557ff7.tar.gz |
Merge pull request #663 from schu/notes-honor-config
Honor core.notesRef config option
Diffstat (limited to 'src')
-rw-r--r-- | src/notes.c | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/src/notes.c b/src/notes.c index 05c70c643..e533478b1 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(¬es_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(¬es_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(¬es_ref, repo); + if (error < 0) + return error; + } error = git_reference_lookup(&ref, repo, notes_ref); if (error < 0) @@ -388,6 +417,12 @@ int git_note_remove(git_repository *repo, const char *notes_ref, return error; } +int git_note_default_ref(const char **out, git_repository *repo) +{ + assert(repo); + return note_get_default_ref(out, repo); +} + const char * git_note_message(git_note *note) { assert(note); |