Subject: Re: bug#20608: 25.0.50; vc-git-log-view-mode inserts "Show 2X entries" at bob when interrupted

From: Dmitry Gutov <[email-masked]>
Date: Mon, 25 May 2015 00:42:33 +0300

On 05/19/2015 08:40 PM, Stefan Monnier wrote:
>> It seems like a general problem, to be fixed either in vc-do-command (by
>> unsetting the process sentinel before deleting the process), or in
>> vc--process-sentinel. Here's the patch for the second option:
>
> Indeed, it's a general problem.  Maybe handling it in vc-do-command
> would be a good idea, but unsetting the process sentinel altogether
> sounds a bit dangerous (the sentinel might also be used to clear the
> ":running" annotation in the modeline and other such things).

I think it's only dangerous if the sentinel is used to clean up some 
other buffer than the one where the process is running (vc-do-command 
will take care about the latter, and anyway it's launching a new 
process, so mode-line-process will be set either way). Do we know of the 
instances of the former?

Doing it in vc--process-sentinel indeed seems more dangerous, because 
it'll preclude doing cleanup even when no new process is being launched.

As far as the current (Show 2X entries) problem goes, we should've been 
able to use a more direct approach, and make the choice inside the 
delayed code, but unfortunately the buffer process is already nil in there.

So, this doesn't work:

diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 1bd04e1..88bd335 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -2263,13 +2263,15 @@ earlier revisions.  Show up to LIMIT entries 
(non-nil means unlimited)."
      ;; the major-mode.
      (pop-to-buffer buffer-name)
      (vc-run-delayed
-     (let ((inhibit-read-only t))
-       (funcall setup-buttons-func backend files retval)
-       (shrink-window-if-larger-than-buffer)
-       (when goto-location-func
-         (funcall goto-location-func backend)
-         (setq vc-sentinel-movepoint (point)))
-       (set-buffer-modified-p nil)))))
+      (let ((inhibit-read-only t)
+            (proc (get-buffer-process buffer-name)))
+        (when (or (null proc) (eq (process-status proc) 'exit))
+          (funcall setup-buttons-func backend files retval)
+          (shrink-window-if-larger-than-buffer)
+          (when goto-location-func
+            (funcall goto-location-func backend)
+            (setq vc-sentinel-movepoint (point)))
+          (set-buffer-modified-p nil))))))

  (defun vc-incoming-outgoing-internal (backend remote-location 
buffer-name type)
    (vc-log-internal-common