git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Antonin Delpeuch via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Elijah Newren <newren@gmail.com>,
	Phillip Wood <phillip.wood123@gmail.com>,
	Antonin Delpeuch <antonin@delpeuch.eu>
Subject: [PATCH v4 0/2] blame: make diff algorithm configurable
Date: Sat, 01 Nov 2025 21:57:30 +0000	[thread overview]
Message-ID: <pull.2075.v4.git.git.1762034252.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2075.v3.git.git.1761686060477.gitgitgadget@gmail.com>

Changes since v3:

 * fix resetting of diff algorithm by adding XDF_NEED_MINIMAL to
   XDF_DIFF_ALGORITHM_MASK
 * restore --no-minimal support
 * fix typo in description of --minimal option
 * remove the 'for now' in test description
 * remove piping in tests
 * pass configuration variables to the blame command directly instead of
   calling 'git config'

Antonin Delpeuch (2):
  xdiff: add 'minimal' to XDF_DIFF_ALGORITHM_MASK
  blame: make diff algorithm configurable

 Documentation/diff-algorithm-option.adoc |  20 +++
 Documentation/diff-options.adoc          |  21 +--
 Documentation/git-blame.adoc             |   2 +
 builtin/blame.c                          |  52 +++++-
 diff.c                                   |   2 -
 merge-ort.c                              |   2 -
 t/meson.build                            |   1 +
 t/t8015-blame-diff-algorithm.sh          | 203 +++++++++++++++++++++++
 xdiff/xdiff.h                            |   2 +-
 9 files changed, 279 insertions(+), 26 deletions(-)
 create mode 100644 Documentation/diff-algorithm-option.adoc
 create mode 100755 t/t8015-blame-diff-algorithm.sh


base-commit: 4253630c6f07a4bdcc9aa62a50e26a4d466219d1
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2075%2Fwetneb%2Fblame_respects_diff_algorithm-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2075/wetneb/blame_respects_diff_algorithm-v4
Pull-Request: https://github.com/git/git/pull/2075

Range-diff vs v3:

 -:  ---------- > 1:  e81a5d2bd2 xdiff: add 'minimal' to XDF_DIFF_ALGORITHM_MASK
 1:  b8bdb03516 ! 2:  920a6f3acb blame: make diff algorithm configurable
     @@ builtin/blame.c: static int blame_move_callback(const struct option *option, con
      +{
      +	int *opt = option->value;
      +
     -+	BUG_ON_OPT_NEG(unset);
      +	BUG_ON_OPT_ARG(arg);
      +
      +	*opt &= ~XDF_DIFF_ALGORITHM_MASK;
     -+	*opt |= XDF_NEED_MINIMAL;
     ++	if (!unset)
     ++		*opt |= XDF_NEED_MINIMAL;
      +
      +	return 0;
      +}
     @@ builtin/blame.c: int cmd_blame(int argc,
       		OPT_BIT(0, "color-by-age", &output_option, N_("color lines by age"), OUTPUT_SHOW_AGE_WITH_COLOR),
      -		OPT_BIT(0, "minimal", &xdl_opts, N_("spend extra cycles to find better match"), XDF_NEED_MINIMAL),
      +		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),
     ++			       N_("spend extra cycles to find a better match"),
     ++			       PARSE_OPT_NOARG, blame_diff_algorithm_minimal),
       		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")),
       		OPT_CALLBACK_F('C', NULL, &opt, N_("score"), N_("find line copies within and across files"), PARSE_OPT_OPTARG, blame_copy_callback),
     @@ t/t8015-blame-diff-algorithm.sh (new)
      +	GIT_AUTHOR_NAME=Commit_2 git commit -m Commit_2
      +'
      +
     -+test_expect_success 'blame uses Myers diff algorithm by default for now' '
     ++test_expect_success 'blame uses Myers diff algorithm by default' '
      +	cat >expected <<-\EOF &&
      +	Commit_2 int g(size_t u)
      +	Commit_1 {
     @@ t/t8015-blame-diff-algorithm.sh (new)
      +	Commit_1 }
      +	EOF
      +
     -+
     -+	git blame file.c | \
     -+		sed -e "s/^[^ ]* (\([^ ]*\) [^)]*)/\1/g" | \
     -+		sed -e "s/ *$//g" > actual &&
     ++	git blame file.c > output &&
     ++	sed -e "s/^[^ ]* (\([^ ]*\) [^)]*)/\1/g" output > without_varying_parts &&
     ++	sed -e "s/ *$//g" without_varying_parts > actual &&
      +	test_cmp expected actual
      +'
      +
     @@ t/t8015-blame-diff-algorithm.sh (new)
      +	Commit_2 }
      +	EOF
      +
     -+	git blame file.c --diff-algorithm histogram | \
     -+		sed -e "s/^[^ ]* (\([^ ]*\) [^)]*)/\1/g" | \
     -+		sed -e "s/ *$//g" > actual &&
     ++	git blame file.c --diff-algorithm histogram > output &&
     ++	sed -e "s/^[^ ]* (\([^ ]*\) [^)]*)/\1/g" output > without_varying_parts &&
     ++	sed -e "s/ *$//g" without_varying_parts > actual &&
      +	test_cmp expected actual
      +'
      +
     @@ t/t8015-blame-diff-algorithm.sh (new)
      +	Commit_2 }
      +	EOF
      +
     -+	git config diff.algorithm histogram &&
     -+	git blame file.c | \
     -+		sed -e "s/^[^ ]* (\([^ ]*\) [^)]*)/\1/g" | \
     -+		sed -e "s/ *$//g" > actual &&
     ++	git -c diff.algorithm=histogram blame file.c > output &&
     ++	sed -e "s/^[^ ]* (\([^ ]*\) [^)]*)/\1/g" output > without_varying_parts &&
     ++	sed -e "s/ *$//g" without_varying_parts > actual &&
      +	test_cmp expected actual
      +'
      +
     @@ t/t8015-blame-diff-algorithm.sh (new)
      +	Commit_2 }
      +	EOF
      +
     -+	git config diff.algorithm myers &&
     -+	git blame file.c --diff-algorithm histogram | \
     -+		sed -e "s/^[^ ]* (\([^ ]*\) [^)]*)/\1/g" | \
     -+		sed -e "s/ *$//g" > actual &&
     ++	git -c diff.algorithm=myers blame file.c --diff-algorithm histogram &&
     ++	sed -e "s/^[^ ]* (\([^ ]*\) [^)]*)/\1/g" output > without_varying_parts &&
     ++	sed -e "s/ *$//g" without_varying_parts > actual &&
      +	test_cmp expected actual
      +'
     ++
      +test_expect_success 'blame honors --minimal option' '
      +	cat >expected <<-\EOF &&
      +	Commit_1 x
     @@ t/t8015-blame-diff-algorithm.sh (new)
      +	Commit_2 G
      +	EOF
      +
     -+	git blame file.txt --minimal | \
     -+		sed -e "s/^[^ ]* (\([^ ]*\) [^)]*)/\1/g" > actual &&
     ++	git blame file.txt --minimal > output &&
     ++	sed -e "s/^[^ ]* (\([^ ]*\) [^)]*)/\1/g" output > actual &&
      +	test_cmp expected actual
      +'
      +
     @@ t/t8015-blame-diff-algorithm.sh (new)
      +	Commit_2 G
      +	EOF
      +
     -+	git blame file.txt --minimal --diff-algorithm myers | \
     -+		sed -e "s/^[^ ]* (\([^ ]*\) [^)]*)/\1/g" > actual &&
     ++	git blame file.txt --minimal --diff-algorithm myers > output &&
     ++	sed -e "s/^[^ ]* (\([^ ]*\) [^)]*)/\1/g" output > actual &&
      +	test_cmp expected actual
      +'
      +
     -+
      +test_done

-- 
gitgitgadget

  parent reply	other threads:[~2025-11-01 21:57 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-20 14:56 [PATCH] blame: make diff algorithm configurable Antonin Delpeuch via GitGitGadget
2025-10-20 16:05 ` Junio C Hamano
2025-10-22  9:37   ` Antonin Delpeuch
2025-10-22 20:39     ` Junio C Hamano
2025-10-23 16:03 ` Phillip Wood
2025-10-28 13:37 ` [PATCH v2] " Antonin Delpeuch via GitGitGadget
2025-10-28 15:22   ` Junio C Hamano
2025-10-28 16:00     ` Antonin Delpeuch
2025-10-28 21:14   ` [PATCH v3] " Antonin Delpeuch via GitGitGadget
2025-10-29 10:16     ` Phillip Wood
2025-10-29 18:46       ` Junio C Hamano
2025-10-30  9:22       ` Antonin Delpeuch
2025-10-30 10:47         ` Phillip Wood
2025-11-01 21:57     ` Antonin Delpeuch via GitGitGadget [this message]
2025-11-01 21:57       ` [PATCH v4 1/2] xdiff: add 'minimal' to XDF_DIFF_ALGORITHM_MASK Antonin Delpeuch via GitGitGadget
2025-11-03 14:32         ` Phillip Wood
2025-11-01 21:57       ` [PATCH v4 2/2] blame: make diff algorithm configurable Antonin Delpeuch via GitGitGadget
2025-11-03 14:32         ` Phillip Wood
2025-11-03 16:15           ` Junio C Hamano
2025-11-06 20:29             ` Junio C Hamano
2025-11-06 22:41       ` [PATCH v5 0/2] " Antonin Delpeuch via GitGitGadget
2025-11-06 22:41         ` [PATCH v5 1/2] xdiff: add 'minimal' to XDF_DIFF_ALGORITHM_MASK Antonin Delpeuch via GitGitGadget
2025-11-07 15:52           ` Junio C Hamano
2025-11-06 22:41         ` [PATCH v5 2/2] blame: make diff algorithm configurable Antonin Delpeuch via GitGitGadget
2025-11-07 15:57           ` Junio C Hamano
2025-11-07 15:49         ` [PATCH v5 0/2] " Phillip Wood
2025-11-17  1:12           ` Junio C Hamano
2025-11-17  8:04         ` [PATCH v6 " Antonin Delpeuch via GitGitGadget
2025-11-17  8:04           ` [PATCH v6 1/2] xdiff: add 'minimal' to XDF_DIFF_ALGORITHM_MASK Antonin Delpeuch via GitGitGadget
2025-11-17  8:04           ` [PATCH v6 2/2] blame: make diff algorithm configurable Antonin Delpeuch via GitGitGadget
2025-11-17 14:13           ` [PATCH v6 0/2] " Phillip Wood
2025-11-17 18:24           ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.2075.v4.git.git.1762034252.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=antonin@delpeuch.eu \
    --cc=git@vger.kernel.org \
    --cc=newren@gmail.com \
    --cc=phillip.wood123@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).