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

[RFC/PATCH 04/18] revert: don't die when write_message() fails

From
Christian Couder <chriscool@tuxfamily.org>
Date
Nov 25, 2010, 21:20 UTC
Message-ID
<20101125212050.5188.41232.chriscool@tuxfamily.org>
In-Reply-To
<20101125210138.5188.13115.chriscool@tuxfamily.org>
Instead we will just return an error code.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 builtin/revert.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/builtin/revert.c b/builtin/revert.c
index 9649d37..947e666 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -257,17 +257,19 @@ static void print_advice(void)
 		       find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
 }
 
-static void write_message(struct strbuf *msgbuf, const char *filename)
+static int write_message(struct strbuf *msgbuf, const char *filename)
 {
 	static struct lock_file msg_file;
 
 	int msg_fd = hold_lock_file_for_update(&msg_file, filename,
 					       LOCK_DIE_ON_ERROR);
 	if (write_in_full(msg_fd, msgbuf->buf, msgbuf->len) < 0)
-		die_errno("Could not write to %s.", filename);
+		return error_errno("Could not write to %s.", filename);
 	strbuf_release(msgbuf);
 	if (commit_lock_file(&msg_file) < 0)
-		die("Error wrapping up %s", filename);
+		return error("Error wrapping up %s", filename);
+
+	return 0;
 }
 
 static struct tree *empty_tree(void)
@@ -397,7 +399,7 @@ static int do_pick_commit(void)
 	struct commit_message msg = { NULL, NULL, NULL, NULL, NULL };
 	char *defmsg = NULL;
 	struct strbuf msgbuf = STRBUF_INIT;
-	int res;
+	int res, write_res;
 
 	if (no_commit) {
 		/*
@@ -495,12 +497,16 @@ static int do_pick_commit(void)
 	if (!strategy || !strcmp(strategy, "recursive") || action == REVERT) {
 		res = do_recursive_merge(base, next, base_label, next_label,
 					 head, &msgbuf);
-		write_message(&msgbuf, defmsg);
+		write_res = write_message(&msgbuf, defmsg);
+		if (write_res)
+			return write_res;
 	} else {
 		struct commit_list *common = NULL;
 		struct commit_list *remotes = NULL;
 
-		write_message(&msgbuf, defmsg);
+		write_res = write_message(&msgbuf, defmsg);
+		if (write_res)
+			return write_res;
 
 		commit_list_insert(base, &common);
 		commit_list_insert(next, &remotes);
-- 
1.7.3.2.504.g59d466
Previous: Junio C HamanoNext: Christian Couder
Message 9 of 27 in “WIP implement cherry-pick/revert --continue”
  1. 00/18 WIP implement cherry-pick/revert --continueChristian Couder, Nov 25, 2010
  2. 01/18 advice: add error_resolve_conflict() functionChristian Couder, Nov 25, 2010
  3. Jonathan NiederNov 26, 2010
  4. 02/18 revert: change many die() calls into "return error()" callsChristian Couder, Nov 25, 2010
  5. Jonathan NiederNov 26, 2010
  6. 03/18 usage: implement error_errno() the same way as die_errno()Christian Couder, Nov 25, 2010
  7. Jonathan NiederNov 26, 2010
  8. Junio C HamanoNov 26, 2010
  9. 04/18 revert: don't die when write_message() failsChristian Couder, Nov 25, 2010
  10. 05/18 commit: move reverse_commit_list() into commit.{h, c}Christian Couder, Nov 25, 2010
  11. 06/18 revert: remove "commit" global variableChristian Couder, Nov 25, 2010
  12. 07/18 revert: put option information in an option structChristian Couder, Nov 25, 2010
  13. Jonathan NiederNov 26, 2010
  14. Junio C HamanoNov 26, 2010
  15. 08/18 revert: refactor code into a new pick_commits() functionChristian Couder, Nov 25, 2010
  16. Daniel BarkalowNov 27, 2010
  17. 09/18 revert: make pick_commits() return an error on --ff incompatible optionChristian Couder, Nov 25, 2010
  18. 10/18 revert: make read_and_refresh_cache() and prepare_revs() return errorsChristian Couder, Nov 25, 2010
  19. 11/18 revert: add get_todo_content() and create_todo_file()Christian Couder, Nov 25, 2010
  20. 12/18 revert: write TODO and DONE files in case of failureChristian Couder, Nov 25, 2010
  21. 13/18 revert: add option parsing for option --continueChristian Couder, Nov 25, 2010
  22. 14/18 revert: move global variable "me" into "struct args_info"Christian Couder, Nov 25, 2010
  23. 15/18 revert: add NONE action and make parse_args() manage itChristian Couder, Nov 25, 2010
  24. 16/18 revert: implement parsing TODO and DONE filesChristian Couder, Nov 25, 2010
  25. 17/18 revert: add remaining instructions in todo fileChristian Couder, Nov 25, 2010
  26. 18/18 revert: implement --continue processingChristian Couder, Nov 25, 2010
  27. Jonathan NiederNov 26, 2010

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.