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

[PATCH v5 12/15] sequencer: die on config error when saving replay opts

From
Patrick Steinhardt <ps@pks.im>
Date
Feb 16, 2016, 12:56 UTC
Message-ID
<1455627402-752-13-git-send-email-ps@pks.im>
In-Reply-To
<1455627402-752-1-git-send-email-ps@pks.im>

When we start picking a range of revisions we save the replay options that are required to restore state when interrupting and later continuing picking the revisions. However, we do not check the return values of the `git_config_set` functions, which may lead us to store incomplete information. As this may lead us to fail when trying to continue the sequence the error can be fatal.

Fix this by dying immediately when we are unable to write back any replay option.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 sequencer.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index 8048786..3590248 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -933,31 +933,31 @@ static void save_opts(struct replay_opts *opts)
 	const char *opts_file = git_path_opts_file();
 
 	if (opts->no_commit)
-		git_config_set_in_file(opts_file, "options.no-commit", "true");
+		git_config_set_in_file_or_die(opts_file, "options.no-commit", "true");
 	if (opts->edit)
-		git_config_set_in_file(opts_file, "options.edit", "true");
+		git_config_set_in_file_or_die(opts_file, "options.edit", "true");
 	if (opts->signoff)
-		git_config_set_in_file(opts_file, "options.signoff", "true");
+		git_config_set_in_file_or_die(opts_file, "options.signoff", "true");
 	if (opts->record_origin)
-		git_config_set_in_file(opts_file, "options.record-origin", "true");
+		git_config_set_in_file_or_die(opts_file, "options.record-origin", "true");
 	if (opts->allow_ff)
-		git_config_set_in_file(opts_file, "options.allow-ff", "true");
+		git_config_set_in_file_or_die(opts_file, "options.allow-ff", "true");
 	if (opts->mainline) {
 		struct strbuf buf = STRBUF_INIT;
 		strbuf_addf(&buf, "%d", opts->mainline);
-		git_config_set_in_file(opts_file, "options.mainline", buf.buf);
+		git_config_set_in_file_or_die(opts_file, "options.mainline", buf.buf);
 		strbuf_release(&buf);
 	}
 	if (opts->strategy)
-		git_config_set_in_file(opts_file, "options.strategy", opts->strategy);
+		git_config_set_in_file_or_die(opts_file, "options.strategy", opts->strategy);
 	if (opts->gpg_sign)
-		git_config_set_in_file(opts_file, "options.gpg-sign", opts->gpg_sign);
+		git_config_set_in_file_or_die(opts_file, "options.gpg-sign", opts->gpg_sign);
 	if (opts->xopts) {
 		int i;
 		for (i = 0; i < opts->xopts_nr; i++)
-			git_config_set_multivar_in_file(opts_file,
-							"options.strategy-option",
-							opts->xopts[i], "^$", 0);
+			git_config_set_multivar_in_file_or_die(opts_file,
+							       "options.strategy-option",
+							       opts->xopts[i], "^$", 0);
 	}
 }
 
-- 
2.7.1
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 15 of 25 in “config: make git_config_set die on failure”
  1. 00/15 config: make git_config_set die on failurePatrick Steinhardt, Feb 16, 2016
  2. 01/15 config: introduce set_or_die wrappersPatrick Steinhardt, Feb 16, 2016
  3. 02/15 branch: report errors in tracking branch setupPatrick Steinhardt, Feb 16, 2016
  4. Junio C HamanoFeb 16, 2016
  5. Patrick SteinhardtFeb 17, 2016
  6. 03/15 branch: die on config error when unsetting upstreamPatrick Steinhardt, Feb 16, 2016
  7. 04/15 branch: die on config error when editing branch descriptionPatrick Steinhardt, Feb 16, 2016
  8. 05/15 submodule: die on config error when linking modulesPatrick Steinhardt, Feb 16, 2016
  9. 06/15 submodule--helper: die on config error when cloning modulePatrick Steinhardt, Feb 16, 2016
  10. 07/15 remote: die on config error when setting URLPatrick Steinhardt, Feb 16, 2016
  11. 08/15 remote: die on config error when setting/adding branchesPatrick Steinhardt, Feb 16, 2016
  12. 09/15 remote: die on config error when manipulating remotesPatrick Steinhardt, Feb 16, 2016
  13. 10/15 clone: die on config error in cmd_clonePatrick Steinhardt, Feb 16, 2016
  14. 11/15 init-db: die on config errors when initializing empty repoPatrick Steinhardt, Feb 16, 2016
  15. 12/15 sequencer: die on config error when saving replay optsPatrick Steinhardt, Feb 16, 2016
  16. 13/15 compat: die when unable to set core.precomposeunicodePatrick Steinhardt, Feb 16, 2016
  17. Lars SchneiderFeb 17, 2016
  18. Patrick SteinhardtFeb 17, 2016
  19. 14/15 config: rename git_config_set to git_config_set_gentlyPatrick Steinhardt, Feb 16, 2016
  20. 15/15 config: rename git_config_set_or_die to git_config_setPatrick Steinhardt, Feb 16, 2016
  21. Michael BlumeFeb 17, 2016
  22. Michael BlumeFeb 17, 2016
  23. Junio C HamanoFeb 17, 2016
  24. Eric SunshineFeb 16, 2016
  25. Patrick SteinhardtFeb 17, 2016

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.