Re: [PATCH 04/26] diff.c: introduce emit_diff_symbol
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 21, 2017, 19:36 UTC
- Message-ID
- <xmqq7f05p1z7.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20170620024816.20021-5-sbeller@google.com>
Stefan Beller <sbeller@google.com> writes:
Show 15 quoted lines
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
> diff.c | 22 +++++++++++++++++++---
> 1 file changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/diff.c b/diff.c
> index 2f9722b382..89466018e5 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -559,6 +559,24 @@ static void emit_line(struct diff_options *o, const char *set, const char *reset
> emit_line_0(o, set, reset, line[0], line+1, len-1);
> }
>
> +enum diff_symbol {
> + DIFF_SYMBOL_SEPARATOR,Drop the last comma from enum?
Show 9 quoted lines
> +static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
> + const char *line, int len)
> +{
> + switch (s) {
> + case DIFF_SYMBOL_SEPARATOR:
> + fprintf(o->file, "%s%c",
> + diff_line_prefix(o),
> + o->line_termination);
> + break;As the first patch in the "diff-symbol" subseries of this topic, this change must seriously be justified. Why is it so important that a printing of an empty line must be moved to a helper function, which later will gain ability to show other kind of lines?
Show 19 quoted lines
> + default:
> + die("BUG: unknown diff symbol");
> + }
> +}
> +
> static int new_blank_line_at_eof(struct emit_callback *ecbdata, const char *line, int len)
> {
> if (!((ecbdata->ws_rule & WS_BLANK_AT_EOF) &&
> @@ -4833,9 +4851,7 @@ void diff_flush(struct diff_options *options)
>
> if (output_format & DIFF_FORMAT_PATCH) {
> if (separator) {
> - fprintf(options->file, "%s%c",
> - diff_line_prefix(options),
> - options->line_termination);
> + emit_diff_symbol(options, DIFF_SYMBOL_SEPARATOR, NULL, 0);
> if (options->stat_sep) {
> /* attach patch instead of inline */
> fputs(options->stat_sep, options->file);