Skip to contentSkip to conversation

format-patch: improve handling of `format.notes`

PATCH In review Denton Liu 5 participants 11 messages Dec 9, 2019 – Dec 10, 2019

lore
Share & tools
lore

Denton Liu

author
#0 lore raw

cover format-patch: improve handling of `format.notes`

In this email[1], Elijah pointed out that the handling of multiple format.notes configurations could be buggy. If we had format.notes = <ref1>, format.notes = false and format.notes = <ref2>, the behaviour is ambiguous. This series uses the way --notes=<ref1> --no-notes --notes=<ref2> is handled as a model and structures the handling of format.notes in a similar manner, allowing one format.notes = false to override previous configs.

Also, in the same email, it was pointed out that git_config() should be called before repo_init_revisions(). In 13cdf78094 (format-patch: teach format.notes config option, 2019-05-16), the order was reversed. This series changes it back such that git_config() is called before repo_init_revisions().

This series is based on top of 'dl/format-patch-notes-config'.

It has minor textual conflicts with 'pu'. The merge resolution can be found at
https://github.com/Denton-L/git.git on branch 'published/published/pu-format-patch-notes-config'.

[1]: https://lore.kernel.org/git/CABPp-BF44+6gvZVNimKf-k7AWbOjw3OK-cJeFunNR96wvZGkcw@mail.gmail.com/

Denton Liu (5):
notes: rename to load_display_notes()
notes: create init_display_notes() helper
notes: extract logic into set_display_notes()
format-patch: use --notes behavior for format.notes
format-patch: move git_config() before repo_init_revisions()

 builtin/log.c           | 26 +++++++++-----------------
 notes.c                 | 30 ++++++++++++++++++++++++++++++
 notes.h                 | 21 ++++++++++++++++++---
 revision.c              | 22 +++++-----------------
 t/t4014-format-patch.sh | 32 ++++++++++++++++++++++++++++++++
 5 files changed, 94 insertions(+), 37 deletions(-)
Signature · 1 line
2.24.0.627.geba02921db
author
#1 lore raw

PATCH 1/5 notes: rename to load_display_notes()

According to the function comment, init_display_notes() was supposed to "Load the notes machinery for displaying several notes trees." Rename this function to load_display_notes() so that its use is more accurately represented.

This is done because, in a future commit, we will reuse the name init_display_notes().

---
 builtin/log.c | 4 ++--
 notes.c       | 2 +-
 notes.h       | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)
builtin/log.c +2 -2
index dad63cffc6..622d6a6cb1 100644
@@ -202,7 +202,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
 	if (!rev->show_notes_given && (!rev->pretty_given || w.notes))
 		rev->show_notes = 1;
 	if (rev->show_notes)
-		init_display_notes(&rev->notes_opt);
+		load_display_notes(&rev->notes_opt);
 
 	if ((rev->diffopt.pickaxe_opts & DIFF_PICKAXE_KINDS_MASK) ||
 	    rev->diffopt.filter || rev->diffopt.flags.follow_renames)
@@ -1749,7 +1749,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		rev.diffopt.flags.binary = 1;
 
 	if (rev.show_notes)
-		init_display_notes(&rev.notes_opt);
+		load_display_notes(&rev.notes_opt);
 
 	if (!output_directory && !use_stdout)
 		output_directory = config_output_directory;
notes.c +1 -1
index 532ec37865..fd6cef14a3 100644
@@ -1039,7 +1039,7 @@ struct notes_tree **load_notes_trees(struct string_list *refs, int flags)
 	return trees;
 }
 
-void init_display_notes(struct display_notes_opt *opt)
+void load_display_notes(struct display_notes_opt *opt)
 {
 	char *display_ref_env;
 	int load_config_refs = 0;
notes.h +3 -3
index 414bc6855a..1ce528442a 100644
@@ -272,18 +272,18 @@ struct display_notes_opt {
  * - extra_notes_refs may contain a list of globs (in the same style
  *   as notes.displayRef) where notes should be loaded from.
  */
-void init_display_notes(struct display_notes_opt *opt);
+void load_display_notes(struct display_notes_opt *opt);
 
 /*
  * Append notes for the given 'object_sha1' from all trees set up by
- * init_display_notes() to 'sb'.  The 'flags' are a bitwise
+ * load_display_notes() to 'sb'.  The 'flags' are a bitwise
  * combination of
  *
  * - NOTES_SHOW_HEADER: add a 'Notes (refname):' header
  *
  * - NOTES_INDENT: indent the notes by 4 places
  *
- * You *must* call init_display_notes() before using this function.
+ * You *must* call load_display_notes() before using this function.
  */
 void format_display_notes(const struct object_id *object_oid,
 			  struct strbuf *sb, const char *output_encoding, int raw);
Signature · 1 line
2.24.0.627.geba02921db
author
#2 lore raw

PATCH 2/5 notes: create init_display_notes() helper

In reply to Denton Liu

We currently open code the initialization for revs->notes_opt. Abstract this away into a helper function so that the logic can be reused in a future commit.

This is slightly wasteful as we memset the struct twice but this is only run once so it shouldn't have any major effect.

---
 notes.c    | 6 ++++++
 notes.h    | 5 +++++
 revision.c | 2 +-
 3 files changed, 12 insertions(+), 1 deletion(-)
notes.c +6 -0
index fd6cef14a3..53d1e7767c 100644
@@ -1039,6 +1039,12 @@ struct notes_tree **load_notes_trees(struct string_list *refs, int flags)
 	return trees;
 }
 
+void init_display_notes(struct display_notes_opt *opt)
+{
+	memset(opt, 0, sizeof(*opt));
+	opt->use_default_notes = -1;
+}
+
 void load_display_notes(struct display_notes_opt *opt)
 {
 	char *display_ref_env;
notes.h +5 -0
index 1ce528442a..c0b712371c 100644
@@ -260,6 +260,11 @@ struct display_notes_opt {
 	struct string_list extra_notes_refs;
 };
 
+/*
+ * Initialize a display_notes_opt to its default value.
+ */
+void init_display_notes(struct display_notes_opt *opt);
+
 /*
  * Load the notes machinery for displaying several notes trees.
  *
revision.c +1 -1
index d4aaf0ef25..24ad974590 100644
@@ -1637,7 +1637,7 @@ void repo_init_revisions(struct repository *r,
 		revs->diffopt.prefix_length = strlen(prefix);
 	}
 
-	revs->notes_opt.use_default_notes = -1;
+	init_display_notes(&revs->notes_opt);
 }
 
 static void add_pending_commit_list(struct rev_info *revs,
Signature · 1 line
2.24.0.627.geba02921db
author
#3 lore raw

PATCH 3/5 notes: extract logic into set_display_notes()

In reply to Denton Liu

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.

---
 notes.c    | 24 ++++++++++++++++++++++++
 notes.h    | 10 ++++++++++
 revision.c | 20 ++++----------------
 3 files changed, 38 insertions(+), 16 deletions(-)
notes.c +24 -0
index 53d1e7767c..c93feff4ab 100644
@@ -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;
notes.h +10 -0
index c0b712371c..a476bfa066 100644
@@ -265,6 +265,16 @@ 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.
+ */
+int set_display_notes(struct display_notes_opt *opt, int show_notes, const char *opt_ref);
+
 /*
  * Load the notes machinery for displaying several notes trees.
  *
revision.c +4 -16
index 24ad974590..c2d8d24939 100644
@@ -2172,9 +2172,8 @@ 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 = 1;
+		revs->show_notes = set_display_notes(&revs->notes_opt, 1, NULL);
 		revs->show_notes_given = 1;
-		revs->notes_opt.use_default_notes = 1;
 	} else if (!strcmp(arg, "--show-signature")) {
 		revs->show_signature = 1;
 	} else if (!strcmp(arg, "--no-show-signature")) {
@@ -2189,25 +2188,14 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 		revs->track_first_time = 1;
 	} else if (skip_prefix(arg, "--show-notes=", &optarg) ||
 		   skip_prefix(arg, "--notes=", &optarg)) {
-		struct strbuf buf = STRBUF_INIT;
-		revs->show_notes = 1;
-		revs->show_notes_given = 1;
 		if (starts_with(arg, "--show-notes=") &&
 		    revs->notes_opt.use_default_notes < 0)
 			revs->notes_opt.use_default_notes = 1;
-		strbuf_addstr(&buf, optarg);
-		expand_notes_ref(&buf);
-		string_list_append(&revs->notes_opt.extra_notes_refs,
-				   strbuf_detach(&buf, NULL));
+		revs->show_notes = set_display_notes(&revs->notes_opt, 1, optarg);
+		revs->show_notes_given = 1;
 	} else if (!strcmp(arg, "--no-notes")) {
-		revs->show_notes = 0;
+		revs->show_notes = set_display_notes(&revs->notes_opt, 0, NULL);
 		revs->show_notes_given = 1;
-		revs->notes_opt.use_default_notes = -1;
-		/* we have been strdup'ing ourselves, so trick
-		 * string_list into free()ing strings */
-		revs->notes_opt.extra_notes_refs.strdup_strings = 1;
-		string_list_clear(&revs->notes_opt.extra_notes_refs, 0);
-		revs->notes_opt.extra_notes_refs.strdup_strings = 0;
 	} else if (!strcmp(arg, "--standard-notes")) {
 		revs->show_notes_given = 1;
 		revs->notes_opt.use_default_notes = 1;
Signature · 1 line
2.24.0.627.geba02921db
author
#7 lore raw

PATCH 4/5 format-patch: use --notes behavior for format.notes

In reply to Denton Liu

When we had multiple format.notes config values where we had <ref1>, false, <ref2> (in that order), then we would print out the notes for both <ref1> and <ref2>. This doesn't make sense, however, since we parse the config in a top-down manner and a false should be able to override previous configurations, just like how --no-notes will override previous --notes.

Duplicate the logic that handles the --[no-]notes[=] option to format.notes for consistency. As a result, when parsing the config from top to bottom, format.notes = true will behave like --notes, format.notes = <ref> will behave like --notes=<ref> and format.notes = false will behave like --no-notes.

This change isn't strictly backwards compatible but since it is an edge case where a sane user would not mix notes refs with false and this feature is relatively new (released only in v2.23.0), this change should be harmless.

---
 builtin/log.c           | 13 +------------
 t/t4014-format-patch.sh | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 12 deletions(-)
builtin/log.c +1 -12
index 622d6a6cb1..1f0405f72b 100644
@@ -867,19 +867,8 @@ static int git_format_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 	if (!strcmp(var, "format.notes")) {
-		struct strbuf buf = STRBUF_INIT;
 		int b = git_parse_maybe_bool(value);
-		if (!b)
-			return 0;
-		rev->show_notes = 1;
-		if (b < 0) {
-			strbuf_addstr(&buf, value);
-			expand_notes_ref(&buf);
-			string_list_append(&rev->notes_opt.extra_notes_refs,
-					strbuf_detach(&buf, NULL));
-		} else {
-			rev->notes_opt.use_default_notes = 1;
-		}
+		rev->show_notes = set_display_notes(&rev->notes_opt, b, b < 0 ? value : NULL);
 		return 0;
 	}
 
t/t4014-format-patch.sh +32 -0
index 4d5719fe2c..5c40ea4397 100755
@@ -808,6 +808,38 @@ test_expect_success 'format-patch with multiple notes refs' '
 	! grep "this is note 2" out
 '
 
+test_expect_success 'format-patch with multiple notes refs in config' '
+	test_when_finished "test_unconfig format.notes" &&
+
+	git notes --ref note1 add -m "this is note 1" HEAD &&
+	test_when_finished git notes --ref note1 remove HEAD &&
+	git notes --ref note2 add -m "this is note 2" HEAD &&
+	test_when_finished git notes --ref note2 remove HEAD &&
+
+	git config format.notes note1 &&
+	git format-patch -1 --stdout >out &&
+	grep "this is note 1" out &&
+	! grep "this is note 2" out &&
+	git config format.notes note2 &&
+	git format-patch -1 --stdout >out &&
+	! grep "this is note 1" out &&
+	grep "this is note 2" out &&
+	git config --add format.notes note1 &&
+	git format-patch -1 --stdout >out &&
+	grep "this is note 1" out &&
+	grep "this is note 2" out &&
+
+	git config --replace-all format.notes note1 &&
+	git config --add format.notes false &&
+	git format-patch -1 --stdout >out &&
+	! grep "this is note 1" out &&
+	! grep "this is note 2" out &&
+	git config --add format.notes note2 &&
+	git format-patch -1 --stdout >out &&
+	! grep "this is note 1" out &&
+	grep "this is note 2" out
+'
+
 echo "fatal: --name-only does not make sense" > expect.name-only
 echo "fatal: --name-status does not make sense" > expect.name-status
 echo "fatal: --check does not make sense" > expect.check
Signature · 1 line
2.24.0.627.geba02921db
author
#8 lore raw

PATCH 5/5 format-patch: move git_config() before repo_init_revisions()

In reply to Denton Liu

In 13cdf78094 (format-patch: teach format.notes config option, 2019-05-16), the order in which git_config() and repo_init_revisions() were swapped so that rev.notes_opt would be initialized before git_config() was called. This is problematic, however, as git_config() should generally be called before repo_init_revisions().

Break this circular dependency by creating show_notes and notes_opt which git_config() reads into. Then, copy these values over to rev.show_notes and rev.notes_opt after repo_init_revisions() is called.

---
 builtin/log.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
builtin/log.c +7 -4
index 1f0405f72b..4225615e7f 100644
@@ -769,6 +769,8 @@ static const char *signature = git_version_string;
 static const char *signature_file;
 static int config_cover_letter;
 static const char *config_output_directory;
+static int show_notes;
+static struct display_notes_opt notes_opt;
 
 enum {
 	COVER_UNSET,
@@ -779,8 +781,6 @@ enum {
 
 static int git_format_config(const char *var, const char *value, void *cb)
 {
-	struct rev_info *rev = cb;
-
 	if (!strcmp(var, "format.headers")) {
 		if (!value)
 			die(_("format.headers without value"));
@@ -868,7 +868,7 @@ 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);
-		rev->show_notes = set_display_notes(&rev->notes_opt, b, b < 0 ? value : NULL);
+		show_notes = set_display_notes(&notes_opt, b, b < 0 ? value : NULL);
 		return 0;
 	}
 
@@ -1624,8 +1624,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	extra_to.strdup_strings = 1;
 	extra_cc.strdup_strings = 1;
 	init_log_defaults();
+	init_display_notes(&notes_opt);
+	git_config(git_format_config, NULL);
 	repo_init_revisions(the_repository, &rev, prefix);
-	git_config(git_format_config, &rev);
+	rev.show_notes = show_notes;
+	memcpy(&rev.notes_opt, &notes_opt, sizeof(notes_opt));
 	rev.commit_format = CMIT_FMT_EMAIL;
 	rev.expand_tabs_in_log_default = 0;
 	rev.verbose_header = 1;
Signature · 1 line
2.24.0.627.geba02921db
#4 lore raw

Re: [PATCH 3/5] notes: extract logic into set_display_notes()

In reply to Denton Liu
Quoted 21 lines · Denton Liu

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.

---

notes.c +13 -0
@@ -1045,6 +1045,30 @@ void init_display_notes(struct display_notes_opt *opt)
+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 {

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

Quoted 10 lines
notes.c +10 -0
+               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;
+}

When you find yourself creating a function in which the entire body is (effectively) a single giant 'if' statement and in which the 'then' and 'else' arms are chosen by an input argument to that function (and remaining input arguments are used only by one or the other branch), it is usually a good sign that you should really be creating two distinct functions. Doing so would reduce cognitive load of people reading and trying to understand the code (as well as reduce the indentation level). For instance, you might introduce these functions:

void enable_display_notes(struct display_notes_opt *opt, const

char *opt_ref);
    void disable_display_notes(struct display_notes_opt *opt);

notes.h struct display_notes_opt { · line 273

Quoted 11 lines
notes.h +9 -0
@@ -265,6 +265,16 @@ struct display_notes_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.
+ */
+int set_display_notes(struct display_notes_opt *opt, int show_notes, const char *opt_ref);

Please drop the meaningless return value. While I understand you did this as a convenience to make calling code a bit more concise, it nevertheless doesn't belong here since it conflates that convenience code with the true purpose of this function (which to enable or disable note display). Worse, it increases cognitive load on people trying to comprehend the code since it requires that they consult the documentation for set_display_notes() to understand what is going on. That is, this is far less obvious:

    revs->show_notes = set_display_notes(&revs->notes_opt, 1, optarg);

than this:

    revs->show_notes = 1;
    enable_display_notes(&revs->notes_opt, optarg);

Alternately, if revs->show_notes and revs->notes_opt really ought always be set in lockstep, then maybe it makes more sense to have the "enable" and "disable" functions accept 'revs' directly in order to be able to adjust both revs->show_notes and revs_notes_opt together:

    void enable_display_notes(struct rev_info *revs, const char *opt_ref);
    void disable_display_notes(struct rev_info *revs);
author
#5 lore raw

Re: [PATCH 3/5] notes: extract logic into set_display_notes()

Hi Eric,

Quoted 42 lines · Eric Sunshine
Quoted 21 lines · Denton Liu

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.

---

notes.c +13 -0
@@ -1045,6 +1045,30 @@ void init_display_notes(struct display_notes_opt *opt)
+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 {

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

Quoted 10 lines
notes.c +10 -0
+               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;
+}

When you find yourself creating a function in which the entire body is (effectively) a single giant 'if' statement and in which the 'then' and 'else' arms are chosen by an input argument to that function (and remaining input arguments are used only by one or the other branch), it is usually a good sign that you should really be creating two distinct functions. Doing so would reduce cognitive load of people reading and trying to understand the code (as well as reduce the indentation level). For instance, you might introduce these functions:

Quoted 3 lines

void enable_display_notes(struct display_notes_opt *opt, const

char *opt_ref);
    void disable_display_notes(struct display_notes_opt *opt);

Makes sense. I'll probably split it off into disable_display_notes(), enable_default_display_notes() and enable_ref_display_notes() since there is no logic shared between when opt_ref is NULL and when it isn't.

Quoted 29 lines

notes.h struct display_notes_opt { · line 273

Quoted 12 lines
notes.h +9 -0
@@ -265,6 +265,16 @@ struct display_notes_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.
+ */
+int set_display_notes(struct display_notes_opt *opt, int show_notes, const char *opt_ref);

Please drop the meaningless return value. While I understand you did this as a convenience to make calling code a bit more concise, it nevertheless doesn't belong here since it conflates that convenience code with the true purpose of this function (which to enable or disable note display). Worse, it increases cognitive load on people trying to comprehend the code since it requires that they consult the documentation for set_display_notes() to understand what is going on. That is, this is far less obvious:

    revs->show_notes = set_display_notes(&revs->notes_opt, 1, optarg);

than this:

    revs->show_notes = 1;
    enable_display_notes(&revs->notes_opt, optarg);
Quoted 7 lines

Alternately, if revs->show_notes and revs->notes_opt really ought always be set in lockstep, then maybe it makes more sense to have the "enable" and "disable" functions accept 'revs' directly in order to be able to adjust both revs->show_notes and revs_notes_opt together:

    void enable_display_notes(struct rev_info *revs, const char *opt_ref);
    void disable_display_notes(struct rev_info *revs);

Hmm, the "lockstep" thing was what I was going for. That's why I ended up using one monolithic function instead of several smaller ones. That way, the caller can just blindly pass in values and then use the values returned to set its own state (i.e. how 4/5 does it). Also, it would ensure that future developers using this function won't forget to set the corresponding show_notes variable to whatever value is appropriate.

The reason why we can't accept revs is because this series attempts to stop depending on revs for the notes configuration entirely. That way, we can call git_config() before repo_init_revisions() since we won't need to have revs initialised.

I considered accepting an int * instead of using the return value to make the intent more explicit but I didn't do that because the return value seemed easier to deal with. Perhaps we could revive that idea with:

void enable_display_notes(struct display_notes_opt *opt,
int *show_notes, const char *opt_ref);
void disable_display_notes(struct display_notes_opt *opt,
int *show_notes);

I'll brood over the alternatives for a little bit before sending a reroll.

Thanks,

Denton

#9 lore raw
In reply to Denton Liu
Quoted 4 lines · Denton Liu

... This series uses
the way --notes=<ref1> --no-notes --notes=<ref2> is handled as a model and structures the handling of format.notes in a similar manner, allowing one format.notes = false to override previous configs.

Makes sense.

Quoted 27 lines

Also, in the same email, it was pointed out that git_config() should be called before repo_init_revisions(). In 13cdf78094 (format-patch: teach format.notes config option, 2019-05-16), the order was reversed. This series changes it back such that git_config() is called before repo_init_revisions().

This series is based on top of 'dl/format-patch-notes-config'.

It has minor textual conflicts with 'pu'. The merge resolution can be found at
https://github.com/Denton-L/git.git on branch 'published/published/pu-format-patch-notes-config'.

[1]: https://lore.kernel.org/git/CABPp-BF44+6gvZVNimKf-k7AWbOjw3OK-cJeFunNR96wvZGkcw@mail.gmail.com/

Denton Liu (5):
notes: rename to load_display_notes()
notes: create init_display_notes() helper
notes: extract logic into set_display_notes()
format-patch: use --notes behavior for format.notes
format-patch: move git_config() before repo_init_revisions()

 builtin/log.c           | 26 +++++++++-----------------
 notes.c                 | 30 ++++++++++++++++++++++++++++++
 notes.h                 | 21 ++++++++++++++++++---
 revision.c              | 22 +++++-----------------
 t/t4014-format-patch.sh | 32 ++++++++++++++++++++++++++++++++
 5 files changed, 94 insertions(+), 37 deletions(-)
#10 lore raw
In reply to Denton Liu
Quoted 9 lines · Denton Liu

In this email[1], Elijah pointed out that the handling of multiple format.notes configurations could be buggy. If we had format.notes = <ref1>, format.notes = false and format.notes = <ref2>, the behaviour is ambiguous. This series uses the way --notes=<ref1> --no-notes --notes=<ref2> is handled as a model and structures the handling of format.notes in a similar manner, allowing one format.notes = false to override previous configs.

Quoted 5 lines

Also, in the same email, it was pointed out that git_config() should be called before repo_init_revisions(). In 13cdf78094 (format-patch: teach format.notes config option, 2019-05-16), the order was reversed. This series changes it back such that git_config() is called before repo_init_revisions().

Sweet, thanks for working on this. I took a very cursory glance over the patches and didn't spot anything egregiously wrong, though I'm also not familiar with the notes machinery. Mostly I'm just piping up to thank you for tackling this so quickly. :-)

#6 lore raw

Re: [PATCH 3/5] notes: extract logic into set_display_notes()

In reply to Denton Liu

HI Denton

Quoted 7 lines · Denton Liu

the "lockstep" thing was what I was going for. That's why I ended up using one monolithic function instead of several smaller ones. That way, the caller can just blindly pass in values and then use the values returned to set its own state (i.e. how 4/5 does it). Also, it would ensure that future developers using this function won't forget to set the corresponding show_notes variable to whatever value is appropriate.

Quoted 8 lines

The reason why we can't accept revs is because this series attempts to stop depending on revs for the notes configuration entirely. That way, we can call git_config() before repo_init_revisions() since we won't need to have revs initialised.

I considered accepting an int * instead of using the return value to make the intent more explicit but I didn't do that because the return value seemed easier to deal with.

Does your explanation: "this series attempts to stop depending on revs for the notes configuration entirely." need adding adding to the commit message? I.e. the "abstract away" phrase probably doesn't carry enough information/context.p

Maybe pick out some of the explanations for the commit message for future readers?

Philip