summaryrefslogtreecommitdiff
path: root/range-diff.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2021-02-04 20:07:50 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-02-05 01:16:42 (GMT)
commita2d474adf32c4ea2585b2c6109c356523124e1f9 (patch)
tree235cdad91c3331d1cc31a56116e411f7a0a1a6e3 /range-diff.c
parent8c29b497946fde2a6ef597d960a05d3dd36dcbf0 (diff)
downloadgit-a2d474adf32c4ea2585b2c6109c356523124e1f9.zip
git-a2d474adf32c4ea2585b2c6109c356523124e1f9.tar.gz
git-a2d474adf32c4ea2585b2c6109c356523124e1f9.tar.bz2
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 b66885a30cb8 (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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'range-diff.c')
-rw-r--r--range-diff.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/range-diff.c b/range-diff.c
index a4d7a90..a83c386 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -135,9 +135,16 @@ static int read_patches(const char *range, struct string_list *list,
orig_len = len;
len = parse_git_diff_header(&root, &linenr, 0, line,
len, size, &patch);
- if (len < 0)
- die(_("could not parse git header '%.*s'"),
- orig_len, line);
+ if (len < 0) {
+ error(_("could not parse git header '%.*s'"),
+ orig_len, line);
+ free(util);
+ free(current_filename);
+ string_list_clear(list, 1);
+ strbuf_release(&buf);
+ strbuf_release(&contents);
+ return -1;
+ }
strbuf_addstr(&buf, " ## ");
if (patch.is_new > 0)
strbuf_addf(&buf, "%s (new)", patch.new_name);