return offset;
}
+/*
+ * Find file diff header
+ *
+ * Returns:
+ * -1 if no header was found
+ * -128 in case of error
+ * the size of the header in bytes (called "offset") otherwise
+ */
static int find_header(struct apply_state *state,
const char *line,
unsigned long size,
struct fragment dummy;
if (parse_fragment_header(line, len, &dummy) < 0)
continue;
- die(_("patch fragment without header at line %d: %.*s"),
- state->linenr, (int)len-1, line);
+ error(_("patch fragment without header at line %d: %.*s"),
+ state->linenr, (int)len-1, line);
+ return -128;
}
if (size < len + 6)
if (git_hdr_len <= len)
continue;
if (!patch->old_name && !patch->new_name) {
- if (!patch->def_name)
- die(Q_("git diff header lacks filename information when removing "
- "%d leading pathname component (line %d)",
- "git diff header lacks filename information when removing "
- "%d leading pathname components (line %d)",
- state->p_value),
- state->p_value, state->linenr);
+ if (!patch->def_name) {
+ error(Q_("git diff header lacks filename information when removing "
+ "%d leading pathname component (line %d)",
+ "git diff header lacks filename information when removing "
+ "%d leading pathname components (line %d)",
+ state->p_value),
+ state->p_value, state->linenr);
+ return -128;
+ }
patch->old_name = xstrdup(patch->def_name);
patch->new_name = xstrdup(patch->def_name);
}
- if (!patch->is_delete && !patch->new_name)
- die("git diff header lacks filename information "
- "(line %d)", state->linenr);
+ if (!patch->is_delete && !patch->new_name) {
+ error("git diff header lacks filename information "
+ "(line %d)", state->linenr);
+ return -128;
+ }
patch->is_toplevel_relative = 1;
*hdrsize = git_hdr_len;
return offset;
int hdrsize, patchsize;
int offset = find_header(state, buffer, size, &hdrsize, patch);
+ if (offset == -128)
+ exit(128);
+
if (offset < 0)
return offset;