summaryrefslogtreecommitdiff
path: root/notes.c
diff options
context:
space:
mode:
authorDenton Liu <liu.denton@gmail.com>2019-12-09 13:10:44 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-12-09 21:36:45 (GMT)
commit452538c3586a76939faf43019fb7c21b3147309b (patch)
tree59871359eee629a5b38711cdb9feb6fc6a3b95f6 /notes.c
parente6e230eeae0f3cb46c4c356e6cd0a0f1119a2a83 (diff)
downloadgit-452538c3586a76939faf43019fb7c21b3147309b.zip
git-452538c3586a76939faf43019fb7c21b3147309b.tar.gz
git-452538c3586a76939faf43019fb7c21b3147309b.tar.bz2
notes: extract logic into set_display_notes()
Instead of open coding the logic that tweaks the variables in `struct display_notes_opt` within handle_revision_opt(), abstract away the logic into set_display_notes() so that it can be reused. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'notes.c')
-rw-r--r--notes.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/notes.c b/notes.c
index 53d1e77..c93feff 100644
--- a/notes.c
+++ b/notes.c
@@ -1045,6 +1045,30 @@ void init_display_notes(struct display_notes_opt *opt)
opt->use_default_notes = -1;
}
+int set_display_notes(struct display_notes_opt *opt, int show_notes, const char *opt_ref)
+{
+ if (show_notes) {
+ if (opt_ref) {
+ struct strbuf buf = STRBUF_INIT;
+ strbuf_addstr(&buf, opt_ref);
+ expand_notes_ref(&buf);
+ string_list_append(&opt->extra_notes_refs,
+ strbuf_detach(&buf, NULL));
+ } else {
+ opt->use_default_notes = 1;
+ }
+ } else {
+ opt->use_default_notes = -1;
+ /* we have been strdup'ing ourselves, so trick
+ * string_list into free()ing strings */
+ opt->extra_notes_refs.strdup_strings = 1;
+ string_list_clear(&opt->extra_notes_refs, 0);
+ opt->extra_notes_refs.strdup_strings = 0;
+ }
+
+ return !!show_notes;
+}
+
void load_display_notes(struct display_notes_opt *opt)
{
char *display_ref_env;