Skip to content

Commit a2d474a

Browse files
dschogitster
authored andcommitted
range-diff: libify the read_patches() function again
In library functions, we do want to avoid the (simple, but rather final) `die()` calls, instead returning with a value indicating an error. Let's do exactly that in the code introduced in b66885a (range-diff: add section header instead of diff header, 2019-07-11) that wants to error out if a diff header could not be parsed. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8c29b49 commit a2d474a

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

range-diff.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,16 @@ static int read_patches(const char *range, struct string_list *list,
135135
orig_len = len;
136136
len = parse_git_diff_header(&root, &linenr, 0, line,
137137
len, size, &patch);
138-
if (len < 0)
139-
die(_("could not parse git header '%.*s'"),
140-
orig_len, line);
138+
if (len < 0) {
139+
error(_("could not parse git header '%.*s'"),
140+
orig_len, line);
141+
free(util);
142+
free(current_filename);
143+
string_list_clear(list, 1);
144+
strbuf_release(&buf);
145+
strbuf_release(&contents);
146+
return -1;
147+
}
141148
strbuf_addstr(&buf, " ## ");
142149
if (patch.is_new > 0)
143150
strbuf_addf(&buf, "%s (new)", patch.new_name);

0 commit comments

Comments
 (0)