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

Re: [PATCH v4 2/3] range-diff/format-patch: handle commit ranges other than A..B

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 4, 2021, 18:51 UTC
Message-ID
<xmqq7dnn7jjz.fsf@gitster.c.googlers.com>
In-Reply-To
<448e6a64fa157990fcc973ce2fe4a9fc2ba1ab32.1612431093.git.gitgitgadget@gmail.com>

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes:

Show 21 quoted lines
>  int is_range_diff_range(const char *arg)
>  {
> -	return !!strstr(arg, "..");
> +	char *copy = xstrdup(arg); /* setup_revisions() modifies it */
> +	const char *argv[] = { "", copy, "--", NULL };
> +	int i, positive = 0, negative = 0;
> +	struct rev_info revs;
> +
> +	init_revisions(&revs, NULL);
> +	if (setup_revisions(3, argv, &revs, 0) == 1) {
> +		for (i = 0; i < revs.pending.nr; i++)
> +			if (revs.pending.objects[i].item->flags & UNINTERESTING)
> +				negative++;
> +			else
> +				positive++;
> +	}
> +
> +	free(copy);
> +	object_array_clear(&revs.pending);
> +	return negative > 0 && positive > 0;
>  }

One thing that worries me with this code is that I do not see anybody that clears UNINTERESTING bit in the flags. In-core objects are singletons, so if a user fed the command two ranges,

	git range-diff A..B C..A

and this code first handled "A..B", smudging the in-core instance of the commit object A with UNINTERESTING bit, that in-core instance will be reused when the second range argument "C..A" is given to this function again.

At that point, has anybody cleared the UNINTERESTING bit in the flags word for the in-core commit A? I do not see it done in this function, but perhaps I am missing it done in the init/setup functions (I somehow doubt it, though)?

Shoudn't we be calling clear_commit_marks(ALL_REF_FLAGS) on the commits in revs.pending[] array before we clear it? Depending on the shape of "arg" that is end-user supplied, we may have walked the history in handle_dotdot_1() to parse it (e.g. "A...B").

Also we'd want to see what needs to be cleared in revs.cmdline that would have been populated by calls to add_rev_cmdline().

Other than that, I quite like the way the actual code turned out to be.

Show 19 quoted lines
> diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh
> index 6eb344be0312..e217cecac9ed 100755
> --- a/t/t3206-range-diff.sh
> +++ b/t/t3206-range-diff.sh
> @@ -150,6 +150,14 @@ test_expect_success 'simple A B C (unmodified)' '
>  	test_cmp expect actual
>  '
>  
> +test_expect_success 'A^! and A^-<n> (unmodified)' '
> +	git range-diff --no-color topic^! unmodified^-1 >actual &&
> +	cat >expect <<-EOF &&
> +	1:  $(test_oid t4) = 1:  $(test_oid u4) s/12/B/
> +	EOF
> +	test_cmp expect actual
> +'
> +
>  test_expect_success 'trivial reordering' '
>  	git range-diff --no-color master topic reordered >actual &&
>  	cat >expect <<-EOF &&
Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin
Message 44 of 63 in “Range diff with ranges lacking dotdot”
  1. 0/3 Range diff with ranges lacking dotdotJohannes Schindelin via GitGitGadget, Jan 21, 2021
  2. 1/3 range-diff: refactor check for commit rangeJohannes Schindelin via GitGitGadget, Jan 21, 2021
  3. Junio C HamanoJan 21, 2021
  4. Phillip WoodJan 22, 2021
  5. Junio C HamanoJan 22, 2021
  6. Phillip WoodJan 23, 2021
  7. Johannes SchindelinJan 26, 2021
  8. 2/3 range-diff: handle commit ranges other than A..BJohannes Schindelin via GitGitGadget, Jan 21, 2021
  9. Eric SunshineJan 21, 2021
  10. Johannes SchindelinJan 22, 2021
  11. Junio C HamanoJan 21, 2021
  12. Johannes SchindelinJan 22, 2021
  13. 3/3 range-diff(docs): explain how to specify commit rangesJohannes Schindelin via GitGitGadget, Jan 21, 2021
  14. Junio C HamanoJan 21, 2021
  15. Johannes SchindelinJan 22, 2021
  16. Junio C HamanoJan 22, 2021
  17. Johannes SchindelinJan 27, 2021
  18. Junio C HamanoJan 28, 2021
  19. Uwe Kleine-KönigJan 22, 2021
  20. Johannes SchindelinJan 26, 2021
  21. Uwe Kleine-KönigJan 22, 2021
  22. 0/3 Range diff with ranges lacking dotdotJohannes Schindelin via GitGitGadget, Jan 22, 2021
  23. 2/3 range-diff/format-patch: handle commit ranges other than A..BJohannes Schindelin via GitGitGadget, Jan 22, 2021
  24. Junio C HamanoJan 22, 2021
  25. Johannes SchindelinJan 27, 2021
  26. Junio C HamanoJan 28, 2021
  27. Johannes SchindelinJan 28, 2021
  28. 3/3 range-diff(docs): explain how to specify commit rangesJohannes Schindelin via GitGitGadget, Jan 22, 2021
  29. 1/3 range-diff/format-patch: refactor check for commit rangeJohannes Schindelin via GitGitGadget, Jan 22, 2021
  30. Junio C HamanoJan 22, 2021
  31. Uwe Kleine-KönigJan 25, 2021
  32. Junio C HamanoJan 25, 2021
  33. Uwe Kleine-KönigJan 25, 2021
  34. Junio C HamanoJan 26, 2021
  35. 0/3 Range diff with ranges lacking dotdotJohannes Schindelin via GitGitGadget, Jan 27, 2021
  36. 3/3 range-diff(docs): explain how to specify commit rangesJohannes Schindelin via GitGitGadget, Jan 27, 2021
  37. 2/3 range-diff/format-patch: handle commit ranges other than A..BJohannes Schindelin via GitGitGadget, Jan 27, 2021
  38. 1/3 range-diff/format-patch: refactor check for commit rangeJohannes Schindelin via GitGitGadget, Jan 27, 2021
  39. 0/3 Range diff with ranges lacking dotdotJohannes Schindelin via GitGitGadget, Feb 4, 2021
  40. 1/3 range-diff/format-patch: refactor check for commit rangeJohannes Schindelin via GitGitGadget, Feb 4, 2021
  41. Junio C HamanoFeb 4, 2021
  42. Johannes SchindelinFeb 4, 2021
  43. 2/3 range-diff/format-patch: handle commit ranges other than A..BJohannes Schindelin via GitGitGadget, Feb 4, 2021
  44. Junio C HamanoFeb 4, 2021
  45. Johannes SchindelinFeb 4, 2021
  46. Junio C HamanoFeb 4, 2021
  47. Johannes SchindelinFeb 4, 2021
  48. 3/3 range-diff(docs): explain how to specify commit rangesJohannes Schindelin via GitGitGadget, Feb 4, 2021
  49. Junio C HamanoFeb 4, 2021
  50. Johannes SchindelinFeb 4, 2021
  51. Junio C HamanoFeb 4, 2021
  52. 0/3 Range diff with ranges lacking dotdotJohannes Schindelin via GitGitGadget, Feb 4, 2021
  53. 3/3 range-diff(docs): explain how to specify commit rangesJohannes Schindelin via GitGitGadget, Feb 4, 2021
  54. 1/3 range-diff/format-patch: refactor check for commit rangeJohannes Schindelin via GitGitGadget, Feb 4, 2021
  55. 2/3 range-diff/format-patch: handle commit ranges other than A..BJohannes Schindelin via GitGitGadget, Feb 4, 2021
  56. Junio C HamanoFeb 5, 2021
  57. Junio C HamanoFeb 5, 2021
  58. Johannes SchindelinFeb 5, 2021
  59. 0/3 Range diff with ranges lacking dotdotJohannes Schindelin via GitGitGadget, Feb 5, 2021
  60. 2/3 range-diff/format-patch: handle commit ranges other than A..BJohannes Schindelin via GitGitGadget, Feb 5, 2021
  61. 3/3 range-diff(docs): explain how to specify commit rangesJohannes Schindelin via GitGitGadget, Feb 5, 2021
  62. 1/3 range-diff/format-patch: refactor check for commit rangeJohannes Schindelin via GitGitGadget, Feb 5, 2021
  63. Johannes SchindelinFeb 6, 2021

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.