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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Instead we will just return an error code.

Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx>
---
 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


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]