diff-highlight: use flush() helper consistently

The current flush() helper only shows the queued diff but does not clear the queue. This is conceptually a bug, but it works because we only call it once at the end of the program. Let's teach it to clear the queue, which will let us use it in more places (one for now, but more in future patches). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 21, 2018 at 01:56 UTC 009a81ed978e5dc81767cf1be6dc4ea38c112801
1 file changed +3 -4
contrib/diff-highlight/DiffHighlight.pm
+3 -4
@@ -46,10 +46,7 @@ sub handle_line {
46 push @added, $_;
47 }
48 else {
49 - show_hunk(\@removed, \@added);
50 - @removed = ();
51 - @added = ();
52 -
49 + flush();
50 $line_cb->($_);
51 $in_hunk = /^$GRAPH*$COLOR*[\@ ]/;
52 }
@@ -71,6 +68,8 @@ sub flush {
68 # Flush any queued hunk (this can happen when there is no trailing
69 # context in the final diff of the input).
70 show_hunk(\@removed, \@added);
71 + @removed = ();
72 + @added = ();
73 }
74
75 sub highlight_stdin {