diff --git a/builtin/log.c b/builtin/log.c index 4225615e7f..b6d43a4a47 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -868,7 +868,12 @@ static int git_format_config(const char *var, const char *value, void *cb) } if (!strcmp(var, "format.notes")) { int b = git_parse_maybe_bool(value); - show_notes = set_display_notes(¬es_opt, b, b < 0 ? value : NULL); + if (b < 0) + enable_ref_display_notes(¬es_opt, &show_notes, value); + else if (b) + enable_default_display_notes(¬es_opt, &show_notes); + else + disable_display_notes(¬es_opt, &show_notes); return 0; } diff --git a/notes.c b/notes.c index c93feff4ab..3133bb181f 100644 --- a/notes.c +++ b/notes.c @@ -1045,28 +1045,31 @@ 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) +void enable_default_display_notes(struct display_notes_opt *opt, int *show_notes) { - 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; - } + opt->use_default_notes = 1; + *show_notes = 1; +} - return !!show_notes; +void enable_ref_display_notes(struct display_notes_opt *opt, int *show_notes, + const char *ref) { + struct strbuf buf = STRBUF_INIT; + strbuf_addstr(&buf, ref); + expand_notes_ref(&buf); + string_list_append(&opt->extra_notes_refs, + strbuf_detach(&buf, NULL)); + *show_notes = 1; +} + +void disable_display_notes(struct display_notes_opt *opt, int *show_notes) +{ + 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; + *show_notes = 0; } void load_display_notes(struct display_notes_opt *opt) diff --git a/notes.h b/notes.h index a476bfa066..3e78448181 100644 --- a/notes.h +++ b/notes.h @@ -266,14 +266,19 @@ struct display_notes_opt { void init_display_notes(struct display_notes_opt *opt); /* - * Set a display_notes_opt to a given state. 'show_notes' is a boolean - * representing whether or not to show notes. 'opt_ref' points to a - * string for the notes ref, or is NULL if the default notes should be - * used. + * This family of functions enables or disables the display of notes. In + * particular, 'enable_default_display_notes' will display the default notes, + * 'enable_default_display_notes' will display the notes ref 'ref' and + * 'disable_display_notes' will disable notes, including those added by previous + * invocations of the 'enable_*_display_notes' functions. * - * Return 'show_notes' normalized to 1 or 0. + * 'show_notes' is a points to a boolean which will be set to 1 if notes are + * displayed, else 0. It must not be NULL. */ -int set_display_notes(struct display_notes_opt *opt, int show_notes, const char *opt_ref); +void enable_default_display_notes(struct display_notes_opt *opt, int *show_notes); +void enable_ref_display_notes(struct display_notes_opt *opt, int *show_notes, + const char *ref); +void disable_display_notes(struct display_notes_opt *opt, int *show_notes); /* * Load the notes machinery for displaying several notes trees. diff --git a/revision.c b/revision.c index c2d8d24939..1b12ed742b 100644 --- a/revision.c +++ b/revision.c @@ -2172,7 +2172,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg die("'%s': not a non-negative integer", arg); revs->expand_tabs_in_log = val; } else if (!strcmp(arg, "--show-notes") || !strcmp(arg, "--notes")) { - revs->show_notes = set_display_notes(&revs->notes_opt, 1, NULL); + enable_default_display_notes(&revs->notes_opt, &revs->show_notes); revs->show_notes_given = 1; } else if (!strcmp(arg, "--show-signature")) { revs->show_signature = 1; @@ -2191,10 +2191,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg if (starts_with(arg, "--show-notes=") && revs->notes_opt.use_default_notes < 0) revs->notes_opt.use_default_notes = 1; - revs->show_notes = set_display_notes(&revs->notes_opt, 1, optarg); + enable_ref_display_notes(&revs->notes_opt, &revs->show_notes, optarg); revs->show_notes_given = 1; } else if (!strcmp(arg, "--no-notes")) { - revs->show_notes = set_display_notes(&revs->notes_opt, 0, NULL); + disable_display_notes(&revs->notes_opt, &revs->show_notes); revs->show_notes_given = 1; } else if (!strcmp(arg, "--standard-notes")) { revs->show_notes_given = 1; diff --git a/revision.h b/revision.h index 4134dc6029..72520780f4 100644 --- a/revision.h +++ b/revision.h @@ -177,10 +177,10 @@ struct rev_info { always_show_header:1; /* Format info */ + int show_notes; unsigned int shown_one:1, shown_dashes:1, show_merge:1, - show_notes:1, show_notes_given:1, show_signature:1, pretty_given:1,