Skip to contentSkip to conversation

dl/format-patch-notes-config-fixup: clean up some leftoverbits

PATCH In review Denton Liu 2 participants 5 messages Dec 12, 2019 – Dec 18, 2019 Documentation

lore
Share & tools
lore

Denton Liu

author
#0 lore raw

cover dl/format-patch-notes-config-fixup: clean up some leftoverbits

This series gives 'dl/format-patch-notes-config-fixup' a few polishing touches. First of all, we document the behaviour of multiple format.notes configuration variables so that end-users are aware of the change.

Also, Eric Sunshine suggested some cleanup in the previous round, like breaking the monolithic set_display_notes() into multiple smaller functions and not using the return value of the function to assign to show_notes.

Denton Liu (2):
config/format.txt: clarify behavior of multiple format.notes
notes: break set_display_notes() into smaller functions

 Documentation/config/format.txt | 18 +++++++++++++-
 builtin/log.c                   |  7 +++++-
 notes.c                         | 43 ++++++++++++++++++---------------
 notes.h                         | 19 +++++++++------
 revision.c                      |  6 ++---
 revision.h                      |  2 +-
 6 files changed, 62 insertions(+), 33 deletions(-)
Signature · 1 line
2.24.0.627.geba02921db
author
#1 lore raw

PATCH 1/2 config/format.txt: clarify behavior of multiple format.notes

In 8164c961e1 (format-patch: use --notes behavior for format.notes, 2019-12-09), we slightly tweaked the behavior of having multiple format.notes configuration variables. We did not update the documentation to reflect this, however.

Explictly state the behavior of having multiple format.notes configuration variables so users are clear on what to expect.

---
 Documentation/config/format.txt | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
Documentation/config/format.txt +17 -1
index 414a5a8a9d..3d708b0aec 100644
@@ -99,4 +99,20 @@ If one wishes to use the ref `ref/notes/true`, please use that literal
 instead.
 +
 This configuration can be specified multiple times in order to allow
-multiple notes refs to be included.
+multiple notes refs to be included. In that case, it will behave
+similarly to multiple `--[no-]notes[=]` options passed in. That is, a
+value of `true` will show the default notes, a value of `<ref>` will
+also show notes from that notes ref and a value of `false` will negate
+previous configurations and not show notes.
++
+For example,
++
+------------
+[format]
+	notes = true
+	notes = foo
+	notes = false
+	notes = bar
+------------
++
+will only show notes from `refs/notes/bar`.
Signature · 1 line
2.24.0.627.geba02921db
author
#2 lore raw

PATCH 2/2 notes: break set_display_notes() into smaller functions

In reply to Denton Liu

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.

---
 builtin/log.c |  7 ++++++-
 notes.c       | 43 +++++++++++++++++++++++--------------------
 notes.h       | 19 ++++++++++++-------
 revision.c    |  6 +++---
 revision.h    |  2 +-
 5 files changed, 45 insertions(+), 32 deletions(-)
builtin/log.c +6 -1
index 4225615e7f..b6d43a4a47 100644
@@ -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(&notes_opt, b, b < 0 ? value : NULL);
+		if (b < 0)
+			enable_ref_display_notes(&notes_opt, &show_notes, value);
+		else if (b)
+			enable_default_display_notes(&notes_opt, &show_notes);
+		else
+			disable_display_notes(&notes_opt, &show_notes);
 		return 0;
 	}
 
notes.c +23 -20

51 lines not on this page · raw message

notes.h +12 -7
index a476bfa066..3e78448181 100644
@@ -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.
- *
- * Return 'show_notes' normalized to 1 or 0.
+ * 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.
+ *
+ * '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.
revision.c +3 -3
index c2d8d24939..1b12ed742b 100644
@@ -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;
revision.h +1 -1
index 4134dc6029..72520780f4 100644
@@ -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,
Signature · 1 line
2.24.0.627.geba02921db
#3 lore raw

Re: [PATCH 2/2] notes: break set_display_notes() into smaller functions

Quoted 10 lines · Denton Liu

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.

---

notes.c void init_display_notes(struct display_notes_opt *opt) · line 1049

Quoted 5 lines
notes.c +5 -0
@@ -1045,28 +1045,31 @@ void init_display_notes(struct display_notes_opt *opt)
+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 */

/*
* Multi-line comment
* style.
*/

Though, apparently the formatting used here predates your changes; you simply moved the code (and comment) around.

notes.h struct display_notes_opt { · line 269

Quoted 11 lines
notes.c +4 -0
+       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;
 }
notes.h +3 -0
@@ -266,14 +266,19 @@ struct display_notes_opt {
 /*
+ * 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

s/enable_default_display_notes/enable_ref_display_notes/

notes.h struct display_notes_opt { · line 275

Quoted 4 lines
notes.h +4 -0
+ * 'disable_display_notes' will disable notes, including those added by previous
+ * invocations of the 'enable_*_display_notes' functions.
+ *
+ * 'show_notes' is a points to a boolean which will be set to 1 if notes are

s/points/pointer/

Quoted 2 lines
notes.h +1 -0
+ * displayed, else 0. It must not be NULL.
  */
author
#4 lore raw

PATCH 1/1 notes.h: fix typos in comment

In 1d7297513d (notes: break set_display_notes() into smaller functions, 2019-12-11), we introduced a comment which had a couple of typos. In the first typo, we referenced 'enable_default_display_notes' instead of 'enable_ref_display_notes'. In the second typo, we wrote "is a points to" instead of "is a pointer to". Correct both of these typos.

---
This patch is based on top of 'dl/format-patch-notes-config-fixup'. Thanks for catching the typo, Eric!

 notes.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
notes.h +2 -2
index 3e78448181..bbab1961ca 100644
@@ -268,11 +268,11 @@ void init_display_notes(struct display_notes_opt *opt);
 /*
  * 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
+ * 'enable_ref_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.
  *
- * 'show_notes' is a points to a boolean which will be set to 1 if notes are
+ * 'show_notes' is a pointer to a boolean which will be set to 1 if notes are
  * displayed, else 0. It must not be NULL.
  */
 void enable_default_display_notes(struct display_notes_opt *opt, int *show_notes);
Signature · 1 line
2.24.1.703.g2f499f1283