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

[PATCH 81/83] apply: roll back index in case of error

From
Christian Couder <christian.couder@gmail.com>
Date
Apr 24, 2016, 13:39 UTC
Message-ID
<1461505189-16234-2-git-send-email-chriscool@tuxfamily.org>
In-Reply-To
<1461505189-16234-1-git-send-email-chriscool@tuxfamily.org>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 apply.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/apply.c b/apply.c
index 86e0d20..7cee834 100644
--- a/apply.c
+++ b/apply.c
@@ -4718,8 +4718,11 @@ int apply_all_patches(struct apply_state *state,
 
 		if (!strcmp(arg, "-")) {
 			res = apply_patch(state, 0, "<stdin>", options);
-			if (res < 0)
+			if (res < 0) {
+				if (state->lock_file)
+					rollback_lock_file(state->lock_file);
 				return -1;
+			}
 			errs |= res;
 			read_stdin = 0;
 			continue;
@@ -4734,16 +4737,22 @@ int apply_all_patches(struct apply_state *state,
 		read_stdin = 0;
 		set_default_whitespace_mode(state);
 		res = apply_patch(state, fd, arg, options);
-		if (res < 0)
+		if (res < 0) {
+			if (state->lock_file)
+				rollback_lock_file(state->lock_file);
 			return -1;
+		}
 		errs |= res;
 		close(fd);
 	}
 	set_default_whitespace_mode(state);
 	if (read_stdin) {
 		res = apply_patch(state, 0, "<stdin>", options);
-		if (res < 0)
+		if (res < 0) {
+			if (state->lock_file)
+				rollback_lock_file(state->lock_file);
 			return -1;
+		}
 		errs |= res;
 	}
 
@@ -4757,11 +4766,14 @@ int apply_all_patches(struct apply_state *state,
 				   squelched),
 				squelched);
 		}
-		if (state->ws_error_action == die_on_ws_error)
+		if (state->ws_error_action == die_on_ws_error) {
+			if (state->lock_file)
+				rollback_lock_file(state->lock_file);
 			return error(Q_("%d line adds whitespace errors.",
 					"%d lines add whitespace errors.",
 					state->whitespace_error),
 				     state->whitespace_error);
+		}
 		if (state->applied_after_fixing_ws && state->apply)
 			warning("%d line%s applied after"
 				" fixing whitespace errors.",
-- 
2.8.1.300.g5fed0c0
Previous: Christian CouderNext: Johannes Schindelin
Message 2 of 24 in “run-command: make dup_devnull() non static”
  1. 80/83 run-command: make dup_devnull() non staticChristian Couder, Apr 24, 2016
  2. 81/83 apply: roll back index in case of errorChristian Couder, Apr 24, 2016
  3. Johannes SchindelinApr 25, 2016
  4. Johannes SchindelinMay 2, 2016
  5. Eric SunshineMay 2, 2016
  6. Christian CouderMay 3, 2016
  7. 82/83 environment: add set_index_file()Christian Couder, Apr 24, 2016
  8. Junio C HamanoMay 3, 2016
  9. Christian CouderMay 4, 2016
  10. 83/83 builtin/am: use apply api in run_apply()Christian Couder, Apr 24, 2016
  11. Johannes SchindelinApr 25, 2016
  12. Christian CouderMay 5, 2016
  13. Johannes SchindelinApr 25, 2016
  14. Christian CouderMay 5, 2016
  15. Johannes SixtMay 5, 2016
  16. Christian CouderMay 6, 2016
  17. Johannes SchindelinMay 6, 2016
  18. Christian CouderMay 7, 2016
  19. Johannes SchindelinMay 7, 2016
  20. Christian CouderMay 7, 2016
  21. Johannes SchindelinMay 8, 2016
  22. Duy NguyenMay 8, 2016
  23. Johannes SchindelinMay 9, 2016
  24. Junio C HamanoMay 9, 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.