struct gitdiff_data {
struct strbuf *root;
+ const char *patch_input_file;
int linenr;
int p_value;
};
}
}
if (!name)
- return error(_("unable to find filename in patch at line %d"), state->linenr);
+ return error(_("unable to find filename in patch at %s:%d"),
+ state->patch_input_file, state->linenr);
return 0;
}
if (*name) {
char *another;
- if (isnull)
+ if (isnull) {
+ if (state->patch_input_file)
+ return error(_("git apply: bad git-diff - expected /dev/null, got %s at %s:%d"),
+ *name, state->patch_input_file, state->linenr);
return error(_("git apply: bad git-diff - expected /dev/null, got %s on line %d"),
*name, state->linenr);
+ }
another = find_name(state->root, line, NULL, state->p_value, TERM_TAB);
if (!another || strcmp(another, *name)) {
free(another);
+ if (state->patch_input_file)
+ return error((side == DIFF_NEW_NAME) ?
+ _("git apply: bad git-diff - inconsistent new filename at %s:%d") :
+ _("git apply: bad git-diff - inconsistent old filename at %s:%d"),
+ state->patch_input_file, state->linenr);
return error((side == DIFF_NEW_NAME) ?
- _("git apply: bad git-diff - inconsistent new filename on line %d") :
- _("git apply: bad git-diff - inconsistent old filename on line %d"), state->linenr);
+ _("git apply: bad git-diff - inconsistent new filename on line %d") :
+ _("git apply: bad git-diff - inconsistent old filename on line %d"),
+ state->linenr);
}
free(another);
} else {
- if (!is_dev_null(line))
- return error(_("git apply: bad git-diff - expected /dev/null on line %d"), state->linenr);
+ if (!is_dev_null(line)) {
+ if (state->patch_input_file)
+ return error(_("git apply: bad git-diff - expected /dev/null at %s:%d"),
+ state->patch_input_file, state->linenr);
+ return error(_("git apply: bad git-diff - expected /dev/null on line %d"),
+ state->linenr);
+ }
}
return 0;
DIFF_NEW_NAME);
}
-static int parse_mode_line(const char *line, int linenr, unsigned int *mode)
+static int parse_mode_line(const char *line,
+ const char *patch_input_file,
+ int linenr,
+ unsigned int *mode)
{
char *end;
*mode = strtoul(line, &end, 8);
- if (end == line || !isspace(*end))
+ if (end == line || !isspace(*end)) {
+ if (patch_input_file)
+ return error(_("invalid mode at %s:%d: %s"),
+ patch_input_file, linenr, line);
return error(_("invalid mode on line %d: %s"), linenr, line);
+ }
*mode = canon_mode(*mode);
return 0;
}
const char *line,
struct patch *patch)
{
- return parse_mode_line(line, state->linenr, &patch->old_mode);
+ return parse_mode_line(line, state->patch_input_file, state->linenr,
+ &patch->old_mode);
}
static int gitdiff_newmode(struct gitdiff_data *state,
const char *line,
struct patch *patch)
{
- return parse_mode_line(line, state->linenr, &patch->new_mode);
+ return parse_mode_line(line, state->patch_input_file, state->linenr,
+ &patch->new_mode);
}
static int gitdiff_delete(struct gitdiff_data *state,
}
int parse_git_diff_header(struct strbuf *root,
+ const char *patch_input_file,
int *linenr,
int p_value,
const char *line,
size -= len;
(*linenr)++;
parse_hdr_state.root = root;
+ parse_hdr_state.patch_input_file = patch_input_file;
parse_hdr_state.linenr = *linenr;
parse_hdr_state.p_value = p_value;
int res;
if (len < oplen || memcmp(p->str, line, oplen))
continue;
+ parse_hdr_state.linenr = *linenr;
res = p->fn(&parse_hdr_state, line + oplen, patch);
if (res < 0)
return -1;
done:
if (!patch->old_name && !patch->new_name) {
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)",
- parse_hdr_state.p_value),
- parse_hdr_state.p_value, *linenr);
+ if (patch_input_file)
+ error(Q_("git diff header lacks filename information when removing "
+ "%d leading pathname component at %s:%d",
+ "git diff header lacks filename information when removing "
+ "%d leading pathname components at %s:%d",
+ parse_hdr_state.p_value),
+ parse_hdr_state.p_value, patch_input_file, *linenr);
+ else
+ 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)",
+ parse_hdr_state.p_value),
+ parse_hdr_state.p_value, *linenr);
return -128;
}
patch->old_name = xstrdup(patch->def_name);
}
if ((!patch->new_name && !patch->is_delete) ||
(!patch->old_name && !patch->is_new)) {
- error(_("git diff header lacks filename information "
- "(line %d)"), *linenr);
+ if (patch_input_file)
+ error(_("git diff header lacks filename information at %s:%d"),
+ patch_input_file, *linenr);
+ else
+ error(_("git diff header lacks filename information (line %d)"),
+ *linenr);
return -128;
}
patch->is_toplevel_relative = 1;
struct fragment dummy;
if (parse_fragment_header(line, len, &dummy) < 0)
continue;
- error(_("patch fragment without header at line %d: %.*s"),
- state->linenr, (int)len-1, line);
+ error(_("patch fragment without header at %s:%d: %.*s"),
+ state->patch_input_file, state->linenr,
+ (int)len-1, line);
return -128;
}
* or mode change, so we handle that specially
*/
if (!memcmp("diff --git ", line, 11)) {
- int git_hdr_len = parse_git_diff_header(&state->root, &state->linenr,
+ int git_hdr_len = parse_git_diff_header(&state->root,
+ state->patch_input_file,
+ &state->linenr,
state->p_value, line, len,
size, patch);
if (git_hdr_len < 0)