range-diff: simplify code spawning `git log`

Previously, we waited for the child process to be finished in every failing code path as well as at the end of the function `show_range_diff()`. However, we do not need to wait that long. Directly after reading the output of the child process, we can wrap up the child process. This also has the advantage that we don't do a bunch of unnecessary work in case `finish_command()` returns with an error anyway. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Feb 4, 2021 at 20:07 UTC 5189bb87249434fba3a82f17b2bc6c93025ba88d
1 file changed +2 -5
range-diff.c
+2 -5
@@ -80,6 +80,8 @@ static int read_patches(const char *range, struct string_list *list,
80 finish_command(&cp);
81 return -1;
82 }
83 + if (finish_command(&cp))
84 + return -1;
85
86 line = contents.buf;
87 size = contents.len;
@@ -101,7 +103,6 @@ static int read_patches(const char *range, struct string_list *list,
103 string_list_clear(list, 1);
104 strbuf_release(&buf);
105 strbuf_release(&contents);
104 - finish_command(&cp);
106 return -1;
107 }
108 util->matching = -1;
@@ -117,7 +118,6 @@ static int read_patches(const char *range, struct string_list *list,
118 string_list_clear(list, 1);
119 strbuf_release(&buf);
120 strbuf_release(&contents);
120 - finish_command(&cp);
121 return -1;
122 }
123
@@ -227,9 +227,6 @@ static int read_patches(const char *range, struct string_list *list,
227 strbuf_release(&buf);
228 free(current_filename);
229
230 - if (finish_command(&cp))
231 - return -1;
232 -
230 return 0;
231 }
232