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

Re: [PATCH 1/3] range-diff: refactor check for commit range

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Jan 22, 2021, 19:12 UTC
Message-ID
<0ce0953a-92b2-2ce6-1e13-6f6240933ce1@gmail.com>
In-Reply-To
<5839ba4f7615819ed6f9a0fcb6de1855cd2e89e1.1611267638.git.gitgitgadget@gmail.com>
Hi Dscho
On 21/01/2021 22:20, Johannes Schindelin via GitGitGadget wrote:
Show 29 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
> 
> Currently, when called with exactly two arguments, we test for a literal
> `..` in each of the two.
> 
> However, `<commit>^!` is a perfectly valid commit range, equivalent to
> `<commit>^..<commit>` according to the `SPECIFYING RANGES` section of
> gitrevisions[7].
> 
> In preparation for allowing more sophisticated ways to specify commit
> ranges, let's refactor the conditional into its own function.
> 
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>   builtin/range-diff.c | 13 +++++++++----
>   1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/builtin/range-diff.c b/builtin/range-diff.c
> index 24c4162f744..551d3e689cb 100644
> --- a/builtin/range-diff.c
> +++ b/builtin/range-diff.c
> @@ -11,6 +11,11 @@ N_("git range-diff [<options>] <base> <old-tip> <new-tip>"),
>   NULL
>   };
>   
> +static int is_range(const char *range)
> +{
> +	return !!strstr(range, "..");
> +}

If the user wrongly passes two arguments referring to single commits with `:/<text>` or `@{/<text>}` where text contains ".." this will give a false positive.

Best Wishes
Phillip
Show 21 quoted lines
>   int cmd_range_diff(int argc, const char **argv, const char *prefix)
>   {
>   	int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT;
> @@ -46,12 +51,12 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
>   		diffopt.use_color = 1;
>   
>   	if (argc == 2) {
> -		if (!strstr(argv[0], ".."))
> -			die(_("no .. in range: '%s'"), argv[0]);
> +		if (!is_range(argv[0]))
> +			die(_("not a commit range: '%s'"), argv[0]);
>   		strbuf_addstr(&range1, argv[0]);
>   
> -		if (!strstr(argv[1], ".."))
> -			die(_("no .. in range: '%s'"), argv[1]);
> +		if (!is_range(argv[1]))
> +			die(_("not a commit range: '%s'"), argv[1]);
>   		strbuf_addstr(&range2, argv[1]);
>   	} else if (argc == 3) {
>   		strbuf_addf(&range1, "%s..%s", argv[0], argv[1]);
> 
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 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.