Subject: Re: bug#62749: 28.2; Emacs keeps opening related file from vc-diff buffer

From: Dmitry Gutov <[email-masked]>
Date: Tue, 11 Apr 2023 01:23:19 +0300

Hi! Thanks for the report.

On 10/04/2023 15:11, Oleksandr Gavenko wrote:
> In GNU Emacs 28.2 (build 1, x86_64-pc-cygwin)
>   of 2022-09-16 built on fv-az140-985
> Repository revision: 70134aa8264ded36d80248204b2ba43ae3d8f599
> 
> Whenever I open vc-diff buffer by "d" (log-view-diff) to read repository
> history from "C-x v L" (vc-print-root-log) Emacs opens all files referenced by
> diff.
> 
> The diff might be very big so:
> 
> * I end with lots of opened files that I need eventually close.
> * Emacs pollutes recentf history - I don't want robotically opened file mixed
>    with human opened files.
> * Cygwin is slow (especially under antivirus supervision) file opening delays
>    Emacs for many seconds.
> 
> Initially I asked for help in Emacs 27.1:
> 
>    https://emacs.stackexchange.com/questions/61760/lags-when-navigating-vc-root-diff-buffer/
> 
> and found workaround with:
> 
>    (setq diff-font-lock-syntax nil)

This workaround should help, in particular to improve performance under 
Cygwin.

The thing about opened files is quite odd, though: 
diff-syntax-fontify-hunk does not visit any new files. It either uses an 
existing buffer, or fetches file contents using insert-file-contents, or 
calls vc-find-revision-no-save which, again, inserts the previous' 
revision file contents into the provided buffer, without visiting a file.

Perhaps you could edebug diff-syntax-fontify-hunk to find the exact 
place where a file is visited (and added to recentf), if that indeed 
happens.