Re: [PATCH 13/26] diff.c: emit_diff_symbol learns about DIFF_SYMBOL_BINARY_FILES

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Stefan Beller <sbeller@xxxxxxxxxx> writes:

> Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx>
> ---
>  diff.c | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/diff.c b/diff.c
> index 95f11ea86f..e56962b844 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -572,6 +572,7 @@ enum diff_symbol {
>  	DIFF_SYMBOL_WORDS,
>  	DIFF_SYMBOL_FILEPAIR,
>  	DIFF_SYMBOL_HEADER,
> +	DIFF_SYMBOL_BINARY_FILES,
>  };
>  /*
>   * Flags for content lines:
> @@ -689,6 +690,10 @@ static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
>  	case DIFF_SYMBOL_HEADER:
>  		fprintf(o->file, "%s", line);
>  		break;
> +	case DIFF_SYMBOL_BINARY_FILES:
> +		fprintf(o->file, "%sBinary files %s differ\n",
> +			diff_line_prefix(o), line);
> +		break;

It is curious why the "line" is defined to be "A and B" here.  It
could have been defined to be the whole string "Binary files A and B
differ" or even with the terminating LF.

And with that it may have been able to share concepts with the
"HEADER" we see above.  SYMBOL_HEADER becomes "oneline without
prefix", and this one (updated to make the caller prepare the whole
sentence) becomes "oneline with prefix".

> @@ -2549,8 +2555,10 @@ static void builtin_diff(const char *name_a,
>  			}
>  			emit_diff_symbol(o, DIFF_SYMBOL_HEADER,
>  					 header.buf, header.len, 0);
> -			fprintf(o->file, "%sBinary files %s and %s differ\n",
> -				line_prefix, lbl[0], lbl[1]);
> +			strbuf_addf(&sb, "%s and %s", lbl[0], lbl[1]);
> +			emit_diff_symbol(o, DIFF_SYMBOL_BINARY_FILES,
> +					 sb.buf, sb.len, 0);
> +			strbuf_release(&sb);
>  			goto free_ab_and_return;
>  		}
>  		if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
> @@ -2567,9 +2575,12 @@ static void builtin_diff(const char *name_a,
>  		strbuf_reset(&header);
>  		if (DIFF_OPT_TST(o, BINARY))
>  			emit_binary_diff(o->file, &mf1, &mf2, line_prefix);
> -		else
> -			fprintf(o->file, "%sBinary files %s and %s differ\n",
> -				line_prefix, lbl[0], lbl[1]);
> +		else {
> +			strbuf_addf(&sb, "%s and %s", lbl[0], lbl[1]);
> +			emit_diff_symbol(o, DIFF_SYMBOL_BINARY_FILES,
> +					 sb.buf, sb.len, 0);
> +			strbuf_release(&sb);
> +		}
>  		o->found_changes = 1;
>  	} else {
>  		/* Crazy xdl interfaces.. */



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux