return 0;
}
+static int diff_error_outofrange(const char *thing)
+{
+ giterr_set(GITERR_INVALID, "Diff patch %s index out of range", thing);
+ return GIT_ENOTFOUND;
+}
+
int git_diff_patch_get_hunk(
const git_diff_range **range,
const char **header,
if (header) *header = NULL;
if (header_len) *header_len = 0;
if (lines_in_hunk) *lines_in_hunk = 0;
- return GIT_ENOTFOUND;
+
+ return diff_error_outofrange("hunk");
}
hunk = &patch->hunks[hunk_idx];
assert(patch);
if (hunk_idx >= patch->hunks_size)
- return GIT_ENOTFOUND;
+ return diff_error_outofrange("hunk");
else
return (int)patch->hunks[hunk_idx].line_count;
}
{
diff_patch_hunk *hunk;
diff_patch_line *line;
+ const char *thing;
assert(patch);
- if (hunk_idx >= patch->hunks_size)
+ if (hunk_idx >= patch->hunks_size) {
+ thing = "hunk";
goto notfound;
+ }
hunk = &patch->hunks[hunk_idx];
- if (line_of_hunk >= hunk->line_count)
+ if (line_of_hunk >= hunk->line_count) {
+ thing = "link";
goto notfound;
+ }
line = &patch->lines[hunk->line_start + line_of_hunk];
if (old_lineno) *old_lineno = -1;
if (new_lineno) *new_lineno = -1;
- return GIT_ENOTFOUND;
+ return diff_error_outofrange(thing);
}
static int print_to_buffer_cb(