Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenton Liu <liu.denton@gmail.com>2019-12-12 03:49:50 +0300
committerJunio C Hamano <gitster@pobox.com>2019-12-13 22:07:15 +0300
commit1d7297513df66873e68af4b254804151b8ba5359 (patch)
treeb13311d7572e5488bef01283449d2ce06d0323d0 /notes.c
parent66f79ee23d51ac11784aeb0ef4f4119af9fbb984 (diff)
notes: break set_display_notes() into smaller functions
In 8164c961e1 (format-patch: use --notes behavior for format.notes, 2019-12-09), we introduced set_display_notes() which was a monolithic function with three mutually exclusive branches. Break the function up into three small and simple functions that each are only responsible for one task. This family of functions accepts an `int *show_notes` instead of returning a value suitable for assignment to `show_notes`. This is for two reasons. First of all, this guarantees that the external `show_notes` variable changes in lockstep with the `struct display_notes_opt`. Second, this prompts future developers to be careful about doing something meaningful with this value. In fact, a NULL check is intentionally omitted because causing a segfault here would tell the future developer that they are meant to use the value for something meaningful. One alternative was making the family of functions accept a `struct rev_info *` instead of the `struct display_notes_opt *`, since the former contains the `show_notes` field as well. This does not work because we have to call git_config() before repo_init_revisions(). However, if we had a `struct rev_info`, we'd need to initialize it before it gets assigned values from git_config(). As a result, we break the circular dependency by having standalone `int show_notes` and `struct display_notes_opt notes_opt` variables which temporarily hold values from git_config() until the values are copied over to `rev`. To implement this change, we need to get a pointer to `rev_info::show_notes`. Unfortunately, this is not possible with bitfields and only direct-assignment is possible. Change `rev_info::show_notes` to a non-bitfield int so that we can get its address. 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.c43
1 files changed, 23 insertions, 20 deletions
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)