git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Denton Liu <liu.denton@gmail.com>
Date
Dec 9, 2019, 13:10 UTC
Message-ID
<709565e734820fcb6d5db027dcf644f53ce2d4c9.1575896661.git.liu.denton@gmail.com>
In-Reply-To
<cover.1575896661.git.liu.denton@gmail.com>

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.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 builtin/log.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/builtin/log.c b/builtin/log.c
index 1f0405f72b..4225615e7f 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -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;
-- 
2.24.0.627.geba02921db
Previous: Denton LiuNext: Junio C Hamano
Message 9 of 11 in “format-patch: improve handling of `format.notes`”
  1. 0/5 format-patch: improve handling of `format.notes`Denton Liu, Dec 9, 2019
  2. 1/5 notes: rename to load_display_notes()Denton Liu, Dec 9, 2019
  3. 2/5 notes: create init_display_notes() helperDenton Liu, Dec 9, 2019
  4. 3/5 notes: extract logic into set_display_notes()Denton Liu, Dec 9, 2019
  5. Eric SunshineDec 9, 2019
  6. Denton LiuDec 9, 2019
  7. Philip OakleyDec 10, 2019
  8. 4/5 format-patch: use --notes behavior for format.notesDenton Liu, Dec 9, 2019
  9. 5/5 format-patch: move git_config() before repo_init_revisions()Denton Liu, Dec 9, 2019
  10. Junio C HamanoDec 9, 2019
  11. Elijah NewrenDec 9, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.