{"thread":{"id":"66514","subject":"Performance regression in `git log --follow`","startedAt":"2026-10-13T13:55:01Z","lastAt":"2026-11-17T07:11:46Z","messageCount":48,"participants":["Patrick Steinhardt","SZEDER Gábor","Miklos Vajna","Junio C Hamano","Toon Claes","Justin Tobler"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"554860","messageId":"as44NVKZA9C9S5ae@pks.im","threadId":"66514","inReplyTo":null,"subject":"Performance regression in `git log --follow`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-13T13:55:01Z","receivedAt":"2026-10-13T13:55:01Z","isPatch":false,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Hi,\n\na user on IRC reported a performance regression in linux.git:\n\n    $ git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git\n    $ git -C linux log --stat --follow -- include/linux/rsc_table.h\n\nI was able to reproduce the performance regression: while this command\ntakes roughly 33 seconds with Git 2.55, it takes almost 8 minutes with\nGit 2.56.\n\nI've bisected the regression to 304812ed33 (log: improve --follow\nfollowing renames for non-linear history, 2026-06-22). I don't have time\nright now to debug any further, so I decided to just forward the report\nto the mailing list. I've also Cc'd the original author of the above\ncommit.\n\nThanks!\n\nPatrick\n\n"},{"id":"554918","messageId":"as6hmUG5AaL5iLbO@szeder.dev","threadId":"66514","inReplyTo":"as44NVKZA9C9S5ae@pks.im","subject":"Re: Performance regression in `git log --follow`","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2026-10-13T21:24:41Z","receivedAt":"2026-10-13T21:24:41Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Tue, Oct 13, 2026 at 03:55:01PM +0200, Patrick Steinhardt wrote:\n> Hi,\n> \n> a user on IRC reported a performance regression in linux.git:\n> \n>     $ git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git\n>     $ git -C linux log --stat --follow -- include/linux/rsc_table.h\n> \n> I was able to reproduce the performance regression: while this command\n> takes roughly 33 seconds with Git 2.55, it takes almost 8 minutes with\n> Git 2.56.\n> \n> I've bisected the regression to 304812ed33 (log: improve --follow\n> following renames for non-linear history, 2026-06-22). I don't have time\n> right now to debug any further, so I decided to just forward the report\n> to the mailing list. I've also Cc'd the original author of the above\n> commit.\n\nThe performance regression is clearly noticable in the git repository,\nthough the slowdown is not as pronounced as in linux.git:\n\n  Benchmark 1: ./304812ed33^/bin/git --no-pager log --oneline --no-patch --follow v2.56.0 t/valgrind/valgrind.sh\n    Time (mean ± σ):      3.275 s ±  0.022 s    [User: 3.157 s, System: 0.116 s]\n    Range (min … max):    3.240 s …  3.313 s    10 runs\n\n  Benchmark 2: ./304812ed33/bin/git --no-pager log --oneline --no-patch --follow v2.56.0 t/valgrind/valgrind.sh\n    Time (mean ± σ):      8.825 s ±  0.029 s    [User: 8.554 s, System: 0.264 s]\n    Range (min … max):    8.769 s …  8.864 s    10 runs\n\n  Summary\n    './304812ed33^/bin/git --no-pager log --oneline --no-patch --follow v2.56.0 t/valgrind/valgrind.sh' ran\n      2.69 ± 0.02 times faster than './304812ed33/bin/git --no-pager log --oneline --no-patch --follow v2.56.0 t/valgrind/valgrind.sh'\n\nThat's 5.5 seconds of runtime difference, and with a bit of trace\nperformance hack[1] it turns out that most of it is spent in a call to\npropagate_follow_pathspec_to_parent() to compare the current commit\nwith its second...N-th parent:\n\n  $ GIT_TRACE_PERFORMANCE=1 ./304812ed33/bin/git --no-pager log --follow --oneline v2.56.0 t/valgrind/valgrind.sh >/dev/null\n  21:59:30.465592 read-cache.c:2364       performance: 0.000626524 s:  read cache .git/index\n  21:59:39.246697 log-tree.c:1158         performance: 1.374980154 s:  first parent propagate_follow_pathspec_to_parent()\n  21:59:39.247164 log-tree.c:1159         performance: 4.448692273 s:  N-th parents propagate_follow_pathspec_to_parent()\n  21:59:39.247192 trace.c:416             performance: 8.799236172 s: git command: ./304812ed33/bin/git --no-pager log --follow --oneline v2.56.0 t/valgrind/valgrind.sh\n\nInterestingly, although line-level log performs its own rename\ntracking, it's still notably faster than \"--follow\" even before this\nperf regression (that \"-L1,40\" means \"track the whole file\"):\n\n  Benchmark 1: ./304812ed33^/bin/git --no-pager log --oneline --no-patch --follow v2.56.0 t/valgrind/valgrind.sh\n    Time (mean ± σ):      3.260 s ±  0.019 s    [User: 3.140 s, System: 0.118 s]\n    Range (min … max):    3.219 s …  3.284 s    10 runs\n\n  Benchmark 2: ./304812ed33^/bin/git --no-pager log --oneline --no-patch -L1,40:t/valgrind/valgrind.sh v2.56.0\n    Time (mean ± σ):      1.454 s ±  0.014 s    [User: 1.369 s, System: 0.084 s]\n    Range (min … max):    1.441 s …  1.481 s    10 runs\n\n  Summary\n    './304812ed33^/bin/git --no-pager log --oneline --no-patch -L1,40:t/valgrind/valgrind.sh v2.56.0' ran\n      2.24 ± 0.02 times faster than './304812ed33^/bin/git --no-pager log --oneline --no-patch --follow v2.56.0 t/valgrind/valgrind.sh'\n\nThe reason for this might be:\n\n  - If line-level log finds that the interesting path is not modified\n    between a merge commit and its first parent, then it doesn't\n    perform a diff between that merge commit and its second..N-th\n    parent.\n    \"--follow\" seems to performs a diff between a merge commit and all\n    its parents.\n\n  - Line-level log checks for renames only when the path is not\n    present in the parent commit.\n    \"--follow\" seems to always look for renames.\n\n\n[1] It really is just a hack:\n\ndiff --git a/log-tree.c b/log-tree.c\nindex 83a3c4bf9b..fd4824fd3e 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -34,6 +34,7 @@\n #include \"wildmatch.h\"\n #include \"write-or-die.h\"\n #include \"pager.h\"\n+#include \"trace.h\"\n \n static struct decoration name_decoration = { \"object names\" };\n static int decoration_loaded;\n@@ -1144,6 +1145,8 @@ static void free_follow_pathspec_slot(char **slot)\n \tFREE_AND_NULL(*slot);\n }\n \n+static uint64_t t_first = 0, t_nth = 0;\n+\n void release_follow_pathspec_slab(struct rev_info *opt)\n {\n \tif (!opt->follow_pathspec_slab)\n@@ -1151,6 +1154,9 @@ void release_follow_pathspec_slab(struct rev_info *opt)\n \tdeep_clear_follow_pathspec_slab(opt->follow_pathspec_slab,\n \t\t\t\t\tfree_follow_pathspec_slot);\n \tFREE_AND_NULL(opt->follow_pathspec_slab);\n+\n+\ttrace_performance(t_first, \"first parent propagate_follow_pathspec_to_parent()\");\n+\ttrace_performance(t_nth, \"N-th parents propagate_follow_pathspec_to_parent()\");\n }\n \n /* Compute a path to follow in parent, if there is one */\n@@ -1304,9 +1310,18 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)\n \t\tstruct commit_list *parents = get_saved_parents(opt, commit);\n \t\tif (parents && parents->next) {\n \t\t\tstruct commit_list *p;\n-\t\t\tfor (p = parents; p; p = p->next)\n+\t\t\tfor (p = parents; p; p = p->next) {\n+\t\t\t\tif (p == parents)\n+\t\t\t\t\tt_first -= getnanotime();\n+\t\t\t\telse\n+\t\t\t\t\tt_nth -= getnanotime();\n \t\t\t\tpropagate_follow_pathspec_to_parent(opt, commit,\n \t\t\t\t\t\t\t\t    p->item);\n+\t\t\t\tif (p == parents)\n+\t\t\t\t\tt_first += getnanotime();\n+\t\t\t\telse\n+\t\t\t\t\tt_nth += getnanotime();\n+\t\t\t}\n \t\t} else if (parents) {\n \t\t\tremember_follow_pathspec(opt, parents->item,\n \t\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n\n"},{"id":"554950","messageId":"as8eS9VyMMTo1pa3@collabora.com","threadId":"66514","inReplyTo":"as44NVKZA9C9S5ae@pks.im","subject":"Re: Performance regression in `git log --follow`","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-10-14T06:16:43Z","receivedAt":"2026-10-14T06:16:43Z","isPatch":false,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Hi Patrick,\n\nOn Tue, Oct 13, 2026 at 03:55:01PM +0200, Patrick Steinhardt <ps@pks.im> wrote:\n> I've bisected the regression to 304812ed33 (log: improve --follow\n> following renames for non-linear history, 2026-06-22). I don't have time\n> right now to debug any further, so I decided to just forward the report\n> to the mailing list. I've also Cc'd the original author of the above\n> commit.\n\nThanks for the report.\n\nTo some extent, this is expected: previously log --follow had a design\nissue, as described at\n<https://lore.kernel.org/git/xmqqjysz7r41.fsf@gitster.g/>. Now log\n--follow finds more commits has it traverses non-linear history, which\ntakes more time.\n\nLet's see if we can find some creative solution that keeps the new\ndesign (storing / restoring the path to follow as you traverse\nnon-linear history) and at the same time improves performance for your\nuse-case. Quite possibly my patch is/was naive and we can avoid some not\nneeded work while still correctly following a path across renames.\n\nI see Gabor already commented in the thread and same some ideas, but I\nhaven't read those yet.\n\nRegards,\n\nMiklos\n\n"},{"id":"555152","messageId":"atDnyzC_2oaLF0Wo@collabora.com","threadId":"66514","inReplyTo":"as6hmUG5AaL5iLbO@szeder.dev","subject":"[PATCH] log: speed up --follow following renames for non-linear history","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-10-15T14:48:43Z","receivedAt":"2026-10-15T14:48:43Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Test the performance of 'git log --stat --follow --\ninclude/linux/rsc_table.h' on linux.git, it used to take about 28\nseconds, and since commit 304812ed33 (log: improve --follow following\nrenames for non-linear history, 2026-06-22), it takes 6m43s.\n\nWhat happens is that propagate_follow_pathspec_to_parent() does a\nsomewhat expensive rename detection of the current commit vs all of its\nparents, and this slows down 'git log --follow'.\n\nFix the problem by introducing two shortcuts:\n1) Only do that when the path is added relative to a parent and\n2) If the path is the same as in one of the parents, then just follow\n   that history\n\nThese shortcuts keep all the uses-cases in t4219-log-follow-merge.sh\nworking, but now the above use case takes 29s, close to the original\ncost.\n\nHelped-by: SZEDER Gábor <szeder.dev@gmail.com>\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n\nHi Gabor, Patrick,\n\nHere is my suggested speed-up patch. I think it's correct to take these two shortcuts since the\noriginal use cases continue to work, and then we're almost back to the original performance.\n\nLet me know what you think; if you don't see problems with it, then a bit later I would send the\npatch to Junio.\n\nThanks,\n\nMiklos\n\n log-tree.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++---\n 1 file changed, 70 insertions(+), 4 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex 83a3c4bf9b..0d7bf001f0 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -1180,6 +1180,74 @@ static void propagate_follow_pathspec_to_parent(struct rev_info *opt,\n \tdiff_free(&diff_opts);\n }\n \n+enum follow_path_change {\n+\tFOLLOW_PATH_SAME,\n+\tFOLLOW_PATH_ADDED,\n+\tFOLLOW_PATH_OTHER,\n+};\n+\n+/* How does the followed path change from parent to commit? */\n+static enum follow_path_change get_follow_path_change(struct rev_info *opt,\n+\t\t\t\t\t\t      struct commit *commit,\n+\t\t\t\t\t\t      struct commit *parent)\n+{\n+\tstruct diff_options diff_opts;\n+\tenum follow_path_change ret = FOLLOW_PATH_OTHER;\n+\n+\tparse_commit_or_die(parent);\n+\trepo_diff_setup(opt->diffopt.repo, &diff_opts);\n+\tcopy_pathspec(&diff_opts.pathspec, &opt->diffopt.pathspec);\n+\tdiff_opts.flags.recursive = 1;\n+\tdiff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;\n+\tdiff_setup_done(&diff_opts);\n+\tdiff_tree_oid(get_commit_tree_oid(parent),\n+\t\t      get_commit_tree_oid(commit),\n+\t\t      \"\", &diff_opts);\n+\n+\tif (!diff_queued_diff.nr)\n+\t\tret = FOLLOW_PATH_SAME;\n+\telse if (diff_queued_diff.nr == 1 &&\n+\t\t !DIFF_FILE_VALID(diff_queued_diff.queue[0]->one))\n+\t\tret = FOLLOW_PATH_ADDED;\n+\n+\tdiff_queue_clear(&diff_queued_diff);\n+\tdiff_free(&diff_opts);\n+\treturn ret;\n+}\n+\n+/* Compute a path to follow in each parent of a merge */\n+static void propagate_follow_pathspec_to_parents(struct rev_info *opt,\n+\t\t\t\t\t\t struct commit *commit,\n+\t\t\t\t\t\t struct commit_list *parents)\n+{\n+\tconst char *path = pathspec_single_path(&opt->diffopt.pathspec);\n+\tstruct commit_list *p;\n+\tenum follow_path_change *changes;\n+\tint nr = commit_list_count(parents), i;\n+\tint has_same = 0;\n+\n+\tif (!path)\n+\t\treturn;\n+\n+\tALLOC_ARRAY(changes, nr);\n+\tfor (p = parents, i = 0; p; p = p->next, i++) {\n+\t\tchanges[i] = get_follow_path_change(opt, commit, p->item);\n+\t\tif (changes[i] == FOLLOW_PATH_SAME) {\n+\t\t\thas_same = 1;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tfor (p = parents, i = 0; p; p = p->next, i++) {\n+\t\tif (!has_same && changes[i] == FOLLOW_PATH_ADDED)\n+\t\t\t/* Never the same, added here: expensive rename detection */\n+\t\t\tpropagate_follow_pathspec_to_parent(opt, commit, p->item);\n+\t\telse\n+\t\t\tremember_follow_pathspec(opt, p->item, path);\n+\t}\n+\tfree(changes);\n+}\n+\n /*\n  * Show the diff of a commit.\n  *\n@@ -1303,10 +1371,8 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)\n \tif (opt->diffopt.flags.follow_renames) {\n \t\tstruct commit_list *parents = get_saved_parents(opt, commit);\n \t\tif (parents && parents->next) {\n-\t\t\tstruct commit_list *p;\n-\t\t\tfor (p = parents; p; p = p->next)\n-\t\t\t\tpropagate_follow_pathspec_to_parent(opt, commit,\n-\t\t\t\t\t\t\t\t    p->item);\n+\t\t\tpropagate_follow_pathspec_to_parents(opt, commit,\n+\t\t\t\t\t\t\t     parents);\n \t\t} else if (parents) {\n \t\t\tremember_follow_pathspec(opt, parents->item,\n \t\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n-- \n2.56.0\n\n\n"},{"id":"555160","messageId":"xmqq8q3yq4u4.fsf@gitster.g","threadId":"66514","inReplyTo":"atDnyzC_2oaLF0Wo@collabora.com","subject":"Re: [PATCH] log: speed up --follow following renames for non-linear history","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-15T16:57:39Z","receivedAt":"2026-10-15T16:57:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Miklos Vajna <vmiklos@collabora.com> writes:\n\n> Test the performance of 'git log --stat --follow --\n> include/linux/rsc_table.h' on linux.git, it used to take about 28\n> seconds, and since commit 304812ed33 (log: improve --follow following\n> renames for non-linear history, 2026-06-22), it takes 6m43s.\n>\n> What happens is that propagate_follow_pathspec_to_parent() does a\n> somewhat expensive rename detection of the current commit vs all of its\n> parents, and this slows down 'git log --follow'.\n>\n> Fix the problem by introducing two shortcuts:\n> 1) Only do that when the path is added relative to a parent and\n> 2) If the path is the same as in one of the parents, then just follow\n>    that history\n>\n> These shortcuts keep all the uses-cases in t4219-log-follow-merge.sh\n> working, but now the above use case takes 29s, close to the original\n> cost.\n\nThe original follow-renames implementation kicked in only when the\npath being followed did not exist in the parent.  log_tree_commit()\ncalls log_tree_diff() to show the diff for the current commit, which\ncalls diff_tree_oid(), which checks with diff_might_be_rename() to\nsee if the path we have been following is missing in the parent and\nonly then runs try_to_follow_renames(), which is expensive, to find\nout where it came from.  It avoided the expensive second diff when\nwe know the path we have been following existed in the parent.\n\nBut reading log_tree_commit() in today's code, it seems that\npropagate_follow_pathspec_to_parent() is called, after we have\nALREADY spent cycles to run the log_tree_diff() and flushed its\noutput.  The precious clue that tells you if the path you have been\nfollowing is shared with the parent has already been flushed at that\npoint.\n\nPerhaps inside log_tree_diff_flush() while we still have the list of\nfilepairs in diff_queue is where you should be able to see if any of\nthe paths you have been following appeared anew relative to the\nparent(s) and to decide if you must adjust the list of paths you\nfollow for renames, instead of calling the diff machinery all the\ntime from propagate_follow_pathspec_to_parent() unconditionally.\n\nI am not sure if it may be cleaner to first rip out all the change\nintroduced in 304812ed33 (log: improve --follow following renames\nfor non-linear history, 2026-06-22) and then rethink the approach,\ninstead of piling more code with additional patches.  I dunno.\n\nThanks.\n\n>  log-tree.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++---\n>  1 file changed, 70 insertions(+), 4 deletions(-)\n>\n> diff --git a/log-tree.c b/log-tree.c\n> index 83a3c4bf9b..0d7bf001f0 100644\n> --- a/log-tree.c\n> +++ b/log-tree.c\n> @@ -1180,6 +1180,74 @@ static void propagate_follow_pathspec_to_parent(struct rev_info *opt,\n>  \tdiff_free(&diff_opts);\n>  }\n>  \n> +enum follow_path_change {\n> +\tFOLLOW_PATH_SAME,\n> +\tFOLLOW_PATH_ADDED,\n> +\tFOLLOW_PATH_OTHER,\n> +};\n> +\n> +/* How does the followed path change from parent to commit? */\n> +static enum follow_path_change get_follow_path_change(struct rev_info *opt,\n> +\t\t\t\t\t\t      struct commit *commit,\n> +\t\t\t\t\t\t      struct commit *parent)\n> +{\n> +\tstruct diff_options diff_opts;\n> +\tenum follow_path_change ret = FOLLOW_PATH_OTHER;\n> +\n> +\tparse_commit_or_die(parent);\n> +\trepo_diff_setup(opt->diffopt.repo, &diff_opts);\n> +\tcopy_pathspec(&diff_opts.pathspec, &opt->diffopt.pathspec);\n> +\tdiff_opts.flags.recursive = 1;\n> +\tdiff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;\n> +\tdiff_setup_done(&diff_opts);\n> +\tdiff_tree_oid(get_commit_tree_oid(parent),\n> +\t\t      get_commit_tree_oid(commit),\n> +\t\t      \"\", &diff_opts);\n> +\n> +\tif (!diff_queued_diff.nr)\n> +\t\tret = FOLLOW_PATH_SAME;\n> +\telse if (diff_queued_diff.nr == 1 &&\n> +\t\t !DIFF_FILE_VALID(diff_queued_diff.queue[0]->one))\n> +\t\tret = FOLLOW_PATH_ADDED;\n> +\n> +\tdiff_queue_clear(&diff_queued_diff);\n> +\tdiff_free(&diff_opts);\n> +\treturn ret;\n> +}\n> +\n> +/* Compute a path to follow in each parent of a merge */\n> +static void propagate_follow_pathspec_to_parents(struct rev_info *opt,\n> +\t\t\t\t\t\t struct commit *commit,\n> +\t\t\t\t\t\t struct commit_list *parents)\n> +{\n> +\tconst char *path = pathspec_single_path(&opt->diffopt.pathspec);\n> +\tstruct commit_list *p;\n> +\tenum follow_path_change *changes;\n> +\tint nr = commit_list_count(parents), i;\n> +\tint has_same = 0;\n> +\n> +\tif (!path)\n> +\t\treturn;\n> +\n> +\tALLOC_ARRAY(changes, nr);\n> +\tfor (p = parents, i = 0; p; p = p->next, i++) {\n> +\t\tchanges[i] = get_follow_path_change(opt, commit, p->item);\n> +\t\tif (changes[i] == FOLLOW_PATH_SAME) {\n> +\t\t\thas_same = 1;\n> +\t\t\tbreak;\n> +\t\t}\n> +\t}\n> +\n> +\tfor (p = parents, i = 0; p; p = p->next, i++) {\n> +\t\tif (!has_same && changes[i] == FOLLOW_PATH_ADDED)\n> +\t\t\t/* Never the same, added here: expensive rename detection */\n> +\t\t\tpropagate_follow_pathspec_to_parent(opt, commit, p->item);\n> +\t\telse\n> +\t\t\tremember_follow_pathspec(opt, p->item, path);\n> +\t}\n> +\tfree(changes);\n> +}\n> +\n>  /*\n>   * Show the diff of a commit.\n>   *\n> @@ -1303,10 +1371,8 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)\n>  \tif (opt->diffopt.flags.follow_renames) {\n>  \t\tstruct commit_list *parents = get_saved_parents(opt, commit);\n>  \t\tif (parents && parents->next) {\n> -\t\t\tstruct commit_list *p;\n> -\t\t\tfor (p = parents; p; p = p->next)\n> -\t\t\t\tpropagate_follow_pathspec_to_parent(opt, commit,\n> -\t\t\t\t\t\t\t\t    p->item);\n> +\t\t\tpropagate_follow_pathspec_to_parents(opt, commit,\n> +\t\t\t\t\t\t\t     parents);\n>  \t\t} else if (parents) {\n>  \t\t\tremember_follow_pathspec(opt, parents->item,\n>  \t\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n\n"},{"id":"555273","messageId":"xmqqy0bxe60n.fsf@gitster.g","threadId":"66514","inReplyTo":"atDnyzC_2oaLF0Wo@collabora.com","subject":"Re: [PATCH] log: speed up --follow following renames for non-linear history","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-16T20:37:28Z","receivedAt":"2026-10-16T20:37:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Miklos Vajna <vmiklos@collabora.com> writes:\n\n> +/* Compute a path to follow in each parent of a merge */\n> +static void propagate_follow_pathspec_to_parents(struct rev_info *opt,\n> +\t\t\t\t\t\t struct commit *commit,\n> +\t\t\t\t\t\t struct commit_list *parents)\n> +{\n> +\tconst char *path = pathspec_single_path(&opt->diffopt.pathspec);\n> +\tstruct commit_list *p;\n> +\tenum follow_path_change *changes;\n> +\tint nr = commit_list_count(parents), i;\n> +\tint has_same = 0;\n> +\n> +\tif (!path)\n> +\t\treturn;\n> +\n> +\tALLOC_ARRAY(changes, nr);\n> +\tfor (p = parents, i = 0; p; p = p->next, i++) {\n> +\t\tchanges[i] = get_follow_path_change(opt, commit, p->item);\n> +\t\tif (changes[i] == FOLLOW_PATH_SAME) {\n> +\t\t\thas_same = 1;\n> +\t\t\tbreak;\n> +\t\t}\n> +\t}\n> +\n> +\tfor (p = parents, i = 0; p; p = p->next, i++) {\n> +\t\tif (!has_same && changes[i] == FOLLOW_PATH_ADDED)\n> +\t\t\t/* Never the same, added here: expensive rename detection */\n> +\t\t\tpropagate_follow_pathspec_to_parent(opt, commit, p->item);\n> +\t\telse\n> +\t\t\tremember_follow_pathspec(opt, p->item, path);\n> +\t}\n> +\tfree(changes);\n> +}\n\nHmph, so if you have two branches A and B that forked from a common\nancestor that had file F,\n\n - A updates F in place\n - B renames F to G in one commit\n - B then updates the renamed G on in another commit\n - A merges B but decides to keep the original name F and\n   original content, deleting G.\n\nthen because has_same would be the same, you do not call\npropagate_follow_pathspec_to_parent() to prepare the traversal into\nbranch B's history when you cross the merge, even when we are not\nsimplifying the history?\n\nThat somehow sounds broken to me.  Am I missing something?\n\n\n"},{"id":"555379","messageId":"atW0ctTe-lNq08A-@collabora.com","threadId":"66514","inReplyTo":"xmqq8q3yq4u4.fsf@gitster.g","subject":"[PATCH v2] log: speed up --follow following renames for non-linear history","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-10-19T06:10:58Z","receivedAt":"2026-10-19T06:10:58Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Test the performance of 'git log --stat --follow --\ninclude/linux/rsc_table.h' on linux.git, it used to take about 28\nseconds, and since commit 304812ed33 (log: improve --follow following\nrenames for non-linear history, 2026-06-22), it takes 6m43s.\n\nWhat happens is that propagate_follow_pathspec_to_parent() diffs the\ncurrent commit against all of its parents with rename following, and\nthis slows down 'git log --follow'.\n\nFix the problem by removing propagate_follow_pathspec_to_parent() and\ninstead recording the path to follow for each parent in the parent loop\nof log_tree_diff(), which already calls diff_tree_oid() with rename\nfollowing, so for non-merge commits the diff that we show is reused.\nMerges are not diffed by default, so in that case run the same loop, but\nonly to find the paths to follow, without showing anything. With -c,\n--cc or --remerge-diff, merges are diffed, but not in this loop, so run\nthe loop for them as well and only show their merge diff after that,\nusing the path of the merge itself. Also, do this in two passes: first\nlook for a parent without rename following, and if the path is\nunchanged against a parent, then just follow that history in all\nparents. Only do the expensive rename following against each parent if\nthe path changed relative to all parents. Given that this way a parent\nmay be asked to follow a path that it doesn't have, also adjust\nremember_follow_pathspec(): if children disagree on what should be the\npath for a commit, then prefer the path that exists in that commit.\n\nFollowing the same path in all parents is not enough when the other side\nrenamed the path, though: if the merge kept F from one parent, but the\nother parent renamed F to G and then modified G, then the commits\nmodifying G would be lost. Handle this by still doing the rename\nfollowing against a parent if that parent doesn't have the path, the\nmerge has it and a merge base of the two parents also has it, i.e. the\npath was renamed or removed on that side. The merge base is only\ncomputed in this rare case, and back-merges where the path was created\nafter the other side forked still skip the expensive rename detection.\nNow the above use case takes 37s, somewhat close to the original cost.\n\nAlso add new testcases: the -c/--cc/--remerge-diff options and the\n--no-ff merging case were working, but were untested, so the\noptimization could have broken them. And cover following a rename on the\nside the merge did not take as well.\n\nHelped-by: SZEDER Gábor <szeder.dev@gmail.com>\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n\nHi Junio,\n\nOn Thu, Oct 15, 2026 at 09:57:39AM -0700, Junio C Hamano <gitster@pobox.com> wrote:\n> I am not sure if it may be cleaner to first rip out all the change\n> introduced in 304812ed33 (log: improve --follow following renames\n> for non-linear history, 2026-06-22) and then rethink the approach,\n> instead of piling more code with additional patches.  I dunno.\n\nHere is my attempt at the redo approach: instead of adding more diffing\non top of 304812ed33, I removed its\npropagate_follow_pathspec_to_parent() and I do the path recording in the\nexisting parent loop of log_tree_diff().  For merges, there is no diff\nto reuse by default, so the same loop runs for them without showing\nanything.\n\nMost of the performance benefit from v1 is still there.\n\nI also found a few cases which had no test coverage, I added tests to\nt4219-log-follow-merge.sh.\n\nOn Fri, Oct 16, 2026 at 01:37:28PM -0700, Junio C Hamano <gitster@pobox.com> wrote:\n> Hmph, so if you have two branches A and B that forked from a common\n> ancestor that had file F,\n> \n>  - A updates F in place\n>  - B renames F to G in one commit\n>  - B then updates the renamed G on in another commit\n>  - A merges B but decides to keep the original name F and\n>    original content, deleting G.\n> \n> then because has_same would be the same, you do not call\n> propagate_follow_pathspec_to_parent() to prepare the traversal into\n> branch B's history when you cross the merge, even when we are not\n> simplifying the history?\n> \n> That somehow sounds broken to me.  Am I missing something?\n\nI didn't consider that case. I've now added a follow_needs_renames() to\nhandle this.\n\nThis leads to a larger patch: should I extract the \"rethink the\napproach\" and the new tests to separate patches or it doesn't matter?\n\nTo sum up, compared to v1, now I 1) redid the approach to avoid\npropagate_follow_pathspec_to_parent() 2) added a few more tests and 3)\nthe above \"following a rename on the side the merge did not take\" case\nnow works as well.\n\nThanks,\n\nMiklos\n\n log-tree.c                  | 201 +++++++++++++++++++++++++-----------\n t/t4219-log-follow-merge.sh | 112 ++++++++++++++++++++\n 2 files changed, 255 insertions(+), 58 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex 83a3c4bf9b..d5ce58d91d 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -31,6 +31,7 @@\n #include \"range-diff.h\"\n #include \"strmap.h\"\n #include \"tree.h\"\n+#include \"tree-walk.h\"\n #include \"wildmatch.h\"\n #include \"write-or-die.h\"\n #include \"pager.h\"\n@@ -1110,6 +1111,17 @@ static void set_pathspec_to_single_path(struct pathspec *ps, const char *path)\n \t\t       PATHSPEC_LITERAL_PATH, \"\", paths);\n }\n \n+static int commit_has_path(struct rev_info *opt, struct commit *c,\n+\t\t\t   const char *path)\n+{\n+\tstruct object_id oid;\n+\tunsigned short mode;\n+\n+\tparse_commit_or_die(c);\n+\treturn !get_tree_entry(opt->diffopt.repo, get_commit_tree_oid(c), path,\n+\t\t\t       &oid, &mode);\n+}\n+\n static void remember_follow_pathspec(struct rev_info *opt,\n \t\t\t\t     struct commit *c, const char *path)\n {\n@@ -1122,8 +1134,12 @@ static void remember_follow_pathspec(struct rev_info *opt,\n \t\tinit_follow_pathspec_slab(opt->follow_pathspec_slab);\n \t}\n \tslot = follow_pathspec_slab_at(opt->follow_pathspec_slab, c);\n-\tif (*slot && !strcmp(*slot, path))\n-\t\treturn;\n+\t/* If children of 'c' disagree on the path, prefer the one 'c' has. */\n+\tif (*slot) {\n+\t\tif (!strcmp(*slot, path) || commit_has_path(opt, c, *slot) ||\n+\t\t    !commit_has_path(opt, c, path))\n+\t\t\treturn;\n+\t}\n \tfree(*slot);\n \t*slot = xstrdup(path);\n }\n@@ -1153,31 +1169,47 @@ void release_follow_pathspec_slab(struct rev_info *opt)\n \tFREE_AND_NULL(opt->follow_pathspec_slab);\n }\n \n-/* Compute a path to follow in parent, if there is one */\n-static void propagate_follow_pathspec_to_parent(struct rev_info *opt,\n-\t\t\t\t\t\tstruct commit *commit,\n-\t\t\t\t\t\tstruct commit *parent)\n+/*\n+ * When the path in a merge is the same as in 'same', does the path still need\n+ * renames to be followed in 'parent'? Only if the merge has the path, 'parent'\n+ * doesn't have it, but its fork point with 'same' had it, e.g. 'parent'\n+ * renamed the path.\n+ */\n+static int follow_needs_renames(struct rev_info *opt, struct commit *parent,\n+\t\t\t\tstruct commit *same, const char *path)\n+{\n+\tstruct commit_list *bases = NULL, *base;\n+\tint ret = 0;\n+\n+\tif (commit_has_path(opt, parent, path) ||\n+\t    !commit_has_path(opt, same, path))\n+\t\treturn 0;\n+\tif (repo_get_merge_bases(opt->diffopt.repo, parent, same, &bases) < 0)\n+\t\texit(128);\n+\tfor (base = bases; base && !ret; base = base->next)\n+\t\tret = commit_has_path(opt, base->item, path);\n+\tcommit_list_free(bases);\n+\treturn ret;\n+}\n+\n+/* Show the remerge or combined diff of a merge commit */\n+static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,\n+\t\t\t       struct commit_list *parents,\n+\t\t\t       struct object_id *oid)\n {\n-\tstruct diff_options diff_opts;\n-\tconst char *path;\n-\n-\tparse_commit_or_die(parent);\n-\trepo_diff_setup(opt->diffopt.repo, &diff_opts);\n-\tcopy_pathspec(&diff_opts.pathspec, &opt->diffopt.pathspec);\n-\tdiff_opts.flags.recursive = 1;\n-\tdiff_opts.flags.follow_renames = 1;\n-\tdiff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;\n-\tdiff_setup_done(&diff_opts);\n-\tdiff_tree_oid(get_commit_tree_oid(parent),\n-\t\t      get_commit_tree_oid(commit),\n-\t\t      \"\", &diff_opts);\n-\n-\tpath = pathspec_single_path(&diff_opts.pathspec);\n-\tif (path)\n-\t\tremember_follow_pathspec(opt, parent, path);\n-\n-\tdiff_queue_clear(&diff_queued_diff);\n-\tdiff_free(&diff_opts);\n+\tint octopus = (parents->next->next != NULL);\n+\n+\tif (opt->remerge_diff) {\n+\t\tif (octopus) {\n+\t\t\tshow_log(opt);\n+\t\t\tfprintf(opt->diffopt.file,\n+\t\t\t\t\"diff: warning: Skipping remerge-diff \"\n+\t\t\t\t\"for octopus merges.\\n\");\n+\t\t\treturn 1;\n+\t\t}\n+\t\treturn do_remerge_diff(opt, parents, oid);\n+\t}\n+\treturn do_diff_combined(opt, commit);\n }\n \n /*\n@@ -1188,10 +1220,12 @@ static void propagate_follow_pathspec_to_parent(struct rev_info *opt,\n static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log)\n {\n \tint showed_log;\n-\tstruct commit_list *parents;\n+\tstruct commit_list *parents, *all_parents, *rename_parents = NULL;\n \tstruct object_id *oid;\n \tint is_merge;\n \tint all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;\n+\tint follow_only = 0;\n+\tchar *path = NULL;\n \n \tif (!all_need_diff && !opt->merges_need_diff)\n \t\treturn 0;\n@@ -1220,47 +1254,113 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t}\n \n \tif (is_merge) {\n-\t\tint octopus = (parents->next->next != NULL);\n-\n-\t\tif (opt->remerge_diff) {\n-\t\t\tif (octopus) {\n-\t\t\t\tshow_log(opt);\n-\t\t\t\tfprintf(opt->diffopt.file,\n-\t\t\t\t\t\"diff: warning: Skipping remerge-diff \"\n-\t\t\t\t\t\"for octopus merges.\\n\");\n-\t\t\t\treturn 1;\n-\t\t\t}\n-\t\t\treturn do_remerge_diff(opt, parents, oid);\n-\t\t}\n-\t\tif (opt->combine_merges)\n-\t\t\treturn do_diff_combined(opt, commit);\n-\t\tif (opt->separate_merges) {\n+\t\tint merge_diff = opt->remerge_diff || opt->combine_merges;\n+\n+\t\tif (merge_diff && !opt->diffopt.flags.follow_renames)\n+\t\t\treturn log_tree_merge_diff(opt, commit, parents, oid);\n+\t\tif (opt->separate_merges && !merge_diff) {\n \t\t\tif (!opt->first_parent_merges) {\n \t\t\t\t/* Show parent info for multiple diffs */\n \t\t\t\tlog->parent = parents->item;\n \t\t\t}\n+\t\t} else if (opt->diffopt.flags.follow_renames) {\n+\t\t\t/* Diff only to find the path to follow in parents */\n+\t\t\tfollow_only = 1;\n \t\t} else\n \t\t\treturn 0;\n \t}\n \n+\tif (opt->diffopt.flags.follow_renames)\n+\t\tpath = xstrdup_or_null(\n+\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n+\n+\tif (follow_only) {\n+\t\t/*\n+\t\t * First look for a parent where the path is unchanged, without\n+\t\t * the expensive rename detection.\n+\t\t */\n+\t\topt->diffopt.flags.follow_renames = 0;\n+\t}\n+\n \tshowed_log = 0;\n+\tall_parents = parents;\n \tfor (;;) {\n \t\tstruct commit *parent = parents->item;\n+\t\tint changed = 1;\n \n \t\tparse_commit_or_die(parent);\n \t\tdiff_tree_oid(get_commit_tree_oid(parent),\n \t\t\t      oid, \"\", &opt->diffopt);\n-\t\tlog_tree_diff_flush(opt);\n+\t\tif (follow_only) {\n+\t\t\tchanged = diff_queued_diff.nr;\n+\t\t\tdiff_queue_clear(&diff_queued_diff);\n+\t\t\topt->diffopt.found_follow = 0;\n+\t\t} else\n+\t\t\tlog_tree_diff_flush(opt);\n \n \t\tshowed_log |= !opt->loginfo;\n \n+\t\tif (!changed) {\n+\t\t\t/*\n+\t\t\t * Same as in this parent, follow that history, but\n+\t\t\t * still look for renames in parents that had the path\n+\t\t\t * at the fork point.\n+\t\t\t */\n+\t\t\tstruct commit_list **tail = &rename_parents;\n+\n+\t\t\tfor (parents = all_parents; parents;\n+\t\t\t     parents = parents->next) {\n+\t\t\t\tif (parents->item != parent &&\n+\t\t\t\t    follow_needs_renames(opt, parents->item,\n+\t\t\t\t\t\t\t parent, path))\n+\t\t\t\t\ttail = &commit_list_insert(parents->item,\n+\t\t\t\t\t\t\t\t   tail)->next;\n+\t\t\t\telse\n+\t\t\t\t\tremember_follow_pathspec(opt,\n+\t\t\t\t\t\t\t\t parents->item,\n+\t\t\t\t\t\t\t\t path);\n+\t\t\t}\n+\t\t\tif (!rename_parents)\n+\t\t\t\tbreak;\n+\t\t\topt->diffopt.flags.follow_renames = 1;\n+\t\t\tparents = rename_parents;\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* The diff updated the pathspec in case of a rename */\n+\t\tif (path && opt->diffopt.flags.follow_renames)\n+\t\t\tremember_follow_pathspec(opt, parent,\n+\t\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n+\n \t\t/* Set up the log info for the next parent, if any.. */\n \t\tparents = parents->next;\n+\t\tif (!parents && follow_only &&\n+\t\t    !opt->diffopt.flags.follow_renames) {\n+\t\t\t/* The path changed in all parents, look for renames. */\n+\t\t\topt->diffopt.flags.follow_renames = 1;\n+\t\t\tparents = all_parents;\n+\t\t}\n \t\tif (!parents || opt->first_parent_merges)\n \t\t\tbreak;\n+\t\tif (path)\n+\t\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec,\n+\t\t\t\t\t\t    path);\n+\t\tif (follow_only)\n+\t\t\tcontinue;\n \t\tlog->parent = parents->item;\n \t\topt->loginfo = log;\n \t}\n+\tif (follow_only)\n+\t\topt->diffopt.flags.follow_renames = 1;\n+\tif (follow_only && (opt->remerge_diff || opt->combine_merges)) {\n+\t\t/* Show the merge diff with the path of this commit */\n+\t\tif (path)\n+\t\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec,\n+\t\t\t\t\t\t    path);\n+\t\tshowed_log = log_tree_merge_diff(opt, commit, all_parents, oid);\n+\t}\n+\tcommit_list_free(rename_parents);\n+\tfree(path);\n \treturn showed_log;\n }\n \n@@ -1298,21 +1398,6 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)\n \t\tfprintf(opt->diffopt.file, \"\\n%s\\n\", opt->break_bar);\n \tif (shown)\n \t\tshow_diff_of_diff(opt);\n-\n-\t/* Record what path each parent of this commit should use */\n-\tif (opt->diffopt.flags.follow_renames) {\n-\t\tstruct commit_list *parents = get_saved_parents(opt, commit);\n-\t\tif (parents && parents->next) {\n-\t\t\tstruct commit_list *p;\n-\t\t\tfor (p = parents; p; p = p->next)\n-\t\t\t\tpropagate_follow_pathspec_to_parent(opt, commit,\n-\t\t\t\t\t\t\t\t    p->item);\n-\t\t} else if (parents) {\n-\t\t\tremember_follow_pathspec(opt, parents->item,\n-\t\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n-\t\t}\n-\t}\n-\n \topt->loginfo = NULL;\n \tmaybe_flush_or_die(opt->diffopt.file, \"stdout\");\n \topt->diffopt.no_free = no_free;\ndiff --git a/t/t4219-log-follow-merge.sh b/t/t4219-log-follow-merge.sh\nindex e370f82955..9616ac64ed 100755\n--- a/t/t4219-log-follow-merge.sh\n+++ b/t/t4219-log-follow-merge.sh\n@@ -126,4 +126,116 @@ test_expect_success '--follow follows renames through a fork in a single history\n \ttest_cmp expect actual.sorted\n '\n \n+for opt in -c --cc --remerge-diff\n+do\n+\ttest_expect_success \"--follow follows renames through a fork with $opt\" '\n+\t\tgit -C diamond log --follow $opt --pretty=tformat:%s path >log &&\n+\t\tgrep \"^[A-Z]: \" log | sort >actual &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tA: add path0\n+\t\tB: modify path0 on upper\n+\t\tC: modify path0 on lower\n+\t\tM: merge with rename to path\n+\t\tX: rename path0 to path1\n+\t\tY: rename path0 to path2\n+\t\tZ: modify path\n+\t\tEOF\n+\t\ttest_cmp expect actual\n+\t'\n+done\n+\n+# Build a merge that takes the renamed path from the second parent, while the\n+# first parent only has the old path. $2 decides which side is committed first,\n+# which decides the walk order.\n+setup_rename_on_second_parent () {\n+\tgit init $1 &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >$1/old &&\n+\tgit -C $1 add old &&\n+\ttest_tick &&\n+\tgit -C $1 commit -m \"A: add old\" &&\n+\tprintf \"line 1\\nline 2\\nline 3 modified\\nline 4\\nline 5\\n\" >$1/old &&\n+\ttest_tick &&\n+\tgit -C $1 commit -am \"B: modify old\" &&\n+\tgit -C $1 branch topic &&\n+\n+\tif test \"$2\" = topic-first\n+\tthen\n+\t\tgit -C $1 checkout topic &&\n+\t\tgit -C $1 mv old new &&\n+\t\ttest_tick &&\n+\t\tgit -C $1 commit -m \"R: rename old to new\" &&\n+\t\tgit -C $1 checkout master\n+\tfi &&\n+\n+\techo other >$1/other &&\n+\tgit -C $1 add other &&\n+\ttest_tick &&\n+\tgit -C $1 commit -m \"M: unrelated change on master\" &&\n+\n+\tif test \"$2\" = master-first\n+\tthen\n+\t\tgit -C $1 checkout topic &&\n+\t\tgit -C $1 mv old new &&\n+\t\ttest_tick &&\n+\t\tgit -C $1 commit -m \"R: rename old to new\" &&\n+\t\tgit -C $1 checkout master\n+\tfi &&\n+\n+\ttest_tick &&\n+\tgit -C $1 merge --no-ff -m \"merge topic\" topic\n+}\n+\n+test_expect_success 'setup merge taking a rename from the second parent' '\n+\tsetup_rename_on_second_parent rename-master-first master-first &&\n+\tsetup_rename_on_second_parent rename-topic-first topic-first\n+'\n+\n+for order in master-first topic-first\n+do\n+\ttest_expect_success \"--follow follows a rename from the second parent ($order)\" '\n+\t\tgit -C rename-$order log --follow --pretty=tformat:%s new >actual &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tR: rename old to new\n+\t\tB: modify old\n+\t\tA: add old\n+\t\tEOF\n+\t\ttest_cmp expect actual\n+\t'\n+done\n+\n+test_expect_success 'setup merge keeping the path, other side renamed it' '\n+\tgit init keep &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >keep/F &&\n+\tgit -C keep add F &&\n+\ttest_tick &&\n+\tgit -C keep commit -m \"O: add F\" &&\n+\tgit -C keep branch B &&\n+\tprintf \"line 1\\nline 2\\nline 3 A\\nline 4\\nline 5\\n\" >keep/F &&\n+\ttest_tick &&\n+\tgit -C keep commit -am \"A1: update F in place\" &&\n+\n+\tgit -C keep checkout B &&\n+\tgit -C keep mv F G &&\n+\ttest_tick &&\n+\tgit -C keep commit -m \"B1: rename F to G\" &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4 B\\nline 5\\n\" >keep/G &&\n+\ttest_tick &&\n+\tgit -C keep commit -am \"B2: update G\" &&\n+\n+\tgit -C keep checkout master &&\n+\ttest_tick &&\n+\tgit -C keep merge -s ours -m \"M: merge B, keep F, drop G\" B\n+'\n+\n+test_expect_success '--follow follows a rename on the side the merge did not take' '\n+\tgit -C keep log --follow --pretty=tformat:%s F >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tB2: update G\n+\tB1: rename F to G\n+\tA1: update F in place\n+\tO: add F\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.56.0\n\n\n"},{"id":"555904","messageId":"cover.1792701579.git.vmiklos@collabora.com","threadId":"66514","inReplyTo":"atW0ctTe-lNq08A-@collabora.com","subject":"[PATCH v3 0/4] log: speed up --follow following renames for non-linear history","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-10-22T20:45:19Z","receivedAt":"2026-10-22T20:45:19Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Hi Junio,\n\nOn Mon, Oct 19, 2026 at 08:11:05AM +0200, Miklos Vajna <vmiklos@collabora.com> wrote:\n> This leads to a larger patch: should I extract the \"rethink the\n> approach\" and the new tests to separate patches or it doesn't matter?\n\nHere is a series where I split the changes into 4 patches: add more\ntests, a refactor, then your suggestion to start over (with one more\ntest) and finally the speedup.\n\nThanks,\n\nMiklos\n\nMiklos Vajna (4):\n  t4219: test more --follow cases across merges\n  log: extract showing the remerge/combined diff of a merge commit\n  log: simplify --follow following renames for non-linear history\n  log: speed up --follow following renames for non-linear history\n\n log-tree.c                  | 201 +++++++++++++++++++++++++-----------\n t/t4219-log-follow-merge.sh | 128 +++++++++++++++++++++++\n 2 files changed, 271 insertions(+), 58 deletions(-)\n\nInterdiff against v2:\ndiff --git a/t/t4219-log-follow-merge.sh b/t/t4219-log-follow-merge.sh\nindex 9616ac64ed..c8474ed151 100755\n--- a/t/t4219-log-follow-merge.sh\n+++ b/t/t4219-log-follow-merge.sh\n@@ -144,6 +144,22 @@ do\n \t'\n done\n \n+test_expect_success '--follow follows renames through a fork with -m' '\n+\tgit -C diamond log --follow -m --pretty=tformat:%s path >log &&\n+\tgrep \"^[A-Z]: \" log | sort >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tA: add path0\n+\tB: modify path0 on upper\n+\tC: modify path0 on lower\n+\tM: merge with rename to path\n+\tM: merge with rename to path\n+\tX: rename path0 to path1\n+\tY: rename path0 to path2\n+\tZ: modify path\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n # Build a merge that takes the renamed path from the second parent, while the\n # first parent only has the old path. $2 decides which side is committed first,\n # which decides the walk order.\n-- \n2.56.0\n\n\n"},{"id":"555905","messageId":"704c6df3ff82ae6a686200fd6df09c41b39619ce.1792701579.git.vmiklos@collabora.com","threadId":"66514","inReplyTo":"cover.1792701579.git.vmiklos@collabora.com","subject":"[PATCH v3 1/4] t4219: test more --follow cases across merges","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-10-22T20:45:48Z","receivedAt":"2026-10-22T20:45:48Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"A later commit in this series will speed up 'git log --follow' for\nmerge commits. Add tests for cases which already work, but had no\ntest coverage, so it's easy to break them while optimizing:\n\n- --follow through a fork with renames on both sides, with -c, --cc\n  and --remerge-diff\n- a --no-ff merge taking a rename from the second parent, in both commit\n  orders, since the result could depend on the walk order\n- a merge keeping the path, while the other side renamed it\n\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n t/t4219-log-follow-merge.sh | 112 ++++++++++++++++++++++++++++++++++++\n 1 file changed, 112 insertions(+)\n\ndiff --git a/t/t4219-log-follow-merge.sh b/t/t4219-log-follow-merge.sh\nindex e370f82955..9616ac64ed 100755\n--- a/t/t4219-log-follow-merge.sh\n+++ b/t/t4219-log-follow-merge.sh\n@@ -126,4 +126,116 @@ test_expect_success '--follow follows renames through a fork in a single history\n \ttest_cmp expect actual.sorted\n '\n \n+for opt in -c --cc --remerge-diff\n+do\n+\ttest_expect_success \"--follow follows renames through a fork with $opt\" '\n+\t\tgit -C diamond log --follow $opt --pretty=tformat:%s path >log &&\n+\t\tgrep \"^[A-Z]: \" log | sort >actual &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tA: add path0\n+\t\tB: modify path0 on upper\n+\t\tC: modify path0 on lower\n+\t\tM: merge with rename to path\n+\t\tX: rename path0 to path1\n+\t\tY: rename path0 to path2\n+\t\tZ: modify path\n+\t\tEOF\n+\t\ttest_cmp expect actual\n+\t'\n+done\n+\n+# Build a merge that takes the renamed path from the second parent, while the\n+# first parent only has the old path. $2 decides which side is committed first,\n+# which decides the walk order.\n+setup_rename_on_second_parent () {\n+\tgit init $1 &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >$1/old &&\n+\tgit -C $1 add old &&\n+\ttest_tick &&\n+\tgit -C $1 commit -m \"A: add old\" &&\n+\tprintf \"line 1\\nline 2\\nline 3 modified\\nline 4\\nline 5\\n\" >$1/old &&\n+\ttest_tick &&\n+\tgit -C $1 commit -am \"B: modify old\" &&\n+\tgit -C $1 branch topic &&\n+\n+\tif test \"$2\" = topic-first\n+\tthen\n+\t\tgit -C $1 checkout topic &&\n+\t\tgit -C $1 mv old new &&\n+\t\ttest_tick &&\n+\t\tgit -C $1 commit -m \"R: rename old to new\" &&\n+\t\tgit -C $1 checkout master\n+\tfi &&\n+\n+\techo other >$1/other &&\n+\tgit -C $1 add other &&\n+\ttest_tick &&\n+\tgit -C $1 commit -m \"M: unrelated change on master\" &&\n+\n+\tif test \"$2\" = master-first\n+\tthen\n+\t\tgit -C $1 checkout topic &&\n+\t\tgit -C $1 mv old new &&\n+\t\ttest_tick &&\n+\t\tgit -C $1 commit -m \"R: rename old to new\" &&\n+\t\tgit -C $1 checkout master\n+\tfi &&\n+\n+\ttest_tick &&\n+\tgit -C $1 merge --no-ff -m \"merge topic\" topic\n+}\n+\n+test_expect_success 'setup merge taking a rename from the second parent' '\n+\tsetup_rename_on_second_parent rename-master-first master-first &&\n+\tsetup_rename_on_second_parent rename-topic-first topic-first\n+'\n+\n+for order in master-first topic-first\n+do\n+\ttest_expect_success \"--follow follows a rename from the second parent ($order)\" '\n+\t\tgit -C rename-$order log --follow --pretty=tformat:%s new >actual &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tR: rename old to new\n+\t\tB: modify old\n+\t\tA: add old\n+\t\tEOF\n+\t\ttest_cmp expect actual\n+\t'\n+done\n+\n+test_expect_success 'setup merge keeping the path, other side renamed it' '\n+\tgit init keep &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >keep/F &&\n+\tgit -C keep add F &&\n+\ttest_tick &&\n+\tgit -C keep commit -m \"O: add F\" &&\n+\tgit -C keep branch B &&\n+\tprintf \"line 1\\nline 2\\nline 3 A\\nline 4\\nline 5\\n\" >keep/F &&\n+\ttest_tick &&\n+\tgit -C keep commit -am \"A1: update F in place\" &&\n+\n+\tgit -C keep checkout B &&\n+\tgit -C keep mv F G &&\n+\ttest_tick &&\n+\tgit -C keep commit -m \"B1: rename F to G\" &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4 B\\nline 5\\n\" >keep/G &&\n+\ttest_tick &&\n+\tgit -C keep commit -am \"B2: update G\" &&\n+\n+\tgit -C keep checkout master &&\n+\ttest_tick &&\n+\tgit -C keep merge -s ours -m \"M: merge B, keep F, drop G\" B\n+'\n+\n+test_expect_success '--follow follows a rename on the side the merge did not take' '\n+\tgit -C keep log --follow --pretty=tformat:%s F >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tB2: update G\n+\tB1: rename F to G\n+\tA1: update F in place\n+\tO: add F\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.56.0\n\n\n"},{"id":"555906","messageId":"2e734ef5a07f3d92eabee6864d3968b90a8ad7f1.1792701579.git.vmiklos@collabora.com","threadId":"66514","inReplyTo":"cover.1792701579.git.vmiklos@collabora.com","subject":"[PATCH v3 2/4] log: extract showing the remerge/combined diff of a merge commit","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-10-22T20:46:13Z","receivedAt":"2026-10-22T20:46:13Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"No functional changes intended. A later commit in this series will also\ncall log_tree_merge_diff() after the parent loop of log_tree_diff(), so\nextract that code to a function to avoid duplicating it.\n\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n log-tree.c | 36 ++++++++++++++++++++++--------------\n 1 file changed, 22 insertions(+), 14 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex 83a3c4bf9b..b4c97b86f5 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -1180,6 +1180,26 @@ static void propagate_follow_pathspec_to_parent(struct rev_info *opt,\n \tdiff_free(&diff_opts);\n }\n \n+/* Show the remerge or combined diff of a merge commit */\n+static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,\n+\t\t\t       struct commit_list *parents,\n+\t\t\t       struct object_id *oid)\n+{\n+\tint octopus = (parents->next->next != NULL);\n+\n+\tif (opt->remerge_diff) {\n+\t\tif (octopus) {\n+\t\t\tshow_log(opt);\n+\t\t\tfprintf(opt->diffopt.file,\n+\t\t\t\t\"diff: warning: Skipping remerge-diff \"\n+\t\t\t\t\"for octopus merges.\\n\");\n+\t\t\treturn 1;\n+\t\t}\n+\t\treturn do_remerge_diff(opt, parents, oid);\n+\t}\n+\treturn do_diff_combined(opt, commit);\n+}\n+\n /*\n  * Show the diff of a commit.\n  *\n@@ -1220,20 +1240,8 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t}\n \n \tif (is_merge) {\n-\t\tint octopus = (parents->next->next != NULL);\n-\n-\t\tif (opt->remerge_diff) {\n-\t\t\tif (octopus) {\n-\t\t\t\tshow_log(opt);\n-\t\t\t\tfprintf(opt->diffopt.file,\n-\t\t\t\t\t\"diff: warning: Skipping remerge-diff \"\n-\t\t\t\t\t\"for octopus merges.\\n\");\n-\t\t\t\treturn 1;\n-\t\t\t}\n-\t\t\treturn do_remerge_diff(opt, parents, oid);\n-\t\t}\n-\t\tif (opt->combine_merges)\n-\t\t\treturn do_diff_combined(opt, commit);\n+\t\tif (opt->remerge_diff || opt->combine_merges)\n+\t\t\treturn log_tree_merge_diff(opt, commit, parents, oid);\n \t\tif (opt->separate_merges) {\n \t\t\tif (!opt->first_parent_merges) {\n \t\t\t\t/* Show parent info for multiple diffs */\n-- \n2.56.0\n\n\n"},{"id":"555907","messageId":"ba2dc35c77b95803f184e63cc9933e3765bd1417.1792701579.git.vmiklos@collabora.com","threadId":"66514","inReplyTo":"cover.1792701579.git.vmiklos@collabora.com","subject":"[PATCH v3 3/4] log: simplify --follow following renames for non-linear history","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-10-22T20:46:39Z","receivedAt":"2026-10-22T20:46:39Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Code added in 304812ed33 (log: improve --follow following renames for\nnon-linear history, 2026-06-22) implemented the feature by introducing a\nnew propagate_follow_pathspec_to_parent() function which adds a new call\nto diff_tree_oid(). Also it introduces a new loop to record what path\neach parent of a merge commit should use when following a path.\n\nThis was working, but fixing its performance would require adding even\nmore custom code, instead of just extending the existing code in\nlog_tree_diff().\n\nRemove propagate_follow_pathspec_to_parent() and the loop calling it\nfor each parent. Instead, record the path to follow for each parent in\nthe parent loop of log_tree_diff(), right after diff_tree_oid() updated\nthe pathspec in case of a rename. Merges are not diffed by default, so\nwith --follow, run the same loop for them as well, but without showing\nanything. With -c, --cc or --remerge-diff, show the merge diff after the\nloop. This gets rid of the additional call to diff_tree_oid(). The\nrework has no positive performance impact yet, it just simplifies the\ncode.\n\nThis also fixes 'git log -m --follow': -m diffs the merge against each\nparent with rename following, so a rename found against the first parent\nupdated the followed path, and the second parent was then diffed with\nthe already renamed path. Also, propagate_follow_pathspec_to_parent()\nstarted from that same updated path, so history was lost on the side of\nthe second parent. Now the path of the merge is restored before diffing\neach parent. Add a test for this, which shows the full history of the\ndiamond case with -m.\n\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n log-tree.c                  | 84 +++++++++++++++++--------------------\n t/t4219-log-follow-merge.sh | 16 +++++++\n 2 files changed, 54 insertions(+), 46 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex b4c97b86f5..c5ac6c2bcb 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -1153,33 +1153,6 @@ void release_follow_pathspec_slab(struct rev_info *opt)\n \tFREE_AND_NULL(opt->follow_pathspec_slab);\n }\n \n-/* Compute a path to follow in parent, if there is one */\n-static void propagate_follow_pathspec_to_parent(struct rev_info *opt,\n-\t\t\t\t\t\tstruct commit *commit,\n-\t\t\t\t\t\tstruct commit *parent)\n-{\n-\tstruct diff_options diff_opts;\n-\tconst char *path;\n-\n-\tparse_commit_or_die(parent);\n-\trepo_diff_setup(opt->diffopt.repo, &diff_opts);\n-\tcopy_pathspec(&diff_opts.pathspec, &opt->diffopt.pathspec);\n-\tdiff_opts.flags.recursive = 1;\n-\tdiff_opts.flags.follow_renames = 1;\n-\tdiff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;\n-\tdiff_setup_done(&diff_opts);\n-\tdiff_tree_oid(get_commit_tree_oid(parent),\n-\t\t      get_commit_tree_oid(commit),\n-\t\t      \"\", &diff_opts);\n-\n-\tpath = pathspec_single_path(&diff_opts.pathspec);\n-\tif (path)\n-\t\tremember_follow_pathspec(opt, parent, path);\n-\n-\tdiff_queue_clear(&diff_queued_diff);\n-\tdiff_free(&diff_opts);\n-}\n-\n /* Show the remerge or combined diff of a merge commit */\n static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,\n \t\t\t       struct commit_list *parents,\n@@ -1208,10 +1181,12 @@ static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,\n static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log)\n {\n \tint showed_log;\n-\tstruct commit_list *parents;\n+\tstruct commit_list *parents, *all_parents;\n \tstruct object_id *oid;\n \tint is_merge;\n \tint all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;\n+\tint follow_only = 0;\n+\tchar *path = NULL;\n \n \tif (!all_need_diff && !opt->merges_need_diff)\n \t\treturn 0;\n@@ -1240,35 +1215,67 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t}\n \n \tif (is_merge) {\n-\t\tif (opt->remerge_diff || opt->combine_merges)\n+\t\tint merge_diff = opt->remerge_diff || opt->combine_merges;\n+\n+\t\tif (merge_diff && !opt->diffopt.flags.follow_renames)\n \t\t\treturn log_tree_merge_diff(opt, commit, parents, oid);\n-\t\tif (opt->separate_merges) {\n+\t\tif (opt->separate_merges && !merge_diff) {\n \t\t\tif (!opt->first_parent_merges) {\n \t\t\t\t/* Show parent info for multiple diffs */\n \t\t\t\tlog->parent = parents->item;\n \t\t\t}\n+\t\t} else if (opt->diffopt.flags.follow_renames) {\n+\t\t\t/* Diff only to find the path to follow in parents */\n+\t\t\tfollow_only = 1;\n \t\t} else\n \t\t\treturn 0;\n \t}\n \n+\tif (opt->diffopt.flags.follow_renames)\n+\t\tpath = xstrdup_or_null(\n+\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n+\n \tshowed_log = 0;\n+\tall_parents = parents;\n \tfor (;;) {\n \t\tstruct commit *parent = parents->item;\n \n \t\tparse_commit_or_die(parent);\n \t\tdiff_tree_oid(get_commit_tree_oid(parent),\n \t\t\t      oid, \"\", &opt->diffopt);\n-\t\tlog_tree_diff_flush(opt);\n+\t\tif (follow_only) {\n+\t\t\tdiff_queue_clear(&diff_queued_diff);\n+\t\t\topt->diffopt.found_follow = 0;\n+\t\t} else\n+\t\t\tlog_tree_diff_flush(opt);\n \n \t\tshowed_log |= !opt->loginfo;\n \n+\t\t/* The diff updated the pathspec in case of a rename */\n+\t\tif (path)\n+\t\t\tremember_follow_pathspec(opt, parent,\n+\t\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n+\n \t\t/* Set up the log info for the next parent, if any.. */\n \t\tparents = parents->next;\n \t\tif (!parents || opt->first_parent_merges)\n \t\t\tbreak;\n+\t\tif (path)\n+\t\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec,\n+\t\t\t\t\t\t    path);\n+\t\tif (follow_only)\n+\t\t\tcontinue;\n \t\tlog->parent = parents->item;\n \t\topt->loginfo = log;\n \t}\n+\tif (follow_only && (opt->remerge_diff || opt->combine_merges)) {\n+\t\t/* Show the merge diff with the path of this commit */\n+\t\tif (path)\n+\t\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec,\n+\t\t\t\t\t\t    path);\n+\t\tshowed_log = log_tree_merge_diff(opt, commit, all_parents, oid);\n+\t}\n+\tfree(path);\n \treturn showed_log;\n }\n \n@@ -1306,21 +1313,6 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)\n \t\tfprintf(opt->diffopt.file, \"\\n%s\\n\", opt->break_bar);\n \tif (shown)\n \t\tshow_diff_of_diff(opt);\n-\n-\t/* Record what path each parent of this commit should use */\n-\tif (opt->diffopt.flags.follow_renames) {\n-\t\tstruct commit_list *parents = get_saved_parents(opt, commit);\n-\t\tif (parents && parents->next) {\n-\t\t\tstruct commit_list *p;\n-\t\t\tfor (p = parents; p; p = p->next)\n-\t\t\t\tpropagate_follow_pathspec_to_parent(opt, commit,\n-\t\t\t\t\t\t\t\t    p->item);\n-\t\t} else if (parents) {\n-\t\t\tremember_follow_pathspec(opt, parents->item,\n-\t\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n-\t\t}\n-\t}\n-\n \topt->loginfo = NULL;\n \tmaybe_flush_or_die(opt->diffopt.file, \"stdout\");\n \topt->diffopt.no_free = no_free;\ndiff --git a/t/t4219-log-follow-merge.sh b/t/t4219-log-follow-merge.sh\nindex 9616ac64ed..c8474ed151 100755\n--- a/t/t4219-log-follow-merge.sh\n+++ b/t/t4219-log-follow-merge.sh\n@@ -144,6 +144,22 @@ do\n \t'\n done\n \n+test_expect_success '--follow follows renames through a fork with -m' '\n+\tgit -C diamond log --follow -m --pretty=tformat:%s path >log &&\n+\tgrep \"^[A-Z]: \" log | sort >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tA: add path0\n+\tB: modify path0 on upper\n+\tC: modify path0 on lower\n+\tM: merge with rename to path\n+\tM: merge with rename to path\n+\tX: rename path0 to path1\n+\tY: rename path0 to path2\n+\tZ: modify path\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n # Build a merge that takes the renamed path from the second parent, while the\n # first parent only has the old path. $2 decides which side is committed first,\n # which decides the walk order.\n-- \n2.56.0\n\n\n"},{"id":"555908","messageId":"6f249099cf214f83d31bc04980bc2e9dfd861bba.1792701579.git.vmiklos@collabora.com","threadId":"66514","inReplyTo":"cover.1792701579.git.vmiklos@collabora.com","subject":"[PATCH v3 4/4] log: speed up --follow following renames for non-linear history","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-10-22T20:47:06Z","receivedAt":"2026-10-22T20:47:06Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Test the performance of 'git log --stat --follow --\ninclude/linux/rsc_table.h' on linux.git, it used to take about 28\nseconds, and since commit 304812ed33 (log: improve --follow following\nrenames for non-linear history, 2026-06-22), it takes 6m43s.\n\nWhat happens is that log_tree_diff() diffs each merge against all of its\nparents with rename following. diff_tree_oid() only does the expensive\nrename detection when the path is added relative to a parent, but that\nis common for merges, e.g. when a branch forked before the path was\ncreated merges mainline, and this slows down 'git log --follow'.\n\nFix the problem by diffing the merge against its parents in two passes:\n- First pass: diff against the parents without rename following. If the\n  path is unchanged against a parent, then just follow that history in\n  all parents.\n  - Except when an other parent doesn't have the path, the merge has it\n    and a merge base of the two parents also has it, i.e. the path was\n    renamed or removed on that side: still do the rename following\n    against such a parent, otherwise the history on that side would be\n    lost. The merge base is only computed in this rare case, and\n    back-merges where the path was created after the other side forked\n    still skip the expensive rename detection.\n- Second pass: only do the rename following against each parent if the\n  path changed relative to all parents.\nGiven that this way a parent may be asked to follow a path that it\ndoesn't have, also adjust remember_follow_pathspec(): if children\ndisagree on what should be the path for a commit, then prefer the path\nthat exists in that commit.\n\nNow the above use case takes 36s, somewhat close to the original cost.\n\nHelped-by: SZEDER Gábor <szeder.dev@gmail.com>\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n log-tree.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++---\n 1 file changed, 89 insertions(+), 4 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex c5ac6c2bcb..d5ce58d91d 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -31,6 +31,7 @@\n #include \"range-diff.h\"\n #include \"strmap.h\"\n #include \"tree.h\"\n+#include \"tree-walk.h\"\n #include \"wildmatch.h\"\n #include \"write-or-die.h\"\n #include \"pager.h\"\n@@ -1110,6 +1111,17 @@ static void set_pathspec_to_single_path(struct pathspec *ps, const char *path)\n \t\t       PATHSPEC_LITERAL_PATH, \"\", paths);\n }\n \n+static int commit_has_path(struct rev_info *opt, struct commit *c,\n+\t\t\t   const char *path)\n+{\n+\tstruct object_id oid;\n+\tunsigned short mode;\n+\n+\tparse_commit_or_die(c);\n+\treturn !get_tree_entry(opt->diffopt.repo, get_commit_tree_oid(c), path,\n+\t\t\t       &oid, &mode);\n+}\n+\n static void remember_follow_pathspec(struct rev_info *opt,\n \t\t\t\t     struct commit *c, const char *path)\n {\n@@ -1122,8 +1134,12 @@ static void remember_follow_pathspec(struct rev_info *opt,\n \t\tinit_follow_pathspec_slab(opt->follow_pathspec_slab);\n \t}\n \tslot = follow_pathspec_slab_at(opt->follow_pathspec_slab, c);\n-\tif (*slot && !strcmp(*slot, path))\n-\t\treturn;\n+\t/* If children of 'c' disagree on the path, prefer the one 'c' has. */\n+\tif (*slot) {\n+\t\tif (!strcmp(*slot, path) || commit_has_path(opt, c, *slot) ||\n+\t\t    !commit_has_path(opt, c, path))\n+\t\t\treturn;\n+\t}\n \tfree(*slot);\n \t*slot = xstrdup(path);\n }\n@@ -1153,6 +1169,29 @@ void release_follow_pathspec_slab(struct rev_info *opt)\n \tFREE_AND_NULL(opt->follow_pathspec_slab);\n }\n \n+/*\n+ * When the path in a merge is the same as in 'same', does the path still need\n+ * renames to be followed in 'parent'? Only if the merge has the path, 'parent'\n+ * doesn't have it, but its fork point with 'same' had it, e.g. 'parent'\n+ * renamed the path.\n+ */\n+static int follow_needs_renames(struct rev_info *opt, struct commit *parent,\n+\t\t\t\tstruct commit *same, const char *path)\n+{\n+\tstruct commit_list *bases = NULL, *base;\n+\tint ret = 0;\n+\n+\tif (commit_has_path(opt, parent, path) ||\n+\t    !commit_has_path(opt, same, path))\n+\t\treturn 0;\n+\tif (repo_get_merge_bases(opt->diffopt.repo, parent, same, &bases) < 0)\n+\t\texit(128);\n+\tfor (base = bases; base && !ret; base = base->next)\n+\t\tret = commit_has_path(opt, base->item, path);\n+\tcommit_list_free(bases);\n+\treturn ret;\n+}\n+\n /* Show the remerge or combined diff of a merge commit */\n static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,\n \t\t\t       struct commit_list *parents,\n@@ -1181,7 +1220,7 @@ static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,\n static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log)\n {\n \tint showed_log;\n-\tstruct commit_list *parents, *all_parents;\n+\tstruct commit_list *parents, *all_parents, *rename_parents = NULL;\n \tstruct object_id *oid;\n \tint is_merge;\n \tint all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;\n@@ -1235,15 +1274,25 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t\tpath = xstrdup_or_null(\n \t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n \n+\tif (follow_only) {\n+\t\t/*\n+\t\t * First look for a parent where the path is unchanged, without\n+\t\t * the expensive rename detection.\n+\t\t */\n+\t\topt->diffopt.flags.follow_renames = 0;\n+\t}\n+\n \tshowed_log = 0;\n \tall_parents = parents;\n \tfor (;;) {\n \t\tstruct commit *parent = parents->item;\n+\t\tint changed = 1;\n \n \t\tparse_commit_or_die(parent);\n \t\tdiff_tree_oid(get_commit_tree_oid(parent),\n \t\t\t      oid, \"\", &opt->diffopt);\n \t\tif (follow_only) {\n+\t\t\tchanged = diff_queued_diff.nr;\n \t\t\tdiff_queue_clear(&diff_queued_diff);\n \t\t\topt->diffopt.found_follow = 0;\n \t\t} else\n@@ -1251,13 +1300,46 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \n \t\tshowed_log |= !opt->loginfo;\n \n+\t\tif (!changed) {\n+\t\t\t/*\n+\t\t\t * Same as in this parent, follow that history, but\n+\t\t\t * still look for renames in parents that had the path\n+\t\t\t * at the fork point.\n+\t\t\t */\n+\t\t\tstruct commit_list **tail = &rename_parents;\n+\n+\t\t\tfor (parents = all_parents; parents;\n+\t\t\t     parents = parents->next) {\n+\t\t\t\tif (parents->item != parent &&\n+\t\t\t\t    follow_needs_renames(opt, parents->item,\n+\t\t\t\t\t\t\t parent, path))\n+\t\t\t\t\ttail = &commit_list_insert(parents->item,\n+\t\t\t\t\t\t\t\t   tail)->next;\n+\t\t\t\telse\n+\t\t\t\t\tremember_follow_pathspec(opt,\n+\t\t\t\t\t\t\t\t parents->item,\n+\t\t\t\t\t\t\t\t path);\n+\t\t\t}\n+\t\t\tif (!rename_parents)\n+\t\t\t\tbreak;\n+\t\t\topt->diffopt.flags.follow_renames = 1;\n+\t\t\tparents = rename_parents;\n+\t\t\tcontinue;\n+\t\t}\n+\n \t\t/* The diff updated the pathspec in case of a rename */\n-\t\tif (path)\n+\t\tif (path && opt->diffopt.flags.follow_renames)\n \t\t\tremember_follow_pathspec(opt, parent,\n \t\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n \n \t\t/* Set up the log info for the next parent, if any.. */\n \t\tparents = parents->next;\n+\t\tif (!parents && follow_only &&\n+\t\t    !opt->diffopt.flags.follow_renames) {\n+\t\t\t/* The path changed in all parents, look for renames. */\n+\t\t\topt->diffopt.flags.follow_renames = 1;\n+\t\t\tparents = all_parents;\n+\t\t}\n \t\tif (!parents || opt->first_parent_merges)\n \t\t\tbreak;\n \t\tif (path)\n@@ -1268,6 +1350,8 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t\tlog->parent = parents->item;\n \t\topt->loginfo = log;\n \t}\n+\tif (follow_only)\n+\t\topt->diffopt.flags.follow_renames = 1;\n \tif (follow_only && (opt->remerge_diff || opt->combine_merges)) {\n \t\t/* Show the merge diff with the path of this commit */\n \t\tif (path)\n@@ -1275,6 +1359,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t\t\t\t\t\t    path);\n \t\tshowed_log = log_tree_merge_diff(opt, commit, all_parents, oid);\n \t}\n+\tcommit_list_free(rename_parents);\n \tfree(path);\n \treturn showed_log;\n }\n-- \n2.56.0\n\n\n"},{"id":"556319","messageId":"at88KXp0vhXlPhFQ@pks.im","threadId":"66514","inReplyTo":"ba2dc35c77b95803f184e63cc9933e3765bd1417.1792701579.git.vmiklos@collabora.com","subject":"Re: [PATCH v3 3/4] log: simplify --follow following renames for non-linear history","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-26T11:40:36Z","receivedAt":"2026-10-26T11:40:36Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Oct 22, 2026 at 10:46:39PM +0200, Miklos Vajna wrote:\n> Code added in 304812ed33 (log: improve --follow following renames for\n> non-linear history, 2026-06-22) implemented the feature by introducing a\n> new propagate_follow_pathspec_to_parent() function which adds a new call\n> to diff_tree_oid(). Also it introduces a new loop to record what path\n> each parent of a merge commit should use when following a path.\n> \n> This was working, but fixing its performance would require adding even\n\nIt's somewhat curious that you start talking about performance here\nwithout even mentioning that performance is what breaks the current\napproach. You mention contributing factors to the performance regression\nwithout really calling it that.\n\n> more custom code, instead of just extending the existing code in\n> log_tree_diff().\n> \n> Remove propagate_follow_pathspec_to_parent() and the loop calling it\n> for each parent. Instead, record the path to follow for each parent in\n> the parent loop of log_tree_diff(), right after diff_tree_oid() updated\n> the pathspec in case of a rename. Merges are not diffed by default, so\n> with --follow, run the same loop for them as well, but without showing\n> anything. With -c, --cc or --remerge-diff, show the merge diff after the\n> loop. This gets rid of the additional call to diff_tree_oid(). The\n> rework has no positive performance impact yet, it just simplifies the\n> code.\n\n> This also fixes 'git log -m --follow': -m diffs the merge against each\n> parent with rename following, so a rename found against the first parent\n> updated the followed path, and the second parent was then diffed with\n> the already renamed path.\n\nSo next to a performance regression there's also a bug? Interesting. I\nfeel like giving a bit more time to introduce and explain the bug would\nhave helped.\n\n> Also, propagate_follow_pathspec_to_parent()\n> started from that same updated path, so history was lost on the side of\n> the second parent. Now the path of the merge is restored before diffing\n> each parent. Add a test for this, which shows the full history of the\n> diamond case with -m.\n\nAnd another bug?\n\nSo in summary we have two bugs and one performance regression? The two\nbugs are fixed by this change, and it also prepares us for the fix to\nthe performance regression? It might be easier to reason through\nall of that if we were able to split this so that we fix one issue at a\ntime, but that may of course not be possible (or just very awkward).\n\n> diff --git a/log-tree.c b/log-tree.c\n> index b4c97b86f5..c5ac6c2bcb 100644\n> --- a/log-tree.c\n> +++ b/log-tree.c\n> @@ -1240,35 +1215,67 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n>  \t}\n>  \n>  \tif (is_merge) {\n> -\t\tif (opt->remerge_diff || opt->combine_merges)\n> +\t\tint merge_diff = opt->remerge_diff || opt->combine_merges;\n> +\n> +\t\tif (merge_diff && !opt->diffopt.flags.follow_renames)\n>  \t\t\treturn log_tree_merge_diff(opt, commit, parents, oid);\n> -\t\tif (opt->separate_merges) {\n> +\t\tif (opt->separate_merges && !merge_diff) {\n>  \t\t\tif (!opt->first_parent_merges) {\n>  \t\t\t\t/* Show parent info for multiple diffs */\n>  \t\t\t\tlog->parent = parents->item;\n>  \t\t\t}\n> +\t\t} else if (opt->diffopt.flags.follow_renames) {\n> +\t\t\t/* Diff only to find the path to follow in parents */\n> +\t\t\tfollow_only = 1;\n>  \t\t} else\n>  \t\t\treturn 0;\n>  \t}\n>  \n> +\tif (opt->diffopt.flags.follow_renames)\n> +\t\tpath = xstrdup_or_null(\n> +\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n> +\n>  \tshowed_log = 0;\n> +\tall_parents = parents;\n>  \tfor (;;) {\n>  \t\tstruct commit *parent = parents->item;\n>  \n>  \t\tparse_commit_or_die(parent);\n>  \t\tdiff_tree_oid(get_commit_tree_oid(parent),\n>  \t\t\t      oid, \"\", &opt->diffopt);\n> -\t\tlog_tree_diff_flush(opt);\n> +\t\tif (follow_only) {\n> +\t\t\tdiff_queue_clear(&diff_queued_diff);\n> +\t\t\topt->diffopt.found_follow = 0;\n> +\t\t} else\n> +\t\t\tlog_tree_diff_flush(opt);\n\nNit: style, if once condition body requires curly braces all of them\nshould have it. Sorry, I cannot really provide more valuable feedback on\nthis patch than this.\n\nPatrick\n\n"},{"id":"556320","messageId":"at88ORA5midZJctp@pks.im","threadId":"66514","inReplyTo":"6f249099cf214f83d31bc04980bc2e9dfd861bba.1792701579.git.vmiklos@collabora.com","subject":"Re: [PATCH v3 4/4] log: speed up --follow following renames for non-linear history","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-26T11:40:41Z","receivedAt":"2026-10-26T11:40:41Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Oct 22, 2026 at 10:47:06PM +0200, Miklos Vajna wrote:\n> diff --git a/log-tree.c b/log-tree.c\n> index c5ac6c2bcb..d5ce58d91d 100644\n> --- a/log-tree.c\n> +++ b/log-tree.c\n> @@ -1153,6 +1169,29 @@ void release_follow_pathspec_slab(struct rev_info *opt)\n>  \tFREE_AND_NULL(opt->follow_pathspec_slab);\n>  }\n>  \n> +/*\n> + * When the path in a merge is the same as in 'same', does the path still need\n> + * renames to be followed in 'parent'? Only if the merge has the path, 'parent'\n> + * doesn't have it, but its fork point with 'same' had it, e.g. 'parent'\n> + * renamed the path.\n> + */\n> +static int follow_needs_renames(struct rev_info *opt, struct commit *parent,\n> +\t\t\t\tstruct commit *same, const char *path)\n> +{\n> +\tstruct commit_list *bases = NULL, *base;\n> +\tint ret = 0;\n> +\n> +\tif (commit_has_path(opt, parent, path) ||\n> +\t    !commit_has_path(opt, same, path))\n> +\t\treturn 0;\n\nDoesn't this miss the reverse case where we have the path in \"parent\",\nbut not in \"same\"? So basically this test case, which is very similar to\nthe one you already added to 4219:\n\ntest_expect_success 'setup merge keeping the renamed path, other side edited the old one' '\n\tgit init keep-renamed &&\n\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >keep-renamed/F &&\n\tgit -C keep-renamed add F &&\n\ttest_tick &&\n\tgit -C keep-renamed commit -m \"O: add F\" &&\n\tgit -C keep-renamed branch B &&\n\tgit -C keep-renamed mv F G &&\n\ttest_tick &&\n\tgit -C keep-renamed commit -m \"A1: rename F to G on master\" &&\n\n\tgit -C keep-renamed checkout B &&\n\tprintf \"line 1\\nline 2\\nline 3\\nline 4 T\\nline 5\\n\" >keep-renamed/F &&\n\ttest_tick &&\n\tgit -C keep-renamed commit -am \"B2: update F on B\" &&\n\n\tgit -C keep-renamed checkout master &&\n\ttest_tick &&\n\tgit -C keep-renamed merge -s ours -m \"M: merge B, keep G, drop F\" B\n'\n\ntest_expect_success '--follow follows an edit on the side the merge did not take' '\n\tgit -C keep-renamed log --follow --pretty=tformat:%s G >actual &&\n\tcat >expect <<-\\EOF &&\n\tB2: update F on B\n\tA1: rename F to G on master\n\tO: add F\n\tEOF\n\ttest_cmp expect actual\n'\n\nThat test passes with HEAD~, but fails with HEAD.\n\nPatrick\n\n"},{"id":"556321","messageId":"at88iclPaLSYfERm@pks.im","threadId":"66514","inReplyTo":"cover.1792701579.git.vmiklos@collabora.com","subject":"Re: [PATCH v3 0/4] log: speed up --follow following renames for non-linear history","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-26T11:42:01Z","receivedAt":"2026-10-26T11:42:01Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Oct 22, 2026 at 10:45:19PM +0200, Miklos Vajna wrote:\n> Hi Junio,\n> \n> On Mon, Oct 19, 2026 at 08:11:05AM +0200, Miklos Vajna <vmiklos@collabora.com> wrote:\n> > This leads to a larger patch: should I extract the \"rethink the\n> > approach\" and the new tests to separate patches or it doesn't matter?\n> \n> Here is a series where I split the changes into 4 patches: add more\n> tests, a refactor, then your suggestion to start over (with one more\n> test) and finally the speedup.\n\nThanks for your work.\n\nI cannot really provide much of value as I'm way out of my depth here,\nbut will try to do so anyway as the regression has now caused an\nincident for GitLab.com. Hope to get this resolved sooner rather than\nlater so that I can ideally avoid backporting patches in favor of\ngetting this series landed.\n\nPatrick\n\n"},{"id":"556959","messageId":"cover.1793298331.git.vmiklos@collabora.com","threadId":"66514","inReplyTo":"cover.1792701579.git.vmiklos@collabora.com","subject":"[PATCH v4 0/6] log: speed up --follow following renames for non-linear history","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-10-30T20:07:00Z","receivedAt":"2026-10-30T20:07:00Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Hi Patrick,\n\nThanks for the reviews of v3. Changes in v4:\n\n- The -m --follow fix is now a separate patch (3/6), so the simplify\n  patch (4/6) no longer changes behavior. The two bugs you pointed out\n  in the old commit message have one cause: the followed path is not\n  restored between the parents of a merge. So 3/6 fixes both. The\n  commit message of 4/6 now says upfront that 304812ed33 (log: improve\n  --follow following renames for non-linear history, 2026-06-22) caused\n  a performance regression.\n\n- Fixed the brace style nit in the simplify patch.\n\n- Patch 6/6 fixes the case you found, where the speedup lost history:\n  one side of the merge renamed the path, and the other side, whose\n  version the merge dropped, edited the old name. It uses your test.\n  I kept it separate from the speedup patch, which is complicated\n  enough already. With the extra check, the linux.git case still takes\n  about 37s.\n\n- I also noticed that the simplify patch lost history with\n  --diff-merges=first-parent, which diffs merges only against their\n  first parent, but still walks all parents. Fixed that and added a\n  test for it to 1/6.\n\nThanks,\n\nMiklos\n\nMiklos Vajna (6):\n  t4219: test more --follow cases across merges\n  log: extract showing the remerge/combined diff of a merge commit\n  log: fix -m --follow losing the history of later parents\n  log: simplify --follow following renames for non-linear history\n  log: speed up --follow following renames for non-linear history\n  log: fix --follow following an edit on a side the merge did not take\n\n log-tree.c                  | 265 +++++++++++++++++++++++++++++-------\n t/t4219-log-follow-merge.sh | 171 +++++++++++++++++++++++\n 2 files changed, 388 insertions(+), 48 deletions(-)\n\nInterdiff against v3:\ndiff --git a/log-tree.c b/log-tree.c\nindex d5ce58d91d..c2c3473f25 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -1111,15 +1111,20 @@ static void set_pathspec_to_single_path(struct pathspec *ps, const char *path)\n \t\t       PATHSPEC_LITERAL_PATH, \"\", paths);\n }\n \n-static int commit_has_path(struct rev_info *opt, struct commit *c,\n-\t\t\t   const char *path)\n+static int tree_has_path(struct rev_info *opt, struct object_id *tree,\n+\t\t\t const char *path)\n {\n \tstruct object_id oid;\n \tunsigned short mode;\n \n+\treturn !get_tree_entry(opt->diffopt.repo, tree, path, &oid, &mode);\n+}\n+\n+static int commit_has_path(struct rev_info *opt, struct commit *c,\n+\t\t\t   const char *path)\n+{\n \tparse_commit_or_die(c);\n-\treturn !get_tree_entry(opt->diffopt.repo, get_commit_tree_oid(c), path,\n-\t\t\t       &oid, &mode);\n+\treturn tree_has_path(opt, get_commit_tree_oid(c), path);\n }\n \n static void remember_follow_pathspec(struct rev_info *opt,\n@@ -1169,26 +1174,97 @@ void release_follow_pathspec_slab(struct rev_info *opt)\n \tFREE_AND_NULL(opt->follow_pathspec_slab);\n }\n \n+/*\n+ * Did 'parent' change a file since 'base' that the merge (with tree 'oid') no\n+ * longer has? Only such a file can be the source of a rename on the other side\n+ * of the merge that still needs to be followed in 'parent'.\n+ */\n+static int follow_parent_changed_dropped_file(struct rev_info *opt,\n+\t\t\t\t\t      struct commit *base,\n+\t\t\t\t\t      struct commit *parent,\n+\t\t\t\t\t      struct object_id *oid)\n+{\n+\tstruct diff_options diff_opts;\n+\tint i, ret = 0;\n+\n+\trepo_diff_setup(opt->diffopt.repo, &diff_opts);\n+\tdiff_opts.flags.recursive = 1;\n+\tdiff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;\n+\tdiff_setup_done(&diff_opts);\n+\tdiff_tree_oid(get_commit_tree_oid(base), get_commit_tree_oid(parent),\n+\t\t      \"\", &diff_opts);\n+\tfor (i = 0; i < diff_queued_diff.nr && !ret; i++) {\n+\t\tstruct diff_filepair *p = diff_queued_diff.queue[i];\n+\n+\t\tret = DIFF_FILE_VALID(p->two) &&\n+\t\t      !tree_has_path(opt, oid, p->two->path);\n+\t}\n+\tdiff_queue_clear(&diff_queued_diff);\n+\tdiff_free(&diff_opts);\n+\treturn ret;\n+}\n+\n+/*\n+ * Is 'path' in the merge (with tree 'oid') renamed from a file of 'parent'?\n+ * Only look at the files that the merge deleted, not at all files of 'parent'\n+ * like --follow does.\n+ */\n+static int follow_has_rename_source(struct rev_info *opt,\n+\t\t\t\t    struct commit *parent,\n+\t\t\t\t    struct object_id *oid, const char *path)\n+{\n+\tstruct diff_options diff_opts;\n+\tint i, ret = 0;\n+\n+\trepo_diff_setup(opt->diffopt.repo, &diff_opts);\n+\tdiff_opts.flags.recursive = 1;\n+\tdiff_opts.detect_rename = DIFF_DETECT_RENAME;\n+\tdiff_opts.rename_score = opt->diffopt.rename_score;\n+\tdiff_opts.single_follow = path;\n+\tdiff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;\n+\tdiff_setup_done(&diff_opts);\n+\tdiff_tree_oid(get_commit_tree_oid(parent), oid, \"\", &diff_opts);\n+\tdiffcore_std(&diff_opts);\n+\tfor (i = 0; i < diff_queued_diff.nr && !ret; i++) {\n+\t\tstruct diff_filepair *p = diff_queued_diff.queue[i];\n+\n+\t\tret = p->status == DIFF_STATUS_RENAMED &&\n+\t\t      !strcmp(p->two->path, path);\n+\t}\n+\tdiff_queue_clear(&diff_queued_diff);\n+\tdiff_free(&diff_opts);\n+\treturn ret;\n+}\n+\n /*\n  * When the path in a merge is the same as in 'same', does the path still need\n  * renames to be followed in 'parent'? Only if the merge has the path, 'parent'\n- * doesn't have it, but its fork point with 'same' had it, e.g. 'parent'\n- * renamed the path.\n+ * doesn't have it, and either:\n+ *\n+ * - its fork point with 'same' had it, e.g. 'parent' renamed the path, or\n+ * - 'same' renamed the path from a file that 'parent' changed.\n  */\n static int follow_needs_renames(struct rev_info *opt, struct commit *parent,\n-\t\t\t\tstruct commit *same, const char *path)\n+\t\t\t\tstruct commit *same, struct object_id *oid,\n+\t\t\t\tconst char *path)\n {\n \tstruct commit_list *bases = NULL, *base;\n-\tint ret = 0;\n+\tint ret = 0, changed_dropped = 0;\n \n \tif (commit_has_path(opt, parent, path) ||\n \t    !commit_has_path(opt, same, path))\n \t\treturn 0;\n \tif (repo_get_merge_bases(opt->diffopt.repo, parent, same, &bases) < 0)\n \t\texit(128);\n-\tfor (base = bases; base && !ret; base = base->next)\n+\tfor (base = bases; base && !ret; base = base->next) {\n \t\tret = commit_has_path(opt, base->item, path);\n+\t\tif (!ret && !changed_dropped)\n+\t\t\tchanged_dropped = follow_parent_changed_dropped_file(\n+\t\t\t\topt, base->item, parent, oid);\n+\t}\n \tcommit_list_free(bases);\n+\tif (!ret && changed_dropped)\n+\t\tret = follow_has_rename_source(opt, parent, oid, path);\n \treturn ret;\n }\n \n@@ -1295,8 +1371,9 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t\t\tchanged = diff_queued_diff.nr;\n \t\t\tdiff_queue_clear(&diff_queued_diff);\n \t\t\topt->diffopt.found_follow = 0;\n-\t\t} else\n+\t\t} else {\n \t\t\tlog_tree_diff_flush(opt);\n+\t\t}\n \n \t\tshowed_log |= !opt->loginfo;\n \n@@ -1312,7 +1389,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t\t\t     parents = parents->next) {\n \t\t\t\tif (parents->item != parent &&\n \t\t\t\t    follow_needs_renames(opt, parents->item,\n-\t\t\t\t\t\t\t parent, path))\n+\t\t\t\t\t\t\t parent, oid, path))\n \t\t\t\t\ttail = &commit_list_insert(parents->item,\n \t\t\t\t\t\t\t\t   tail)->next;\n \t\t\t\telse\n@@ -1340,8 +1417,15 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t\t\topt->diffopt.flags.follow_renames = 1;\n \t\t\tparents = all_parents;\n \t\t}\n-\t\tif (!parents || opt->first_parent_merges)\n+\t\tif (!parents)\n \t\t\tbreak;\n+\t\tif (opt->first_parent_merges && !follow_only) {\n+\t\t\tif (!path || opt->first_parent_only)\n+\t\t\t\tbreak;\n+\t\t\t/* Only find the path to follow in the other parents */\n+\t\t\tfollow_only = 1;\n+\t\t\topt->diffopt.flags.follow_renames = 0;\n+\t\t}\n \t\tif (path)\n \t\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec,\n \t\t\t\t\t\t    path);\ndiff --git a/t/t4219-log-follow-merge.sh b/t/t4219-log-follow-merge.sh\nindex c8474ed151..a85fb78ca2 100755\n--- a/t/t4219-log-follow-merge.sh\n+++ b/t/t4219-log-follow-merge.sh\n@@ -254,4 +254,47 @@ test_expect_success '--follow follows a rename on the side the merge did not tak\n \ttest_cmp expect actual\n '\n \n+test_expect_success '--follow with --diff-merges=first-parent follows all parents' '\n+\tgit -C keep log --follow --diff-merges=first-parent --no-patch \\\n+\t\t--pretty=tformat:%s F >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tB2: update G\n+\tB1: rename F to G\n+\tA1: update F in place\n+\tO: add F\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'setup merge keeping the renamed path, other side edited the old one' '\n+\tgit init keep-renamed &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >keep-renamed/F &&\n+\tgit -C keep-renamed add F &&\n+\ttest_tick &&\n+\tgit -C keep-renamed commit -m \"O: add F\" &&\n+\tgit -C keep-renamed branch B &&\n+\tgit -C keep-renamed mv F G &&\n+\ttest_tick &&\n+\tgit -C keep-renamed commit -m \"A1: rename F to G on master\" &&\n+\n+\tgit -C keep-renamed checkout B &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4 T\\nline 5\\n\" >keep-renamed/F &&\n+\ttest_tick &&\n+\tgit -C keep-renamed commit -am \"B2: update F on B\" &&\n+\n+\tgit -C keep-renamed checkout master &&\n+\ttest_tick &&\n+\tgit -C keep-renamed merge -s ours -m \"M: merge B, keep G, drop F\" B\n+'\n+\n+test_expect_success '--follow follows an edit on the side the merge did not take' '\n+\tgit -C keep-renamed log --follow --pretty=tformat:%s G >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tB2: update F on B\n+\tA1: rename F to G on master\n+\tO: add F\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.56.0\n\n\n"},{"id":"556960","messageId":"aabf5652c91f2a38ab3cb8b18c7c368ec7269201.1793298331.git.vmiklos@collabora.com","threadId":"66514","inReplyTo":"cover.1793298331.git.vmiklos@collabora.com","subject":"[PATCH v4 1/6] t4219: test more --follow cases across merges","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-10-30T20:07:28Z","receivedAt":"2026-10-30T20:07:28Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"A later commit in this series will speed up 'git log --follow' for\nmerge commits. Add tests for cases which already work, but had no\ntest coverage, so it's easy to break them while optimizing:\n\n- --follow through a fork with renames on both sides, with -c, --cc\n  and --remerge-diff\n- a --no-ff merge taking a rename from the second parent, in both commit\n  orders, since the result could depend on the walk order\n- a merge keeping the path, while the other side renamed it\n- --diff-merges=first-parent, which diffs merges only against their\n  first parent, but still walks all parents\n\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n t/t4219-log-follow-merge.sh | 124 ++++++++++++++++++++++++++++++++++++\n 1 file changed, 124 insertions(+)\n\ndiff --git a/t/t4219-log-follow-merge.sh b/t/t4219-log-follow-merge.sh\nindex e370f82955..c109c29f70 100755\n--- a/t/t4219-log-follow-merge.sh\n+++ b/t/t4219-log-follow-merge.sh\n@@ -126,4 +126,128 @@ test_expect_success '--follow follows renames through a fork in a single history\n \ttest_cmp expect actual.sorted\n '\n \n+for opt in -c --cc --remerge-diff\n+do\n+\ttest_expect_success \"--follow follows renames through a fork with $opt\" '\n+\t\tgit -C diamond log --follow $opt --pretty=tformat:%s path >log &&\n+\t\tgrep \"^[A-Z]: \" log | sort >actual &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tA: add path0\n+\t\tB: modify path0 on upper\n+\t\tC: modify path0 on lower\n+\t\tM: merge with rename to path\n+\t\tX: rename path0 to path1\n+\t\tY: rename path0 to path2\n+\t\tZ: modify path\n+\t\tEOF\n+\t\ttest_cmp expect actual\n+\t'\n+done\n+\n+# Build a merge that takes the renamed path from the second parent, while the\n+# first parent only has the old path. $2 decides which side is committed first,\n+# which decides the walk order.\n+setup_rename_on_second_parent () {\n+\tgit init $1 &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >$1/old &&\n+\tgit -C $1 add old &&\n+\ttest_tick &&\n+\tgit -C $1 commit -m \"A: add old\" &&\n+\tprintf \"line 1\\nline 2\\nline 3 modified\\nline 4\\nline 5\\n\" >$1/old &&\n+\ttest_tick &&\n+\tgit -C $1 commit -am \"B: modify old\" &&\n+\tgit -C $1 branch topic &&\n+\n+\tif test \"$2\" = topic-first\n+\tthen\n+\t\tgit -C $1 checkout topic &&\n+\t\tgit -C $1 mv old new &&\n+\t\ttest_tick &&\n+\t\tgit -C $1 commit -m \"R: rename old to new\" &&\n+\t\tgit -C $1 checkout master\n+\tfi &&\n+\n+\techo other >$1/other &&\n+\tgit -C $1 add other &&\n+\ttest_tick &&\n+\tgit -C $1 commit -m \"M: unrelated change on master\" &&\n+\n+\tif test \"$2\" = master-first\n+\tthen\n+\t\tgit -C $1 checkout topic &&\n+\t\tgit -C $1 mv old new &&\n+\t\ttest_tick &&\n+\t\tgit -C $1 commit -m \"R: rename old to new\" &&\n+\t\tgit -C $1 checkout master\n+\tfi &&\n+\n+\ttest_tick &&\n+\tgit -C $1 merge --no-ff -m \"merge topic\" topic\n+}\n+\n+test_expect_success 'setup merge taking a rename from the second parent' '\n+\tsetup_rename_on_second_parent rename-master-first master-first &&\n+\tsetup_rename_on_second_parent rename-topic-first topic-first\n+'\n+\n+for order in master-first topic-first\n+do\n+\ttest_expect_success \"--follow follows a rename from the second parent ($order)\" '\n+\t\tgit -C rename-$order log --follow --pretty=tformat:%s new >actual &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tR: rename old to new\n+\t\tB: modify old\n+\t\tA: add old\n+\t\tEOF\n+\t\ttest_cmp expect actual\n+\t'\n+done\n+\n+test_expect_success 'setup merge keeping the path, other side renamed it' '\n+\tgit init keep &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >keep/F &&\n+\tgit -C keep add F &&\n+\ttest_tick &&\n+\tgit -C keep commit -m \"O: add F\" &&\n+\tgit -C keep branch B &&\n+\tprintf \"line 1\\nline 2\\nline 3 A\\nline 4\\nline 5\\n\" >keep/F &&\n+\ttest_tick &&\n+\tgit -C keep commit -am \"A1: update F in place\" &&\n+\n+\tgit -C keep checkout B &&\n+\tgit -C keep mv F G &&\n+\ttest_tick &&\n+\tgit -C keep commit -m \"B1: rename F to G\" &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4 B\\nline 5\\n\" >keep/G &&\n+\ttest_tick &&\n+\tgit -C keep commit -am \"B2: update G\" &&\n+\n+\tgit -C keep checkout master &&\n+\ttest_tick &&\n+\tgit -C keep merge -s ours -m \"M: merge B, keep F, drop G\" B\n+'\n+\n+test_expect_success '--follow follows a rename on the side the merge did not take' '\n+\tgit -C keep log --follow --pretty=tformat:%s F >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tB2: update G\n+\tB1: rename F to G\n+\tA1: update F in place\n+\tO: add F\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success '--follow with --diff-merges=first-parent follows all parents' '\n+\tgit -C keep log --follow --diff-merges=first-parent --no-patch \\\n+\t\t--pretty=tformat:%s F >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tB2: update G\n+\tB1: rename F to G\n+\tA1: update F in place\n+\tO: add F\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.56.0\n\n\n"},{"id":"556961","messageId":"b172890bf4c80d54e653168baf9fad65073fa667.1793298331.git.vmiklos@collabora.com","threadId":"66514","inReplyTo":"cover.1793298331.git.vmiklos@collabora.com","subject":"[PATCH v4 2/6] log: extract showing the remerge/combined diff of a merge commit","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-10-30T20:07:53Z","receivedAt":"2026-10-30T20:07:53Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"No functional changes intended. A later commit in this series will also\ncall log_tree_merge_diff() after the parent loop of log_tree_diff(), so\nextract that code to a function to avoid duplicating it.\n\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n log-tree.c | 36 ++++++++++++++++++++++--------------\n 1 file changed, 22 insertions(+), 14 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex 83a3c4bf9b..b4c97b86f5 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -1180,6 +1180,26 @@ static void propagate_follow_pathspec_to_parent(struct rev_info *opt,\n \tdiff_free(&diff_opts);\n }\n \n+/* Show the remerge or combined diff of a merge commit */\n+static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,\n+\t\t\t       struct commit_list *parents,\n+\t\t\t       struct object_id *oid)\n+{\n+\tint octopus = (parents->next->next != NULL);\n+\n+\tif (opt->remerge_diff) {\n+\t\tif (octopus) {\n+\t\t\tshow_log(opt);\n+\t\t\tfprintf(opt->diffopt.file,\n+\t\t\t\t\"diff: warning: Skipping remerge-diff \"\n+\t\t\t\t\"for octopus merges.\\n\");\n+\t\t\treturn 1;\n+\t\t}\n+\t\treturn do_remerge_diff(opt, parents, oid);\n+\t}\n+\treturn do_diff_combined(opt, commit);\n+}\n+\n /*\n  * Show the diff of a commit.\n  *\n@@ -1220,20 +1240,8 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t}\n \n \tif (is_merge) {\n-\t\tint octopus = (parents->next->next != NULL);\n-\n-\t\tif (opt->remerge_diff) {\n-\t\t\tif (octopus) {\n-\t\t\t\tshow_log(opt);\n-\t\t\t\tfprintf(opt->diffopt.file,\n-\t\t\t\t\t\"diff: warning: Skipping remerge-diff \"\n-\t\t\t\t\t\"for octopus merges.\\n\");\n-\t\t\t\treturn 1;\n-\t\t\t}\n-\t\t\treturn do_remerge_diff(opt, parents, oid);\n-\t\t}\n-\t\tif (opt->combine_merges)\n-\t\t\treturn do_diff_combined(opt, commit);\n+\t\tif (opt->remerge_diff || opt->combine_merges)\n+\t\t\treturn log_tree_merge_diff(opt, commit, parents, oid);\n \t\tif (opt->separate_merges) {\n \t\t\tif (!opt->first_parent_merges) {\n \t\t\t\t/* Show parent info for multiple diffs */\n-- \n2.56.0\n\n\n"},{"id":"556962","messageId":"6586e8f00456a9b80d85b79284a8fb8f9819d1d6.1793298331.git.vmiklos@collabora.com","threadId":"66514","inReplyTo":"cover.1793298331.git.vmiklos@collabora.com","subject":"[PATCH v4 3/6] log: fix -m --follow losing the history of later parents","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-10-30T20:08:19Z","receivedAt":"2026-10-30T20:08:19Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"With 'git log -m --follow', a merge is diffed against each of its\nparents, with rename following. Take the diamond case of t4219: the two\nsides of a fork rename path0 to path1 and to path2, and the merge\nrenames the file to path. Here 'git log -m --follow path' doesn't show\n\"A: add path0\" and \"C: modify path0 on lower\".\n\nThe problem is that the parent loop in log_tree_diff() doesn't restore\nthe followed path between parents. When the diff against the first\nparent finds a rename, the followed path is updated, and this has two\neffects. First, the second parent is diffed with the already renamed\npath, not with the path of the merge. Second, the path that\npropagate_follow_pathspec_to_parent() records for each parent also\nstarts from that updated path, so history is lost on the side of the\nsecond parent. Without -m, merges are not diffed, so the followed path\nis not updated there.\n\nFix the problem by saving the path of the merge before the parent loop,\nand restoring it before diffing each parent and after the loop. Do this\nonly for merges: for a commit with a single parent, the renamed path is\nwhat --follow needs to continue with. Add a test for this, which shows\nthe full history of the diamond case with -m.\n\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n log-tree.c                  | 13 +++++++++++++\n t/t4219-log-follow-merge.sh | 16 ++++++++++++++++\n 2 files changed, 29 insertions(+)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex b4c97b86f5..befc5c8b22 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -1212,6 +1212,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \tstruct object_id *oid;\n \tint is_merge;\n \tint all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;\n+\tchar *path = NULL;\n \n \tif (!all_need_diff && !opt->merges_need_diff)\n \t\treturn 0;\n@@ -1251,10 +1252,18 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t\t\treturn 0;\n \t}\n \n+\tif (is_merge && opt->diffopt.flags.follow_renames)\n+\t\tpath = xstrdup_or_null(\n+\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n+\n \tshowed_log = 0;\n \tfor (;;) {\n \t\tstruct commit *parent = parents->item;\n \n+\t\t/* Diff each parent with the path of the merge */\n+\t\tif (path)\n+\t\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec,\n+\t\t\t\t\t\t    path);\n \t\tparse_commit_or_die(parent);\n \t\tdiff_tree_oid(get_commit_tree_oid(parent),\n \t\t\t      oid, \"\", &opt->diffopt);\n@@ -1269,6 +1278,10 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t\tlog->parent = parents->item;\n \t\topt->loginfo = log;\n \t}\n+\t/* Propagate to parents starting from the path of the merge, too */\n+\tif (path)\n+\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec, path);\n+\tfree(path);\n \treturn showed_log;\n }\n \ndiff --git a/t/t4219-log-follow-merge.sh b/t/t4219-log-follow-merge.sh\nindex c109c29f70..36204ae2bf 100755\n--- a/t/t4219-log-follow-merge.sh\n+++ b/t/t4219-log-follow-merge.sh\n@@ -144,6 +144,22 @@ do\n \t'\n done\n \n+test_expect_success '--follow follows renames through a fork with -m' '\n+\tgit -C diamond log --follow -m --pretty=tformat:%s path >log &&\n+\tgrep \"^[A-Z]: \" log | sort >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tA: add path0\n+\tB: modify path0 on upper\n+\tC: modify path0 on lower\n+\tM: merge with rename to path\n+\tM: merge with rename to path\n+\tX: rename path0 to path1\n+\tY: rename path0 to path2\n+\tZ: modify path\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n # Build a merge that takes the renamed path from the second parent, while the\n # first parent only has the old path. $2 decides which side is committed first,\n # which decides the walk order.\n-- \n2.56.0\n\n\n"},{"id":"556963","messageId":"b903152bc4bd977e4f4eeec9476d8faa2114b7b2.1793298331.git.vmiklos@collabora.com","threadId":"66514","inReplyTo":"cover.1793298331.git.vmiklos@collabora.com","subject":"[PATCH v4 4/6] log: simplify --follow following renames for non-linear history","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-10-30T20:08:43Z","receivedAt":"2026-10-30T20:08:43Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Code added in 304812ed33 (log: improve --follow following renames for\nnon-linear history, 2026-06-22) implemented the feature by introducing a\nnew propagate_follow_pathspec_to_parent() function which adds a new call\nto diff_tree_oid(). Also it introduces a new loop to record what path\neach parent of a merge commit should use when following a path.\n\nThis was working, but it caused a performance regression: e.g. 'git log\n--stat --follow -- include/linux/rsc_table.h' in linux.git went from 28s\nto 6m43s. The new code diffs each merge against each of its parents with\nrename detection, which is expensive when a parent doesn't have the\nfollowed path yet. Fixing this would require adding even more custom\ncode, instead of just extending the existing code in log_tree_diff(). So\nfirst simplify the code here, and fix the performance regression in a\nfollow-up commit.\n\nRemove propagate_follow_pathspec_to_parent() and the loop calling it\nfor each parent. Instead, record the path to follow for each parent in\nthe parent loop of log_tree_diff(), right after diff_tree_oid() updated\nthe pathspec in case of a rename. Merges are not diffed by default, so\nwith --follow, run the same loop for them as well, but without showing\nanything. With -c, --cc or --remerge-diff, show the merge diff after the\nloop. With --diff-merges=first-parent, keep diffing the other parents\nsilently, unless the walk only follows first parents. This gets rid of\nthe additional call to diff_tree_oid(). The rework has no positive\nperformance impact yet, it just simplifies the code.\n\nThe previous commit restores the path of the merge before diffing each\nparent, and also after the loop, for\npropagate_follow_pathspec_to_parent(). Keep restoring it between\nparents, but not after the loop, since there is no later propagation\nanymore.\n\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n log-tree.c | 96 +++++++++++++++++++++++-------------------------------\n 1 file changed, 41 insertions(+), 55 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex befc5c8b22..0aa27fb210 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -1153,33 +1153,6 @@ void release_follow_pathspec_slab(struct rev_info *opt)\n \tFREE_AND_NULL(opt->follow_pathspec_slab);\n }\n \n-/* Compute a path to follow in parent, if there is one */\n-static void propagate_follow_pathspec_to_parent(struct rev_info *opt,\n-\t\t\t\t\t\tstruct commit *commit,\n-\t\t\t\t\t\tstruct commit *parent)\n-{\n-\tstruct diff_options diff_opts;\n-\tconst char *path;\n-\n-\tparse_commit_or_die(parent);\n-\trepo_diff_setup(opt->diffopt.repo, &diff_opts);\n-\tcopy_pathspec(&diff_opts.pathspec, &opt->diffopt.pathspec);\n-\tdiff_opts.flags.recursive = 1;\n-\tdiff_opts.flags.follow_renames = 1;\n-\tdiff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;\n-\tdiff_setup_done(&diff_opts);\n-\tdiff_tree_oid(get_commit_tree_oid(parent),\n-\t\t      get_commit_tree_oid(commit),\n-\t\t      \"\", &diff_opts);\n-\n-\tpath = pathspec_single_path(&diff_opts.pathspec);\n-\tif (path)\n-\t\tremember_follow_pathspec(opt, parent, path);\n-\n-\tdiff_queue_clear(&diff_queued_diff);\n-\tdiff_free(&diff_opts);\n-}\n-\n /* Show the remerge or combined diff of a merge commit */\n static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,\n \t\t\t       struct commit_list *parents,\n@@ -1208,10 +1181,11 @@ static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,\n static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log)\n {\n \tint showed_log;\n-\tstruct commit_list *parents;\n+\tstruct commit_list *parents, *all_parents;\n \tstruct object_id *oid;\n \tint is_merge;\n \tint all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;\n+\tint follow_only = 0;\n \tchar *path = NULL;\n \n \tif (!all_need_diff && !opt->merges_need_diff)\n@@ -1241,46 +1215,73 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t}\n \n \tif (is_merge) {\n-\t\tif (opt->remerge_diff || opt->combine_merges)\n+\t\tint merge_diff = opt->remerge_diff || opt->combine_merges;\n+\n+\t\tif (merge_diff && !opt->diffopt.flags.follow_renames)\n \t\t\treturn log_tree_merge_diff(opt, commit, parents, oid);\n-\t\tif (opt->separate_merges) {\n+\t\tif (opt->separate_merges && !merge_diff) {\n \t\t\tif (!opt->first_parent_merges) {\n \t\t\t\t/* Show parent info for multiple diffs */\n \t\t\t\tlog->parent = parents->item;\n \t\t\t}\n+\t\t} else if (opt->diffopt.flags.follow_renames) {\n+\t\t\t/* Diff only to find the path to follow in parents */\n+\t\t\tfollow_only = 1;\n \t\t} else\n \t\t\treturn 0;\n \t}\n \n-\tif (is_merge && opt->diffopt.flags.follow_renames)\n+\tif (opt->diffopt.flags.follow_renames)\n \t\tpath = xstrdup_or_null(\n \t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n \n \tshowed_log = 0;\n+\tall_parents = parents;\n \tfor (;;) {\n \t\tstruct commit *parent = parents->item;\n \n-\t\t/* Diff each parent with the path of the merge */\n-\t\tif (path)\n-\t\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec,\n-\t\t\t\t\t\t    path);\n \t\tparse_commit_or_die(parent);\n \t\tdiff_tree_oid(get_commit_tree_oid(parent),\n \t\t\t      oid, \"\", &opt->diffopt);\n-\t\tlog_tree_diff_flush(opt);\n+\t\tif (follow_only) {\n+\t\t\tdiff_queue_clear(&diff_queued_diff);\n+\t\t\topt->diffopt.found_follow = 0;\n+\t\t} else {\n+\t\t\tlog_tree_diff_flush(opt);\n+\t\t}\n \n \t\tshowed_log |= !opt->loginfo;\n \n+\t\t/* The diff updated the pathspec in case of a rename */\n+\t\tif (path)\n+\t\t\tremember_follow_pathspec(opt, parent,\n+\t\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n+\n \t\t/* Set up the log info for the next parent, if any.. */\n \t\tparents = parents->next;\n-\t\tif (!parents || opt->first_parent_merges)\n+\t\tif (!parents)\n \t\t\tbreak;\n+\t\tif (opt->first_parent_merges) {\n+\t\t\tif (!path || opt->first_parent_only)\n+\t\t\t\tbreak;\n+\t\t\t/* Only find the path to follow in the other parents */\n+\t\t\tfollow_only = 1;\n+\t\t}\n+\t\tif (path)\n+\t\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec,\n+\t\t\t\t\t\t    path);\n+\t\tif (follow_only)\n+\t\t\tcontinue;\n \t\tlog->parent = parents->item;\n \t\topt->loginfo = log;\n \t}\n-\t/* Propagate to parents starting from the path of the merge, too */\n-\tif (path)\n-\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec, path);\n+\tif (follow_only && (opt->remerge_diff || opt->combine_merges)) {\n+\t\t/* Show the merge diff with the path of this commit */\n+\t\tif (path)\n+\t\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec,\n+\t\t\t\t\t\t    path);\n+\t\tshowed_log = log_tree_merge_diff(opt, commit, all_parents, oid);\n+\t}\n \tfree(path);\n \treturn showed_log;\n }\n@@ -1319,21 +1320,6 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)\n \t\tfprintf(opt->diffopt.file, \"\\n%s\\n\", opt->break_bar);\n \tif (shown)\n \t\tshow_diff_of_diff(opt);\n-\n-\t/* Record what path each parent of this commit should use */\n-\tif (opt->diffopt.flags.follow_renames) {\n-\t\tstruct commit_list *parents = get_saved_parents(opt, commit);\n-\t\tif (parents && parents->next) {\n-\t\t\tstruct commit_list *p;\n-\t\t\tfor (p = parents; p; p = p->next)\n-\t\t\t\tpropagate_follow_pathspec_to_parent(opt, commit,\n-\t\t\t\t\t\t\t\t    p->item);\n-\t\t} else if (parents) {\n-\t\t\tremember_follow_pathspec(opt, parents->item,\n-\t\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n-\t\t}\n-\t}\n-\n \topt->loginfo = NULL;\n \tmaybe_flush_or_die(opt->diffopt.file, \"stdout\");\n \topt->diffopt.no_free = no_free;\n-- \n2.56.0\n\n\n"},{"id":"556964","messageId":"072d90b865c9c046f7c0dd00a265eb11bc9b48a2.1793298331.git.vmiklos@collabora.com","threadId":"66514","inReplyTo":"cover.1793298331.git.vmiklos@collabora.com","subject":"[PATCH v4 5/6] log: speed up --follow following renames for non-linear history","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-10-30T20:09:11Z","receivedAt":"2026-10-30T20:09:11Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Test the performance of 'git log --stat --follow --\ninclude/linux/rsc_table.h' on linux.git, it used to take about 28\nseconds, and since commit 304812ed33 (log: improve --follow following\nrenames for non-linear history, 2026-06-22), it takes 6m43s.\n\nWhat happens is that log_tree_diff() diffs each merge against all of its\nparents with rename following. diff_tree_oid() only does the expensive\nrename detection when the path is added relative to a parent, but that\nis common for merges, e.g. when a branch forked before the path was\ncreated merges mainline, and this slows down 'git log --follow'.\n\nFix the problem by diffing the merge against its parents in two passes:\n- First pass: diff against the parents without rename following. If the\n  path is unchanged against a parent, then just follow that history in\n  all parents.\n  - Except when an other parent doesn't have the path, the merge has it\n    and a merge base of the two parents also has it, i.e. the path was\n    renamed or removed on that side: still do the rename following\n    against such a parent, otherwise the history on that side would be\n    lost. The merge base is only computed in this rare case, and\n    back-merges where the path was created after the other side forked\n    still skip the expensive rename detection.\n- Second pass: only do the rename following against each parent if the\n  path changed relative to all parents.\nGiven that this way a parent may be asked to follow a path that it\ndoesn't have, also adjust remember_follow_pathspec(): if children\ndisagree on what should be the path for a commit, then prefer the path\nthat exists in that commit.\n\nNow the above use case takes 36s, somewhat close to the original cost.\n\nHelped-by: SZEDER Gábor <szeder.dev@gmail.com>\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n log-tree.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++---\n 1 file changed, 91 insertions(+), 5 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex 0aa27fb210..0dc71be61e 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -31,6 +31,7 @@\n #include \"range-diff.h\"\n #include \"strmap.h\"\n #include \"tree.h\"\n+#include \"tree-walk.h\"\n #include \"wildmatch.h\"\n #include \"write-or-die.h\"\n #include \"pager.h\"\n@@ -1110,6 +1111,17 @@ static void set_pathspec_to_single_path(struct pathspec *ps, const char *path)\n \t\t       PATHSPEC_LITERAL_PATH, \"\", paths);\n }\n \n+static int commit_has_path(struct rev_info *opt, struct commit *c,\n+\t\t\t   const char *path)\n+{\n+\tstruct object_id oid;\n+\tunsigned short mode;\n+\n+\tparse_commit_or_die(c);\n+\treturn !get_tree_entry(opt->diffopt.repo, get_commit_tree_oid(c), path,\n+\t\t\t       &oid, &mode);\n+}\n+\n static void remember_follow_pathspec(struct rev_info *opt,\n \t\t\t\t     struct commit *c, const char *path)\n {\n@@ -1122,8 +1134,12 @@ static void remember_follow_pathspec(struct rev_info *opt,\n \t\tinit_follow_pathspec_slab(opt->follow_pathspec_slab);\n \t}\n \tslot = follow_pathspec_slab_at(opt->follow_pathspec_slab, c);\n-\tif (*slot && !strcmp(*slot, path))\n-\t\treturn;\n+\t/* If children of 'c' disagree on the path, prefer the one 'c' has. */\n+\tif (*slot) {\n+\t\tif (!strcmp(*slot, path) || commit_has_path(opt, c, *slot) ||\n+\t\t    !commit_has_path(opt, c, path))\n+\t\t\treturn;\n+\t}\n \tfree(*slot);\n \t*slot = xstrdup(path);\n }\n@@ -1153,6 +1169,29 @@ void release_follow_pathspec_slab(struct rev_info *opt)\n \tFREE_AND_NULL(opt->follow_pathspec_slab);\n }\n \n+/*\n+ * When the path in a merge is the same as in 'same', does the path still need\n+ * renames to be followed in 'parent'? Only if the merge has the path, 'parent'\n+ * doesn't have it, but its fork point with 'same' had it, e.g. 'parent'\n+ * renamed the path.\n+ */\n+static int follow_needs_renames(struct rev_info *opt, struct commit *parent,\n+\t\t\t\tstruct commit *same, const char *path)\n+{\n+\tstruct commit_list *bases = NULL, *base;\n+\tint ret = 0;\n+\n+\tif (commit_has_path(opt, parent, path) ||\n+\t    !commit_has_path(opt, same, path))\n+\t\treturn 0;\n+\tif (repo_get_merge_bases(opt->diffopt.repo, parent, same, &bases) < 0)\n+\t\texit(128);\n+\tfor (base = bases; base && !ret; base = base->next)\n+\t\tret = commit_has_path(opt, base->item, path);\n+\tcommit_list_free(bases);\n+\treturn ret;\n+}\n+\n /* Show the remerge or combined diff of a merge commit */\n static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,\n \t\t\t       struct commit_list *parents,\n@@ -1181,7 +1220,7 @@ static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,\n static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log)\n {\n \tint showed_log;\n-\tstruct commit_list *parents, *all_parents;\n+\tstruct commit_list *parents, *all_parents, *rename_parents = NULL;\n \tstruct object_id *oid;\n \tint is_merge;\n \tint all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;\n@@ -1235,15 +1274,25 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t\tpath = xstrdup_or_null(\n \t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n \n+\tif (follow_only) {\n+\t\t/*\n+\t\t * First look for a parent where the path is unchanged, without\n+\t\t * the expensive rename detection.\n+\t\t */\n+\t\topt->diffopt.flags.follow_renames = 0;\n+\t}\n+\n \tshowed_log = 0;\n \tall_parents = parents;\n \tfor (;;) {\n \t\tstruct commit *parent = parents->item;\n+\t\tint changed = 1;\n \n \t\tparse_commit_or_die(parent);\n \t\tdiff_tree_oid(get_commit_tree_oid(parent),\n \t\t\t      oid, \"\", &opt->diffopt);\n \t\tif (follow_only) {\n+\t\t\tchanged = diff_queued_diff.nr;\n \t\t\tdiff_queue_clear(&diff_queued_diff);\n \t\t\topt->diffopt.found_follow = 0;\n \t\t} else {\n@@ -1252,20 +1301,54 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \n \t\tshowed_log |= !opt->loginfo;\n \n+\t\tif (!changed) {\n+\t\t\t/*\n+\t\t\t * Same as in this parent, follow that history, but\n+\t\t\t * still look for renames in parents that had the path\n+\t\t\t * at the fork point.\n+\t\t\t */\n+\t\t\tstruct commit_list **tail = &rename_parents;\n+\n+\t\t\tfor (parents = all_parents; parents;\n+\t\t\t     parents = parents->next) {\n+\t\t\t\tif (parents->item != parent &&\n+\t\t\t\t    follow_needs_renames(opt, parents->item,\n+\t\t\t\t\t\t\t parent, path))\n+\t\t\t\t\ttail = &commit_list_insert(parents->item,\n+\t\t\t\t\t\t\t\t   tail)->next;\n+\t\t\t\telse\n+\t\t\t\t\tremember_follow_pathspec(opt,\n+\t\t\t\t\t\t\t\t parents->item,\n+\t\t\t\t\t\t\t\t path);\n+\t\t\t}\n+\t\t\tif (!rename_parents)\n+\t\t\t\tbreak;\n+\t\t\topt->diffopt.flags.follow_renames = 1;\n+\t\t\tparents = rename_parents;\n+\t\t\tcontinue;\n+\t\t}\n+\n \t\t/* The diff updated the pathspec in case of a rename */\n-\t\tif (path)\n+\t\tif (path && opt->diffopt.flags.follow_renames)\n \t\t\tremember_follow_pathspec(opt, parent,\n \t\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n \n \t\t/* Set up the log info for the next parent, if any.. */\n \t\tparents = parents->next;\n+\t\tif (!parents && follow_only &&\n+\t\t    !opt->diffopt.flags.follow_renames) {\n+\t\t\t/* The path changed in all parents, look for renames. */\n+\t\t\topt->diffopt.flags.follow_renames = 1;\n+\t\t\tparents = all_parents;\n+\t\t}\n \t\tif (!parents)\n \t\t\tbreak;\n-\t\tif (opt->first_parent_merges) {\n+\t\tif (opt->first_parent_merges && !follow_only) {\n \t\t\tif (!path || opt->first_parent_only)\n \t\t\t\tbreak;\n \t\t\t/* Only find the path to follow in the other parents */\n \t\t\tfollow_only = 1;\n+\t\t\topt->diffopt.flags.follow_renames = 0;\n \t\t}\n \t\tif (path)\n \t\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec,\n@@ -1275,6 +1358,8 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t\tlog->parent = parents->item;\n \t\topt->loginfo = log;\n \t}\n+\tif (follow_only)\n+\t\topt->diffopt.flags.follow_renames = 1;\n \tif (follow_only && (opt->remerge_diff || opt->combine_merges)) {\n \t\t/* Show the merge diff with the path of this commit */\n \t\tif (path)\n@@ -1282,6 +1367,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t\t\t\t\t\t    path);\n \t\tshowed_log = log_tree_merge_diff(opt, commit, all_parents, oid);\n \t}\n+\tcommit_list_free(rename_parents);\n \tfree(path);\n \treturn showed_log;\n }\n-- \n2.56.0\n\n\n"},{"id":"556965","messageId":"7be8cfb3ba58a4d4dc040fb2f229524599524b78.1793298331.git.vmiklos@collabora.com","threadId":"66514","inReplyTo":"cover.1793298331.git.vmiklos@collabora.com","subject":"[PATCH v4 6/6] log: fix --follow following an edit on a side the merge did not take","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-10-30T20:10:14Z","receivedAt":"2026-10-30T20:10:14Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Take a history where F is renamed to G on master, F is edited on a side\nbranch, and the side branch is merged with '-s ours', so the merge keeps\nG and drops F. Here 'git log --follow G' doesn't show the edit of F on\nthe side branch, while it did before the previous commit.\n\nThe problem is that follow_needs_renames() only searches for renames in\na parent without the path if the merge base still has the path, which\ncovers the case when the parent renamed the path. Here the other side\nof the merge did the rename, so the merge base only has the old name.\nThe parent is then told to follow G, which it doesn't have, and the\nhistory of F on its side is lost. Searching for renames in each parent\nthat lacks the path would fix this, but that is the expensive search\nthat the previous commit avoids, e.g. 148 merges hit this case for\ninclude/linux/rsc_table.h in linux.git.\n\nFix the problem by also searching for renames when the merge base\ndoesn't have the path, but the parent changed a file since the merge\nbase that the merge no longer has: only such a file can be the old name\nof the path that still needs to be followed in the parent. This check\nis cheap, since it only diffs the changes of the side branch, and it\nrules out 146 of the 148 merges in linux.git. Then do a plain rename\ndetection from the parent to the merge, which only looks at the files\ndeleted by the merge, not at all files of the parent like --follow does.\n\nReported-by: Patrick Steinhardt <ps@pks.im>\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n log-tree.c                  | 96 +++++++++++++++++++++++++++++++++----\n t/t4219-log-follow-merge.sh | 31 ++++++++++++\n 2 files changed, 117 insertions(+), 10 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex 0dc71be61e..c2c3473f25 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -1111,15 +1111,20 @@ static void set_pathspec_to_single_path(struct pathspec *ps, const char *path)\n \t\t       PATHSPEC_LITERAL_PATH, \"\", paths);\n }\n \n-static int commit_has_path(struct rev_info *opt, struct commit *c,\n-\t\t\t   const char *path)\n+static int tree_has_path(struct rev_info *opt, struct object_id *tree,\n+\t\t\t const char *path)\n {\n \tstruct object_id oid;\n \tunsigned short mode;\n \n+\treturn !get_tree_entry(opt->diffopt.repo, tree, path, &oid, &mode);\n+}\n+\n+static int commit_has_path(struct rev_info *opt, struct commit *c,\n+\t\t\t   const char *path)\n+{\n \tparse_commit_or_die(c);\n-\treturn !get_tree_entry(opt->diffopt.repo, get_commit_tree_oid(c), path,\n-\t\t\t       &oid, &mode);\n+\treturn tree_has_path(opt, get_commit_tree_oid(c), path);\n }\n \n static void remember_follow_pathspec(struct rev_info *opt,\n@@ -1169,26 +1174,97 @@ void release_follow_pathspec_slab(struct rev_info *opt)\n \tFREE_AND_NULL(opt->follow_pathspec_slab);\n }\n \n+/*\n+ * Did 'parent' change a file since 'base' that the merge (with tree 'oid') no\n+ * longer has? Only such a file can be the source of a rename on the other side\n+ * of the merge that still needs to be followed in 'parent'.\n+ */\n+static int follow_parent_changed_dropped_file(struct rev_info *opt,\n+\t\t\t\t\t      struct commit *base,\n+\t\t\t\t\t      struct commit *parent,\n+\t\t\t\t\t      struct object_id *oid)\n+{\n+\tstruct diff_options diff_opts;\n+\tint i, ret = 0;\n+\n+\trepo_diff_setup(opt->diffopt.repo, &diff_opts);\n+\tdiff_opts.flags.recursive = 1;\n+\tdiff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;\n+\tdiff_setup_done(&diff_opts);\n+\tdiff_tree_oid(get_commit_tree_oid(base), get_commit_tree_oid(parent),\n+\t\t      \"\", &diff_opts);\n+\tfor (i = 0; i < diff_queued_diff.nr && !ret; i++) {\n+\t\tstruct diff_filepair *p = diff_queued_diff.queue[i];\n+\n+\t\tret = DIFF_FILE_VALID(p->two) &&\n+\t\t      !tree_has_path(opt, oid, p->two->path);\n+\t}\n+\tdiff_queue_clear(&diff_queued_diff);\n+\tdiff_free(&diff_opts);\n+\treturn ret;\n+}\n+\n+/*\n+ * Is 'path' in the merge (with tree 'oid') renamed from a file of 'parent'?\n+ * Only look at the files that the merge deleted, not at all files of 'parent'\n+ * like --follow does.\n+ */\n+static int follow_has_rename_source(struct rev_info *opt,\n+\t\t\t\t    struct commit *parent,\n+\t\t\t\t    struct object_id *oid, const char *path)\n+{\n+\tstruct diff_options diff_opts;\n+\tint i, ret = 0;\n+\n+\trepo_diff_setup(opt->diffopt.repo, &diff_opts);\n+\tdiff_opts.flags.recursive = 1;\n+\tdiff_opts.detect_rename = DIFF_DETECT_RENAME;\n+\tdiff_opts.rename_score = opt->diffopt.rename_score;\n+\tdiff_opts.single_follow = path;\n+\tdiff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;\n+\tdiff_setup_done(&diff_opts);\n+\tdiff_tree_oid(get_commit_tree_oid(parent), oid, \"\", &diff_opts);\n+\tdiffcore_std(&diff_opts);\n+\tfor (i = 0; i < diff_queued_diff.nr && !ret; i++) {\n+\t\tstruct diff_filepair *p = diff_queued_diff.queue[i];\n+\n+\t\tret = p->status == DIFF_STATUS_RENAMED &&\n+\t\t      !strcmp(p->two->path, path);\n+\t}\n+\tdiff_queue_clear(&diff_queued_diff);\n+\tdiff_free(&diff_opts);\n+\treturn ret;\n+}\n+\n /*\n  * When the path in a merge is the same as in 'same', does the path still need\n  * renames to be followed in 'parent'? Only if the merge has the path, 'parent'\n- * doesn't have it, but its fork point with 'same' had it, e.g. 'parent'\n- * renamed the path.\n+ * doesn't have it, and either:\n+ *\n+ * - its fork point with 'same' had it, e.g. 'parent' renamed the path, or\n+ * - 'same' renamed the path from a file that 'parent' changed.\n  */\n static int follow_needs_renames(struct rev_info *opt, struct commit *parent,\n-\t\t\t\tstruct commit *same, const char *path)\n+\t\t\t\tstruct commit *same, struct object_id *oid,\n+\t\t\t\tconst char *path)\n {\n \tstruct commit_list *bases = NULL, *base;\n-\tint ret = 0;\n+\tint ret = 0, changed_dropped = 0;\n \n \tif (commit_has_path(opt, parent, path) ||\n \t    !commit_has_path(opt, same, path))\n \t\treturn 0;\n \tif (repo_get_merge_bases(opt->diffopt.repo, parent, same, &bases) < 0)\n \t\texit(128);\n-\tfor (base = bases; base && !ret; base = base->next)\n+\tfor (base = bases; base && !ret; base = base->next) {\n \t\tret = commit_has_path(opt, base->item, path);\n+\t\tif (!ret && !changed_dropped)\n+\t\t\tchanged_dropped = follow_parent_changed_dropped_file(\n+\t\t\t\topt, base->item, parent, oid);\n+\t}\n \tcommit_list_free(bases);\n+\tif (!ret && changed_dropped)\n+\t\tret = follow_has_rename_source(opt, parent, oid, path);\n \treturn ret;\n }\n \n@@ -1313,7 +1389,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t\t\t     parents = parents->next) {\n \t\t\t\tif (parents->item != parent &&\n \t\t\t\t    follow_needs_renames(opt, parents->item,\n-\t\t\t\t\t\t\t parent, path))\n+\t\t\t\t\t\t\t parent, oid, path))\n \t\t\t\t\ttail = &commit_list_insert(parents->item,\n \t\t\t\t\t\t\t\t   tail)->next;\n \t\t\t\telse\ndiff --git a/t/t4219-log-follow-merge.sh b/t/t4219-log-follow-merge.sh\nindex 36204ae2bf..a85fb78ca2 100755\n--- a/t/t4219-log-follow-merge.sh\n+++ b/t/t4219-log-follow-merge.sh\n@@ -266,4 +266,35 @@ test_expect_success '--follow with --diff-merges=first-parent follows all parent\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'setup merge keeping the renamed path, other side edited the old one' '\n+\tgit init keep-renamed &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >keep-renamed/F &&\n+\tgit -C keep-renamed add F &&\n+\ttest_tick &&\n+\tgit -C keep-renamed commit -m \"O: add F\" &&\n+\tgit -C keep-renamed branch B &&\n+\tgit -C keep-renamed mv F G &&\n+\ttest_tick &&\n+\tgit -C keep-renamed commit -m \"A1: rename F to G on master\" &&\n+\n+\tgit -C keep-renamed checkout B &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4 T\\nline 5\\n\" >keep-renamed/F &&\n+\ttest_tick &&\n+\tgit -C keep-renamed commit -am \"B2: update F on B\" &&\n+\n+\tgit -C keep-renamed checkout master &&\n+\ttest_tick &&\n+\tgit -C keep-renamed merge -s ours -m \"M: merge B, keep G, drop F\" B\n+'\n+\n+test_expect_success '--follow follows an edit on the side the merge did not take' '\n+\tgit -C keep-renamed log --follow --pretty=tformat:%s G >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tB2: update F on B\n+\tA1: rename F to G on master\n+\tO: add F\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.56.0\n\n\n"},{"id":"557681","messageId":"au3gn7kUFYZWUinE@pks.im","threadId":"66514","inReplyTo":"cover.1793298331.git.vmiklos@collabora.com","subject":"Re: [PATCH v4 0/6] log: speed up --follow following renames for non-linear history","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T14:14:03Z","receivedAt":"2026-11-06T14:14:03Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Hi Miklos,\n\nOn Fri, Oct 30, 2026 at 09:07:00PM +0100, Miklos Vajna wrote:\n> Hi Patrick,\n> \n> Thanks for the reviews of v3. Changes in v4:\n\nplease note that the expectation is that you answer to the review\ncomments directly instead of only answering reviews via the cover letter\nof the next version. We want there to be discussions, and reviewers\nshould not have to figure out by themselves whether you did or did not\naddress specific concerns.\n\n> - Patch 6/6 fixes the case you found, where the speedup lost history:\n>   one side of the merge renamed the path, and the other side, whose\n>   version the merge dropped, edited the old name. It uses your test.\n>   I kept it separate from the speedup patch, which is complicated\n>   enough already. With the extra check, the linux.git case still takes\n>   about 37s.\n\nHmm, okay. But isn't it the case that your speedup patch introduces a\nregression where we now don't follow history in some specific cases\nanymore, and that regression was only introduced in the preceding\ncommit? So it's a bit curious to have this be an extra commit.\n\n> - I also noticed that the simplify patch lost history with\n>   --diff-merges=first-parent, which diffs merges only against their\n>   first parent, but still walks all parents. Fixed that and added a\n>   test for it to 1/6.\n\n> Interdiff against v3:\n\nInstead of an interdiff, could you please send a range-diff next time?\nThat makes it was easier to see which specific commits I need to have a\nlook at again, and it also shows diffs to commit messages.\n\nPatrick\n\n"},{"id":"557682","messageId":"au3gswJZzhutGlpR@pks.im","threadId":"66514","inReplyTo":"072d90b865c9c046f7c0dd00a265eb11bc9b48a2.1793298331.git.vmiklos@collabora.com","subject":"Re: [PATCH v4 5/6] log: speed up --follow following renames for non-linear history","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T14:14:11Z","receivedAt":"2026-11-06T14:14:11Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, Oct 30, 2026 at 09:09:11PM +0100, Miklos Vajna wrote:\n> diff --git a/log-tree.c b/log-tree.c\n> index 0aa27fb210..0dc71be61e 100644\n> --- a/log-tree.c\n> +++ b/log-tree.c\n> @@ -1153,6 +1169,29 @@ void release_follow_pathspec_slab(struct rev_info *opt)\n>  \tFREE_AND_NULL(opt->follow_pathspec_slab);\n>  }\n>  \n> +/*\n> + * When the path in a merge is the same as in 'same', does the path still need\n> + * renames to be followed in 'parent'? Only if the merge has the path, 'parent'\n> + * doesn't have it, but its fork point with 'same' had it, e.g. 'parent'\n> + * renamed the path.\n> + */\n> +static int follow_needs_renames(struct rev_info *opt, struct commit *parent,\n> +\t\t\t\tstruct commit *same, const char *path)\n> +{\n> +\tstruct commit_list *bases = NULL, *base;\n> +\tint ret = 0;\n> +\n> +\tif (commit_has_path(opt, parent, path) ||\n> +\t    !commit_has_path(opt, same, path))\n> +\t\treturn 0;\n> +\tif (repo_get_merge_bases(opt->diffopt.repo, parent, same, &bases) < 0)\n> +\t\texit(128);\n> +\tfor (base = bases; base && !ret; base = base->next)\n> +\t\tret = commit_has_path(opt, base->item, path);\n> +\tcommit_list_free(bases);\n> +\treturn ret;\n> +}\n\nWith unrelated histories this would return no bases at all, and hence\nwe'd always return 0 in such a case. But 304812ed33d (log: improve\n--follow following renames for non-linear history, 2026-06-22)\nexplicitly mentioned the use case of sub-tree merges of unrelated\nhistories, so isn't this a regression?\n\nPatrick\n\n"},{"id":"557683","messageId":"au3guSIBfekx7gNL@pks.im","threadId":"66514","inReplyTo":"7be8cfb3ba58a4d4dc040fb2f229524599524b78.1793298331.git.vmiklos@collabora.com","subject":"Re: [PATCH v4 6/6] log: fix --follow following an edit on a side the merge did not take","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T14:14:17Z","receivedAt":"2026-11-06T14:14:17Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, Oct 30, 2026 at 09:10:14PM +0100, Miklos Vajna wrote:\n> Take a history where F is renamed to G on master, F is edited on a side\n> branch, and the side branch is merged with '-s ours', so the merge keeps\n> G and drops F. Here 'git log --follow G' doesn't show the edit of F on\n> the side branch, while it did before the previous commit.\n> \n> The problem is that follow_needs_renames() only searches for renames in\n> a parent without the path if the merge base still has the path, which\n> covers the case when the parent renamed the path. Here the other side\n> of the merge did the rename, so the merge base only has the old name.\n> The parent is then told to follow G, which it doesn't have, and the\n> history of F on its side is lost. Searching for renames in each parent\n> that lacks the path would fix this, but that is the expensive search\n> that the previous commit avoids, e.g. 148 merges hit this case for\n> include/linux/rsc_table.h in linux.git.\n> \n> Fix the problem by also searching for renames when the merge base\n> doesn't have the path, but the parent changed a file since the merge\n> base that the merge no longer has: only such a file can be the old name\n> of the path that still needs to be followed in the parent.\n\nThis isn't true though in the case where you copy a file though, is it?\nE.g. the following test case is exactly the same as the one you add in\nthis commit, but instead of using a rename we use a copy:\n\ndiff --git a/t/t4219-log-follow-merge.sh b/t/t4219-log-follow-merge.sh\nindex a85fb78ca28..c67d9481ab5 100755\n--- a/t/t4219-log-follow-merge.sh\n+++ b/t/t4219-log-follow-merge.sh\n@@ -297,4 +297,36 @@ test_expect_success '--follow follows an edit on the side the merge did not take\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'setup merge keeping the copied path, other side edited the original' '\n+\tgit init keep-copied &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >keep-copied/F &&\n+\tgit -C keep-copied add F &&\n+\ttest_tick &&\n+\tgit -C keep-copied commit -m \"O: add F\" &&\n+\tgit -C keep-copied branch B &&\n+\tcp keep-copied/F keep-copied/G &&\n+\tgit -C keep-copied add G &&\n+\ttest_tick &&\n+\tgit -C keep-copied commit -m \"A1: copy F to G on master\" &&\n+\n+\tgit -C keep-copied checkout B &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4 T\\nline 5\\n\" >keep-copied/F &&\n+\ttest_tick &&\n+\tgit -C keep-copied commit -am \"B2: update F on B\" &&\n+\n+\tgit -C keep-copied checkout master &&\n+\ttest_tick &&\n+\tgit -C keep-copied merge -s ours -m \"M: merge B, keep F and G\" B\n+'\n+\n+test_expect_success '--follow follows an edit of the copy source on the side the merge did not take' '\n+\tgit -C keep-copied log --follow --pretty=tformat:%s G >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tB2: update F on B\n+\tA1: copy F to G on master\n+\tO: add F\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\n\nThis test passes on master, but fails with your patch series.\n\nPatrick\n\n"},{"id":"557887","messageId":"avF92deaqNI1G4vw@collabora.com","threadId":"66514","inReplyTo":"au3gn7kUFYZWUinE@pks.im","subject":"Re: [PATCH v4 0/6] log: speed up --follow following renames for non-linear history","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-11-09T08:01:29Z","receivedAt":"2026-11-09T08:01:29Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Hi Patrick,\n\nOn Fri, Nov 06, 2026 at 03:14:03PM +0100, Patrick Steinhardt <ps@pks.im> wrote:\n> please note that the expectation is that you answer to the review\n> comments directly instead of only answering reviews via the cover letter\n> of the next version. We want there to be discussions, and reviewers\n> should not have to figure out by themselves whether you did or did not\n> address specific concerns.\n\nI see, I'll stick to that way from now on.\n\n> Hmm, okay. But isn't it the case that your speedup patch introduces a\n> regression where we now don't follow history in some specific cases\n> anymore, and that regression was only introduced in the preceding\n> commit? So it's a bit curious to have this be an extra commit.\n\nI've squashed patch 6 into patch 5 in v5. This way 5/5 in v5 is a bit\nlarger, but no patch in the series fixes a regression from the same\nseries.\n\n> > Interdiff against v3:\n> \n> Instead of an interdiff, could you please send a range-diff next time?\n> That makes it was easier to see which specific commits I need to have a\n> look at again, and it also shows diffs to commit messages.\n\nI did it that way in v5.\n\nThanks,\n\nMiklos\n\n"},{"id":"557888","messageId":"avF-HwjximDD54P_@collabora.com","threadId":"66514","inReplyTo":"au3gswJZzhutGlpR@pks.im","subject":"Re: [PATCH v4 5/6] log: speed up --follow following renames for non-linear history","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-11-09T08:02:39Z","receivedAt":"2026-11-09T08:02:39Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Hi Patrick,\n\nOn Fri, Nov 06, 2026 at 03:14:11PM +0100, Patrick Steinhardt <ps@pks.im> wrote:\n> With unrelated histories this would return no bases at all, and hence\n> we'd always return 0 in such a case. But 304812ed33d (log: improve\n> --follow following renames for non-linear history, 2026-06-22)\n> explicitly mentioned the use case of sub-tree merges of unrelated\n> histories, so isn't this a regression?\n\nYou're right. The existing '--follow finds the pre-merge commit through\na subtree merge' test didn't catch this, because there no parent has the\npath unchanged, so follow_needs_renames() is not called.\n\nWhen there is no merge base, follow_needs_renames() now returns 1, so\nrenames are followed as before.\n\nI've added a new '--follow finds the history of a copied file through a\nsubtree merge' test to 1/5 in v5 for such a case, and 5/5 now passes it.\n\nThanks,\n\nMiklos\n\n"},{"id":"557889","messageId":"avF-N2Pva7mZE40M@collabora.com","threadId":"66514","inReplyTo":"au3guSIBfekx7gNL@pks.im","subject":"Re: [PATCH v4 6/6] log: fix --follow following an edit on a side the merge did not take","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-11-09T08:03:03Z","receivedAt":"2026-11-09T08:03:03Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Hi Patrick,\n\nOn Fri, Nov 06, 2026 at 03:14:17PM +0100, Patrick Steinhardt <ps@pks.im> wrote:\n> > Fix the problem by also searching for renames when the merge base\n> > doesn't have the path, but the parent changed a file since the merge\n> > base that the merge no longer has: only such a file can be the old name\n> > of the path that still needs to be followed in the parent.\n> \n> This isn't true though in the case where you copy a file though, is it?\n> E.g. the following test case is exactly the same as the one you add in\n> this commit, but instead of using a rename we use a copy:\n\nYou're right, I didn't consider copying. I've added your test to 1/5 and\nfixed 5/5 in v5 to handle this correctly.\n\nThe pre-filter now also takes a file into account that the merge still\nhas, but with the version of the other side, and the rename check now\nalso detects copies. This makes the linux.git case take about 42s,\ninstead of 37s here.\n\nThanks,\n\nMiklos\n\n"},{"id":"557890","messageId":"cover.1794078554.git.vmiklos@collabora.com","threadId":"66514","inReplyTo":"cover.1793298331.git.vmiklos@collabora.com","subject":"[PATCH v5 0/5] log: speed up --follow following renames for non-linear history","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-11-09T08:03:33Z","receivedAt":"2026-11-09T08:03:33Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Hi Patrick,\n\nThanks for the reviews of v4. Changes in v5:\n\n- The fix of the old 6/6 is now squashed into the speedup patch (5/5),\n  so no commit in the series loses history, and its test is moved to\n  1/5. While at it, I simplified 5/5: instead of two passes of diffs\n  against the parents, it first finds a parent where the path is\n  unchanged, and then only diffs against the other parents if they\n  still need renames to be followed. Because of the squash, the\n  range-diff pairs the new 5/5 with the old 6/6.\n\n- 5/5 now also follows renames when a parent has no merge base with\n  the parent where the path is unchanged, e.g. a subtree merge of\n  unrelated histories. Added a test for this to 1/5.\n\n- 5/5 now also follows copies, not only renames, when the merge dropped\n  the edit of the copy source. Added your test for this to 1/5. With\n  this, the linux.git case takes about 42s, instead of 37s.\n\nThanks,\n\nMiklos\n\nMiklos Vajna (5):\n  t4219: test more --follow cases across merges\n  log: extract showing the remerge/combined diff of a merge commit\n  log: fix -m --follow losing the history of later parents\n  log: simplify --follow following renames for non-linear history\n  log: speed up --follow following renames for non-linear history\n\n log-tree.c                  | 258 +++++++++++++++++++++++++++++-------\n t/t4219-log-follow-merge.sh | 230 ++++++++++++++++++++++++++++++++\n 2 files changed, 438 insertions(+), 50 deletions(-)\n\nRange-diff against v4:\n1:  aabf5652c9 ! 1:  5512aa682f t4219: test more --follow cases across merges\n    @@ Commit message\n         t4219: test more --follow cases across merges\n     \n         A later commit in this series will speed up 'git log --follow' for\n    -    merge commits. Add tests for cases which already work, but had no\n    +    merge commits. Add tests for cases which already work, but have no\n         test coverage, so it's easy to break them while optimizing:\n     \n    +    - a subtree merge adding the history of a file that was copied before\n         - --follow through a fork with renames on both sides, with -c, --cc\n           and --remerge-diff\n         - a --no-ff merge taking a rename from the second parent, in both commit\n    @@ Commit message\n         - a merge keeping the path, while the other side renamed it\n         - --diff-merges=first-parent, which diffs merges only against their\n           first parent, but still walks all parents\n    +    - a merge keeping the renamed path, while the other side edited the old\n    +      one\n    +    - a merge keeping the copied path, while the other side edited the\n    +      original\n     \n    +    Helped-by: Patrick Steinhardt <ps@pks.im>\n         Signed-off-by: Miklos Vajna <vmiklos@collabora.com>\n     \n      ## t/t4219-log-follow-merge.sh ##\n    +@@ t/t4219-log-follow-merge.sh: test_expect_success '--follow finds the pre-merge commit through a subtree merge\n    + \ttest_cmp expect actual\n    + '\n    + \n    ++test_expect_success 'setup subtree merge adding the history of a copied file' '\n    ++\tgit init graft &&\n    ++\techo outer >graft/outer.txt &&\n    ++\tgit -C graft add outer.txt &&\n    ++\ttest_tick &&\n    ++\tgit -C graft commit -m \"outer init\" &&\n    ++\tmkdir graft/inner &&\n    ++\tcp inner/inner.txt graft/inner/ &&\n    ++\tgit -C graft add inner &&\n    ++\ttest_tick &&\n    ++\tgit -C graft commit -m \"copy inner.txt to inner/\" &&\n    ++\n    ++\tgit -C graft fetch ../inner master &&\n    ++\ttest_tick &&\n    ++\tgit -C graft merge -s ours --allow-unrelated-histories \\\n    ++\t\t-m \"Merge the history of inner/\" FETCH_HEAD\n    ++'\n    ++\n    ++test_expect_success '--follow finds the history of a copied file through a subtree merge' '\n    ++\tgit -C graft log --follow --pretty=tformat:%s inner/inner.txt >actual &&\n    ++\tcat >expect <<-\\EOF &&\n    ++\tcopy inner.txt to inner/\n    ++\tinner init\n    ++\tEOF\n    ++\ttest_cmp expect actual\n    ++'\n    ++\n    + test_expect_success 'setup merge of two branches that both renamed a file to README' '\n    + \tgit init foo &&\n    + \tmkdir foo/foo &&\n     @@ t/t4219-log-follow-merge.sh: test_expect_success '--follow follows renames through a fork in a single history\n      \ttest_cmp expect actual.sorted\n      '\n    @@ t/t4219-log-follow-merge.sh: test_expect_success '--follow follows renames throu\n     +\tEOF\n     +\ttest_cmp expect actual\n     +'\n    ++\n    ++test_expect_success 'setup merge keeping the renamed path, other side edited the old one' '\n    ++\tgit init keep-renamed &&\n    ++\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >keep-renamed/F &&\n    ++\tgit -C keep-renamed add F &&\n    ++\ttest_tick &&\n    ++\tgit -C keep-renamed commit -m \"O: add F\" &&\n    ++\tgit -C keep-renamed branch B &&\n    ++\tgit -C keep-renamed mv F G &&\n    ++\ttest_tick &&\n    ++\tgit -C keep-renamed commit -m \"A1: rename F to G on master\" &&\n    ++\n    ++\tgit -C keep-renamed checkout B &&\n    ++\tprintf \"line 1\\nline 2\\nline 3\\nline 4 T\\nline 5\\n\" >keep-renamed/F &&\n    ++\ttest_tick &&\n    ++\tgit -C keep-renamed commit -am \"B2: update F on B\" &&\n    ++\n    ++\tgit -C keep-renamed checkout master &&\n    ++\ttest_tick &&\n    ++\tgit -C keep-renamed merge -s ours -m \"M: merge B, keep G, drop F\" B\n    ++'\n    ++\n    ++test_expect_success '--follow follows an edit on the side the merge did not take' '\n    ++\tgit -C keep-renamed log --follow --pretty=tformat:%s G >actual &&\n    ++\tcat >expect <<-\\EOF &&\n    ++\tB2: update F on B\n    ++\tA1: rename F to G on master\n    ++\tO: add F\n    ++\tEOF\n    ++\ttest_cmp expect actual\n    ++'\n    ++\n    ++test_expect_success 'setup merge keeping the copied path, other side edited the original' '\n    ++\tgit init keep-copied &&\n    ++\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >keep-copied/F &&\n    ++\tgit -C keep-copied add F &&\n    ++\ttest_tick &&\n    ++\tgit -C keep-copied commit -m \"O: add F\" &&\n    ++\tgit -C keep-copied branch B &&\n    ++\tcp keep-copied/F keep-copied/G &&\n    ++\tgit -C keep-copied add G &&\n    ++\ttest_tick &&\n    ++\tgit -C keep-copied commit -m \"A1: copy F to G on master\" &&\n    ++\n    ++\tgit -C keep-copied checkout B &&\n    ++\tprintf \"line 1\\nline 2\\nline 3\\nline 4 T\\nline 5\\n\" >keep-copied/F &&\n    ++\ttest_tick &&\n    ++\tgit -C keep-copied commit -am \"B2: update F on B\" &&\n    ++\n    ++\tgit -C keep-copied checkout master &&\n    ++\ttest_tick &&\n    ++\tgit -C keep-copied merge -s ours -m \"M: merge B, keep F and G\" B\n    ++'\n    ++\n    ++test_expect_success '--follow follows an edit of the copy source on the side the merge did not take' '\n    ++\tgit -C keep-copied log --follow --pretty=tformat:%s G >actual &&\n    ++\tcat >expect <<-\\EOF &&\n    ++\tB2: update F on B\n    ++\tA1: copy F to G on master\n    ++\tO: add F\n    ++\tEOF\n    ++\ttest_cmp expect actual\n    ++'\n     +\n      test_done\n2:  b172890bf4 = 2:  f36129714b log: extract showing the remerge/combined diff of a merge commit\n3:  6586e8f004 = 3:  85b6067fbd log: fix -m --follow losing the history of later parents\n4:  b903152bc4 ! 4:  5ba93e49cf log: simplify --follow following renames for non-linear history\n    @@ Commit message\n         log: simplify --follow following renames for non-linear history\n     \n         Code added in 304812ed33 (log: improve --follow following renames for\n    -    non-linear history, 2026-06-22) implemented the feature by introducing a\n    +    non-linear history, 2026-06-22) implements the feature by introducing a\n         new propagate_follow_pathspec_to_parent() function which adds a new call\n         to diff_tree_oid(). Also it introduces a new loop to record what path\n         each parent of a merge commit should use when following a path.\n     \n    -    This was working, but it caused a performance regression: e.g. 'git log\n    -    --stat --follow -- include/linux/rsc_table.h' in linux.git went from 28s\n    -    to 6m43s. The new code diffs each merge against each of its parents with\n    -    rename detection, which is expensive when a parent doesn't have the\n    -    followed path yet. Fixing this would require adding even more custom\n    -    code, instead of just extending the existing code in log_tree_diff(). So\n    -    first simplify the code here, and fix the performance regression in a\n    -    follow-up commit.\n    +    This works, but it causes a performance regression: e.g. 'git log\n    +    --stat --follow -- include/linux/rsc_table.h' in linux.git takes 6m43s,\n    +    while it took 28s before that commit. The new code diffs each merge\n    +    against each of its parents with rename detection, which is expensive\n    +    when a parent doesn't have the followed path yet. Fixing this would\n    +    require adding even more custom code, instead of just extending the\n    +    existing code in log_tree_diff(). So first simplify the code here, and\n    +    fix the performance regression in a follow-up commit.\n     \n         Remove propagate_follow_pathspec_to_parent() and the loop calling it\n         for each parent. Instead, record the path to follow for each parent in\n    -    the parent loop of log_tree_diff(), right after diff_tree_oid() updated\n    +    the parent loop of log_tree_diff(), right after diff_tree_oid() updates\n         the pathspec in case of a rename. Merges are not diffed by default, so\n         with --follow, run the same loop for them as well, but without showing\n         anything. With -c, --cc or --remerge-diff, show the merge diff after the\n5:  072d90b865 < -:  ---------- log: speed up --follow following renames for non-linear history\n6:  7be8cfb3ba ! 5:  ddcac2115e log: fix --follow following an edit on a side the merge did not take\n    @@ Metadata\n     Author: Miklos Vajna <vmiklos@collabora.com>\n     \n      ## Commit message ##\n    -    log: fix --follow following an edit on a side the merge did not take\n    +    log: speed up --follow following renames for non-linear history\n     \n    -    Take a history where F is renamed to G on master, F is edited on a side\n    -    branch, and the side branch is merged with '-s ours', so the merge keeps\n    -    G and drops F. Here 'git log --follow G' doesn't show the edit of F on\n    -    the side branch, while it did before the previous commit.\n    +    Test the performance of 'git log --stat --follow --\n    +    include/linux/rsc_table.h' on linux.git: since commit 304812ed33 (log:\n    +    improve --follow following renames for non-linear history, 2026-06-22),\n    +    it takes 6m43s, while it took about 28 seconds before.\n     \n    -    The problem is that follow_needs_renames() only searches for renames in\n    -    a parent without the path if the merge base still has the path, which\n    -    covers the case when the parent renamed the path. Here the other side\n    -    of the merge did the rename, so the merge base only has the old name.\n    -    The parent is then told to follow G, which it doesn't have, and the\n    -    history of F on its side is lost. Searching for renames in each parent\n    -    that lacks the path would fix this, but that is the expensive search\n    -    that the previous commit avoids, e.g. 148 merges hit this case for\n    -    include/linux/rsc_table.h in linux.git.\n    +    What happens is that log_tree_diff() diffs each merge against all of its\n    +    parents with rename following. diff_tree_oid() only does the expensive\n    +    rename detection when the path is added relative to a parent, but that\n    +    is common for merges, e.g. when a branch forked before the path was\n    +    created merges mainline, and this slows down 'git log --follow'.\n     \n    -    Fix the problem by also searching for renames when the merge base\n    -    doesn't have the path, but the parent changed a file since the merge\n    -    base that the merge no longer has: only such a file can be the old name\n    -    of the path that still needs to be followed in the parent. This check\n    -    is cheap, since it only diffs the changes of the side branch, and it\n    -    rules out 146 of the 148 merges in linux.git. Then do a plain rename\n    -    detection from the parent to the merge, which only looks at the files\n    -    deleted by the merge, not at all files of the parent like --follow does.\n    +    Fix the problem by first diffing the merge against its parents without\n    +    rename following, to find a parent where the path is unchanged. If there\n    +    is such a parent, then skip the diff against the other parents and just\n    +    follow the same path there. The exception is a parent that doesn't have\n    +    the path, but still needs renames to be followed:\n    +    - The merge base has the path, i.e. that side renamed or removed it, or\n    +      there is no merge base, e.g. a subtree merge of unrelated histories.\n    +    - The merge base doesn't have the path, but the parent changed a file\n    +      since then, and the merge dropped that change. A copy detection also\n    +      finds that file as the source of the path, i.e. the other side renamed\n    +      or copied the path from that file.\n    +    If the path changed relative to all parents, then diff against them with\n    +    rename following, as before. Given that this way a parent may be asked\n    +    to follow a path that it doesn't have, also adjust\n    +    remember_follow_pathspec(): if children disagree on what should be the\n    +    path for a commit, then prefer the path that exists in that commit.\n     \n    -    Reported-by: Patrick Steinhardt <ps@pks.im>\n    +    Now the above use case takes 42s, somewhat close to the original cost.\n    +\n    +    Helped-by: SZEDER Gábor <szeder.dev@gmail.com>\n    +    Helped-by: Patrick Steinhardt <ps@pks.im>\n         Signed-off-by: Miklos Vajna <vmiklos@collabora.com>\n     \n      ## log-tree.c ##\n    +@@\n    + #include \"range-diff.h\"\n    + #include \"strmap.h\"\n    + #include \"tree.h\"\n    ++#include \"tree-walk.h\"\n    + #include \"wildmatch.h\"\n    + #include \"write-or-die.h\"\n    + #include \"pager.h\"\n     @@ log-tree.c: static void set_pathspec_to_single_path(struct pathspec *ps, const char *path)\n      \t\t       PATHSPEC_LITERAL_PATH, \"\", paths);\n      }\n      \n    --static int commit_has_path(struct rev_info *opt, struct commit *c,\n    --\t\t\t   const char *path)\n     +static int tree_has_path(struct rev_info *opt, struct object_id *tree,\n     +\t\t\t const char *path)\n    - {\n    - \tstruct object_id oid;\n    - \tunsigned short mode;\n    - \n    ++{\n    ++\tstruct object_id oid;\n    ++\tunsigned short mode;\n    ++\n     +\treturn !get_tree_entry(opt->diffopt.repo, tree, path, &oid, &mode);\n     +}\n     +\n     +static int commit_has_path(struct rev_info *opt, struct commit *c,\n     +\t\t\t   const char *path)\n     +{\n    - \tparse_commit_or_die(c);\n    --\treturn !get_tree_entry(opt->diffopt.repo, get_commit_tree_oid(c), path,\n    --\t\t\t       &oid, &mode);\n    ++\tparse_commit_or_die(c);\n     +\treturn tree_has_path(opt, get_commit_tree_oid(c), path);\n    - }\n    - \n    ++}\n    ++\n      static void remember_follow_pathspec(struct rev_info *opt,\n    + \t\t\t\t     struct commit *c, const char *path)\n    + {\n    +@@ log-tree.c: static void remember_follow_pathspec(struct rev_info *opt,\n    + \t\tinit_follow_pathspec_slab(opt->follow_pathspec_slab);\n    + \t}\n    + \tslot = follow_pathspec_slab_at(opt->follow_pathspec_slab, c);\n    +-\tif (*slot && !strcmp(*slot, path))\n    +-\t\treturn;\n    ++\t/* If children of 'c' disagree on the path, prefer the one 'c' has. */\n    ++\tif (*slot) {\n    ++\t\tif (!strcmp(*slot, path) || commit_has_path(opt, c, *slot) ||\n    ++\t\t    !commit_has_path(opt, c, path))\n    ++\t\t\treturn;\n    ++\t}\n    + \tfree(*slot);\n    + \t*slot = xstrdup(path);\n    + }\n     @@ log-tree.c: void release_follow_pathspec_slab(struct rev_info *opt)\n      \tFREE_AND_NULL(opt->follow_pathspec_slab);\n      }\n      \n    ++/* Find a parent where 'path' is the same as in the merge. */\n    ++static struct commit *follow_same_parent(struct rev_info *opt,\n    ++\t\t\t\t\t struct commit_list *parents,\n    ++\t\t\t\t\t struct object_id *merge_tree)\n    ++{\n    ++\tstruct commit *same = NULL;\n    ++\n    ++\topt->diffopt.flags.follow_renames = 0;\n    ++\tfor (; parents && !same; parents = parents->next) {\n    ++\t\tparse_commit_or_die(parents->item);\n    ++\t\tdiff_tree_oid(get_commit_tree_oid(parents->item), merge_tree,\n    ++\t\t\t      \"\", &opt->diffopt);\n    ++\t\tif (!diff_queued_diff.nr)\n    ++\t\t\tsame = parents->item;\n    ++\t\tdiff_queue_clear(&diff_queued_diff);\n    ++\t}\n    ++\topt->diffopt.flags.follow_renames = 1;\n    ++\treturn same;\n    ++}\n    ++\n     +/*\n    -+ * Did 'parent' change a file since 'base' that the merge (with tree 'oid') no\n    -+ * longer has? Only such a file can be the source of a rename on the other side\n    -+ * of the merge that still needs to be followed in 'parent'.\n    ++ * Did 'parent' change a file since 'base', but the merge tree dropped that\n    ++ * change? I.e. the merge doesn't have the file or it's the same as in 'same'.\n     + */\n     +static int follow_parent_changed_dropped_file(struct rev_info *opt,\n     +\t\t\t\t\t      struct commit *base,\n     +\t\t\t\t\t      struct commit *parent,\n    -+\t\t\t\t\t      struct object_id *oid)\n    ++\t\t\t\t\t      struct commit *same,\n    ++\t\t\t\t\t      struct object_id *merge_tree)\n     +{\n     +\tstruct diff_options diff_opts;\n     +\tint i, ret = 0;\n    @@ log-tree.c: void release_follow_pathspec_slab(struct rev_info *opt)\n     +\t\t      \"\", &diff_opts);\n     +\tfor (i = 0; i < diff_queued_diff.nr && !ret; i++) {\n     +\t\tstruct diff_filepair *p = diff_queued_diff.queue[i];\n    ++\t\tstruct object_id merge_oid, same_oid;\n    ++\t\tunsigned short mode;\n     +\n    -+\t\tret = DIFF_FILE_VALID(p->two) &&\n    -+\t\t      !tree_has_path(opt, oid, p->two->path);\n    ++\t\tif (!DIFF_FILE_VALID(p->two))\n    ++\t\t\tcontinue;\n    ++\t\tif (get_tree_entry(opt->diffopt.repo, merge_tree, p->two->path,\n    ++\t\t\t\t   &merge_oid, &mode))\n    ++\t\t\tret = 1;\n    ++\t\telse\n    ++\t\t\tret = !oideq(&merge_oid, &p->two->oid) &&\n    ++\t\t\t      !get_tree_entry(opt->diffopt.repo,\n    ++\t\t\t\t\t      get_commit_tree_oid(same),\n    ++\t\t\t\t\t      p->two->path, &same_oid, &mode) &&\n    ++\t\t\t      oideq(&merge_oid, &same_oid);\n     +\t}\n     +\tdiff_queue_clear(&diff_queued_diff);\n     +\tdiff_free(&diff_opts);\n     +\treturn ret;\n     +}\n     +\n    -+/*\n    -+ * Is 'path' in the merge (with tree 'oid') renamed from a file of 'parent'?\n    -+ * Only look at the files that the merge deleted, not at all files of 'parent'\n    -+ * like --follow does.\n    -+ */\n    ++/* Is 'path' in the merge tree renamed or copied from a file of 'parent'? */\n     +static int follow_has_rename_source(struct rev_info *opt,\n     +\t\t\t\t    struct commit *parent,\n    -+\t\t\t\t    struct object_id *oid, const char *path)\n    ++\t\t\t\t    struct object_id *merge_tree,\n    ++\t\t\t\t    const char *path)\n     +{\n     +\tstruct diff_options diff_opts;\n     +\tint i, ret = 0;\n     +\n     +\trepo_diff_setup(opt->diffopt.repo, &diff_opts);\n     +\tdiff_opts.flags.recursive = 1;\n    -+\tdiff_opts.detect_rename = DIFF_DETECT_RENAME;\n    ++\tdiff_opts.detect_rename = DIFF_DETECT_COPY;\n     +\tdiff_opts.rename_score = opt->diffopt.rename_score;\n     +\tdiff_opts.single_follow = path;\n     +\tdiff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;\n     +\tdiff_setup_done(&diff_opts);\n    -+\tdiff_tree_oid(get_commit_tree_oid(parent), oid, \"\", &diff_opts);\n    ++\tdiff_tree_oid(get_commit_tree_oid(parent), merge_tree, \"\", &diff_opts);\n     +\tdiffcore_std(&diff_opts);\n     +\tfor (i = 0; i < diff_queued_diff.nr && !ret; i++) {\n     +\t\tstruct diff_filepair *p = diff_queued_diff.queue[i];\n     +\n    -+\t\tret = p->status == DIFF_STATUS_RENAMED &&\n    ++\t\tret = (p->status == DIFF_STATUS_RENAMED ||\n    ++\t\t       p->status == DIFF_STATUS_COPIED) &&\n     +\t\t      !strcmp(p->two->path, path);\n     +\t}\n     +\tdiff_queue_clear(&diff_queued_diff);\n    @@ log-tree.c: void release_follow_pathspec_slab(struct rev_info *opt)\n     +\treturn ret;\n     +}\n     +\n    - /*\n    -  * When the path in a merge is the same as in 'same', does the path still need\n    -  * renames to be followed in 'parent'? Only if the merge has the path, 'parent'\n    -- * doesn't have it, but its fork point with 'same' had it, e.g. 'parent'\n    -- * renamed the path.\n    -+ * doesn't have it, and either:\n    -+ *\n    -+ * - its fork point with 'same' had it, e.g. 'parent' renamed the path, or\n    -+ * - 'same' renamed the path from a file that 'parent' changed.\n    -  */\n    - static int follow_needs_renames(struct rev_info *opt, struct commit *parent,\n    --\t\t\t\tstruct commit *same, const char *path)\n    -+\t\t\t\tstruct commit *same, struct object_id *oid,\n    -+\t\t\t\tconst char *path)\n    - {\n    - \tstruct commit_list *bases = NULL, *base;\n    --\tint ret = 0;\n    ++/*\n    ++ * When the path in a merge tree is the same as in 'same', does the path still\n    ++ * need renames to be followed in 'parent'?\n    ++ */\n    ++static int follow_needs_renames(struct rev_info *opt, struct commit *parent,\n    ++\t\t\t\tstruct commit *same,\n    ++\t\t\t\tstruct object_id *merge_tree, const char *path)\n    ++{\n    ++\tstruct commit_list *bases = NULL, *base;\n     +\tint ret = 0, changed_dropped = 0;\n    - \n    - \tif (commit_has_path(opt, parent, path) ||\n    - \t    !commit_has_path(opt, same, path))\n    - \t\treturn 0;\n    - \tif (repo_get_merge_bases(opt->diffopt.repo, parent, same, &bases) < 0)\n    - \t\texit(128);\n    --\tfor (base = bases; base && !ret; base = base->next)\n    ++\n    ++\tif (parent == same || commit_has_path(opt, parent, path) ||\n    ++\t    !commit_has_path(opt, same, path))\n    ++\t\treturn 0;\n    ++\tif (repo_get_merge_bases(opt->diffopt.repo, parent, same, &bases) < 0)\n    ++\t\texit(128);\n    ++\t/* Unrelated histories, e.g. a subtree merge */\n    ++\tret = !bases;\n     +\tfor (base = bases; base && !ret; base = base->next) {\n    - \t\tret = commit_has_path(opt, base->item, path);\n    ++\t\tret = commit_has_path(opt, base->item, path);\n     +\t\tif (!ret && !changed_dropped)\n     +\t\t\tchanged_dropped = follow_parent_changed_dropped_file(\n    -+\t\t\t\topt, base->item, parent, oid);\n    ++\t\t\t\topt, base->item, parent, same, merge_tree);\n     +\t}\n    - \tcommit_list_free(bases);\n    ++\tcommit_list_free(bases);\n     +\tif (!ret && changed_dropped)\n    -+\t\tret = follow_has_rename_source(opt, parent, oid, path);\n    - \treturn ret;\n    - }\n    ++\t\tret = follow_has_rename_source(opt, parent, merge_tree, path);\n    ++\treturn ret;\n    ++}\n    ++\n    + /* Show the remerge or combined diff of a merge commit */\n    + static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,\n    + \t\t\t       struct commit_list *parents,\n    +@@ log-tree.c: static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n    + \tint all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;\n    + \tint follow_only = 0;\n    + \tchar *path = NULL;\n    ++\tstruct commit *same = NULL;\n      \n    + \tif (!all_need_diff && !opt->merges_need_diff)\n    + \t\treturn 0;\n     @@ log-tree.c: static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n    - \t\t\t     parents = parents->next) {\n    - \t\t\t\tif (parents->item != parent &&\n    - \t\t\t\t    follow_needs_renames(opt, parents->item,\n    --\t\t\t\t\t\t\t parent, path))\n    -+\t\t\t\t\t\t\t parent, oid, path))\n    - \t\t\t\t\ttail = &commit_list_insert(parents->item,\n    - \t\t\t\t\t\t\t\t   tail)->next;\n    - \t\t\t\telse\n    -\n    - ## t/t4219-log-follow-merge.sh ##\n    -@@ t/t4219-log-follow-merge.sh: test_expect_success '--follow with --diff-merges=first-parent follows all parent\n    - \ttest_cmp expect actual\n    - '\n    + \tif (opt->diffopt.flags.follow_renames)\n    + \t\tpath = xstrdup_or_null(\n    + \t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n    ++\tif (path && is_merge && (follow_only || opt->first_parent_merges))\n    ++\t\tsame = follow_same_parent(opt, parents, oid);\n      \n    -+test_expect_success 'setup merge keeping the renamed path, other side edited the old one' '\n    -+\tgit init keep-renamed &&\n    -+\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >keep-renamed/F &&\n    -+\tgit -C keep-renamed add F &&\n    -+\ttest_tick &&\n    -+\tgit -C keep-renamed commit -m \"O: add F\" &&\n    -+\tgit -C keep-renamed branch B &&\n    -+\tgit -C keep-renamed mv F G &&\n    -+\ttest_tick &&\n    -+\tgit -C keep-renamed commit -m \"A1: rename F to G on master\" &&\n    -+\n    -+\tgit -C keep-renamed checkout B &&\n    -+\tprintf \"line 1\\nline 2\\nline 3\\nline 4 T\\nline 5\\n\" >keep-renamed/F &&\n    -+\ttest_tick &&\n    -+\tgit -C keep-renamed commit -am \"B2: update F on B\" &&\n    -+\n    -+\tgit -C keep-renamed checkout master &&\n    -+\ttest_tick &&\n    -+\tgit -C keep-renamed merge -s ours -m \"M: merge B, keep G, drop F\" B\n    -+'\n    -+\n    -+test_expect_success '--follow follows an edit on the side the merge did not take' '\n    -+\tgit -C keep-renamed log --follow --pretty=tformat:%s G >actual &&\n    -+\tcat >expect <<-\\EOF &&\n    -+\tB2: update F on B\n    -+\tA1: rename F to G on master\n    -+\tO: add F\n    -+\tEOF\n    -+\ttest_cmp expect actual\n    -+'\n    -+\n    - test_done\n    + \tshowed_log = 0;\n    + \tall_parents = parents;\n    +@@ log-tree.c: static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n    + \t\tstruct commit *parent = parents->item;\n    + \n    + \t\tparse_commit_or_die(parent);\n    +-\t\tdiff_tree_oid(get_commit_tree_oid(parent),\n    +-\t\t\t      oid, \"\", &opt->diffopt);\n    ++\t\t/*\n    ++\t\t * Same as in a parent: follow the path as-is, unless renames\n    ++\t\t * still need to be followed in this parent.\n    ++\t\t */\n    ++\t\tif (!follow_only || !same ||\n    ++\t\t    follow_needs_renames(opt, parent, same, oid, path))\n    ++\t\t\tdiff_tree_oid(get_commit_tree_oid(parent),\n    ++\t\t\t\t      oid, \"\", &opt->diffopt);\n    + \t\tif (follow_only) {\n    + \t\t\tdiff_queue_clear(&diff_queued_diff);\n    + \t\t\topt->diffopt.found_follow = 0;\n-- \n2.51.0\n\n\n"},{"id":"557891","messageId":"5512aa682f71243378c06dcb8cda2b53150d4e39.1794078554.git.vmiklos@collabora.com","threadId":"66514","inReplyTo":"cover.1794078554.git.vmiklos@collabora.com","subject":"[PATCH v5 1/5] t4219: test more --follow cases across merges","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-11-09T08:04:00Z","receivedAt":"2026-11-09T08:04:00Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"A later commit in this series will speed up 'git log --follow' for\nmerge commits. Add tests for cases which already work, but have no\ntest coverage, so it's easy to break them while optimizing:\n\n- a subtree merge adding the history of a file that was copied before\n- --follow through a fork with renames on both sides, with -c, --cc\n  and --remerge-diff\n- a --no-ff merge taking a rename from the second parent, in both commit\n  orders, since the result could depend on the walk order\n- a merge keeping the path, while the other side renamed it\n- --diff-merges=first-parent, which diffs merges only against their\n  first parent, but still walks all parents\n- a merge keeping the renamed path, while the other side edited the old\n  one\n- a merge keeping the copied path, while the other side edited the\n  original\n\nHelped-by: Patrick Steinhardt <ps@pks.im>\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n t/t4219-log-follow-merge.sh | 214 ++++++++++++++++++++++++++++++++++++\n 1 file changed, 214 insertions(+)\n\ndiff --git a/t/t4219-log-follow-merge.sh b/t/t4219-log-follow-merge.sh\nindex e370f82955..806ccc24bd 100755\n--- a/t/t4219-log-follow-merge.sh\n+++ b/t/t4219-log-follow-merge.sh\n@@ -31,6 +31,33 @@ test_expect_success '--follow finds the pre-merge commit through a subtree merge\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'setup subtree merge adding the history of a copied file' '\n+\tgit init graft &&\n+\techo outer >graft/outer.txt &&\n+\tgit -C graft add outer.txt &&\n+\ttest_tick &&\n+\tgit -C graft commit -m \"outer init\" &&\n+\tmkdir graft/inner &&\n+\tcp inner/inner.txt graft/inner/ &&\n+\tgit -C graft add inner &&\n+\ttest_tick &&\n+\tgit -C graft commit -m \"copy inner.txt to inner/\" &&\n+\n+\tgit -C graft fetch ../inner master &&\n+\ttest_tick &&\n+\tgit -C graft merge -s ours --allow-unrelated-histories \\\n+\t\t-m \"Merge the history of inner/\" FETCH_HEAD\n+'\n+\n+test_expect_success '--follow finds the history of a copied file through a subtree merge' '\n+\tgit -C graft log --follow --pretty=tformat:%s inner/inner.txt >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tcopy inner.txt to inner/\n+\tinner init\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'setup merge of two branches that both renamed a file to README' '\n \tgit init foo &&\n \tmkdir foo/foo &&\n@@ -126,4 +153,191 @@ test_expect_success '--follow follows renames through a fork in a single history\n \ttest_cmp expect actual.sorted\n '\n \n+for opt in -c --cc --remerge-diff\n+do\n+\ttest_expect_success \"--follow follows renames through a fork with $opt\" '\n+\t\tgit -C diamond log --follow $opt --pretty=tformat:%s path >log &&\n+\t\tgrep \"^[A-Z]: \" log | sort >actual &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tA: add path0\n+\t\tB: modify path0 on upper\n+\t\tC: modify path0 on lower\n+\t\tM: merge with rename to path\n+\t\tX: rename path0 to path1\n+\t\tY: rename path0 to path2\n+\t\tZ: modify path\n+\t\tEOF\n+\t\ttest_cmp expect actual\n+\t'\n+done\n+\n+# Build a merge that takes the renamed path from the second parent, while the\n+# first parent only has the old path. $2 decides which side is committed first,\n+# which decides the walk order.\n+setup_rename_on_second_parent () {\n+\tgit init $1 &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >$1/old &&\n+\tgit -C $1 add old &&\n+\ttest_tick &&\n+\tgit -C $1 commit -m \"A: add old\" &&\n+\tprintf \"line 1\\nline 2\\nline 3 modified\\nline 4\\nline 5\\n\" >$1/old &&\n+\ttest_tick &&\n+\tgit -C $1 commit -am \"B: modify old\" &&\n+\tgit -C $1 branch topic &&\n+\n+\tif test \"$2\" = topic-first\n+\tthen\n+\t\tgit -C $1 checkout topic &&\n+\t\tgit -C $1 mv old new &&\n+\t\ttest_tick &&\n+\t\tgit -C $1 commit -m \"R: rename old to new\" &&\n+\t\tgit -C $1 checkout master\n+\tfi &&\n+\n+\techo other >$1/other &&\n+\tgit -C $1 add other &&\n+\ttest_tick &&\n+\tgit -C $1 commit -m \"M: unrelated change on master\" &&\n+\n+\tif test \"$2\" = master-first\n+\tthen\n+\t\tgit -C $1 checkout topic &&\n+\t\tgit -C $1 mv old new &&\n+\t\ttest_tick &&\n+\t\tgit -C $1 commit -m \"R: rename old to new\" &&\n+\t\tgit -C $1 checkout master\n+\tfi &&\n+\n+\ttest_tick &&\n+\tgit -C $1 merge --no-ff -m \"merge topic\" topic\n+}\n+\n+test_expect_success 'setup merge taking a rename from the second parent' '\n+\tsetup_rename_on_second_parent rename-master-first master-first &&\n+\tsetup_rename_on_second_parent rename-topic-first topic-first\n+'\n+\n+for order in master-first topic-first\n+do\n+\ttest_expect_success \"--follow follows a rename from the second parent ($order)\" '\n+\t\tgit -C rename-$order log --follow --pretty=tformat:%s new >actual &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tR: rename old to new\n+\t\tB: modify old\n+\t\tA: add old\n+\t\tEOF\n+\t\ttest_cmp expect actual\n+\t'\n+done\n+\n+test_expect_success 'setup merge keeping the path, other side renamed it' '\n+\tgit init keep &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >keep/F &&\n+\tgit -C keep add F &&\n+\ttest_tick &&\n+\tgit -C keep commit -m \"O: add F\" &&\n+\tgit -C keep branch B &&\n+\tprintf \"line 1\\nline 2\\nline 3 A\\nline 4\\nline 5\\n\" >keep/F &&\n+\ttest_tick &&\n+\tgit -C keep commit -am \"A1: update F in place\" &&\n+\n+\tgit -C keep checkout B &&\n+\tgit -C keep mv F G &&\n+\ttest_tick &&\n+\tgit -C keep commit -m \"B1: rename F to G\" &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4 B\\nline 5\\n\" >keep/G &&\n+\ttest_tick &&\n+\tgit -C keep commit -am \"B2: update G\" &&\n+\n+\tgit -C keep checkout master &&\n+\ttest_tick &&\n+\tgit -C keep merge -s ours -m \"M: merge B, keep F, drop G\" B\n+'\n+\n+test_expect_success '--follow follows a rename on the side the merge did not take' '\n+\tgit -C keep log --follow --pretty=tformat:%s F >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tB2: update G\n+\tB1: rename F to G\n+\tA1: update F in place\n+\tO: add F\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success '--follow with --diff-merges=first-parent follows all parents' '\n+\tgit -C keep log --follow --diff-merges=first-parent --no-patch \\\n+\t\t--pretty=tformat:%s F >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tB2: update G\n+\tB1: rename F to G\n+\tA1: update F in place\n+\tO: add F\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'setup merge keeping the renamed path, other side edited the old one' '\n+\tgit init keep-renamed &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >keep-renamed/F &&\n+\tgit -C keep-renamed add F &&\n+\ttest_tick &&\n+\tgit -C keep-renamed commit -m \"O: add F\" &&\n+\tgit -C keep-renamed branch B &&\n+\tgit -C keep-renamed mv F G &&\n+\ttest_tick &&\n+\tgit -C keep-renamed commit -m \"A1: rename F to G on master\" &&\n+\n+\tgit -C keep-renamed checkout B &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4 T\\nline 5\\n\" >keep-renamed/F &&\n+\ttest_tick &&\n+\tgit -C keep-renamed commit -am \"B2: update F on B\" &&\n+\n+\tgit -C keep-renamed checkout master &&\n+\ttest_tick &&\n+\tgit -C keep-renamed merge -s ours -m \"M: merge B, keep G, drop F\" B\n+'\n+\n+test_expect_success '--follow follows an edit on the side the merge did not take' '\n+\tgit -C keep-renamed log --follow --pretty=tformat:%s G >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tB2: update F on B\n+\tA1: rename F to G on master\n+\tO: add F\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'setup merge keeping the copied path, other side edited the original' '\n+\tgit init keep-copied &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >keep-copied/F &&\n+\tgit -C keep-copied add F &&\n+\ttest_tick &&\n+\tgit -C keep-copied commit -m \"O: add F\" &&\n+\tgit -C keep-copied branch B &&\n+\tcp keep-copied/F keep-copied/G &&\n+\tgit -C keep-copied add G &&\n+\ttest_tick &&\n+\tgit -C keep-copied commit -m \"A1: copy F to G on master\" &&\n+\n+\tgit -C keep-copied checkout B &&\n+\tprintf \"line 1\\nline 2\\nline 3\\nline 4 T\\nline 5\\n\" >keep-copied/F &&\n+\ttest_tick &&\n+\tgit -C keep-copied commit -am \"B2: update F on B\" &&\n+\n+\tgit -C keep-copied checkout master &&\n+\ttest_tick &&\n+\tgit -C keep-copied merge -s ours -m \"M: merge B, keep F and G\" B\n+'\n+\n+test_expect_success '--follow follows an edit of the copy source on the side the merge did not take' '\n+\tgit -C keep-copied log --follow --pretty=tformat:%s G >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tB2: update F on B\n+\tA1: copy F to G on master\n+\tO: add F\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.51.0\n\n\n"},{"id":"557892","messageId":"f36129714b3270b788dd44c43c7cfb01c9e00893.1794078554.git.vmiklos@collabora.com","threadId":"66514","inReplyTo":"cover.1794078554.git.vmiklos@collabora.com","subject":"[PATCH v5 2/5] log: extract showing the remerge/combined diff of a merge commit","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-11-09T08:05:06Z","receivedAt":"2026-11-09T08:05:06Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"No functional changes intended. A later commit in this series will also\ncall log_tree_merge_diff() after the parent loop of log_tree_diff(), so\nextract that code to a function to avoid duplicating it.\n\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n log-tree.c | 36 ++++++++++++++++++++++--------------\n 1 file changed, 22 insertions(+), 14 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex 83a3c4bf9b..b4c97b86f5 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -1180,6 +1180,26 @@ static void propagate_follow_pathspec_to_parent(struct rev_info *opt,\n \tdiff_free(&diff_opts);\n }\n \n+/* Show the remerge or combined diff of a merge commit */\n+static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,\n+\t\t\t       struct commit_list *parents,\n+\t\t\t       struct object_id *oid)\n+{\n+\tint octopus = (parents->next->next != NULL);\n+\n+\tif (opt->remerge_diff) {\n+\t\tif (octopus) {\n+\t\t\tshow_log(opt);\n+\t\t\tfprintf(opt->diffopt.file,\n+\t\t\t\t\"diff: warning: Skipping remerge-diff \"\n+\t\t\t\t\"for octopus merges.\\n\");\n+\t\t\treturn 1;\n+\t\t}\n+\t\treturn do_remerge_diff(opt, parents, oid);\n+\t}\n+\treturn do_diff_combined(opt, commit);\n+}\n+\n /*\n  * Show the diff of a commit.\n  *\n@@ -1220,20 +1240,8 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t}\n \n \tif (is_merge) {\n-\t\tint octopus = (parents->next->next != NULL);\n-\n-\t\tif (opt->remerge_diff) {\n-\t\t\tif (octopus) {\n-\t\t\t\tshow_log(opt);\n-\t\t\t\tfprintf(opt->diffopt.file,\n-\t\t\t\t\t\"diff: warning: Skipping remerge-diff \"\n-\t\t\t\t\t\"for octopus merges.\\n\");\n-\t\t\t\treturn 1;\n-\t\t\t}\n-\t\t\treturn do_remerge_diff(opt, parents, oid);\n-\t\t}\n-\t\tif (opt->combine_merges)\n-\t\t\treturn do_diff_combined(opt, commit);\n+\t\tif (opt->remerge_diff || opt->combine_merges)\n+\t\t\treturn log_tree_merge_diff(opt, commit, parents, oid);\n \t\tif (opt->separate_merges) {\n \t\t\tif (!opt->first_parent_merges) {\n \t\t\t\t/* Show parent info for multiple diffs */\n-- \n2.51.0\n\n\n"},{"id":"557893","messageId":"85b6067fbda4fdf9a99ab81396dd1a2b89066954.1794078554.git.vmiklos@collabora.com","threadId":"66514","inReplyTo":"cover.1794078554.git.vmiklos@collabora.com","subject":"[PATCH v5 3/5] log: fix -m --follow losing the history of later parents","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-11-09T08:05:26Z","receivedAt":"2026-11-09T08:05:26Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"With 'git log -m --follow', a merge is diffed against each of its\nparents, with rename following. Take the diamond case of t4219: the two\nsides of a fork rename path0 to path1 and to path2, and the merge\nrenames the file to path. Here 'git log -m --follow path' doesn't show\n\"A: add path0\" and \"C: modify path0 on lower\".\n\nThe problem is that the parent loop in log_tree_diff() doesn't restore\nthe followed path between parents. When the diff against the first\nparent finds a rename, the followed path is updated, and this has two\neffects. First, the second parent is diffed with the already renamed\npath, not with the path of the merge. Second, the path that\npropagate_follow_pathspec_to_parent() records for each parent also\nstarts from that updated path, so history is lost on the side of the\nsecond parent. Without -m, merges are not diffed, so the followed path\nis not updated there.\n\nFix the problem by saving the path of the merge before the parent loop,\nand restoring it before diffing each parent and after the loop. Do this\nonly for merges: for a commit with a single parent, the renamed path is\nwhat --follow needs to continue with. Add a test for this, which shows\nthe full history of the diamond case with -m.\n\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n log-tree.c                  | 13 +++++++++++++\n t/t4219-log-follow-merge.sh | 16 ++++++++++++++++\n 2 files changed, 29 insertions(+)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex b4c97b86f5..befc5c8b22 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -1212,6 +1212,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \tstruct object_id *oid;\n \tint is_merge;\n \tint all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;\n+\tchar *path = NULL;\n \n \tif (!all_need_diff && !opt->merges_need_diff)\n \t\treturn 0;\n@@ -1251,10 +1252,18 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t\t\treturn 0;\n \t}\n \n+\tif (is_merge && opt->diffopt.flags.follow_renames)\n+\t\tpath = xstrdup_or_null(\n+\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n+\n \tshowed_log = 0;\n \tfor (;;) {\n \t\tstruct commit *parent = parents->item;\n \n+\t\t/* Diff each parent with the path of the merge */\n+\t\tif (path)\n+\t\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec,\n+\t\t\t\t\t\t    path);\n \t\tparse_commit_or_die(parent);\n \t\tdiff_tree_oid(get_commit_tree_oid(parent),\n \t\t\t      oid, \"\", &opt->diffopt);\n@@ -1269,6 +1278,10 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t\tlog->parent = parents->item;\n \t\topt->loginfo = log;\n \t}\n+\t/* Propagate to parents starting from the path of the merge, too */\n+\tif (path)\n+\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec, path);\n+\tfree(path);\n \treturn showed_log;\n }\n \ndiff --git a/t/t4219-log-follow-merge.sh b/t/t4219-log-follow-merge.sh\nindex 806ccc24bd..ac9ab85888 100755\n--- a/t/t4219-log-follow-merge.sh\n+++ b/t/t4219-log-follow-merge.sh\n@@ -171,6 +171,22 @@ do\n \t'\n done\n \n+test_expect_success '--follow follows renames through a fork with -m' '\n+\tgit -C diamond log --follow -m --pretty=tformat:%s path >log &&\n+\tgrep \"^[A-Z]: \" log | sort >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tA: add path0\n+\tB: modify path0 on upper\n+\tC: modify path0 on lower\n+\tM: merge with rename to path\n+\tM: merge with rename to path\n+\tX: rename path0 to path1\n+\tY: rename path0 to path2\n+\tZ: modify path\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n # Build a merge that takes the renamed path from the second parent, while the\n # first parent only has the old path. $2 decides which side is committed first,\n # which decides the walk order.\n-- \n2.51.0\n\n\n"},{"id":"557894","messageId":"5ba93e49cff31e61621ac166f2d60b8133937f20.1794078554.git.vmiklos@collabora.com","threadId":"66514","inReplyTo":"cover.1794078554.git.vmiklos@collabora.com","subject":"[PATCH v5 4/5] log: simplify --follow following renames for non-linear history","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-11-09T08:05:53Z","receivedAt":"2026-11-09T08:05:53Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Code added in 304812ed33 (log: improve --follow following renames for\nnon-linear history, 2026-06-22) implements the feature by introducing a\nnew propagate_follow_pathspec_to_parent() function which adds a new call\nto diff_tree_oid(). Also it introduces a new loop to record what path\neach parent of a merge commit should use when following a path.\n\nThis works, but it causes a performance regression: e.g. 'git log\n--stat --follow -- include/linux/rsc_table.h' in linux.git takes 6m43s,\nwhile it took 28s before that commit. The new code diffs each merge\nagainst each of its parents with rename detection, which is expensive\nwhen a parent doesn't have the followed path yet. Fixing this would\nrequire adding even more custom code, instead of just extending the\nexisting code in log_tree_diff(). So first simplify the code here, and\nfix the performance regression in a follow-up commit.\n\nRemove propagate_follow_pathspec_to_parent() and the loop calling it\nfor each parent. Instead, record the path to follow for each parent in\nthe parent loop of log_tree_diff(), right after diff_tree_oid() updates\nthe pathspec in case of a rename. Merges are not diffed by default, so\nwith --follow, run the same loop for them as well, but without showing\nanything. With -c, --cc or --remerge-diff, show the merge diff after the\nloop. With --diff-merges=first-parent, keep diffing the other parents\nsilently, unless the walk only follows first parents. This gets rid of\nthe additional call to diff_tree_oid(). The rework has no positive\nperformance impact yet, it just simplifies the code.\n\nThe previous commit restores the path of the merge before diffing each\nparent, and also after the loop, for\npropagate_follow_pathspec_to_parent(). Keep restoring it between\nparents, but not after the loop, since there is no later propagation\nanymore.\n\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n log-tree.c | 96 +++++++++++++++++++++++-------------------------------\n 1 file changed, 41 insertions(+), 55 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex befc5c8b22..0aa27fb210 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -1153,33 +1153,6 @@ void release_follow_pathspec_slab(struct rev_info *opt)\n \tFREE_AND_NULL(opt->follow_pathspec_slab);\n }\n \n-/* Compute a path to follow in parent, if there is one */\n-static void propagate_follow_pathspec_to_parent(struct rev_info *opt,\n-\t\t\t\t\t\tstruct commit *commit,\n-\t\t\t\t\t\tstruct commit *parent)\n-{\n-\tstruct diff_options diff_opts;\n-\tconst char *path;\n-\n-\tparse_commit_or_die(parent);\n-\trepo_diff_setup(opt->diffopt.repo, &diff_opts);\n-\tcopy_pathspec(&diff_opts.pathspec, &opt->diffopt.pathspec);\n-\tdiff_opts.flags.recursive = 1;\n-\tdiff_opts.flags.follow_renames = 1;\n-\tdiff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;\n-\tdiff_setup_done(&diff_opts);\n-\tdiff_tree_oid(get_commit_tree_oid(parent),\n-\t\t      get_commit_tree_oid(commit),\n-\t\t      \"\", &diff_opts);\n-\n-\tpath = pathspec_single_path(&diff_opts.pathspec);\n-\tif (path)\n-\t\tremember_follow_pathspec(opt, parent, path);\n-\n-\tdiff_queue_clear(&diff_queued_diff);\n-\tdiff_free(&diff_opts);\n-}\n-\n /* Show the remerge or combined diff of a merge commit */\n static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,\n \t\t\t       struct commit_list *parents,\n@@ -1208,10 +1181,11 @@ static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,\n static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log)\n {\n \tint showed_log;\n-\tstruct commit_list *parents;\n+\tstruct commit_list *parents, *all_parents;\n \tstruct object_id *oid;\n \tint is_merge;\n \tint all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;\n+\tint follow_only = 0;\n \tchar *path = NULL;\n \n \tif (!all_need_diff && !opt->merges_need_diff)\n@@ -1241,46 +1215,73 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t}\n \n \tif (is_merge) {\n-\t\tif (opt->remerge_diff || opt->combine_merges)\n+\t\tint merge_diff = opt->remerge_diff || opt->combine_merges;\n+\n+\t\tif (merge_diff && !opt->diffopt.flags.follow_renames)\n \t\t\treturn log_tree_merge_diff(opt, commit, parents, oid);\n-\t\tif (opt->separate_merges) {\n+\t\tif (opt->separate_merges && !merge_diff) {\n \t\t\tif (!opt->first_parent_merges) {\n \t\t\t\t/* Show parent info for multiple diffs */\n \t\t\t\tlog->parent = parents->item;\n \t\t\t}\n+\t\t} else if (opt->diffopt.flags.follow_renames) {\n+\t\t\t/* Diff only to find the path to follow in parents */\n+\t\t\tfollow_only = 1;\n \t\t} else\n \t\t\treturn 0;\n \t}\n \n-\tif (is_merge && opt->diffopt.flags.follow_renames)\n+\tif (opt->diffopt.flags.follow_renames)\n \t\tpath = xstrdup_or_null(\n \t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n \n \tshowed_log = 0;\n+\tall_parents = parents;\n \tfor (;;) {\n \t\tstruct commit *parent = parents->item;\n \n-\t\t/* Diff each parent with the path of the merge */\n-\t\tif (path)\n-\t\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec,\n-\t\t\t\t\t\t    path);\n \t\tparse_commit_or_die(parent);\n \t\tdiff_tree_oid(get_commit_tree_oid(parent),\n \t\t\t      oid, \"\", &opt->diffopt);\n-\t\tlog_tree_diff_flush(opt);\n+\t\tif (follow_only) {\n+\t\t\tdiff_queue_clear(&diff_queued_diff);\n+\t\t\topt->diffopt.found_follow = 0;\n+\t\t} else {\n+\t\t\tlog_tree_diff_flush(opt);\n+\t\t}\n \n \t\tshowed_log |= !opt->loginfo;\n \n+\t\t/* The diff updated the pathspec in case of a rename */\n+\t\tif (path)\n+\t\t\tremember_follow_pathspec(opt, parent,\n+\t\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n+\n \t\t/* Set up the log info for the next parent, if any.. */\n \t\tparents = parents->next;\n-\t\tif (!parents || opt->first_parent_merges)\n+\t\tif (!parents)\n \t\t\tbreak;\n+\t\tif (opt->first_parent_merges) {\n+\t\t\tif (!path || opt->first_parent_only)\n+\t\t\t\tbreak;\n+\t\t\t/* Only find the path to follow in the other parents */\n+\t\t\tfollow_only = 1;\n+\t\t}\n+\t\tif (path)\n+\t\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec,\n+\t\t\t\t\t\t    path);\n+\t\tif (follow_only)\n+\t\t\tcontinue;\n \t\tlog->parent = parents->item;\n \t\topt->loginfo = log;\n \t}\n-\t/* Propagate to parents starting from the path of the merge, too */\n-\tif (path)\n-\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec, path);\n+\tif (follow_only && (opt->remerge_diff || opt->combine_merges)) {\n+\t\t/* Show the merge diff with the path of this commit */\n+\t\tif (path)\n+\t\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec,\n+\t\t\t\t\t\t    path);\n+\t\tshowed_log = log_tree_merge_diff(opt, commit, all_parents, oid);\n+\t}\n \tfree(path);\n \treturn showed_log;\n }\n@@ -1319,21 +1320,6 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)\n \t\tfprintf(opt->diffopt.file, \"\\n%s\\n\", opt->break_bar);\n \tif (shown)\n \t\tshow_diff_of_diff(opt);\n-\n-\t/* Record what path each parent of this commit should use */\n-\tif (opt->diffopt.flags.follow_renames) {\n-\t\tstruct commit_list *parents = get_saved_parents(opt, commit);\n-\t\tif (parents && parents->next) {\n-\t\t\tstruct commit_list *p;\n-\t\t\tfor (p = parents; p; p = p->next)\n-\t\t\t\tpropagate_follow_pathspec_to_parent(opt, commit,\n-\t\t\t\t\t\t\t\t    p->item);\n-\t\t} else if (parents) {\n-\t\t\tremember_follow_pathspec(opt, parents->item,\n-\t\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n-\t\t}\n-\t}\n-\n \topt->loginfo = NULL;\n \tmaybe_flush_or_die(opt->diffopt.file, \"stdout\");\n \topt->diffopt.no_free = no_free;\n-- \n2.51.0\n\n\n"},{"id":"557895","messageId":"ddcac2115e901994ae24351e81f1f487567ffa82.1794078554.git.vmiklos@collabora.com","threadId":"66514","inReplyTo":"cover.1794078554.git.vmiklos@collabora.com","subject":"[PATCH v5 5/5] log: speed up --follow following renames for non-linear history","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-11-09T08:06:18Z","receivedAt":"2026-11-09T08:06:18Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Test the performance of 'git log --stat --follow --\ninclude/linux/rsc_table.h' on linux.git: since commit 304812ed33 (log:\nimprove --follow following renames for non-linear history, 2026-06-22),\nit takes 6m43s, while it took about 28 seconds before.\n\nWhat happens is that log_tree_diff() diffs each merge against all of its\nparents with rename following. diff_tree_oid() only does the expensive\nrename detection when the path is added relative to a parent, but that\nis common for merges, e.g. when a branch forked before the path was\ncreated merges mainline, and this slows down 'git log --follow'.\n\nFix the problem by first diffing the merge against its parents without\nrename following, to find a parent where the path is unchanged. If there\nis such a parent, then skip the diff against the other parents and just\nfollow the same path there. The exception is a parent that doesn't have\nthe path, but still needs renames to be followed:\n- The merge base has the path, i.e. that side renamed or removed it, or\n  there is no merge base, e.g. a subtree merge of unrelated histories.\n- The merge base doesn't have the path, but the parent changed a file\n  since then, and the merge dropped that change. A copy detection also\n  finds that file as the source of the path, i.e. the other side renamed\n  or copied the path from that file.\nIf the path changed relative to all parents, then diff against them with\nrename following, as before. Given that this way a parent may be asked\nto follow a path that it doesn't have, also adjust\nremember_follow_pathspec(): if children disagree on what should be the\npath for a commit, then prefer the path that exists in that commit.\n\nNow the above use case takes 42s, somewhat close to the original cost.\n\nHelped-by: SZEDER Gábor <szeder.dev@gmail.com>\nHelped-by: Patrick Steinhardt <ps@pks.im>\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n log-tree.c | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++--\n 1 file changed, 155 insertions(+), 4 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex 0aa27fb210..1dc02822f1 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -31,6 +31,7 @@\n #include \"range-diff.h\"\n #include \"strmap.h\"\n #include \"tree.h\"\n+#include \"tree-walk.h\"\n #include \"wildmatch.h\"\n #include \"write-or-die.h\"\n #include \"pager.h\"\n@@ -1110,6 +1111,22 @@ static void set_pathspec_to_single_path(struct pathspec *ps, const char *path)\n \t\t       PATHSPEC_LITERAL_PATH, \"\", paths);\n }\n \n+static int tree_has_path(struct rev_info *opt, struct object_id *tree,\n+\t\t\t const char *path)\n+{\n+\tstruct object_id oid;\n+\tunsigned short mode;\n+\n+\treturn !get_tree_entry(opt->diffopt.repo, tree, path, &oid, &mode);\n+}\n+\n+static int commit_has_path(struct rev_info *opt, struct commit *c,\n+\t\t\t   const char *path)\n+{\n+\tparse_commit_or_die(c);\n+\treturn tree_has_path(opt, get_commit_tree_oid(c), path);\n+}\n+\n static void remember_follow_pathspec(struct rev_info *opt,\n \t\t\t\t     struct commit *c, const char *path)\n {\n@@ -1122,8 +1139,12 @@ static void remember_follow_pathspec(struct rev_info *opt,\n \t\tinit_follow_pathspec_slab(opt->follow_pathspec_slab);\n \t}\n \tslot = follow_pathspec_slab_at(opt->follow_pathspec_slab, c);\n-\tif (*slot && !strcmp(*slot, path))\n-\t\treturn;\n+\t/* If children of 'c' disagree on the path, prefer the one 'c' has. */\n+\tif (*slot) {\n+\t\tif (!strcmp(*slot, path) || commit_has_path(opt, c, *slot) ||\n+\t\t    !commit_has_path(opt, c, path))\n+\t\t\treturn;\n+\t}\n \tfree(*slot);\n \t*slot = xstrdup(path);\n }\n@@ -1153,6 +1174,127 @@ void release_follow_pathspec_slab(struct rev_info *opt)\n \tFREE_AND_NULL(opt->follow_pathspec_slab);\n }\n \n+/* Find a parent where 'path' is the same as in the merge. */\n+static struct commit *follow_same_parent(struct rev_info *opt,\n+\t\t\t\t\t struct commit_list *parents,\n+\t\t\t\t\t struct object_id *merge_tree)\n+{\n+\tstruct commit *same = NULL;\n+\n+\topt->diffopt.flags.follow_renames = 0;\n+\tfor (; parents && !same; parents = parents->next) {\n+\t\tparse_commit_or_die(parents->item);\n+\t\tdiff_tree_oid(get_commit_tree_oid(parents->item), merge_tree,\n+\t\t\t      \"\", &opt->diffopt);\n+\t\tif (!diff_queued_diff.nr)\n+\t\t\tsame = parents->item;\n+\t\tdiff_queue_clear(&diff_queued_diff);\n+\t}\n+\topt->diffopt.flags.follow_renames = 1;\n+\treturn same;\n+}\n+\n+/*\n+ * Did 'parent' change a file since 'base', but the merge tree dropped that\n+ * change? I.e. the merge doesn't have the file or it's the same as in 'same'.\n+ */\n+static int follow_parent_changed_dropped_file(struct rev_info *opt,\n+\t\t\t\t\t      struct commit *base,\n+\t\t\t\t\t      struct commit *parent,\n+\t\t\t\t\t      struct commit *same,\n+\t\t\t\t\t      struct object_id *merge_tree)\n+{\n+\tstruct diff_options diff_opts;\n+\tint i, ret = 0;\n+\n+\trepo_diff_setup(opt->diffopt.repo, &diff_opts);\n+\tdiff_opts.flags.recursive = 1;\n+\tdiff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;\n+\tdiff_setup_done(&diff_opts);\n+\tdiff_tree_oid(get_commit_tree_oid(base), get_commit_tree_oid(parent),\n+\t\t      \"\", &diff_opts);\n+\tfor (i = 0; i < diff_queued_diff.nr && !ret; i++) {\n+\t\tstruct diff_filepair *p = diff_queued_diff.queue[i];\n+\t\tstruct object_id merge_oid, same_oid;\n+\t\tunsigned short mode;\n+\n+\t\tif (!DIFF_FILE_VALID(p->two))\n+\t\t\tcontinue;\n+\t\tif (get_tree_entry(opt->diffopt.repo, merge_tree, p->two->path,\n+\t\t\t\t   &merge_oid, &mode))\n+\t\t\tret = 1;\n+\t\telse\n+\t\t\tret = !oideq(&merge_oid, &p->two->oid) &&\n+\t\t\t      !get_tree_entry(opt->diffopt.repo,\n+\t\t\t\t\t      get_commit_tree_oid(same),\n+\t\t\t\t\t      p->two->path, &same_oid, &mode) &&\n+\t\t\t      oideq(&merge_oid, &same_oid);\n+\t}\n+\tdiff_queue_clear(&diff_queued_diff);\n+\tdiff_free(&diff_opts);\n+\treturn ret;\n+}\n+\n+/* Is 'path' in the merge tree renamed or copied from a file of 'parent'? */\n+static int follow_has_rename_source(struct rev_info *opt,\n+\t\t\t\t    struct commit *parent,\n+\t\t\t\t    struct object_id *merge_tree,\n+\t\t\t\t    const char *path)\n+{\n+\tstruct diff_options diff_opts;\n+\tint i, ret = 0;\n+\n+\trepo_diff_setup(opt->diffopt.repo, &diff_opts);\n+\tdiff_opts.flags.recursive = 1;\n+\tdiff_opts.detect_rename = DIFF_DETECT_COPY;\n+\tdiff_opts.rename_score = opt->diffopt.rename_score;\n+\tdiff_opts.single_follow = path;\n+\tdiff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;\n+\tdiff_setup_done(&diff_opts);\n+\tdiff_tree_oid(get_commit_tree_oid(parent), merge_tree, \"\", &diff_opts);\n+\tdiffcore_std(&diff_opts);\n+\tfor (i = 0; i < diff_queued_diff.nr && !ret; i++) {\n+\t\tstruct diff_filepair *p = diff_queued_diff.queue[i];\n+\n+\t\tret = (p->status == DIFF_STATUS_RENAMED ||\n+\t\t       p->status == DIFF_STATUS_COPIED) &&\n+\t\t      !strcmp(p->two->path, path);\n+\t}\n+\tdiff_queue_clear(&diff_queued_diff);\n+\tdiff_free(&diff_opts);\n+\treturn ret;\n+}\n+\n+/*\n+ * When the path in a merge tree is the same as in 'same', does the path still\n+ * need renames to be followed in 'parent'?\n+ */\n+static int follow_needs_renames(struct rev_info *opt, struct commit *parent,\n+\t\t\t\tstruct commit *same,\n+\t\t\t\tstruct object_id *merge_tree, const char *path)\n+{\n+\tstruct commit_list *bases = NULL, *base;\n+\tint ret = 0, changed_dropped = 0;\n+\n+\tif (parent == same || commit_has_path(opt, parent, path) ||\n+\t    !commit_has_path(opt, same, path))\n+\t\treturn 0;\n+\tif (repo_get_merge_bases(opt->diffopt.repo, parent, same, &bases) < 0)\n+\t\texit(128);\n+\t/* Unrelated histories, e.g. a subtree merge */\n+\tret = !bases;\n+\tfor (base = bases; base && !ret; base = base->next) {\n+\t\tret = commit_has_path(opt, base->item, path);\n+\t\tif (!ret && !changed_dropped)\n+\t\t\tchanged_dropped = follow_parent_changed_dropped_file(\n+\t\t\t\topt, base->item, parent, same, merge_tree);\n+\t}\n+\tcommit_list_free(bases);\n+\tif (!ret && changed_dropped)\n+\t\tret = follow_has_rename_source(opt, parent, merge_tree, path);\n+\treturn ret;\n+}\n+\n /* Show the remerge or combined diff of a merge commit */\n static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,\n \t\t\t       struct commit_list *parents,\n@@ -1187,6 +1329,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \tint all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;\n \tint follow_only = 0;\n \tchar *path = NULL;\n+\tstruct commit *same = NULL;\n \n \tif (!all_need_diff && !opt->merges_need_diff)\n \t\treturn 0;\n@@ -1234,6 +1377,8 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \tif (opt->diffopt.flags.follow_renames)\n \t\tpath = xstrdup_or_null(\n \t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n+\tif (path && is_merge && (follow_only || opt->first_parent_merges))\n+\t\tsame = follow_same_parent(opt, parents, oid);\n \n \tshowed_log = 0;\n \tall_parents = parents;\n@@ -1241,8 +1386,14 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n \t\tstruct commit *parent = parents->item;\n \n \t\tparse_commit_or_die(parent);\n-\t\tdiff_tree_oid(get_commit_tree_oid(parent),\n-\t\t\t      oid, \"\", &opt->diffopt);\n+\t\t/*\n+\t\t * Same as in a parent: follow the path as-is, unless renames\n+\t\t * still need to be followed in this parent.\n+\t\t */\n+\t\tif (!follow_only || !same ||\n+\t\t    follow_needs_renames(opt, parent, same, oid, path))\n+\t\t\tdiff_tree_oid(get_commit_tree_oid(parent),\n+\t\t\t\t      oid, \"\", &opt->diffopt);\n \t\tif (follow_only) {\n \t\t\tdiff_queue_clear(&diff_queued_diff);\n \t\t\topt->diffopt.found_follow = 0;\n-- \n2.51.0\n\n\n"},{"id":"558108","messageId":"877bik63ep.fsf@dev.null.iotcl.com.invalid","threadId":"66514","inReplyTo":"5ba93e49cff31e61621ac166f2d60b8133937f20.1794078554.git.vmiklos@collabora.com","subject":"Re: [PATCH v5 4/5] log: simplify --follow following renames for non-linear history","fromName":"Toon Claes","fromEmail":"toon@iotcl.com","sentAt":"2026-11-10T16:45:50Z","receivedAt":"2026-11-10T16:45:50Z","isPatch":true,"sender":{"key":"toon@iotcl.com","avatar":"https://avatars.githubusercontent.com/u/121621?v=4"},"body":"Miklos Vajna <vmiklos@collabora.com> writes:\n\n> Code added in 304812ed33 (log: improve --follow following renames for\n> non-linear history, 2026-06-22) implements the feature by introducing a\n> new propagate_follow_pathspec_to_parent() function which adds a new call\n> to diff_tree_oid(). Also it introduces a new loop to record what path\n> each parent of a merge commit should use when following a path.\n>\n> This works, but it causes a performance regression: e.g. 'git log\n> --stat --follow -- include/linux/rsc_table.h' in linux.git takes 6m43s,\n> while it took 28s before that commit. The new code diffs each merge\n> against each of its parents with rename detection, which is expensive\n> when a parent doesn't have the followed path yet. Fixing this would\n> require adding even more custom code, instead of just extending the\n> existing code in log_tree_diff(). So first simplify the code here, and\n> fix the performance regression in a follow-up commit.\n>\n> Remove propagate_follow_pathspec_to_parent() and the loop calling it\n> for each parent. Instead, record the path to follow for each parent in\n> the parent loop of log_tree_diff(), right after diff_tree_oid() updates\n> the pathspec in case of a rename. Merges are not diffed by default, so\n> with --follow, run the same loop for them as well, but without showing\n> anything. With -c, --cc or --remerge-diff, show the merge diff after the\n> loop. With --diff-merges=first-parent, keep diffing the other parents\n> silently, unless the walk only follows first parents. This gets rid of\n> the additional call to diff_tree_oid(). The rework has no positive\n> performance impact yet, it just simplifies the code.\n>\n> The previous commit restores the path of the merge before diffing each\n> parent, and also after the loop, for\n> propagate_follow_pathspec_to_parent(). Keep restoring it between\n> parents, but not after the loop, since there is no later propagation\n> anymore.\n>\n> Signed-off-by: Miklos Vajna <vmiklos@collabora.com>\n> ---\n>  log-tree.c | 96 +++++++++++++++++++++++-------------------------------\n>  1 file changed, 41 insertions(+), 55 deletions(-)\n>\n> diff --git a/log-tree.c b/log-tree.c\n> index befc5c8b22..0aa27fb210 100644\n> --- a/log-tree.c\n> +++ b/log-tree.c\n> @@ -1153,33 +1153,6 @@ void release_follow_pathspec_slab(struct rev_info *opt)\n>  \tFREE_AND_NULL(opt->follow_pathspec_slab);\n>  }\n>  \n> -/* Compute a path to follow in parent, if there is one */\n> -static void propagate_follow_pathspec_to_parent(struct rev_info *opt,\n> -\t\t\t\t\t\tstruct commit *commit,\n> -\t\t\t\t\t\tstruct commit *parent)\n> -{\n> -\tstruct diff_options diff_opts;\n> -\tconst char *path;\n> -\n> -\tparse_commit_or_die(parent);\n> -\trepo_diff_setup(opt->diffopt.repo, &diff_opts);\n> -\tcopy_pathspec(&diff_opts.pathspec, &opt->diffopt.pathspec);\n> -\tdiff_opts.flags.recursive = 1;\n> -\tdiff_opts.flags.follow_renames = 1;\n> -\tdiff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;\n> -\tdiff_setup_done(&diff_opts);\n> -\tdiff_tree_oid(get_commit_tree_oid(parent),\n> -\t\t      get_commit_tree_oid(commit),\n> -\t\t      \"\", &diff_opts);\n> -\n> -\tpath = pathspec_single_path(&diff_opts.pathspec);\n> -\tif (path)\n> -\t\tremember_follow_pathspec(opt, parent, path);\n> -\n> -\tdiff_queue_clear(&diff_queued_diff);\n> -\tdiff_free(&diff_opts);\n> -}\n> -\n>  /* Show the remerge or combined diff of a merge commit */\n>  static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,\n>  \t\t\t       struct commit_list *parents,\n> @@ -1208,10 +1181,11 @@ static int log_tree_merge_diff(struct rev_info *opt, struct commit *commit,\n>  static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log)\n>  {\n>  \tint showed_log;\n> -\tstruct commit_list *parents;\n> +\tstruct commit_list *parents, *all_parents;\n>  \tstruct object_id *oid;\n>  \tint is_merge;\n>  \tint all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;\n> +\tint follow_only = 0;\n>  \tchar *path = NULL;\n>  \n>  \tif (!all_need_diff && !opt->merges_need_diff)\n> @@ -1241,46 +1215,73 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log\n>  \t}\n>  \n>  \tif (is_merge) {\n> -\t\tif (opt->remerge_diff || opt->combine_merges)\n> +\t\tint merge_diff = opt->remerge_diff || opt->combine_merges;\n> +\n> +\t\tif (merge_diff && !opt->diffopt.flags.follow_renames)\n>  \t\t\treturn log_tree_merge_diff(opt, commit, parents, oid);\n> -\t\tif (opt->separate_merges) {\n> +\t\tif (opt->separate_merges && !merge_diff) {\n>  \t\t\tif (!opt->first_parent_merges) {\n>  \t\t\t\t/* Show parent info for multiple diffs */\n>  \t\t\t\tlog->parent = parents->item;\n>  \t\t\t}\n> +\t\t} else if (opt->diffopt.flags.follow_renames) {\n> +\t\t\t/* Diff only to find the path to follow in parents */\n> +\t\t\tfollow_only = 1;\n>  \t\t} else\n>  \t\t\treturn 0;\n\nThis part of code has become pretty tough to read if you ask me. I've\ntried to rewrite it:\n\n        if (is_merge) {\n                /* -c, --cc or --remerge-diff: show one diff for the whole merge. */\n                int merge_diff = opt->remerge_diff || opt->combine_merges;\n\n                /* Without --follow the parent loop is only needed for -m. */\n                if (!opt->diffopt.flags.follow_renames) {\n                        /* -c, --cc or --remerge-diff: show it, no parent loop. */\n                        if (merge_diff)\n                                return log_tree_merge_diff(opt, commit, parents, oid);\n                        /* No -m either, i.e. merge diffs are off: show nothing. */\n                        if (!opt->separate_merges)\n                                return 0;\n                }\n\n                /* Run the loop silently, unless -m shows a diff per parent. */\n                follow_only = !opt->separate_merges || merge_diff;\n\n                /* -m showing all parents: label each diff \"(from <parent>)\". */\n                if (!follow_only && !opt->first_parent_merges)\n                        /* Label the first diff, others are labeled in parent loop. */\n                        log->parent = parents->item;\n        }\n\nThe comments I've added are possibly too verbose for the Git project,\nbut they helped me understand what happens at each line. I hope it's\nfunctionally the same?\n\n(This is as far as I have gotten in the review today, but I wanted to\nsend this out already)\n\n>  \t}\n>  \n> -\tif (is_merge && opt->diffopt.flags.follow_renames)\n> +\tif (opt->diffopt.flags.follow_renames)\n>  \t\tpath = xstrdup_or_null(\n>  \t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n>  \n>  \tshowed_log = 0;\n> +\tall_parents = parents;\n>  \tfor (;;) {\n>  \t\tstruct commit *parent = parents->item;\n>  \n> -\t\t/* Diff each parent with the path of the merge */\n> -\t\tif (path)\n> -\t\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec,\n> -\t\t\t\t\t\t    path);\n>  \t\tparse_commit_or_die(parent);\n>  \t\tdiff_tree_oid(get_commit_tree_oid(parent),\n>  \t\t\t      oid, \"\", &opt->diffopt);\n> -\t\tlog_tree_diff_flush(opt);\n> +\t\tif (follow_only) {\n> +\t\t\tdiff_queue_clear(&diff_queued_diff);\n> +\t\t\topt->diffopt.found_follow = 0;\n> +\t\t} else {\n> +\t\t\tlog_tree_diff_flush(opt);\n> +\t\t}\n>  \n>  \t\tshowed_log |= !opt->loginfo;\n>  \n> +\t\t/* The diff updated the pathspec in case of a rename */\n> +\t\tif (path)\n> +\t\t\tremember_follow_pathspec(opt, parent,\n> +\t\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n> +\n>  \t\t/* Set up the log info for the next parent, if any.. */\n>  \t\tparents = parents->next;\n> -\t\tif (!parents || opt->first_parent_merges)\n> +\t\tif (!parents)\n>  \t\t\tbreak;\n> +\t\tif (opt->first_parent_merges) {\n> +\t\t\tif (!path || opt->first_parent_only)\n> +\t\t\t\tbreak;\n> +\t\t\t/* Only find the path to follow in the other parents */\n> +\t\t\tfollow_only = 1;\n> +\t\t}\n> +\t\tif (path)\n> +\t\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec,\n> +\t\t\t\t\t\t    path);\n> +\t\tif (follow_only)\n> +\t\t\tcontinue;\n>  \t\tlog->parent = parents->item;\n>  \t\topt->loginfo = log;\n>  \t}\n> -\t/* Propagate to parents starting from the path of the merge, too */\n> -\tif (path)\n> -\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec, path);\n> +\tif (follow_only && (opt->remerge_diff || opt->combine_merges)) {\n> +\t\t/* Show the merge diff with the path of this commit */\n> +\t\tif (path)\n> +\t\t\tset_pathspec_to_single_path(&opt->diffopt.pathspec,\n> +\t\t\t\t\t\t    path);\n> +\t\tshowed_log = log_tree_merge_diff(opt, commit, all_parents, oid);\n> +\t}\n>  \tfree(path);\n>  \treturn showed_log;\n>  }\n> @@ -1319,21 +1320,6 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)\n>  \t\tfprintf(opt->diffopt.file, \"\\n%s\\n\", opt->break_bar);\n>  \tif (shown)\n>  \t\tshow_diff_of_diff(opt);\n> -\n> -\t/* Record what path each parent of this commit should use */\n> -\tif (opt->diffopt.flags.follow_renames) {\n> -\t\tstruct commit_list *parents = get_saved_parents(opt, commit);\n> -\t\tif (parents && parents->next) {\n> -\t\t\tstruct commit_list *p;\n> -\t\t\tfor (p = parents; p; p = p->next)\n> -\t\t\t\tpropagate_follow_pathspec_to_parent(opt, commit,\n> -\t\t\t\t\t\t\t\t    p->item);\n> -\t\t} else if (parents) {\n> -\t\t\tremember_follow_pathspec(opt, parents->item,\n> -\t\t\t\tpathspec_single_path(&opt->diffopt.pathspec));\n> -\t\t}\n> -\t}\n> -\n>  \topt->loginfo = NULL;\n>  \tmaybe_flush_or_die(opt->diffopt.file, \"stdout\");\n>  \topt->diffopt.no_free = no_free;\n> -- \n> 2.51.0\n>\n\n-- \nLaters,\nToon\n\n"},{"id":"558152","messageId":"avOWhV09WfNsAptg@jtobler--20250820-SHC54","threadId":"66514","inReplyTo":"5512aa682f71243378c06dcb8cda2b53150d4e39.1794078554.git.vmiklos@collabora.com","subject":"Re: [PATCH v5 1/5] t4219: test more --follow cases across merges","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-10T23:06:49Z","receivedAt":"2026-11-10T23:06:49Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 26/11/09 09:04AM, Miklos Vajna wrote:\n>A later commit in this series will speed up 'git log --follow' for\n>merge commits. Add tests for cases which already work, but have no\n>test coverage, so it's easy to break them while optimizing:\n>\n>- a subtree merge adding the history of a file that was copied before\n>- --follow through a fork with renames on both sides, with -c, --cc\n>  and --remerge-diff\n>- a --no-ff merge taking a rename from the second parent, in both commit\n>  orders, since the result could depend on the walk order\n>- a merge keeping the path, while the other side renamed it\n>- --diff-merges=first-parent, which diffs merges only against their\n>  first parent, but still walks all parents\n>- a merge keeping the renamed path, while the other side edited the old\n>  one\n>- a merge keeping the copied path, while the other side edited the\n>  original\n\nThis explains what tests we are adding, but it doesn't really provide\nreaders with much context as do why they are the expected behaviors.\n\n>\n>Helped-by: Patrick Steinhardt <ps@pks.im>\n>Signed-off-by: Miklos Vajna <vmiklos@collabora.com>\n>---\n> t/t4219-log-follow-merge.sh | 214 ++++++++++++++++++++++++++++++++++++\n> 1 file changed, 214 insertions(+)\n>\n>diff --git a/t/t4219-log-follow-merge.sh b/t/t4219-log-follow-merge.sh\n>index e370f82955..806ccc24bd 100755\n>--- a/t/t4219-log-follow-merge.sh\n>+++ b/t/t4219-log-follow-merge.sh\n>@@ -31,6 +31,33 @@ test_expect_success '--follow finds the pre-merge commit through a subtree merge\n> \ttest_cmp expect actual\n> '\n>\n>+test_expect_success 'setup subtree merge adding the history of a copied file' '\n>+\tgit init graft &&\n>+\techo outer >graft/outer.txt &&\n>+\tgit -C graft add outer.txt &&\n>+\ttest_tick &&\n>+\tgit -C graft commit -m \"outer init\" &&\n>+\tmkdir graft/inner &&\n>+\tcp inner/inner.txt graft/inner/ &&\n>+\tgit -C graft add inner &&\n>+\ttest_tick &&\n>+\tgit -C graft commit -m \"copy inner.txt to inner/\" &&\n>+\n>+\tgit -C graft fetch ../inner master &&\n>+\ttest_tick &&\n>+\tgit -C graft merge -s ours --allow-unrelated-histories \\\n>+\t\t-m \"Merge the history of inner/\" FETCH_HEAD\n>+'\n\nOk IIUC, this test is setting up a repository has manually copied and\ncommitted from another repository, but then later merges the unrelated\nhistory. It took me a little bit to parse what exactly was going on\nhere. Maybe some comments would be a bit helpful here?\n\n>+\n>+test_expect_success '--follow finds the history of a copied file through a subtree merge' '\n>+\tgit -C graft log --follow --pretty=tformat:%s inner/inner.txt >actual &&\n>+\tcat >expect <<-\\EOF &&\n>+\tcopy inner.txt to inner/\n>+\tinner init\n>+\tEOF\n>+\ttest_cmp expect actual\n>+'\n\nOk and here we validate that we follow the file into the now merged\nunrelated history. I assume that prior to 304812ed33de (log: improve\n--follow following renames for non-linear history, 2026-06-22), this\nwould not have passed? If so, it might be helpful to more directly\nmention this in the commit message?\n\n>+\n> test_expect_success 'setup merge of two branches that both renamed a file to README' '\n> \tgit init foo &&\n> \tmkdir foo/foo &&\n>@@ -126,4 +153,191 @@ test_expect_success '--follow follows renames through a fork in a single history\n> \ttest_cmp expect actual.sorted\n> '\n>\n>+for opt in -c --cc --remerge-diff\n>+do\n>+\ttest_expect_success \"--follow follows renames through a fork with $opt\" '\n>+\t\tgit -C diamond log --follow $opt --pretty=tformat:%s path >log &&\n>+\t\tgrep \"^[A-Z]: \" log | sort >actual &&\n>+\t\tcat >expect <<-\\EOF &&\n>+\t\tA: add path0\n>+\t\tB: modify path0 on upper\n>+\t\tC: modify path0 on lower\n>+\t\tM: merge with rename to path\n>+\t\tX: rename path0 to path1\n>+\t\tY: rename path0 to path2\n>+\t\tZ: modify path\n>+\t\tEOF\n>+\t\ttest_cmp expect actual\n>+\t'\n>+done\n\nI assume here we are validating that the merge is printed?\n\n>+\n>+# Build a merge that takes the renamed path from the second parent, while the\n>+# first parent only has the old path. $2 decides which side is committed first,\n>+# which decides the walk order.\n>+setup_rename_on_second_parent () {\n>+\tgit init $1 &&\n>+\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >$1/old &&\n>+\tgit -C $1 add old &&\n>+\ttest_tick &&\n>+\tgit -C $1 commit -m \"A: add old\" &&\n>+\tprintf \"line 1\\nline 2\\nline 3 modified\\nline 4\\nline 5\\n\" >$1/old &&\n>+\ttest_tick &&\n>+\tgit -C $1 commit -am \"B: modify old\" &&\n>+\tgit -C $1 branch topic &&\n>+\n>+\tif test \"$2\" = topic-first\n>+\tthen\n>+\t\tgit -C $1 checkout topic &&\n>+\t\tgit -C $1 mv old new &&\n>+\t\ttest_tick &&\n>+\t\tgit -C $1 commit -m \"R: rename old to new\" &&\n>+\t\tgit -C $1 checkout master\n>+\tfi &&\n>+\n>+\techo other >$1/other &&\n>+\tgit -C $1 add other &&\n>+\ttest_tick &&\n>+\tgit -C $1 commit -m \"M: unrelated change on master\" &&\n>+\n>+\tif test \"$2\" = master-first\n>+\tthen\n>+\t\tgit -C $1 checkout topic &&\n>+\t\tgit -C $1 mv old new &&\n>+\t\ttest_tick &&\n>+\t\tgit -C $1 commit -m \"R: rename old to new\" &&\n>+\t\tgit -C $1 checkout master\n>+\tfi &&\n>+\n>+\ttest_tick &&\n>+\tgit -C $1 merge --no-ff -m \"merge topic\" topic\n>+}\n\nOk, because the walk order is based on commiter date, we have a helper\nfunction here that can create various test setups to validate we can\nfollow a file through the history.\n\n>+\n>+test_expect_success 'setup merge taking a rename from the second parent' '\n>+\tsetup_rename_on_second_parent rename-master-first master-first &&\n>+\tsetup_rename_on_second_parent rename-topic-first topic-first\n>+'\n>+\n>+for order in master-first topic-first\n>+do\n>+\ttest_expect_success \"--follow follows a rename from the second parent ($order)\" '\n>+\t\tgit -C rename-$order log --follow --pretty=tformat:%s new >actual &&\n>+\t\tcat >expect <<-\\EOF &&\n>+\t\tR: rename old to new\n>+\t\tB: modify old\n>+\t\tA: add old\n>+\t\tEOF\n>+\t\ttest_cmp expect actual\n>+\t'\n>+done\n\nOk, so we expect the results to be same the same and the file to be\nfound on both sides here. I realize we are crafting very specific\nrepository histories to validate here, but I must say the test setup\nhere is rather complex IMO.\n\n>+\n>+test_expect_success 'setup merge keeping the path, other side renamed it' '\n>+\tgit init keep &&\n>+\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >keep/F &&\n>+\tgit -C keep add F &&\n>+\ttest_tick &&\n>+\tgit -C keep commit -m \"O: add F\" &&\n>+\tgit -C keep branch B &&\n>+\tprintf \"line 1\\nline 2\\nline 3 A\\nline 4\\nline 5\\n\" >keep/F &&\n>+\ttest_tick &&\n>+\tgit -C keep commit -am \"A1: update F in place\" &&\n>+\n>+\tgit -C keep checkout B &&\n>+\tgit -C keep mv F G &&\n>+\ttest_tick &&\n>+\tgit -C keep commit -m \"B1: rename F to G\" &&\n>+\tprintf \"line 1\\nline 2\\nline 3\\nline 4 B\\nline 5\\n\" >keep/G &&\n>+\ttest_tick &&\n>+\tgit -C keep commit -am \"B2: update G\" &&\n>+\n>+\tgit -C keep checkout master &&\n>+\ttest_tick &&\n>+\tgit -C keep merge -s ours -m \"M: merge B, keep F, drop G\" B\n>+'\n\nOk, here we are creating a history where a topic modifies and renames a\nfile, but the merge drops these changes. Some comments here might also\nbe helpful for readers.\n\n>+\n>+test_expect_success '--follow follows a rename on the side the merge did not take' '\n>+\tgit -C keep log --follow --pretty=tformat:%s F >actual &&\n>+\tcat >expect <<-\\EOF &&\n>+\tB2: update G\n>+\tB1: rename F to G\n>+\tA1: update F in place\n>+\tO: add F\n>+\tEOF\n>+\ttest_cmp expect actual\n>+'\n\nWe expect that the commits from branch B are still inspected even though\nthe merge dropped them. Makes sense.\n\n>+\n>+test_expect_success '--follow with --diff-merges=first-parent follows all parents' '\n>+\tgit -C keep log --follow --diff-merges=first-parent --no-patch \\\n>+\t\t--pretty=tformat:%s F >actual &&\n>+\tcat >expect <<-\\EOF &&\n>+\tB2: update G\n>+\tB1: rename F to G\n>+\tA1: update F in place\n>+\tO: add F\n>+\tEOF\n>+\ttest_cmp expect actual\n>+'\n\nhmmmm, is the expectation here that `--diff-merges=first-parent` doesn't\nprevent us from visiting commits from the second parent?\n\n>+\n>+test_expect_success 'setup merge keeping the renamed path, other side edited the old one' '\n>+\tgit init keep-renamed &&\n>+\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >keep-renamed/F &&\n>+\tgit -C keep-renamed add F &&\n>+\ttest_tick &&\n>+\tgit -C keep-renamed commit -m \"O: add F\" &&\n>+\tgit -C keep-renamed branch B &&\n>+\tgit -C keep-renamed mv F G &&\n>+\ttest_tick &&\n>+\tgit -C keep-renamed commit -m \"A1: rename F to G on master\" &&\n>+\n>+\tgit -C keep-renamed checkout B &&\n>+\tprintf \"line 1\\nline 2\\nline 3\\nline 4 T\\nline 5\\n\" >keep-renamed/F &&\n>+\ttest_tick &&\n>+\tgit -C keep-renamed commit -am \"B2: update F on B\" &&\n>+\n>+\tgit -C keep-renamed checkout master &&\n>+\ttest_tick &&\n>+\tgit -C keep-renamed merge -s ours -m \"M: merge B, keep G, drop F\" B\n>+'\n\nHere the merge keeps master's renamed G and discards branch B's edit to\nF.\n\n>+\n>+test_expect_success '--follow follows an edit on the side the merge did not take' '\n>+\tgit -C keep-renamed log --follow --pretty=tformat:%s G >actual &&\n>+\tcat >expect <<-\\EOF &&\n>+\tB2: update F on B\n>+\tA1: rename F to G on master\n>+\tO: add F\n>+\tEOF\n>+\ttest_cmp expect actual\n>+'\n\nCommits from both sides along with the original commit are expected.\nMakes sense.\n\n>+\n>+test_expect_success 'setup merge keeping the copied path, other side edited the original' '\n>+\tgit init keep-copied &&\n>+\tprintf \"line 1\\nline 2\\nline 3\\nline 4\\nline 5\\n\" >keep-copied/F &&\n>+\tgit -C keep-copied add F &&\n>+\ttest_tick &&\n>+\tgit -C keep-copied commit -m \"O: add F\" &&\n>+\tgit -C keep-copied branch B &&\n>+\tcp keep-copied/F keep-copied/G &&\n>+\tgit -C keep-copied add G &&\n>+\ttest_tick &&\n>+\tgit -C keep-copied commit -m \"A1: copy F to G on master\" &&\n>+\n>+\tgit -C keep-copied checkout B &&\n>+\tprintf \"line 1\\nline 2\\nline 3\\nline 4 T\\nline 5\\n\" >keep-copied/F &&\n>+\ttest_tick &&\n>+\tgit -C keep-copied commit -am \"B2: update F on B\" &&\n>+\n>+\tgit -C keep-copied checkout master &&\n>+\ttest_tick &&\n>+\tgit -C keep-copied merge -s ours -m \"M: merge B, keep F and G\" B\n>+'\n>+\n>+test_expect_success '--follow follows an edit of the copy source on the side the merge did not take' '\n>+\tgit -C keep-copied log --follow --pretty=tformat:%s G >actual &&\n>+\tcat >expect <<-\\EOF &&\n>+\tB2: update F on B\n>+\tA1: copy F to G on master\n>+\tO: add F\n>+\tEOF\n>+\ttest_cmp expect actual\n>+'\n>+\n> test_done\n\nOk, these tests are similar to last set, but copied instead of renamed.\n\n-Justin\n\n"},{"id":"558153","messageId":"avOzVCHdGBNIG8sT@jtobler--20250820-SHC54","threadId":"66514","inReplyTo":"cover.1794078554.git.vmiklos@collabora.com","subject":"Re: [PATCH v5 0/5] log: speed up --follow following renames for non-linear history","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-11T00:40:00Z","receivedAt":"2026-11-11T00:40:00Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 26/11/09 09:03AM, Miklos Vajna wrote:\n>Hi Patrick,\n>\n>Thanks for the reviews of v4. Changes in v5:\n>\n>- The fix of the old 6/6 is now squashed into the speedup patch (5/5),\n>  so no commit in the series loses history, and its test is moved to\n>  1/5. While at it, I simplified 5/5: instead of two passes of diffs\n>  against the parents, it first finds a parent where the path is\n>  unchanged, and then only diffs against the other parents if they\n>  still need renames to be followed. Because of the squash, the\n>  range-diff pairs the new 5/5 with the old 6/6.\n>\n>- 5/5 now also follows renames when a parent has no merge base with\n>  the parent where the path is unchanged, e.g. a subtree merge of\n>  unrelated histories. Added a test for this to 1/5.\n>\n>- 5/5 now also follows copies, not only renames, when the merge dropped\n>  the edit of the copy source. Added your test for this to 1/5. With\n>  this, the linux.git case takes about 42s, instead of 37s.\n\nI'm a bit late to the party, but I decided to run some benchmarks\nagainst linux.git to showcase performance with 304812ed33de (log:\nimprove --follow following renames for non-linear history, 2026-06-22)\nreverted, at the regression, and with v5 of this series applied:\n\n  Benchmark 1: git log --stat --follow -- include/linux/rsc_table.h (rev = 304812ed33 reverted)\n    Time (mean ± σ):     23.493 s ±  0.645 s    [User: 23.001 s, System: 0.389 s]\n    Range (min … max):   22.748 s … 23.883 s    3 runs\n\n  Benchmark 2: git log --stat --follow -- include/linux/rsc_table.h (rev = 304812ed33)\n    Time (mean ± σ):     335.883 s ±  4.866 s    [User: 333.773 s, System: 0.577 s]\n    Range (min … max):   332.296 s … 341.422 s    3 runs\n\n  Benchmark 3: git log --stat --follow -- include/linux/rsc_table.h (rev = v5)\n    Time (mean ± σ):     38.688 s ±  0.379 s    [User: 38.081 s, System: 0.415 s]\n    Range (min … max):   38.250 s … 38.923 s    3 runs\n\n  Summary\n    git log --stat --follow -- include/linux/rsc_table.h (rev = 304812ed33 reverted) ran\n     14.30 ± 0.44 times faster than git log --stat --follow -- include/linux/rsc_table.h (rev = 304812ed33)\n      1.65 ± 0.05 times faster than git log --stat --follow -- include/linux/rsc_table.h (rev = v5)\n\nWhile the fix in this series does improve the state of things, it is\nstill overall a significant performance regression that I expect will\nresult in increased file history timeouts on the server-side for some\nrepositories we host at GitLab. Rename following for a file's history\neven prior to this regression can be expensive for large repositories.\n\nWhile the original patch and this series do improve correctness of\nfollowing a file through history, I wonder if the increased cost is\nultimately worth it in most scenarios. Maybe this could be something\nopt-in with another flag instead of toggled on my default?\n\nWith this in mind, maybe it would be worth it to revert 304812ed33de\n(log: improve --follow following renames for non-linear history,\n2026-06-22) and restart with a fresh series. IMO, it might make the\nchanges here a bit easier to validate also.\n\nThanks,\n-Justin\n\n"},{"id":"558169","messageId":"avRG5r8DPrS23Nmk@pks.im","threadId":"66514","inReplyTo":"avOzVCHdGBNIG8sT@jtobler--20250820-SHC54","subject":"Re: [PATCH v5 0/5] log: speed up --follow following renames for non-linear history","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T10:43:50Z","receivedAt":"2026-11-11T10:43:50Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Nov 10, 2026 at 06:40:00PM -0600, Justin Tobler wrote:\n> On 26/11/09 09:03AM, Miklos Vajna wrote:\n> > Hi Patrick,\n> > \n> > Thanks for the reviews of v4. Changes in v5:\n> > \n> > - The fix of the old 6/6 is now squashed into the speedup patch (5/5),\n> >  so no commit in the series loses history, and its test is moved to\n> >  1/5. While at it, I simplified 5/5: instead of two passes of diffs\n> >  against the parents, it first finds a parent where the path is\n> >  unchanged, and then only diffs against the other parents if they\n> >  still need renames to be followed. Because of the squash, the\n> >  range-diff pairs the new 5/5 with the old 6/6.\n> > \n> > - 5/5 now also follows renames when a parent has no merge base with\n> >  the parent where the path is unchanged, e.g. a subtree merge of\n> >  unrelated histories. Added a test for this to 1/5.\n> > \n> > - 5/5 now also follows copies, not only renames, when the merge dropped\n> >  the edit of the copy source. Added your test for this to 1/5. With\n> >  this, the linux.git case takes about 42s, instead of 37s.\n> \n> I'm a bit late to the party, but I decided to run some benchmarks\n> against linux.git to showcase performance with 304812ed33de (log:\n> improve --follow following renames for non-linear history, 2026-06-22)\n> reverted, at the regression, and with v5 of this series applied:\n> \n>   Benchmark 1: git log --stat --follow -- include/linux/rsc_table.h (rev = 304812ed33 reverted)\n>     Time (mean ± σ):     23.493 s ±  0.645 s    [User: 23.001 s, System: 0.389 s]\n>     Range (min … max):   22.748 s … 23.883 s    3 runs\n> \n>   Benchmark 2: git log --stat --follow -- include/linux/rsc_table.h (rev = 304812ed33)\n>     Time (mean ± σ):     335.883 s ±  4.866 s    [User: 333.773 s, System: 0.577 s]\n>     Range (min … max):   332.296 s … 341.422 s    3 runs\n> \n>   Benchmark 3: git log --stat --follow -- include/linux/rsc_table.h (rev = v5)\n>     Time (mean ± σ):     38.688 s ±  0.379 s    [User: 38.081 s, System: 0.415 s]\n>     Range (min … max):   38.250 s … 38.923 s    3 runs\n> \n>   Summary\n>     git log --stat --follow -- include/linux/rsc_table.h (rev = 304812ed33 reverted) ran\n>      14.30 ± 0.44 times faster than git log --stat --follow -- include/linux/rsc_table.h (rev = 304812ed33)\n>       1.65 ± 0.05 times faster than git log --stat --follow -- include/linux/rsc_table.h (rev = v5)\n> \n> While the fix in this series does improve the state of things, it is\n> still overall a significant performance regression that I expect will\n> result in increased file history timeouts on the server-side for some\n> repositories we host at GitLab. Rename following for a file's history\n> even prior to this regression can be expensive for large repositories.\n> \n> While the original patch and this series do improve correctness of\n> following a file through history, I wonder if the increased cost is\n> ultimately worth it in most scenarios. Maybe this could be something\n> opt-in with another flag instead of toggled on my default?\n\nYeah, by now I'm also leaning into this direction. The performance cost\nis definitely way too high for us, so we need a way to disable this new\nfeature altogether at GitLab.\n\n> With this in mind, maybe it would be worth it to revert 304812ed33de\n> (log: improve --follow following renames for non-linear history,\n> 2026-06-22) and restart with a fresh series. IMO, it might make the\n> changes here a bit easier to validate also.\n\nI don't have a strong sense on whether or not we should revert the whole\nseries. I find the patches quite hard to review, but that may not be\nbecause we're fixing things incrementally and rather be because I myself\nam not familiar with this subsystem.\n\nBut in case we decide to not revert I'd like to see a toggle to disable\nthis feature as a first step. As mentioned, this change has caused a\nrather big regression for GitLab, so we'd ideally have a way to disable\nthis feature soon so that we can mitigate it.\n\nI don't want to make you (Miklos) responsible for delivering that of\ncourse, I just want us to align on a fast path forward. In case we don't\nrevert we can help out and contribute such a default-disabled toggle.\nAnd if so, that would also give us more time to fix the issue properly.\n\nThanks!\n\nPatrick\n\n"},{"id":"558198","messageId":"avRicTWUWuyOuUNP@collabora.com","threadId":"66514","inReplyTo":"avRG5r8DPrS23Nmk@pks.im","subject":"Re: [PATCH v5 0/5] log: speed up --follow following renames for non-linear history","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-11-11T12:41:21Z","receivedAt":"2026-11-11T12:41:21Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Hi Patrick,\n\nOn Wed, Nov 11, 2026 at 11:43:50AM +0100, Patrick Steinhardt <ps@pks.im> wrote:\n> > While the original patch and this series do improve correctness of\n> > following a file through history, I wonder if the increased cost is\n> > ultimately worth it in most scenarios. Maybe this could be something\n> > opt-in with another flag instead of toggled on my default?\n> \n> Yeah, by now I'm also leaning into this direction. The performance cost\n> is definitely way too high for us, so we need a way to disable this new\n> feature altogether at GitLab.\n\nI have no problem with turning this from default to opt-in. I would be\nhappy to not revert, since a lot of effort went into this, and some see\nthis as a bug in git-log, not showing some history which is there.\n\n> I don't have a strong sense on whether or not we should revert the whole\n> series. I find the patches quite hard to review, but that may not be\n> because we're fixing things incrementally and rather be because I myself\n> am not familiar with this subsystem.\n> \n> But in case we decide to not revert I'd like to see a toggle to disable\n> this feature as a first step. As mentioned, this change has caused a\n> rather big regression for GitLab, so we'd ideally have a way to disable\n> this feature soon so that we can mitigate it.\n\nMakes sense. To be honest, I'm not too happy about the complexity the\nlast patch in the series introduces -- but having performance that is\nsomewhat close to the old behavior seems to justify it.\n\n> I don't want to make you (Miklos) responsible for delivering that of\n> course, I just want us to align on a fast path forward. In case we don't\n> revert we can help out and contribute such a default-disabled toggle.\n> And if so, that would also give us more time to fix the issue properly.\n\nYes, aligning on what we want would be good. :-) I'm OK to replace the\nlast patch in the series with a patch that turns this off by default,\nbut then how to opt in, would be be fine to have a new config option for\nthis (similar to log.follow)? Would that do what you need or you want\nsomething else?\n\nThanks,\n\nMiklos\n\n"},{"id":"558206","messageId":"avRtsm5VQpC_g9yN@pks.im","threadId":"66514","inReplyTo":"avRicTWUWuyOuUNP@collabora.com","subject":"Re: [PATCH v5 0/5] log: speed up --follow following renames for non-linear history","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T13:29:22Z","receivedAt":"2026-11-11T13:29:22Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Wed, Nov 11, 2026 at 12:41:21PM +0000, Miklos Vajna wrote:\n> On Wed, Nov 11, 2026 at 11:43:50AM +0100, Patrick Steinhardt <ps@pks.im> wrote:\n[snip]\n> > I don't want to make you (Miklos) responsible for delivering that of\n> > course, I just want us to align on a fast path forward. In case we don't\n> > revert we can help out and contribute such a default-disabled toggle.\n> > And if so, that would also give us more time to fix the issue properly.\n> \n> Yes, aligning on what we want would be good. :-) I'm OK to replace the\n> last patch in the series with a patch that turns this off by default,\n> but then how to opt in, would be be fine to have a new config option for\n> this (similar to log.follow)? Would that do what you need or you want\n> something else?\n\nI don't really have a good sense of how far this patch series is on its\nroad to getting merged. So how about we first land a single-patch series\nthat introduces the knob that we can merge without the remaining parts\nin this series here?\n\n  (For context, we deploy from Git's master branch at GitLab, and hence\n  my desire to have this regression fixed fast. As said, I'm happy to\n  help out with that, I don't want to push the whole burden on you\n  here.)\n\nWith regards to how to opt-in, I can see two ways:\n\n  - We could extend \"--follow\" to take an optional parameter so that the\n    user can pass \"--follow=merges\". Same with \"log.follow\", we could\n    teach it another option \"merges\".\n\n  - We could introduce \"--follow-merges\" and \"log.followMerges\".\n\nI'm leaning towards the first option myself.\n\nThanks!\n\nPatrick\n\n"},{"id":"558236","messageId":"xmqqo6bvnwqt.fsf@gitster.g","threadId":"66514","inReplyTo":"avOzVCHdGBNIG8sT@jtobler--20250820-SHC54","subject":"Re: [PATCH v5 0/5] log: speed up --follow following renames for non-linear history","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-11T16:44:42Z","receivedAt":"2026-11-11T16:44:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Justin Tobler <jltobler@gmail.com> writes:\n\n>    Summary\n>      git log --stat --follow -- include/linux/rsc_table.h (rev = 304812ed33 reverted) ran\n>       14.30 ± 0.44 times faster than git log --stat --follow -- include/linux/rsc_table.h (rev = 304812ed33)\n>        1.65 ± 0.05 times faster than git log --stat --follow -- include/linux/rsc_table.h (rev = v5)\n> ...\n> While the original patch and this series do improve correctness of\n> following a file through history, I wonder if the increased cost is\n> ultimately worth it in most scenarios. Maybe this could be something\n> opt-in with another flag instead of toggled on my default?\n>\n> With this in mind, maybe it would be worth it to revert 304812ed33de\n> (log: improve --follow following renames for non-linear history,\n> 2026-06-22) and restart with a fresh series. IMO, it might make the\n> changes here a bit easier to validate also.\n\nThis sounds sensible, and is far better than reverting and declaring\n\"The original 'checkbox hack' should stay here forever because doing\nit right will be very expensive\".  Giving it a fresh start would be\nvaluable as following a single the is an important operation in some\nworkflows.\n\nThanks.\n\n"},{"id":"558282","messageId":"avWBQ_10mHUNQcFi@collabora.com","threadId":"66514","inReplyTo":"avRtsm5VQpC_g9yN@pks.im","subject":"[PATCH] log: make --follow following renames for non-linear history optional","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-11-12T09:05:07Z","receivedAt":"2026-11-12T09:05:07Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Since commit 304812ed33 (log: improve --follow following renames for\nnon-linear history, 2026-06-22), 'git log --stat --follow --\ninclude/linux/rsc_table.h' on linux.git takes 6m43s, while it took about\n28 seconds before.\n\nWhat happens is that log_tree_commit() diffs each merge against all of\nits parents with rename following, to find the path to follow in each\nparent. diff_tree_oid() only does the expensive rename detection when\nthe path is added relative to a parent, but that is common for merges,\ne.g. when a branch forked before the path was created merges mainline.\n\nFix the problem by making this per-parent diffing opt-in: plain --follow\nbehaves as before 304812ed33 again, and 'git log --follow=merges'\nfollows the path separately in each parent of a merge. Add a matching\nlog.follow=merges configuration option as well.\n\nSuggested-by: Patrick Steinhardt <ps@pks.im>\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n\nHi Junio,\n\nOn Wed, Nov 11, 2026 at 08:44:42AM -0800, Junio C Hamano <gitster@pobox.com> wrote:\n> This sounds sensible, and is far better than reverting and declaring\n> \"The original 'checkbox hack' should stay here forever because doing\n> it right will be very expensive\".\n\nIf that is fine with you, I suggest just replacing the\nmv/log-follow-speedup branch with this patch.\n\nHi Patrick,\n\nOn Wed, Nov 11, 2026 at 02:29:22PM +0100, Patrick Steinhardt <ps@pks.im> wrote:\n> I don't really have a good sense of how far this patch series is on its\n> road to getting merged. So how about we first land a single-patch series\n> that introduces the knob that we can merge without the remaining parts\n> in this series here?\n\nI like the idea, here is a patch to do that.\n\n> With regards to how to opt-in, I can see two ways:\n> \n>   - We could extend \"--follow\" to take an optional parameter so that the\n>     user can pass \"--follow=merges\". Same with \"log.follow\", we could\n>     teach it another option \"merges\".\n> \n>   - We could introduce \"--follow-merges\" and \"log.followMerges\".\n> \n> I'm leaning towards the first option myself.\n\nYes, --follow=merges also appears more natural to me, so I implemented\nit that way.\n\nThanks,\n\nMiklos\n\n Documentation/config/log.adoc |  4 +++-\n Documentation/git-log.adoc    |  7 +++++--\n builtin/log.c                 | 15 +++++++++++++--\n diff.c                        | 15 +++++++++++----\n diff.h                        |  2 ++\n log-tree.c                    |  6 ++++--\n t/t4219-log-follow-merge.sh   | 32 +++++++++++++++++++++++++-------\n 7 files changed, 63 insertions(+), 18 deletions(-)\n\ndiff --git a/Documentation/config/log.adoc b/Documentation/config/log.adoc\nindex f7dfce69b5..72a3486a73 100644\n--- a/Documentation/config/log.adoc\n+++ b/Documentation/config/log.adoc\n@@ -53,7 +53,9 @@ This is the same as the `--decorate` option of the `git log`.\n `log.follow`::\n \tIf `true`, `git log` will act as if the `--follow` option was used when\n \ta single <path> is given.  This has the same limitations as `--follow`,\n-\ti.e. it cannot be used to follow multiple files.\n+\ti.e. it cannot be used to follow multiple files and does not work well\n+\ton non-linear history.  If `merges`, `git log` will act as if the\n+\t`--follow=merges` option was used.\n \n `log.graphColors`::\n \tA list of colors, separated by commas, that can be used to draw\ndiff --git a/Documentation/git-log.adoc b/Documentation/git-log.adoc\nindex fb3ac11283..742b832bbf 100644\n--- a/Documentation/git-log.adoc\n+++ b/Documentation/git-log.adoc\n@@ -27,9 +27,12 @@ each commit introduces are shown.\n OPTIONS\n -------\n \n-`--follow`::\n+`--follow[=merges]`::\n \tContinue listing the history of a file beyond renames\n-\t(works only for a single file).\n+\t(works only for a single file). This does not work well on\n+\tnon-linear history, unless `merges` is given: then the path is\n+\tfollowed separately for each parent of a merge, which is more\n+\texpensive.\n \n `--no-decorate`::\n `--decorate[=(short|full|auto|no)]`::\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 350b35c556..db707877f6 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -108,6 +108,7 @@ static int parse_decoration_style(const char *value)\n struct log_config {\n \tint default_abbrev_commit;\n \tint default_show_root;\n+\t/* 0: no, 1: yes, 2: merges */\n \tint default_follow;\n \tint default_show_signature;\n \tint default_encode_email_headers;\n@@ -205,6 +206,8 @@ static void cmd_log_init_defaults(struct rev_info *rev,\n \t\tget_commit_format(cfg->fmt_pretty, rev);\n \tif (cfg->default_follow)\n \t\trev->diffopt.flags.default_follow_renames = 1;\n+\tif (cfg->default_follow == 2)\n+\t\trev->diffopt.flags.default_follow_merges = 1;\n \trev->verbose_header = 1;\n \tinit_diffstat_widths(&rev->diffopt);\n \trev->diffopt.flags.recursive = 1;\n@@ -505,7 +508,10 @@ static int git_log_config(const char *var, const char *value,\n \t\treturn 0;\n \t}\n \tif (!strcmp(var, \"log.follow\")) {\n-\t\tcfg->default_follow = git_config_bool(var, value);\n+\t\tif (value && !strcmp(value, \"merges\"))\n+\t\t\tcfg->default_follow = 2;\n+\t\telse\n+\t\t\tcfg->default_follow = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n \tif (skip_prefix(var, \"color.decorate.\", &slot_name))\n@@ -814,9 +820,14 @@ int cmd_log_reflog(int argc,\n \n static void log_setup_revisions_tweak(struct rev_info *rev)\n {\n+\t/* If --follow is not used, use the log.follow option. */\n \tif (rev->diffopt.flags.default_follow_renames &&\n-\t    diff_check_follow_pathspec(&rev->prune_data, 0))\n+\t    !rev->diffopt.flags.follow_renames &&\n+\t    diff_check_follow_pathspec(&rev->prune_data, 0)) {\n \t\trev->diffopt.flags.follow_renames = 1;\n+\t\trev->diffopt.flags.follow_merges =\n+\t\t\trev->diffopt.flags.default_follow_merges;\n+\t}\n \n \tif (rev->first_parent_only)\n \t\tdiff_merges_default_to_first_parent(rev);\ndiff --git a/diff.c b/diff.c\nindex 414532d09f..b633cbea09 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5739,12 +5739,19 @@ static int diff_opt_follow(const struct option *opt,\n {\n \tstruct diff_options *options = opt->value;\n \n-\tBUG_ON_OPT_ARG(arg);\n \tif (unset) {\n \t\toptions->flags.follow_renames = 0;\n+\t\toptions->flags.follow_merges = 0;\n \t\toptions->flags.default_follow_renames = 0;\n-\t} else {\n+\t\toptions->flags.default_follow_merges = 0;\n+\t} else if (!arg) {\n \t\toptions->flags.follow_renames = 1;\n+\t\toptions->flags.follow_merges = 0;\n+\t} else if (!strcmp(arg, \"merges\")) {\n+\t\toptions->flags.follow_renames = 1;\n+\t\toptions->flags.follow_merges = 1;\n+\t} else {\n+\t\treturn error(_(\"invalid argument to --follow: '%s'\"), arg);\n \t}\n \treturn 0;\n }\n@@ -6161,9 +6168,9 @@ struct option *add_diff_options(const struct option *opts,\n \t\t\t      0, PARSE_OPT_NONEG),\n \t\tOPT_BOOL(0, \"rename-empty\", &options->flags.rename_empty,\n \t\t\t N_(\"use empty blobs as rename source\")),\n-\t\tOPT_CALLBACK_F(0, \"follow\", options, NULL,\n+\t\tOPT_CALLBACK_F(0, \"follow\", options, N_(\"merges\"),\n \t\t\t       N_(\"continue listing the history of a file beyond renames\"),\n-\t\t\t       PARSE_OPT_NOARG, diff_opt_follow),\n+\t\t\t       PARSE_OPT_OPTARG, diff_opt_follow),\n \t\tOPT_INTEGER('l', NULL, &options->rename_limit,\n \t\t\t    N_(\"limit to cheap rename/copy detection if the number of rename/copy targets exceeds this value\")),\n \ndiff --git a/diff.h b/diff.h\nindex bb5cddaf34..2548739e83 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -154,6 +154,7 @@ struct diff_flags {\n \tunsigned find_copies_harder;\n \n \tunsigned follow_renames;\n+\tunsigned follow_merges;\n \tunsigned rename_empty;\n \n \t/* Internal; used for optimization to see if there is any change. */\n@@ -202,6 +203,7 @@ struct diff_flags {\n \tunsigned dirstat_by_line;\n \tunsigned funccontext;\n \tunsigned default_follow_renames;\n+\tunsigned default_follow_merges;\n \tunsigned stat_with_summary;\n \tunsigned suppress_diff_headers;\n \tunsigned dual_color_diffed_diffs;\ndiff --git a/log-tree.c b/log-tree.c\nindex 83a3c4bf9b..93cc61af2d 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -1277,7 +1277,8 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)\n \topt->diffopt.no_free = 1;\n \n \t/* Any recorded path for this commit? If so, restore it */\n-\tif (opt->diffopt.flags.follow_renames) {\n+\tif (opt->diffopt.flags.follow_renames &&\n+\t    opt->diffopt.flags.follow_merges) {\n \t\tconst char *stored = recall_follow_pathspec(opt, commit);\n \t\tif (stored) {\n \t\t\tconst char *current = pathspec_single_path(&opt->diffopt.pathspec);\n@@ -1300,7 +1301,8 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)\n \t\tshow_diff_of_diff(opt);\n \n \t/* Record what path each parent of this commit should use */\n-\tif (opt->diffopt.flags.follow_renames) {\n+\tif (opt->diffopt.flags.follow_renames &&\n+\t    opt->diffopt.flags.follow_merges) {\n \t\tstruct commit_list *parents = get_saved_parents(opt, commit);\n \t\tif (parents && parents->next) {\n \t\t\tstruct commit_list *p;\ndiff --git a/t/t4219-log-follow-merge.sh b/t/t4219-log-follow-merge.sh\nindex e370f82955..c2bc2b0c13 100755\n--- a/t/t4219-log-follow-merge.sh\n+++ b/t/t4219-log-follow-merge.sh\n@@ -1,6 +1,6 @@\n #!/bin/sh\n \n-test_description='Test --follow follows renames across merges'\n+test_description='Test --follow=merges follows renames across merges'\n \n GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\n export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n@@ -25,12 +25,30 @@ test_expect_success 'setup subtree-merged repository' '\n \tgit -C outer commit -m \"Merge inner repo into inner/ subdirectory\"\n '\n \n-test_expect_success '--follow finds the pre-merge commit through a subtree merge' '\n-\tgit -C outer log --follow --pretty=tformat:%s inner/inner.txt >actual &&\n+test_expect_success '--follow=merges finds the pre-merge commit through a subtree merge' '\n+\tgit -C outer log --follow=merges --pretty=tformat:%s inner/inner.txt >actual &&\n \techo \"inner init\" >expect &&\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'log.follow=merges acts as --follow=merges' '\n+\tgit -C outer -c log.follow=merges log --pretty=tformat:%s \\\n+\t\tinner/inner.txt >actual &&\n+\techo \"inner init\" >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success '--follow overrides log.follow=merges' '\n+\tgit -C outer -c log.follow=merges log --follow \\\n+\t\t--pretty=tformat:%s inner/inner.txt >actual &&\n+\ttest_must_be_empty actual\n+'\n+\n+test_expect_success '--follow rejects an unknown argument' '\n+\ttest_must_fail git -C outer log --follow=foo inner/inner.txt 2>err &&\n+\ttest_grep \"invalid argument to --follow: ${SQ}foo${SQ}\" err\n+'\n+\n test_expect_success 'setup merge of two branches that both renamed a file to README' '\n \tgit init foo &&\n \tmkdir foo/foo &&\n@@ -65,8 +83,8 @@ test_expect_success 'setup merge of two branches that both renamed a file to REA\n \tgit -C foo commit -m \"merge bar into foo\"\n '\n \n-test_expect_success '--follow follows renames across both sides of a merge' '\n-\tgit -C foo log --follow --pretty=tformat:%s README >actual &&\n+test_expect_success '--follow=merges follows renames across both sides of a merge' '\n+\tgit -C foo log --follow=merges --pretty=tformat:%s README >actual &&\n \tsort actual >actual.sorted &&\n \tcat >expect <<-\\EOF &&\n \tadd bar README\n@@ -112,8 +130,8 @@ test_expect_success 'setup diamond with renames on both sides of a fork' '\n \tgit -C diamond commit -am \"Z: modify path\"\n '\n \n-test_expect_success '--follow follows renames through a fork in a single history' '\n-\tgit -C diamond log --follow --pretty=tformat:%s path >actual &&\n+test_expect_success '--follow=merges follows renames through a fork in a single history' '\n+\tgit -C diamond log --follow=merges --pretty=tformat:%s path >actual &&\n \tsort actual >actual.sorted &&\n \tcat >expect <<-\\EOF &&\n \tA: add path0\n-- \n2.51.0\n\n\n"},{"id":"558328","messageId":"xmqqqzgpj28w.fsf@gitster.g","threadId":"66514","inReplyTo":"avWBQ_10mHUNQcFi@collabora.com","subject":"Re: [PATCH] log: make --follow following renames for non-linear history optional","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-12T19:09:19Z","receivedAt":"2026-11-12T19:09:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Miklos Vajna <vmiklos@collabora.com> writes:\n\n> Hi Junio,\n>\n> On Wed, Nov 11, 2026 at 08:44:42AM -0800, Junio C Hamano <gitster@pobox.com> wrote:\n>> This sounds sensible, and is far better than reverting and declaring\n>> \"The original 'checkbox hack' should stay here forever because doing\n>> it right will be very expensive\".\n>\n> If that is fine with you, I suggest just replacing the\n> mv/log-follow-speedup branch with this patch.\n>\n> Hi Patrick,\n>\n> On Wed, Nov 11, 2026 at 02:29:22PM +0100, Patrick Steinhardt <ps@pks.im> wrote:\n>> I don't really have a good sense of how far this patch series is on its\n>> road to getting merged. So how about we first land a single-patch series\n>> that introduces the knob that we can merge without the remaining parts\n>> in this series here?\n>\n> I like the idea, here is a patch to do that.\n\nOK, let me eject the \"speedup\" topic and queue this one instead for\nnow.  We can discuss how the --follow-merge code can be improved\nseparately once we are happy with this \"opt-in\" change.\n\nThanks.\n\n"},{"id":"558367","messageId":"ava1ax5UFfcvkU_d@pks.im","threadId":"66514","inReplyTo":"avWBQ_10mHUNQcFi@collabora.com","subject":"Re: [PATCH] log: make --follow following renames for non-linear history optional","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-13T07:00:07Z","receivedAt":"2026-11-13T07:00:07Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Nov 12, 2026 at 09:05:07AM +0000, Miklos Vajna wrote:\n> diff --git a/Documentation/config/log.adoc b/Documentation/config/log.adoc\n> index f7dfce69b5..72a3486a73 100644\n> --- a/Documentation/config/log.adoc\n> +++ b/Documentation/config/log.adoc\n> @@ -53,7 +53,9 @@ This is the same as the `--decorate` option of the `git log`.\n>  `log.follow`::\n>  \tIf `true`, `git log` will act as if the `--follow` option was used when\n>  \ta single <path> is given.  This has the same limitations as `--follow`,\n> -\ti.e. it cannot be used to follow multiple files.\n> +\ti.e. it cannot be used to follow multiple files and does not work well\n> +\ton non-linear history.  If `merges`, `git log` will act as if the\n> +\t`--follow=merges` option was used.\n>  \n>  `log.graphColors`::\n>  \tA list of colors, separated by commas, that can be used to draw\n\nI'd think we should also document here that \"merges\" is expensive, same\nas you do for \"--follow[=merges]\".\n\n> diff --git a/builtin/log.c b/builtin/log.c\n> index 350b35c556..db707877f6 100644\n> --- a/builtin/log.c\n> +++ b/builtin/log.c\n> @@ -505,7 +508,10 @@ static int git_log_config(const char *var, const char *value,\n>  \t\treturn 0;\n>  \t}\n>  \tif (!strcmp(var, \"log.follow\")) {\n> -\t\tcfg->default_follow = git_config_bool(var, value);\n> +\t\tif (value && !strcmp(value, \"merges\"))\n> +\t\t\tcfg->default_follow = 2;\n> +\t\telse\n> +\t\t\tcfg->default_follow = git_config_bool(var, value);\n>  \t\treturn 0;\n>  \t}\n>  \tif (skip_prefix(var, \"color.decorate.\", &slot_name))\n\nI think we should use `git_parse_maybe_bool()` here, as we otherwise die\nwith \"fatal: bad boolean config value 'bogus' for 'log.follow'\" in case\nit's not a boolean. Then we can die with our own error message.\n\n> @@ -814,9 +820,14 @@ int cmd_log_reflog(int argc,\n>  \n>  static void log_setup_revisions_tweak(struct rev_info *rev)\n>  {\n> +\t/* If --follow is not used, use the log.follow option. */\n>  \tif (rev->diffopt.flags.default_follow_renames &&\n> -\t    diff_check_follow_pathspec(&rev->prune_data, 0))\n> +\t    !rev->diffopt.flags.follow_renames &&\n> +\t    diff_check_follow_pathspec(&rev->prune_data, 0)) {\n>  \t\trev->diffopt.flags.follow_renames = 1;\n> +\t\trev->diffopt.flags.follow_merges =\n> +\t\t\trev->diffopt.flags.default_follow_merges;\n> +\t}\n>  \n>  \tif (rev->first_parent_only)\n>  \t\tdiff_merges_default_to_first_parent(rev);\n\nI assume that this change here is done so that \"--follow\" overrides\n\"log.follow=merge\". Makes sense.\n\n> diff --git a/log-tree.c b/log-tree.c\n> index 83a3c4bf9b..93cc61af2d 100644\n> --- a/log-tree.c\n> +++ b/log-tree.c\n> @@ -1277,7 +1277,8 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)\n>  \topt->diffopt.no_free = 1;\n>  \n>  \t/* Any recorded path for this commit? If so, restore it */\n> -\tif (opt->diffopt.flags.follow_renames) {\n> +\tif (opt->diffopt.flags.follow_renames &&\n> +\t    opt->diffopt.flags.follow_merges) {\n>  \t\tconst char *stored = recall_follow_pathspec(opt, commit);\n>  \t\tif (stored) {\n>  \t\t\tconst char *current = pathspec_single_path(&opt->diffopt.pathspec);\n> @@ -1300,7 +1301,8 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)\n>  \t\tshow_diff_of_diff(opt);\n>  \n>  \t/* Record what path each parent of this commit should use */\n> -\tif (opt->diffopt.flags.follow_renames) {\n> +\tif (opt->diffopt.flags.follow_renames &&\n> +\t    opt->diffopt.flags.follow_merges) {\n>  \t\tstruct commit_list *parents = get_saved_parents(opt, commit);\n>  \t\tif (parents && parents->next) {\n>  \t\t\tstruct commit_list *p;\n\nOkay, and these two changes here disable the logic where we record the\nchanged paths on all parents, and that should get us back to previous\nspeed by default. Good.\n\nAs far as I've seen we only ever set `follow_merges` when\n`follow_renames = 1`, so it feels redundant to check for both. But on\nthe other hand that's a bit more defensive, so maybe that's not a bad\nidea.\n\nOther than those nits this patch looks good to me, thanks!\n\nPatrick\n\n"},{"id":"558516","messageId":"avqyVuMvKeQshZYS@collabora.com","threadId":"66514","inReplyTo":"ava1ax5UFfcvkU_d@pks.im","subject":"[PATCH v2] log: make --follow following renames for non-linear history optional","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-11-16T07:35:50Z","receivedAt":"2026-11-16T07:35:50Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Since commit 304812ed33 (log: improve --follow following renames for\nnon-linear history, 2026-06-22), 'git log --stat --follow --\ninclude/linux/rsc_table.h' on linux.git takes 6m43s, while it took about\n28 seconds before.\n\nWhat happens is that log_tree_commit() diffs each merge against all of\nits parents with rename following, to find the path to follow in each\nparent. diff_tree_oid() only does the expensive rename detection when\nthe path is added relative to a parent, but that is common for merges,\ne.g. when a branch forked before the path was created merges mainline.\n\nFix the problem by making this per-parent diffing opt-in: plain --follow\nbehaves as before 304812ed33 again, and 'git log --follow=merges'\nfollows the path separately in each parent of a merge. Add a matching\nlog.follow=merges configuration option as well.\n\nSuggested-by: Patrick Steinhardt <ps@pks.im>\nSigned-off-by: Miklos Vajna <vmiklos@collabora.com>\n---\n\nHi Patrick,\n\nOn Fri, Nov 13, 2026 at 08:00:07AM +0100, Patrick Steinhardt <ps@pks.im> wrote:\n> > +\ti.e. it cannot be used to follow multiple files and does not work well\n> > +\ton non-linear history.  If `merges`, `git log` will act as if the\n> > +\t`--follow=merges` option was used.\n> >  \n> >  `log.graphColors`::\n> >  \tA list of colors, separated by commas, that can be used to draw\n> \n> I'd think we should also document here that \"merges\" is expensive, same\n> as you do for \"--follow[=merges]\".\n\nDone.\n\n> > +\t\tif (value && !strcmp(value, \"merges\"))\n> > +\t\t\tcfg->default_follow = 2;\n> > +\t\telse\n> > +\t\t\tcfg->default_follow = git_config_bool(var, value);\n> >  \t\treturn 0;\n> >  \t}\n> >  \tif (skip_prefix(var, \"color.decorate.\", &slot_name))\n> \n> I think we should use `git_parse_maybe_bool()` here, as we otherwise die\n> with \"fatal: bad boolean config value 'bogus' for 'log.follow'\" in case\n> it's not a boolean. Then we can die with our own error message.\n\nDone, I also added a test for this.\n\n> > +\t/* If --follow is not used, use the log.follow option. */\n> >  \tif (rev->diffopt.flags.default_follow_renames &&\n> > -\t    diff_check_follow_pathspec(&rev->prune_data, 0))\n> > +\t    !rev->diffopt.flags.follow_renames &&\n> > +\t    diff_check_follow_pathspec(&rev->prune_data, 0)) {\n> >  \t\trev->diffopt.flags.follow_renames = 1;\n> > +\t\trev->diffopt.flags.follow_merges =\n> > +\t\t\trev->diffopt.flags.default_follow_merges;\n> > +\t}\n> >  \n> >  \tif (rev->first_parent_only)\n> >  \t\tdiff_merges_default_to_first_parent(rev);\n> \n> I assume that this change here is done so that \"--follow\" overrides\n> \"log.follow=merge\". Makes sense.\n\nYes. :-) The comment is meant to communicate that intent.\n\n> > +\tif (opt->diffopt.flags.follow_renames &&\n> > +\t    opt->diffopt.flags.follow_merges) {\n...\n> As far as I've seen we only ever set `follow_merges` when\n> `follow_renames = 1`, so it feels redundant to check for both. But on\n> the other hand that's a bit more defensive, so maybe that's not a bad\n> idea.\n\nMy thinking was that follow_merges is a modifier of follow_renames. If\nsome code path clears follow_renames later (like builtin/blame.c does)\nwithout knowing about follow_merges, checking both flags means that we\nstill skip the per-parent rename diffs. So I would keep it as-is.\n\nThanks,\n\nMiklos\n\n Documentation/config/log.adoc |  5 ++++-\n Documentation/git-log.adoc    |  7 +++++--\n builtin/log.c                 | 19 ++++++++++++++++--\n diff.c                        | 15 ++++++++++----\n diff.h                        |  2 ++\n log-tree.c                    |  6 ++++--\n t/t4219-log-follow-merge.sh   | 37 ++++++++++++++++++++++++++++-------\n 7 files changed, 73 insertions(+), 18 deletions(-)\n\ndiff --git a/Documentation/config/log.adoc b/Documentation/config/log.adoc\nindex f7dfce69b5..95867fa593 100644\n--- a/Documentation/config/log.adoc\n+++ b/Documentation/config/log.adoc\n@@ -53,7 +53,10 @@ This is the same as the `--decorate` option of the `git log`.\n `log.follow`::\n \tIf `true`, `git log` will act as if the `--follow` option was used when\n \ta single <path> is given.  This has the same limitations as `--follow`,\n-\ti.e. it cannot be used to follow multiple files.\n+\ti.e. it cannot be used to follow multiple files and does not work well\n+\ton non-linear history.  If `merges`, `git log` will act as if the\n+\t`--follow=merges` option was used, which follows the path separately\n+\tfor each parent of a merge, but is more expensive.\n \n `log.graphColors`::\n \tA list of colors, separated by commas, that can be used to draw\ndiff --git a/Documentation/git-log.adoc b/Documentation/git-log.adoc\nindex fb3ac11283..742b832bbf 100644\n--- a/Documentation/git-log.adoc\n+++ b/Documentation/git-log.adoc\n@@ -27,9 +27,12 @@ each commit introduces are shown.\n OPTIONS\n -------\n \n-`--follow`::\n+`--follow[=merges]`::\n \tContinue listing the history of a file beyond renames\n-\t(works only for a single file).\n+\t(works only for a single file). This does not work well on\n+\tnon-linear history, unless `merges` is given: then the path is\n+\tfollowed separately for each parent of a merge, which is more\n+\texpensive.\n \n `--no-decorate`::\n `--decorate[=(short|full|auto|no)]`::\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 350b35c556..c0e7d7d14b 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -108,6 +108,7 @@ static int parse_decoration_style(const char *value)\n struct log_config {\n \tint default_abbrev_commit;\n \tint default_show_root;\n+\t/* 0: no, 1: yes, 2: merges */\n \tint default_follow;\n \tint default_show_signature;\n \tint default_encode_email_headers;\n@@ -205,6 +206,8 @@ static void cmd_log_init_defaults(struct rev_info *rev,\n \t\tget_commit_format(cfg->fmt_pretty, rev);\n \tif (cfg->default_follow)\n \t\trev->diffopt.flags.default_follow_renames = 1;\n+\tif (cfg->default_follow == 2)\n+\t\trev->diffopt.flags.default_follow_merges = 1;\n \trev->verbose_header = 1;\n \tinit_diffstat_widths(&rev->diffopt);\n \trev->diffopt.flags.recursive = 1;\n@@ -505,7 +508,14 @@ static int git_log_config(const char *var, const char *value,\n \t\treturn 0;\n \t}\n \tif (!strcmp(var, \"log.follow\")) {\n-\t\tcfg->default_follow = git_config_bool(var, value);\n+\t\tint b = git_parse_maybe_bool(value);\n+\t\tif (b >= 0)\n+\t\t\tcfg->default_follow = b;\n+\t\telse if (!strcmp(value, \"merges\"))\n+\t\t\tcfg->default_follow = 2;\n+\t\telse\n+\t\t\treturn error(_(\"invalid value for '%s': '%s'\"),\n+\t\t\t\t     var, value);\n \t\treturn 0;\n \t}\n \tif (skip_prefix(var, \"color.decorate.\", &slot_name))\n@@ -814,9 +824,14 @@ int cmd_log_reflog(int argc,\n \n static void log_setup_revisions_tweak(struct rev_info *rev)\n {\n+\t/* If --follow is not used, use the log.follow option. */\n \tif (rev->diffopt.flags.default_follow_renames &&\n-\t    diff_check_follow_pathspec(&rev->prune_data, 0))\n+\t    !rev->diffopt.flags.follow_renames &&\n+\t    diff_check_follow_pathspec(&rev->prune_data, 0)) {\n \t\trev->diffopt.flags.follow_renames = 1;\n+\t\trev->diffopt.flags.follow_merges =\n+\t\t\trev->diffopt.flags.default_follow_merges;\n+\t}\n \n \tif (rev->first_parent_only)\n \t\tdiff_merges_default_to_first_parent(rev);\ndiff --git a/diff.c b/diff.c\nindex 414532d09f..b633cbea09 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5739,12 +5739,19 @@ static int diff_opt_follow(const struct option *opt,\n {\n \tstruct diff_options *options = opt->value;\n \n-\tBUG_ON_OPT_ARG(arg);\n \tif (unset) {\n \t\toptions->flags.follow_renames = 0;\n+\t\toptions->flags.follow_merges = 0;\n \t\toptions->flags.default_follow_renames = 0;\n-\t} else {\n+\t\toptions->flags.default_follow_merges = 0;\n+\t} else if (!arg) {\n \t\toptions->flags.follow_renames = 1;\n+\t\toptions->flags.follow_merges = 0;\n+\t} else if (!strcmp(arg, \"merges\")) {\n+\t\toptions->flags.follow_renames = 1;\n+\t\toptions->flags.follow_merges = 1;\n+\t} else {\n+\t\treturn error(_(\"invalid argument to --follow: '%s'\"), arg);\n \t}\n \treturn 0;\n }\n@@ -6161,9 +6168,9 @@ struct option *add_diff_options(const struct option *opts,\n \t\t\t      0, PARSE_OPT_NONEG),\n \t\tOPT_BOOL(0, \"rename-empty\", &options->flags.rename_empty,\n \t\t\t N_(\"use empty blobs as rename source\")),\n-\t\tOPT_CALLBACK_F(0, \"follow\", options, NULL,\n+\t\tOPT_CALLBACK_F(0, \"follow\", options, N_(\"merges\"),\n \t\t\t       N_(\"continue listing the history of a file beyond renames\"),\n-\t\t\t       PARSE_OPT_NOARG, diff_opt_follow),\n+\t\t\t       PARSE_OPT_OPTARG, diff_opt_follow),\n \t\tOPT_INTEGER('l', NULL, &options->rename_limit,\n \t\t\t    N_(\"limit to cheap rename/copy detection if the number of rename/copy targets exceeds this value\")),\n \ndiff --git a/diff.h b/diff.h\nindex bb5cddaf34..2548739e83 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -154,6 +154,7 @@ struct diff_flags {\n \tunsigned find_copies_harder;\n \n \tunsigned follow_renames;\n+\tunsigned follow_merges;\n \tunsigned rename_empty;\n \n \t/* Internal; used for optimization to see if there is any change. */\n@@ -202,6 +203,7 @@ struct diff_flags {\n \tunsigned dirstat_by_line;\n \tunsigned funccontext;\n \tunsigned default_follow_renames;\n+\tunsigned default_follow_merges;\n \tunsigned stat_with_summary;\n \tunsigned suppress_diff_headers;\n \tunsigned dual_color_diffed_diffs;\ndiff --git a/log-tree.c b/log-tree.c\nindex 83a3c4bf9b..93cc61af2d 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -1277,7 +1277,8 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)\n \topt->diffopt.no_free = 1;\n \n \t/* Any recorded path for this commit? If so, restore it */\n-\tif (opt->diffopt.flags.follow_renames) {\n+\tif (opt->diffopt.flags.follow_renames &&\n+\t    opt->diffopt.flags.follow_merges) {\n \t\tconst char *stored = recall_follow_pathspec(opt, commit);\n \t\tif (stored) {\n \t\t\tconst char *current = pathspec_single_path(&opt->diffopt.pathspec);\n@@ -1300,7 +1301,8 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)\n \t\tshow_diff_of_diff(opt);\n \n \t/* Record what path each parent of this commit should use */\n-\tif (opt->diffopt.flags.follow_renames) {\n+\tif (opt->diffopt.flags.follow_renames &&\n+\t    opt->diffopt.flags.follow_merges) {\n \t\tstruct commit_list *parents = get_saved_parents(opt, commit);\n \t\tif (parents && parents->next) {\n \t\t\tstruct commit_list *p;\ndiff --git a/t/t4219-log-follow-merge.sh b/t/t4219-log-follow-merge.sh\nindex e370f82955..3f8a0009dd 100755\n--- a/t/t4219-log-follow-merge.sh\n+++ b/t/t4219-log-follow-merge.sh\n@@ -1,6 +1,6 @@\n #!/bin/sh\n \n-test_description='Test --follow follows renames across merges'\n+test_description='Test --follow=merges follows renames across merges'\n \n GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\n export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n@@ -25,12 +25,35 @@ test_expect_success 'setup subtree-merged repository' '\n \tgit -C outer commit -m \"Merge inner repo into inner/ subdirectory\"\n '\n \n-test_expect_success '--follow finds the pre-merge commit through a subtree merge' '\n-\tgit -C outer log --follow --pretty=tformat:%s inner/inner.txt >actual &&\n+test_expect_success '--follow=merges finds the pre-merge commit through a subtree merge' '\n+\tgit -C outer log --follow=merges --pretty=tformat:%s inner/inner.txt >actual &&\n \techo \"inner init\" >expect &&\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'log.follow=merges acts as --follow=merges' '\n+\tgit -C outer -c log.follow=merges log --pretty=tformat:%s \\\n+\t\tinner/inner.txt >actual &&\n+\techo \"inner init\" >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success '--follow overrides log.follow=merges' '\n+\tgit -C outer -c log.follow=merges log --follow \\\n+\t\t--pretty=tformat:%s inner/inner.txt >actual &&\n+\ttest_must_be_empty actual\n+'\n+\n+test_expect_success 'log.follow rejects an unknown value' '\n+\ttest_must_fail git -C outer -c log.follow=foo log inner/inner.txt 2>err &&\n+\ttest_grep \"invalid value for ${SQ}log.follow${SQ}: ${SQ}foo${SQ}\" err\n+'\n+\n+test_expect_success '--follow rejects an unknown argument' '\n+\ttest_must_fail git -C outer log --follow=foo inner/inner.txt 2>err &&\n+\ttest_grep \"invalid argument to --follow: ${SQ}foo${SQ}\" err\n+'\n+\n test_expect_success 'setup merge of two branches that both renamed a file to README' '\n \tgit init foo &&\n \tmkdir foo/foo &&\n@@ -65,8 +88,8 @@ test_expect_success 'setup merge of two branches that both renamed a file to REA\n \tgit -C foo commit -m \"merge bar into foo\"\n '\n \n-test_expect_success '--follow follows renames across both sides of a merge' '\n-\tgit -C foo log --follow --pretty=tformat:%s README >actual &&\n+test_expect_success '--follow=merges follows renames across both sides of a merge' '\n+\tgit -C foo log --follow=merges --pretty=tformat:%s README >actual &&\n \tsort actual >actual.sorted &&\n \tcat >expect <<-\\EOF &&\n \tadd bar README\n@@ -112,8 +135,8 @@ test_expect_success 'setup diamond with renames on both sides of a fork' '\n \tgit -C diamond commit -am \"Z: modify path\"\n '\n \n-test_expect_success '--follow follows renames through a fork in a single history' '\n-\tgit -C diamond log --follow --pretty=tformat:%s path >actual &&\n+test_expect_success '--follow=merges follows renames through a fork in a single history' '\n+\tgit -C diamond log --follow=merges --pretty=tformat:%s path >actual &&\n \tsort actual >actual.sorted &&\n \tcat >expect <<-\\EOF &&\n \tA: add path0\n\nRange-diff against v1:\n1:  cdf63f7017 ! 1:  cd19ed03cc log: make --follow following renames for non-linear history optional\n    @@ Documentation/config/log.adoc: This is the same as the `--decorate` option of th\n     -\ti.e. it cannot be used to follow multiple files.\n     +\ti.e. it cannot be used to follow multiple files and does not work well\n     +\ton non-linear history.  If `merges`, `git log` will act as if the\n    -+\t`--follow=merges` option was used.\n    ++\t`--follow=merges` option was used, which follows the path separately\n    ++\tfor each parent of a merge, but is more expensive.\n      \n      `log.graphColors`::\n      \tA list of colors, separated by commas, that can be used to draw\n    @@ builtin/log.c: static int git_log_config(const char *var, const char *value,\n      \t}\n      \tif (!strcmp(var, \"log.follow\")) {\n     -\t\tcfg->default_follow = git_config_bool(var, value);\n    -+\t\tif (value && !strcmp(value, \"merges\"))\n    ++\t\tint b = git_parse_maybe_bool(value);\n    ++\t\tif (b >= 0)\n    ++\t\t\tcfg->default_follow = b;\n    ++\t\telse if (!strcmp(value, \"merges\"))\n     +\t\t\tcfg->default_follow = 2;\n     +\t\telse\n    -+\t\t\tcfg->default_follow = git_config_bool(var, value);\n    ++\t\t\treturn error(_(\"invalid value for '%s': '%s'\"),\n    ++\t\t\t\t     var, value);\n      \t\treturn 0;\n      \t}\n      \tif (skip_prefix(var, \"color.decorate.\", &slot_name))\n    @@ t/t4219-log-follow-merge.sh: test_expect_success 'setup subtree-merged repositor\n     +\ttest_must_be_empty actual\n     +'\n     +\n    ++test_expect_success 'log.follow rejects an unknown value' '\n    ++\ttest_must_fail git -C outer -c log.follow=foo log inner/inner.txt 2>err &&\n    ++\ttest_grep \"invalid value for ${SQ}log.follow${SQ}: ${SQ}foo${SQ}\" err\n    ++'\n    ++\n     +test_expect_success '--follow rejects an unknown argument' '\n     +\ttest_must_fail git -C outer log --follow=foo inner/inner.txt 2>err &&\n     +\ttest_grep \"invalid argument to --follow: ${SQ}foo${SQ}\" err\n-- \n2.51.0\n\n\n"},{"id":"558523","messageId":"avq4QewLSGVLkCjv@pks.im","threadId":"66514","inReplyTo":"avqyVuMvKeQshZYS@collabora.com","subject":"Re: [PATCH v2] log: make --follow following renames for non-linear history optional","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-16T08:01:05Z","receivedAt":"2026-11-16T08:01:05Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Nov 16, 2026 at 08:35:50AM +0100, Miklos Vajna wrote:\n[snip]\n> > > +\tif (opt->diffopt.flags.follow_renames &&\n> > > +\t    opt->diffopt.flags.follow_merges) {\n> ...\n> > As far as I've seen we only ever set `follow_merges` when\n> > `follow_renames = 1`, so it feels redundant to check for both. But on\n> > the other hand that's a bit more defensive, so maybe that's not a bad\n> > idea.\n> \n> My thinking was that follow_merges is a modifier of follow_renames. If\n> some code path clears follow_renames later (like builtin/blame.c does)\n> without knowing about follow_merges, checking both flags means that we\n> still skip the per-parent rename diffs. So I would keep it as-is.\n\nMakes sense.\n\nOne hint: please reply to review feedback on the mail that gave the\nfeedback instead of posting it as part of v2. That makes it easier for\nothers to see which review feedback was addressed.\n\n> Range-diff against v1:\n> 1:  cdf63f7017 ! 1:  cd19ed03cc log: make --follow following renames for non-linear history optional\n>     @@ Documentation/config/log.adoc: This is the same as the `--decorate` option of th\n>      -\ti.e. it cannot be used to follow multiple files.\n>      +\ti.e. it cannot be used to follow multiple files and does not work well\n>      +\ton non-linear history.  If `merges`, `git log` will act as if the\n>     -+\t`--follow=merges` option was used.\n>     ++\t`--follow=merges` option was used, which follows the path separately\n>     ++\tfor each parent of a merge, but is more expensive.\n>       \n>       `log.graphColors`::\n>       \tA list of colors, separated by commas, that can be used to draw\n\nGood, this gives the user the necessary context to decide why they may\nor may not want to enable this config.\n\n>     @@ builtin/log.c: static int git_log_config(const char *var, const char *value,\n>       \t}\n>       \tif (!strcmp(var, \"log.follow\")) {\n>      -\t\tcfg->default_follow = git_config_bool(var, value);\n>     -+\t\tif (value && !strcmp(value, \"merges\"))\n>     ++\t\tint b = git_parse_maybe_bool(value);\n>     ++\t\tif (b >= 0)\n>     ++\t\t\tcfg->default_follow = b;\n>     ++\t\telse if (!strcmp(value, \"merges\"))\n>      +\t\t\tcfg->default_follow = 2;\n>      +\t\telse\n>     -+\t\t\tcfg->default_follow = git_config_bool(var, value);\n>     ++\t\t\treturn error(_(\"invalid value for '%s': '%s'\"),\n>     ++\t\t\t\t     var, value);\n\nAnd this fixes the broken error message when an invalid value was\npassed.\n\nThanks, this version looks good to me.\n\nPatrick\n\n"},{"id":"558566","messageId":"xmqqld6sllq7.fsf@gitster.g","threadId":"66514","inReplyTo":"avq4QewLSGVLkCjv@pks.im","subject":"Re: [PATCH v2] log: make --follow following renames for non-linear history optional","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-16T17:39:12Z","receivedAt":"2026-11-16T17:39:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> One hint: please reply to review feedback on the mail that gave the\n> feedback instead of posting it as part of v2. That makes it easier for\n> others to see which review feedback was addressed.\n>\n> ...\n> Thanks, this version looks good to me.\n\nOK, let me mark the topic ready for 'next'.\n\n"},{"id":"558597","messageId":"avv-MhYrtlM53GNv@collabora.com","threadId":"66514","inReplyTo":"avq4QewLSGVLkCjv@pks.im","subject":"Re: [PATCH v2] log: make --follow following renames for non-linear history optional","fromName":"Miklos Vajna","fromEmail":"vmiklos@collabora.com","sentAt":"2026-11-17T07:11:46Z","receivedAt":"2026-11-17T07:11:46Z","isPatch":true,"sender":{"key":"vmiklos@collabora.com","avatar":"https://avatars.githubusercontent.com/u/13838?v=4"},"body":"Hi Patrick,\n\nOn Mon, Nov 16, 2026 at 09:01:05AM +0100, Patrick Steinhardt <ps@pks.im> wrote:\n> One hint: please reply to review feedback on the mail that gave the\n> feedback instead of posting it as part of v2. That makes it easier for\n> others to see which review feedback was addressed.\n\nMakes sense, I'll stick to that in the future.\n\nThanks,\n\nMiklos\n\n"}]}