Re: [PATCH v3 3/4] log: simplify --follow following renames for non-linear history
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Oct 26, 2026, 11:40 UTC
- Message-ID
- <at88KXp0vhXlPhFQ@pks.im>
- In-Reply-To
- <ba2dc35c77b95803f184e63cc9933e3765bd1417.1792701579.git.vmiklos@collabora.com>
On Thu, Oct 22, 2026 at 10:46:39PM +0200, Miklos Vajna wrote:
Show 7 quoted lines
> Code added in 304812ed33 (log: improve --follow following renames for > non-linear history, 2026-06-22) implemented the feature by introducing a > new propagate_follow_pathspec_to_parent() function which adds a new call > to diff_tree_oid(). Also it introduces a new loop to record what path > each parent of a merge commit should use when following a path. > > This was working, but fixing its performance would require adding even
It's somewhat curious that you start talking about performance here without even mentioning that performance is what breaks the current approach. You mention contributing factors to the performance regression without really calling it that.
Show 12 quoted lines
> more custom code, instead of just extending the existing code in > log_tree_diff(). > > Remove propagate_follow_pathspec_to_parent() and the loop calling it > for each parent. Instead, record the path to follow for each parent in > the parent loop of log_tree_diff(), right after diff_tree_oid() updated > the pathspec in case of a rename. Merges are not diffed by default, so > with --follow, run the same loop for them as well, but without showing > anything. With -c, --cc or --remerge-diff, show the merge diff after the > loop. This gets rid of the additional call to diff_tree_oid(). The > rework has no positive performance impact yet, it just simplifies the > code.
> This also fixes 'git log -m --follow': -m diffs the merge against each > parent with rename following, so a rename found against the first parent > updated the followed path, and the second parent was then diffed with > the already renamed path.
So next to a performance regression there's also a bug? Interesting. I feel like giving a bit more time to introduce and explain the bug would have helped.
Show 5 quoted lines
> Also, propagate_follow_pathspec_to_parent() > started from that same updated path, so history was lost on the side of > the second parent. Now the path of the merge is restored before diffing > each parent. Add a test for this, which shows the full history of the > diamond case with -m.
And another bug?
So in summary we have two bugs and one performance regression? The two bugs are fixed by this change, and it also prepares us for the fix to the performance regression? It might be easier to reason through all of that if we were able to split this so that we fix one issue at a time, but that may of course not be possible (or just very awkward).
Show 44 quoted lines
> diff --git a/log-tree.c b/log-tree.c
> index b4c97b86f5..c5ac6c2bcb 100644
> --- a/log-tree.c
> +++ b/log-tree.c
> @@ -1240,35 +1215,67 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
> }
>
> if (is_merge) {
> - if (opt->remerge_diff || opt->combine_merges)
> + int merge_diff = opt->remerge_diff || opt->combine_merges;
> +
> + if (merge_diff && !opt->diffopt.flags.follow_renames)
> return log_tree_merge_diff(opt, commit, parents, oid);
> - if (opt->separate_merges) {
> + if (opt->separate_merges && !merge_diff) {
> if (!opt->first_parent_merges) {
> /* Show parent info for multiple diffs */
> log->parent = parents->item;
> }
> + } else if (opt->diffopt.flags.follow_renames) {
> + /* Diff only to find the path to follow in parents */
> + follow_only = 1;
> } else
> return 0;
> }
>
> + if (opt->diffopt.flags.follow_renames)
> + path = xstrdup_or_null(
> + pathspec_single_path(&opt->diffopt.pathspec));
> +
> showed_log = 0;
> + all_parents = parents;
> for (;;) {
> struct commit *parent = parents->item;
>
> parse_commit_or_die(parent);
> diff_tree_oid(get_commit_tree_oid(parent),
> oid, "", &opt->diffopt);
> - log_tree_diff_flush(opt);
> + if (follow_only) {
> + diff_queue_clear(&diff_queued_diff);
> + opt->diffopt.found_follow = 0;
> + } else
> + log_tree_diff_flush(opt);Nit: style, if once condition body requires curly braces all of them should have it. Sorry, I cannot really provide more valuable feedback on this patch than this.
Patrick