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

Re: [PATCH v4 6/6] log: fix --follow following an edit on a side the merge did not take

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 6, 2026, 14:14 UTC
Message-ID
<au3guSIBfekx7gNL@pks.im>
In-Reply-To
<7be8cfb3ba58a4d4dc040fb2f229524599524b78.1793298331.git.vmiklos@collabora.com>
On Fri, Oct 30, 2026 at 09:10:14PM +0100, Miklos Vajna wrote:
Show 19 quoted lines
> Take a history where F is renamed to G on master, F is edited on a side
> branch, and the side branch is merged with '-s ours', so the merge keeps
> G and drops F. Here 'git log --follow G' doesn't show the edit of F on
> the side branch, while it did before the previous commit.
> 
> The problem is that follow_needs_renames() only searches for renames in
> a parent without the path if the merge base still has the path, which
> covers the case when the parent renamed the path. Here the other side
> of the merge did the rename, so the merge base only has the old name.
> The parent is then told to follow G, which it doesn't have, and the
> history of F on its side is lost. Searching for renames in each parent
> that lacks the path would fix this, but that is the expensive search
> that the previous commit avoids, e.g. 148 merges hit this case for
> include/linux/rsc_table.h in linux.git.
> 
> Fix the problem by also searching for renames when the merge base
> doesn't have the path, but the parent changed a file since the merge
> base that the merge no longer has: only such a file can be the old name
> of the path that still needs to be followed in the parent.

This isn't true though in the case where you copy a file though, is it? E.g. the following test case is exactly the same as the one you add in this commit, but instead of using a rename we use a copy:

diff --git a/t/t4219-log-follow-merge.sh b/t/t4219-log-follow-merge.sh
index a85fb78ca28..c67d9481ab5 100755
--- a/t/t4219-log-follow-merge.sh
+++ b/t/t4219-log-follow-merge.sh
@@ -297,4 +297,36 @@ test_expect_success '--follow follows an edit on the side the merge did not take
 	test_cmp expect actual
 '
 
+test_expect_success 'setup merge keeping the copied path, other side edited the original' '
+	git init keep-copied &&
+	printf "line 1\nline 2\nline 3\nline 4\nline 5\n" >keep-copied/F &&
+	git -C keep-copied add F &&
+	test_tick &&
+	git -C keep-copied commit -m "O: add F" &&
+	git -C keep-copied branch B &&
+	cp keep-copied/F keep-copied/G &&
+	git -C keep-copied add G &&
+	test_tick &&
+	git -C keep-copied commit -m "A1: copy F to G on master" &&
+
+	git -C keep-copied checkout B &&
+	printf "line 1\nline 2\nline 3\nline 4 T\nline 5\n" >keep-copied/F &&
+	test_tick &&
+	git -C keep-copied commit -am "B2: update F on B" &&
+
+	git -C keep-copied checkout master &&
+	test_tick &&
+	git -C keep-copied merge -s ours -m "M: merge B, keep F and G" B
+'
+
+test_expect_success '--follow follows an edit of the copy source on the side the merge did not take' '
+	git -C keep-copied log --follow --pretty=tformat:%s G >actual &&
+	cat >expect <<-\EOF &&
+	B2: update F on B
+	A1: copy F to G on master
+	O: add F
+	EOF
+	test_cmp expect actual
+'
+
 test_done

This test passes on master, but fails with your patch series.

Patrick
Previous: Miklos VajnaNext: Miklos Vajna
Message 23 of 48 in “Performance regression in `git log --follow`”
  1. Patrick SteinhardtOct 13, 2026
  2. SZEDER GáborOct 13, 2026
  3. log: speed up --follow following renames for non-linear historyMiklos Vajna, Oct 15, 2026
  4. Junio C HamanoOct 15, 2026
  5. log: speed up --follow following renames for non-linear historyMiklos Vajna, Oct 19, 2026
  6. 0/4 log: speed up --follow following renames for non-linear historyMiklos Vajna, Oct 22, 2026
  7. 1/4 t4219: test more --follow cases across mergesMiklos Vajna, Oct 22, 2026
  8. 2/4 log: extract showing the remerge/combined diff of a merge commitMiklos Vajna, Oct 22, 2026
  9. 3/4 log: simplify --follow following renames for non-linear historyMiklos Vajna, Oct 22, 2026
  10. Patrick SteinhardtOct 26, 2026
  11. 4/4 log: speed up --follow following renames for non-linear historyMiklos Vajna, Oct 22, 2026
  12. Patrick SteinhardtOct 26, 2026
  13. Patrick SteinhardtOct 26, 2026
  14. 0/6 log: speed up --follow following renames for non-linear historyMiklos Vajna, Oct 30, 2026
  15. 1/6 t4219: test more --follow cases across mergesMiklos Vajna, Oct 30, 2026
  16. 2/6 log: extract showing the remerge/combined diff of a merge commitMiklos Vajna, Oct 30, 2026
  17. 3/6 log: fix -m --follow losing the history of later parentsMiklos Vajna, Oct 30, 2026
  18. 4/6 log: simplify --follow following renames for non-linear historyMiklos Vajna, Oct 30, 2026
  19. 5/6 log: speed up --follow following renames for non-linear historyMiklos Vajna, Oct 30, 2026
  20. Patrick SteinhardtNov 6, 2026
  21. Miklos VajnaNov 9, 2026
  22. 6/6 log: fix --follow following an edit on a side the merge did not takeMiklos Vajna, Oct 30, 2026
  23. Patrick SteinhardtNov 6, 2026
  24. Miklos VajnaNov 9, 2026
  25. Patrick SteinhardtNov 6, 2026
  26. Miklos VajnaNov 9, 2026
  27. 0/5 log: speed up --follow following renames for non-linear historyMiklos Vajna, Nov 9, 2026
  28. 1/5 t4219: test more --follow cases across mergesMiklos Vajna, Nov 9, 2026
  29. Justin ToblerNov 10, 2026
  30. 2/5 log: extract showing the remerge/combined diff of a merge commitMiklos Vajna, Nov 9, 2026
  31. 3/5 log: fix -m --follow losing the history of later parentsMiklos Vajna, Nov 9, 2026
  32. 4/5 log: simplify --follow following renames for non-linear historyMiklos Vajna, Nov 9, 2026
  33. Toon ClaesNov 10, 2026
  34. 5/5 log: speed up --follow following renames for non-linear historyMiklos Vajna, Nov 9, 2026
  35. Justin ToblerNov 11, 2026
  36. Patrick SteinhardtNov 11, 2026
  37. Miklos VajnaNov 11, 2026
  38. Patrick SteinhardtNov 11, 2026
  39. log: make --follow following renames for non-linear history optionalMiklos Vajna, Nov 12, 2026
  40. Junio C HamanoNov 12, 2026
  41. Patrick SteinhardtNov 13, 2026
  42. log: make --follow following renames for non-linear history optionalMiklos Vajna, Nov 16, 2026
  43. Patrick SteinhardtNov 16, 2026
  44. Junio C HamanoNov 16, 2026
  45. Miklos VajnaNov 17, 2026
  46. Junio C HamanoNov 11, 2026
  47. Junio C HamanoOct 16, 2026
  48. Miklos VajnaOct 14, 2026

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.