Re: [PATCH v7 02/40] builtin/apply: make apply_patch() return -1 instead of die()ing

2 messages, 2 authors, 2016-06-16 · open the first message on its own page

Re: [PATCH v7 02/40] builtin/apply: make apply_patch() return -1 instead of die()ing

From: Junio C Hamano <hidden>
Date: 2016-06-16 06:55:52

Christian Couder [off-list ref] writes:
quoted hunk
+/*
+ * Try to apply a patch.
+ *
+ * Returns:
+ *  -1 if an error happened
+ *   0 if the patch applied
+ *   1 if the patch did not apply
+ */
 static int apply_patch(struct apply_state *state,
 		       int fd,
 		       const char *filename,
@@ -4413,6 +4421,7 @@ static int apply_patch(struct apply_state *state,
 	struct strbuf buf = STRBUF_INIT; /* owns the patch text */
 	struct patch *list = NULL, **listp = &list;
 	int skipped_patch = 0;
+	int res = 0;
 
 	state->patch_input_file = filename;
 	read_patch_file(&buf, fd);
@@ -4445,8 +4454,10 @@ static int apply_patch(struct apply_state *state,
 		offset += nr;
 	}
 
-	if (!list && !skipped_patch)
-		die(_("unrecognized input"));
+	if (!list && !skipped_patch) {
+		res = error(_("unrecognized input"));
+		goto end;
+	}
Before this patch, the program said "fatal: $message" and exited
with status = 128.  All these changes in this step modifies the
external behaviour and make it say "error: $message" and exit with
status = 1 (at least the caller in apply_all_patches() does so).

Will that be an issue for the calling scripts?

Re: [PATCH v7 02/40] builtin/apply: make apply_patch() return -1 instead of die()ing

From: Christian Couder <hidden>
Date: 2016-06-16 06:55:52

On Tue, Jun 14, 2016 at 12:55 AM, Junio C Hamano [off-list ref] wrote:
Christian Couder [off-list ref] writes:
quoted
+/*
+ * Try to apply a patch.
+ *
+ * Returns:
+ *  -1 if an error happened
+ *   0 if the patch applied
+ *   1 if the patch did not apply
+ */
 static int apply_patch(struct apply_state *state,
                     int fd,
                     const char *filename,
@@ -4413,6 +4421,7 @@ static int apply_patch(struct apply_state *state,
      struct strbuf buf = STRBUF_INIT; /* owns the patch text */
      struct patch *list = NULL, **listp = &list;
      int skipped_patch = 0;
+     int res = 0;

      state->patch_input_file = filename;
      read_patch_file(&buf, fd);
@@ -4445,8 +4454,10 @@ static int apply_patch(struct apply_state *state,
              offset += nr;
      }

-     if (!list && !skipped_patch)
-             die(_("unrecognized input"));
+     if (!list && !skipped_patch) {
+             res = error(_("unrecognized input"));
+             goto end;
+     }
Before this patch, the program said "fatal: $message" and exited
with status = 128.  All these changes in this step modifies the
external behaviour and make it say "error: $message" and exit with
status = 1 (at least the caller in apply_all_patches() does so).

Will that be an issue for the calling scripts?
Hopefully the scripts don't check the specific error code and message.

I will add something about this in the commit message.

Do you think something else that should be done about this?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help