git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 3/4] diff: add flag to indicate textconv was set via cmdline

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 31, 2017, 05:02 UTC
Message-ID
<xmqq4lqf3o5q.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20171030194646.27473-4-bmwill@google.com>
Brandon Williams <bmwill@google.com> writes:
Show 12 quoted lines
> diff --git a/builtin/log.c b/builtin/log.c
> index dc28d43eb..82131751d 100644
> --- a/builtin/log.c
> +++ b/builtin/log.c
> @@ -485,7 +485,7 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
>  	unsigned long size;
>  
>  	fflush(rev->diffopt.file);
> -	if (!DIFF_OPT_TOUCHED(&rev->diffopt, ALLOW_TEXTCONV) ||
> +	if (!DIFF_OPT_TST(&rev->diffopt, TEXTCONV_SET_VIA_CMDLINE) ||
>  	    !DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV))
>  		return stream_blob_to_fd(1, oid, NULL, 0);
The original is equivalent to 
	if (! (DIFF_OPT_TOUCHED() && DIFF_OPT_TST()))
		return stream_blob_to_fd();

which means that we must have used DIFF_OPT_SET() or DIFF_OPT_CLR() to touch the ALLOW_TEXTCONV bit, and ALLOW_TEXTCONV bit is currently set, in order for the flow to skip this "just stream it out".

And the way it implemented it was:

#define DIFF_OPT_TOUCHED(opts, flag) ((opts)->touched_flags & DIFF_OPT_##flag) #define DIFF_OPT_SET(opts, flag) (((opts)->flags |= DIFF_OPT_##flag),((opts)->touched_flags |= DIFF_OPT_##flag)) #define DIFF_OPT_CLR(opts, flag) (((opts)->flags &= ~DIFF_OPT_##flag),((opts)->touched_flags |= DIFF_OPT_##flag))

Notice that touched_flags is SET in both OPT_SET() and OPT_CLR(), because the point of _TOUCHED() was "did the user made an explicit request to affect the value of the bit from the command line?".

Show 18 quoted lines
> diff --git a/diff.c b/diff.c
> index 3ad9c9b31..8b700b1bd 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -4762,11 +4762,13 @@ int diff_opt_parse(struct diff_options *options,
>  		DIFF_OPT_SET(options, ALLOW_EXTERNAL);
>  	else if (!strcmp(arg, "--no-ext-diff"))
>  		DIFF_OPT_CLR(options, ALLOW_EXTERNAL);
> -	else if (!strcmp(arg, "--textconv"))
> +	else if (!strcmp(arg, "--textconv")) {
>  		DIFF_OPT_SET(options, ALLOW_TEXTCONV);
> -	else if (!strcmp(arg, "--no-textconv"))
> +		DIFF_OPT_SET(options, TEXTCONV_SET_VIA_CMDLINE);
> +	} else if (!strcmp(arg, "--no-textconv")) {
>  		DIFF_OPT_CLR(options, ALLOW_TEXTCONV);
> -	else if (!strcmp(arg, "--ignore-submodules")) {
> +		DIFF_OPT_CLR(options, TEXTCONV_SET_VIA_CMDLINE);
> +	} else if (!strcmp(arg, "--ignore-submodules")) {

If we were aiming for faithful conversion, the above must be DIFF_OPT_SET(options, TEXTCONV_SET_VIA_CMDLINE), not CLR.

HOWEVER, I think it is fine to define TEXTCONV_SET_VIA_CMDLINE bit differently from what DIFF_OPT_TOUCHED(ALLOW_TEXTCONV) meant in the old code (i.e. "did the user made an explicit request to affect the value?"). That is, we can define the new one as "did the user explicitly SET the bit from the command line?", the conditional in show_blob_object() is prepared to take either interpretation. "User explicitly set the bit to true, and the bit is true" and "User explicitly set the bit to something, and the bit is true" are pretty much the same thing.

And that leads me to suggest dropping the last change here, to touch VIA_CMDLINE in response to "--no-textconv".

Other than that, looks good to me.
Thanks.
Previous: Brandon WilliamsNext: Junio C Hamano
Message 25 of 47 in “convert diff flags to be stored in a struct”
  1. 0/3 convert diff flags to be stored in a structBrandon Williams, Oct 27, 2017
  2. 1/3 add: use DIFF_OPT_SET macro to set a diff flagBrandon Williams, Oct 27, 2017
  3. 2/3 reset: use DIFF_OPT_SET macro to set a diff flagBrandon Williams, Oct 27, 2017
  4. Junio C HamanoOct 29, 2017
  5. Brandon WilliamsOct 30, 2017
  6. 3/3 diff: convert flags to be stored in bitfieldsBrandon Williams, Oct 27, 2017
  7. Junio C HamanoOct 29, 2017
  8. Junio C HamanoOct 30, 2017
  9. Brandon WilliamsOct 30, 2017
  10. Junio C HamanoOct 31, 2017
  11. Brandon WilliamsOct 30, 2017
  12. Junio C HamanoOct 29, 2017
  13. Stefan BellerOct 29, 2017
  14. 0/4 convert diff flags to be stored in a structBrandon Williams, Oct 30, 2017
  15. 1/4 add, reset: use DIFF_OPT_SET macro to set a diff flagBrandon Williams, Oct 30, 2017
  16. 2/4 diff: convert flags to be stored in bitfieldsBrandon Williams, Oct 30, 2017
  17. Junio C HamanoOct 31, 2017
  18. 5/4 diff: avoid returning a struct by value from diff_flags_or()Junio C Hamano, Oct 31, 2017
  19. Brandon WilliamsOct 31, 2017
  20. 4/4 diff: remove touched flagsBrandon Williams, Oct 30, 2017
  21. 3/4 diff: add flag to indicate textconv was set via cmdlineBrandon Williams, Oct 30, 2017
  22. Stefan BellerOct 30, 2017
  23. Brandon WilliamsOct 30, 2017
  24. Brandon WilliamsOct 30, 2017
  25. Junio C HamanoOct 31, 2017
  26. 5/4 diff: set TEXTCONV_VIA_CMDLINE only when it is set to trueJunio C Hamano, Oct 31, 2017
  27. Brandon WilliamsOct 31, 2017
  28. 5/4 diff: remove DIFF_OPT_TST macroBrandon Williams, Oct 30, 2017
  29. 7/4 diff: remove DIFF_OPT_CLR macroBrandon Williams, Oct 30, 2017
  30. 6/4 diff: remove DIFF_OPT_SET macroBrandon Williams, Oct 30, 2017
  31. 8/4 diff: make struct diff_flags members lowercaseBrandon Williams, Oct 30, 2017
  32. 0/8 convert diff flags to be stored in a structBrandon Williams, Oct 31, 2017
  33. 1/8 add, reset: use DIFF_OPT_SET macro to set a diff flagBrandon Williams, Oct 31, 2017
  34. 2/8 diff: convert flags to be stored in bitfieldsBrandon Williams, Oct 31, 2017
  35. Stefan BellerOct 31, 2017
  36. Junio C HamanoNov 1, 2017
  37. Stefan BellerNov 1, 2017
  38. 4/8 diff: remove touched flagsBrandon Williams, Oct 31, 2017
  39. 5/8 diff: remove DIFF_OPT_TST macroBrandon Williams, Oct 31, 2017
  40. 3/8 diff: add flag to indicate textconv was set via cmdlineBrandon Williams, Oct 31, 2017
  41. 6/8 diff: remove DIFF_OPT_SET macroBrandon Williams, Oct 31, 2017
  42. 7/8 diff: remove DIFF_OPT_CLR macroBrandon Williams, Oct 31, 2017
  43. Stefan BellerOct 31, 2017
  44. Junio C HamanoNov 1, 2017
  45. 8/8 diff: make struct diff_flags members lowercaseBrandon Williams, Oct 31, 2017
  46. Stefan BellerOct 31, 2017
  47. Junio C HamanoNov 1, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.