git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 16:55 UTC

Re: [PATCH v2] blame: make diff algorithm configurable

From
Antonin Delpeuch <antonin@delpeuch.eu>
Date
Oct 28, 2025, 16:00 UTC
Message-ID
<362c7dc4-c35f-440a-ae20-e1d06e183fce@delpeuch.eu>
In-Reply-To
<xmqqjz0fdpa3.fsf@gitster.g>
Hi Junio,
On 28/10/2025 16:22, Junio C Hamano wrote:
Show 9 quoted lines
>>      Changes since v1:
>>      
>>       * add tests
>>       * ignore --diff-algorithm when it is provided before --minimal
> Sensible.
>
> I presume the reverse is true, i.e. giving "--minimal" and then
> "--diff-algorithm=histogram" in this order would make "histogram"
> survive, in other words, the usual "last one wins" rule is applied?

Yes, that was already the case in the version 1 of this patch. Philipp noticed that it was only true in one direction, so this fixes it.

Show 24 quoted lines
>>   static int is_a_rev(const char *name)
>>   {
>>   	struct object_id oid;
>> @@ -915,10 +960,17 @@ int cmd_blame(int argc,
>>   		OPT_BIT('s', NULL, &output_option, N_("suppress author name and timestamp (Default: off)"), OUTPUT_NO_AUTHOR),
>>   		OPT_BIT('e', "show-email", &output_option, N_("show author email instead of name (Default: off)"), OUTPUT_SHOW_EMAIL),
>>   		OPT_BIT('w', NULL, &xdl_opts, N_("ignore whitespace differences"), XDF_IGNORE_WHITESPACE),
>> +		OPT_CALLBACK_F(0, "diff-algorithm", &xdl_opts, N_("<algorithm>"),
>> +			       N_("choose a diff algorithm"),
>> +			       PARSE_OPT_NONEG, blame_diff_algorithm_callback),
>>   		OPT_STRING_LIST(0, "ignore-rev", &ignore_rev_list, N_("rev"), N_("ignore <rev> when blaming")),
>>   		OPT_STRING_LIST(0, "ignore-revs-file", &ignore_revs_file_list, N_("file"), N_("ignore revisions from <file>")),
>>   		OPT_BIT(0, "color-lines", &output_option, N_("color redundant metadata from previous line differently"), OUTPUT_COLOR_LINE),
>>   		OPT_BIT(0, "color-by-age", &output_option, N_("color lines by age"), OUTPUT_SHOW_AGE_WITH_COLOR),
>> +		OPT_CALLBACK_F(0, "minimal", &xdl_opts, NULL,
>> +			       N_("spend extra cycles to find better match"),
>> +			       PARSE_OPT_NONEG | PARSE_OPT_NOARG,
>> +			       blame_diff_algorithm_minimal),
>>   		OPT_BIT(0, "minimal", &xdl_opts, N_("spend extra cycles to find better match"), XDF_NEED_MINIMAL),
> This OPT_BIT() can stay here?  I thought parse_options_check() was
> capable of detecting duplicated long-form commands as programming
> error, but apparently it does not.  (#leftoverbits) We should look
> into teaching parse_options_check() to check duplicated option
> names.
Oops, that's an oversight on my part indeed. I'll fix it.
Show 26 quoted lines
>
>>   		OPT_STRING('S', NULL, &revs_file, N_("file"), N_("use revisions from <file> instead of calling git-rev-list")),
>>   		OPT_STRING(0, "contents", &contents_from, N_("file"), N_("use <file>'s contents as the final image")),
>> ...
>> +test_expect_success 'blame honors --minimal option' '
>> +	cat >expected <<-\EOF &&
>> +	Initial
>> +	Initial
>> +	Initial
>> +	Second
>> +	Second
>> +	Second
>> +	Second
>> +	Initial
>> +	Second
>> +	Second
>> +	Second
>> +	EOF
>> +
>> +	git blame file.txt --minimal | \
>> +		grep --only-matching -e Initial -e Second > actual &&
>> +	test_cmp expected actual
>> +'
> Do we need to test combination of configuration variables and
> command line options (to verify that options trump configuration),
> or two command line options (to verify that the last one wins)?
It's easy enough to add such tests, I can add a few more.
Show 10 quoted lines
>
> When xdiff/ part of the system gets improved, the above expected
> patterns may have to change, these tests may fail.  Whoever updates
> the diff algorithm to cause such a failure has to tell between a
> genuine _bug_ in their update to diff implementation and the test
> expecting a suboptimal result based on the behaviour of the diff
> algorithm before their improvement.  And for that, they need to
> debug these tests.  But I suspect that these tests will probably be
> very difficult to debug, as it is almost impossible to see which
> line in the original each of these lines correspond to.

I'm happy to make the tests a bit clearer by including the lines in the expected output.

I'll submit a new version with those changes.
Best,
Antonin
Previous: Junio C HamanoNext: Antonin Delpeuch via GitGitGadget
Message 8 of 32 in “blame: make diff algorithm configurable”
  1. blame: make diff algorithm configurableAntonin Delpeuch via GitGitGadget, Oct 20, 2025
  2. Junio C HamanoOct 20, 2025
  3. Antonin DelpeuchOct 22, 2025
  4. Junio C HamanoOct 22, 2025
  5. Phillip WoodOct 23, 2025
  6. blame: make diff algorithm configurableAntonin Delpeuch via GitGitGadget, Oct 28, 2025
  7. Junio C HamanoOct 28, 2025
  8. Antonin DelpeuchOct 28, 2025
  9. blame: make diff algorithm configurableAntonin Delpeuch via GitGitGadget, Oct 28, 2025
  10. Phillip WoodOct 29, 2025
  11. Junio C HamanoOct 29, 2025
  12. Antonin DelpeuchOct 30, 2025
  13. Phillip WoodOct 30, 2025
  14. 0/2 blame: make diff algorithm configurableAntonin Delpeuch via GitGitGadget, Nov 1, 2025
  15. 1/2 xdiff: add 'minimal' to XDF_DIFF_ALGORITHM_MASKAntonin Delpeuch via GitGitGadget, Nov 1, 2025
  16. 2/2 blame: make diff algorithm configurableAntonin Delpeuch via GitGitGadget, Nov 1, 2025
  17. Phillip WoodNov 3, 2025
  18. Phillip WoodNov 3, 2025
  19. Junio C HamanoNov 3, 2025
  20. Junio C HamanoNov 6, 2025
  21. 0/2 blame: make diff algorithm configurableAntonin Delpeuch via GitGitGadget, Nov 6, 2025
  22. 1/2 xdiff: add 'minimal' to XDF_DIFF_ALGORITHM_MASKAntonin Delpeuch via GitGitGadget, Nov 6, 2025
  23. 2/2 blame: make diff algorithm configurableAntonin Delpeuch via GitGitGadget, Nov 6, 2025
  24. Phillip WoodNov 7, 2025
  25. Junio C HamanoNov 7, 2025
  26. Junio C HamanoNov 7, 2025
  27. Junio C HamanoNov 17, 2025
  28. 0/2 blame: make diff algorithm configurableAntonin Delpeuch via GitGitGadget, Nov 17, 2025
  29. 1/2 xdiff: add 'minimal' to XDF_DIFF_ALGORITHM_MASKAntonin Delpeuch via GitGitGadget, Nov 17, 2025
  30. 2/2 blame: make diff algorithm configurableAntonin Delpeuch via GitGitGadget, Nov 17, 2025
  31. Phillip WoodNov 17, 2025
  32. Junio C HamanoNov 17, 2025

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.